RuntimeTests.cs
7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine.TestTools;
using UnityEditor;
using UnityEngine.Rendering;
namespace UnityEngine.XR.Management.Tests
{
[TestFixture(0, -1)] // No loaders, should never have any results
[TestFixture(1, -1)] // 1 loader, fails so no active loaders
[TestFixture(1, 0)] // All others, make sure the active loader is expected loader.
[TestFixture(2, 0)]
[TestFixture(2, 1)]
[TestFixture(3, 2)]
class ManualLifetimeTests
{
XRManagerSettings m_Manager;
List<XRLoader> m_Loaders = new List<XRLoader>();
int m_LoaderCount;
int m_LoaderIndexToWin;
public ManualLifetimeTests(int loaderCount, int loaderIndexToWin)
{
m_LoaderCount = loaderCount;
m_LoaderIndexToWin = loaderIndexToWin;
}
[SetUp]
public void SetupXRManagerTest()
{
m_Manager = ScriptableObject.CreateInstance<XRManagerSettings>();
m_Manager.automaticLoading = false;
m_Loaders = new List<XRLoader>();
for (int i = 0; i < m_LoaderCount; i++)
{
DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader;
dl.id = i;
dl.shouldFail = (i != m_LoaderIndexToWin);
m_Loaders.Add(dl);
m_Manager.loaders.Add(dl);
}
}
[TearDown]
public void TeardownXRManagerTest()
{
Object.Destroy(m_Manager);
m_Manager = null;
}
[UnityTest]
public IEnumerator CheckActivatedLoader()
{
Assert.IsNotNull(m_Manager);
yield return m_Manager.InitializeLoader();
if (m_LoaderIndexToWin < 0 || m_LoaderIndexToWin >= m_Loaders.Count)
{
Assert.IsNull(m_Manager.activeLoader);
}
else
{
Assert.IsNotNull(m_Manager.activeLoader);
Assert.AreEqual(m_Loaders[m_LoaderIndexToWin], m_Manager.activeLoader);
}
m_Manager.DeinitializeLoader();
Assert.IsNull(m_Manager.activeLoader);
m_Manager.loaders.Clear();
}
}
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
#if UNITY_EDITOR_WIN
[TestFixture(GraphicsDeviceType.Direct3D11, 0, new [] { GraphicsDeviceType.Direct3D11})]
[TestFixture(GraphicsDeviceType.Direct3D11, 1, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Direct3D11})]
[TestFixture(GraphicsDeviceType.Direct3D11, -1, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Vulkan})]
[TestFixture(GraphicsDeviceType.Direct3D11, 0, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})]
[TestFixture(GraphicsDeviceType.Direct3D11, 1, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})]
#elif UNITY_EDITOR_OSX
[TestFixture(GraphicsDeviceType.Metal, 0, new [] { GraphicsDeviceType.Metal})]
[TestFixture(GraphicsDeviceType.Metal, 1, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Metal})]
[TestFixture(GraphicsDeviceType.Metal, -1, new [] { GraphicsDeviceType.OpenGLES3, GraphicsDeviceType.Vulkan})]
[TestFixture(GraphicsDeviceType.Metal, 0, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})]
[TestFixture(GraphicsDeviceType.Metal, 1, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})]
#endif
class GraphicsAPICompatibilityTests
{
XRManagerSettings m_Manager;
List<XRLoader> m_Loaders = new List<XRLoader>();
private GraphicsDeviceType m_PlayerSettingsDeviceType;
private GraphicsDeviceType[] m_LoadersSupporteDeviceTypes;
int m_LoaderIndexToWin;
public GraphicsAPICompatibilityTests(GraphicsDeviceType playerSettingsDeviceType, int indexToWin, GraphicsDeviceType[] loaders)
{
m_LoaderIndexToWin = indexToWin;
m_PlayerSettingsDeviceType = playerSettingsDeviceType;
m_LoadersSupporteDeviceTypes = loaders;
}
[SetUp]
public void SetupPlayerSettings()
{
GraphicsDeviceType[] deviceTypes = PlayerSettings.GetGraphicsAPIs(BuildTarget.StandaloneOSX);
var oldGfxType = m_PlayerSettingsDeviceType;
// If the type we want to check isn't the supported graphics type, then substitute it out
// so we can still pass the tests. Semantics are the same regardless of actual devices.
if (SystemInfo.graphicsDeviceType != m_PlayerSettingsDeviceType)
{
m_PlayerSettingsDeviceType = SystemInfo.graphicsDeviceType;
for (int i = 0; i < m_LoadersSupporteDeviceTypes.Length; i++)
{
if (oldGfxType == m_LoadersSupporteDeviceTypes[i])
{
m_LoadersSupporteDeviceTypes[i] = m_PlayerSettingsDeviceType;
}
}
}
#if UNITY_EDITOR_WIN
PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneWindows64, new[] { m_PlayerSettingsDeviceType });
#elif UNITY_EDITOR_OSX
PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneOSX, new[] { m_PlayerSettingsDeviceType });
#endif
m_Manager = ScriptableObject.CreateInstance<XRManagerSettings>();
m_Manager.automaticLoading = false;
m_Loaders = new List<XRLoader>();
for (int i = 0; i < m_LoadersSupporteDeviceTypes.Length; i++)
{
DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader;
dl.id = i;
dl.supportedDeviceType = m_LoadersSupporteDeviceTypes[i];
dl.shouldFail = (i != m_LoaderIndexToWin);
m_Loaders.Add(dl);
m_Manager.loaders.Add(dl);
}
}
[TearDown]
public void TeadDown()
{
Object.Destroy(m_Manager);
m_Manager = null;
}
[Test]
public void CheckGraphicsAPICompatibilitySync()
{
m_Manager.InitializeLoaderSync();
if (m_LoaderIndexToWin < 0 || m_LoaderIndexToWin >= m_Loaders.Count)
{
Assert.IsNull(m_Manager.activeLoader);
}
else
{
Assert.IsNotNull(m_Manager.activeLoader);
Assert.AreEqual(m_Loaders[m_LoaderIndexToWin], m_Manager.activeLoader);
m_Manager.DeinitializeLoader();
}
m_Manager.loaders.Clear();
}
[UnityTest]
public IEnumerator CheckGraphicsAPICompatibility()
{
yield return m_Manager.InitializeLoader();
if (m_LoaderIndexToWin < 0 || m_LoaderIndexToWin >= m_Loaders.Count)
{
Assert.IsNull(m_Manager.activeLoader);
}
else
{
Assert.IsNotNull(m_Manager.activeLoader);
Assert.AreEqual(m_Loaders[m_LoaderIndexToWin], m_Manager.activeLoader);
m_Manager.DeinitializeLoader();
}
m_Manager.loaders.Clear();
}
}
#endif // UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
}