Skip to content

Commit 3a1b162

Browse files
Adding unit tests
- Bunch of test checking changes done on additional properties of volumes components - Testing the Volume component editors to check the set and get of the overrides states.
1 parent 84d160d commit 3a1b162

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using UnityEditor.Rendering;
8+
9+
namespace UnityEngine.Rendering.Tests.Volumes
10+
{
11+
public class VolumeComponentEditorTests<TComponent>
12+
where TComponent : VolumeComponent
13+
{
14+
protected TComponent component { get; set; }
15+
protected VolumeComponentEditor editor { get; set; }
16+
17+
[SetUp]
18+
public void Init()
19+
{
20+
component = ScriptableObject.CreateInstance<TComponent>();
21+
editor = (VolumeComponentEditor)Activator.CreateInstance(typeof(VolumeComponentEditor));
22+
editor.Invoke("Init", component, null);
23+
}
24+
25+
[TearDown]
26+
public void Dispose()
27+
{
28+
ScriptableObject.DestroyImmediate(component);
29+
}
30+
31+
protected void CheckWithCurrentAdditionalProperties(List<string> additionalProperties)
32+
{
33+
var fields = component
34+
.GetFields()
35+
.Where(f => f.GetCustomAttribute<AdditionalAttribute>() != null)
36+
.Select(f => f.Name)
37+
.ToList();
38+
39+
var stringBuilder = new StringBuilder();
40+
stringBuilder.AppendLine($"{typeof(TComponent)}`");
41+
stringBuilder.AppendLine($"\"{string.Join("\",\"", fields)}\"");
42+
stringBuilder.AppendLine("vs");
43+
stringBuilder.AppendLine($"\"{string.Join("\",\"", additionalProperties)}\"");
44+
45+
Assert.True(fields.Count == additionalProperties.Count, $"The size of the additional parameters is different: {stringBuilder}");
46+
Assert.True(additionalProperties.All(fields.Contains), $"The additional parameters has changed {stringBuilder}");
47+
}
48+
49+
protected void CheckOverridesChanges()
50+
{
51+
component.SetAllOverridesTo(false);
52+
bool allOverridesState = (bool)editor.Invoke("AreAllOverridesTo", false);
53+
Assert.True(allOverridesState);
54+
55+
component.SetAllOverridesTo(true);
56+
57+
// Was the change correct?
58+
allOverridesState = (bool)editor.Invoke("AreAllOverridesTo", true);
59+
Assert.True(allOverridesState);
60+
61+
// Enable the advance mode on the editor
62+
component.SetField("m_AdvancedMode", true);
63+
64+
// Everything is false
65+
component.SetAllOverridesTo(false);
66+
67+
// Disable the advance mode on the editor
68+
component.SetField("m_AdvancedMode", false);
69+
70+
// Now just set to true the overrides of non additional properties
71+
editor.Invoke("SetOverridesTo", true);
72+
73+
// Check that the non additional properties must be false
74+
allOverridesState = (bool)editor.Invoke("AreAllOverridesTo", true);
75+
Assert.False(allOverridesState);
76+
}
77+
}
78+
}
79+

com.unity.render-pipelines.core/Tests/Editor/Volumes/VolumeComponentTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using NUnit.Framework;
2+
using System.Collections.Generic;
3+
using UnityEngine.Rendering.Tests.Volumes;
4+
5+
namespace UnityEngine.Rendering.HighDefinition.Tests.Volumes
6+
{
7+
public class DepthOfFieldEditorTests : VolumeComponentEditorTests<DepthOfField>
8+
{
9+
[Test]
10+
public virtual void DepthOfField_TestOverridesChanges()
11+
{
12+
CheckOverridesChanges();
13+
}
14+
15+
[Test]
16+
public virtual void DepthOfField_AdditionalProperties()
17+
{
18+
var additionalProperties = new List<string>
19+
{"m_HighQualityFiltering","m_Resolution","m_PhysicallyBased"};
20+
21+
CheckWithCurrentAdditionalProperties(additionalProperties);
22+
}
23+
}
24+
}
25+

com.unity.render-pipelines.high-definition/Tests/Editor/Volumes/DepthOfFieldEitorTests.cs.meta

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

0 commit comments

Comments
 (0)