RuntimeTests.cs 7.2 KB

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