Skip to content

Commit b9b4964

Browse files
PaulDemeulenaereEvergreen
authored andcommitted
[VFX/Test] Add Minimal Coverage for Samples
Add basic validation check for additional sample and fix couple of known issue: - Warning as error generating issue with `kMouseX` & `kMouseY` - Not up to date script in package (velocity has been deprecated, replaced by linearVelocity) - Corrupted ShaderGraph file see f6aac94712e73c970305122a2e90f90e473df0c7 Bonus: upgrade sample script to ease @orson-favrel upgrades. This test is among update but isn't included in upgrade suite, it can only be launched locally, see in action: N.B.: I moved `Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/Samples/` to another path because test are simply wiping this folder in test. It prevents imported data being mixed with versioned data.
1 parent d7552fc commit b9b4964

File tree

21 files changed

+202
-37
lines changed

21 files changed

+202
-37
lines changed

Packages/com.unity.render-pipelines.core/Samples~/Common/TextMesh Pro/Resources/Fonts & Materials/SamplesLit_Inter.shadergraph

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -604,24 +604,6 @@
604604
}
605605
}
606606

607-
{
608-
"m_SGVersion": 2,
609-
"m_Type": "UnityEditor.Rendering.BuiltIn.ShaderGraph.BuiltInTarget",
610-
"m_ObjectId": "11e879f62c0d472e9330636a29adfcaa",
611-
"m_Datas": [],
612-
"m_ActiveSubTarget": {
613-
"m_Id": "b844ef3864e3479fbb65c83c4867b45e"
614-
},
615-
"m_AllowMaterialOverride": false,
616-
"m_SurfaceType": 1,
617-
"m_ZWriteControl": 0,
618-
"m_ZTestMode": 4,
619-
"m_AlphaMode": 0,
620-
"m_RenderFace": 2,
621-
"m_AlphaClip": false,
622-
"m_CustomEditorGUI": ""
623-
}
624-
625607
{
626608
"m_SGVersion": 0,
627609
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",

Packages/com.unity.visualeffectgraph/Editor/SamplesLinkPackageManagerExtension.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ static SamplesLinkPackageManagerExtension()
3131

3232
void IPackageManagerExtension.OnPackageSelectionChange(PackageInfo packageInfo)
3333
{
34+
if (samplesButton == null)
35+
return;
36+
3437
// Prevent the button from rendering on other packages
3538
if (samplesButton.parent != null)
3639
parent = samplesButton.parent;

Packages/com.unity.visualeffectgraph/Samples~/VFXOutputEventHandlers/Runtime/VFXOutputEventPrefabAttributeRigidBodyVelocityHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override void OnVFXEventAttribute(VFXEventAttribute eventAttribute, Visua
2323
if (TryGetComponent<Rigidbody>(out m_RigidBody))
2424
{
2525
m_RigidBody.WakeUp();
26-
m_RigidBody.velocity = velocity;
26+
m_RigidBody.linearVelocity = velocity;
2727
}
2828
}
2929
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using System.Collections;
2+
using System.IO;
3+
using System.Linq;
4+
using NUnit.Framework;
5+
using UnityEditor.Compilation;
6+
using UnityEditor.PackageManager;
7+
using UnityEditor.PackageManager.UI;
8+
using UnityEngine;
9+
using UnityEngine.TestTools;
10+
using UnityEngine.VFX;
11+
12+
namespace UnityEditor.VFX.Test
13+
{
14+
[TestFixture]
15+
public class VFXAdditionalPackageTest
16+
{
17+
public static string[] kAdditionalSampleMatches = new [] {"Additions", "Helpers", "Learning"};
18+
19+
private static readonly string kSampleExpectedPath = "Assets/Samples";
20+
21+
[SerializeField]
22+
private static string m_CurrentMatch;
23+
24+
[UnityTest, Timeout(10 * 60 * 1000)]
25+
public IEnumerator Check_Additional_Doesnt_Generate_Any_Errors([ValueSource(nameof(kAdditionalSampleMatches))] string expectedMatch)
26+
{
27+
m_CurrentMatch = expectedMatch;
28+
29+
if (Directory.Exists(kSampleExpectedPath))
30+
{
31+
AssetDatabase.DeleteAsset(kSampleExpectedPath);
32+
CompilationPipeline.RequestScriptCompilation();
33+
yield return new WaitForDomainReload();
34+
}
35+
36+
Assert.IsFalse(Directory.Exists(kSampleExpectedPath));
37+
var searchRequest = Client.Search("com.unity.visualeffectgraph", true);
38+
while (!searchRequest.IsCompleted)
39+
{
40+
yield return null;
41+
}
42+
43+
Assert.AreEqual(StatusCode.Success, searchRequest.Status);
44+
Assert.AreEqual(1, searchRequest.Result.Length);
45+
46+
var version = searchRequest.Result[0].version;
47+
Assert.IsFalse(string.IsNullOrEmpty(version));
48+
49+
var allSample = Sample.FindByPackage("com.unity.visualeffectgraph", version).ToArray();
50+
Assert.AreEqual(3, allSample.Length);
51+
52+
var matching = allSample.Where(o => o.displayName.Contains(m_CurrentMatch)).ToArray();
53+
Assert.AreEqual(1, matching.Length);
54+
55+
//Workaround for UUM-63664
56+
var current = matching[0];
57+
{
58+
foreach (var extension in PackageManagerExtensions.Extensions)
59+
extension.OnPackageSelectionChange(searchRequest.Result[0]);
60+
61+
//Force import of dependencies before importing anything else
62+
var samplePath = Path.Combine(kSampleExpectedPath, "Visual Effect Graph", version, current.displayName);
63+
Directory.CreateDirectory(samplePath);
64+
File.WriteAllText(samplePath + "/dummy.txt", "UUM-63664 workaround for test.");
65+
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
66+
}
67+
68+
var result = current.Import(Sample.ImportOptions.HideImportWindow | Sample.ImportOptions.OverridePreviousImports);
69+
Assert.IsTrue(result);
70+
71+
CompilationPipeline.RequestScriptCompilation();
72+
yield return new WaitForDomainReload();
73+
74+
Assert.IsTrue(Directory.Exists(kSampleExpectedPath));
75+
if (m_CurrentMatch == "Learning")
76+
{
77+
//Extra check for learning sample consistency
78+
foreach (var guid in AssetDatabase.FindAssets("t:VisualEffectAsset", new[] { kSampleExpectedPath }))
79+
{
80+
var path = AssetDatabase.GUIDToAssetPath(guid);
81+
var vfxAsset = AssetDatabase.LoadAssetAtPath<VisualEffectAsset>(path);
82+
var graph = vfxAsset.GetResource().GetOrCreateGraph();
83+
84+
foreach (var initialize in graph.children.OfType<VFXBasicInitialize>())
85+
{
86+
var dataParticle = initialize.GetData() as VFXDataParticle;
87+
Assert.IsNotNull(dataParticle);
88+
Assert.AreEqual(BoundsSettingMode.Manual, dataParticle.boundsMode);
89+
}
90+
91+
Assert.IsTrue(graph.children.OfType<VFXAbstractRenderedOutput>().Any());
92+
Assert.IsTrue(graph.UIInfos.stickyNoteInfos.Length > 0);
93+
}
94+
}
95+
m_CurrentMatch = null;
96+
97+
AssetDatabase.DeleteAsset(kSampleExpectedPath);
98+
CompilationPipeline.RequestScriptCompilation();
99+
yield return new WaitForDomainReload();
100+
}
101+
}
102+
}

Tests/SRPTests/Packages/com.unity.testing.visualeffectgraph/Tests/Editor/VFXAdditionalPackageTest.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SRPTests/Packages/com.unity.testing.visualeffectgraph/Tests/Editor/VFXUpdateTest.cs

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System.Collections;
77
using System.IO;
88
using Object = UnityEngine.Object;
9+
using UnityEditor.PackageManager;
10+
using UnityEditor.PackageManager.UI;
11+
using UnityEditor.Compilation;
912

1013
//Not strictly test, these helpers are used to upgrade project
1114
namespace UnityEditor.VFX.Update
@@ -76,13 +79,102 @@ public IEnumerator Upgrade_Many_VFX_Package()
7679
}
7780
AssetDatabase.ExportPackage(exportedPackageAssetList.ToArray(), absolutePath, ExportPackageOptions.Recurse);
7881
yield return null;
79-
Directory.Delete(expectedDirectory, true);
80-
File.Delete(expectedDirectory + ".meta");
82+
83+
AssetDatabase.DeleteAsset(expectedDirectory);
8184
yield return null;
8285
Debug.unityLogger.logHandler = quietLog.m_ForwardLog;
8386

8487
Assert.IsFalse(Directory.Exists(expectedDirectory));
8588
}
89+
90+
private static void CopyFiles(string sourcePath, string targetPath)
91+
{
92+
foreach (var dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
93+
{
94+
Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath));
95+
}
96+
97+
foreach (var newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories))
98+
{
99+
File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);
100+
}
101+
}
102+
103+
104+
[SerializeField] private string m_Version;
105+
private static readonly string kSampleExpectedBasePath = "Assets/Samples";
106+
107+
[UnityTest, Timeout(6000 * 1000)]
108+
public IEnumerator Upgrade_Additional_Sample()
109+
{
110+
var searchRequest = Client.Search("com.unity.visualeffectgraph", true);
111+
while (!searchRequest.IsCompleted)
112+
{
113+
yield return null;
114+
}
115+
116+
Assert.AreEqual(StatusCode.Success, searchRequest.Status);
117+
Assert.AreEqual(1, searchRequest.Result.Length);
118+
m_Version = searchRequest.Result[0].version;
119+
120+
var addRequest = Client.Add(@"file:../../../../../Packages/com.unity.render-pipelines.universal");
121+
while (!addRequest.IsCompleted)
122+
yield return null;
123+
Assert.AreEqual(StatusCode.Success, addRequest.Status);
124+
125+
//Workaround for UUM-63664
126+
{
127+
var tempSamples = Sample.FindByPackage("com.unity.visualeffectgraph", m_Version);
128+
foreach (var extension in PackageManagerExtensions.Extensions)
129+
extension.OnPackageSelectionChange(searchRequest.Result[0]);
130+
foreach (var sample in tempSamples)
131+
{
132+
//Force import of dependencies before importing anything else
133+
var samplePath = Path.Combine(kSampleExpectedBasePath, "Visual Effect Graph", m_Version, sample.displayName);
134+
Directory.CreateDirectory(samplePath);
135+
var dummy = samplePath + "/dummy.txt";
136+
File.WriteAllText(dummy, "UUM-63664 workaround for test.");
137+
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
138+
AssetDatabase.DeleteAsset(dummy);
139+
}
140+
}
141+
142+
CompilationPipeline.RequestScriptCompilation();
143+
yield return new WaitForDomainReload();
144+
145+
var samples = Sample.FindByPackage("com.unity.visualeffectgraph", m_Version);
146+
foreach (var sample in samples)
147+
{
148+
var result = sample.Import(Sample.ImportOptions.HideImportWindow | Sample.ImportOptions.OverridePreviousImports);
149+
Assert.IsTrue(result);
150+
}
151+
152+
//VFXAssetManager.Build(true); //Shouldn't be needed to upgrade dirty imported asset
153+
AssetDatabase.SaveAssets();
154+
155+
var baseTarget = @"../../../../Packages/com.unity.visualeffectgraph";
156+
Directory.Delete(baseTarget + "/Samples~", true);
157+
158+
var commonAssetPath = Path.Combine(kSampleExpectedBasePath, "Visual Effect Graph", "Common");
159+
var commonTargetPath = Path.Combine(baseTarget, "Samples~", "Common");
160+
CopyFiles(commonAssetPath, commonTargetPath);
161+
162+
samples = Sample.FindByPackage("com.unity.visualeffectgraph", m_Version);
163+
foreach (var sample in samples)
164+
{
165+
var assetPath = Path.Combine(kSampleExpectedBasePath, "Visual Effect Graph", m_Version, sample.displayName);
166+
var targetPath = sample.resolvedPath;
167+
CopyFiles(assetPath, targetPath);
168+
}
169+
AssetDatabase.DeleteAsset(kSampleExpectedBasePath);
170+
171+
var removeRequest = Client.Remove("com.unity.render-pipelines.universal");
172+
while (!removeRequest.IsCompleted)
173+
yield return null;
174+
Assert.AreEqual(StatusCode.Success, removeRequest.Status);
175+
yield return new WaitForDomainReload();
176+
}
177+
86178
#endif
87179
}
88180
}

0 commit comments

Comments
 (0)