BuildTests.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. using UnityEditor.Build;
  4. using UnityEngine;
  5. using UnityEngine.Rendering;
  6. using UnityEngine.XR.Management;
  7. using UnityEngine.XR.Management.Tests;
  8. using Object = UnityEngine.Object;
  9. #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
  10. namespace UnityEditor.XR.Management.Tests.BuildTests
  11. {
  12. #if UNITY_EDITOR_WIN
  13. [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Direct3D11})]
  14. [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Direct3D11})]
  15. [TestFixture(GraphicsDeviceType.Direct3D11, true, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Vulkan})]
  16. [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})]
  17. [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})]
  18. #elif UNITY_EDITOR_OSX
  19. [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Metal})]
  20. [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Metal})]
  21. [TestFixture(GraphicsDeviceType.Metal, true, new [] { GraphicsDeviceType.OpenGLES3, GraphicsDeviceType.Vulkan})]
  22. [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})]
  23. [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})]
  24. #endif
  25. class GraphicsAPICompatibilityTests
  26. {
  27. XRManagerSettings m_Manager;
  28. List<XRLoader> m_Loaders = new List<XRLoader>();
  29. private GraphicsDeviceType m_PlayerSettingsDeviceType;
  30. private GraphicsDeviceType[] m_LoadersSupporteDeviceTypes;
  31. bool m_BuildFails;
  32. public GraphicsAPICompatibilityTests(GraphicsDeviceType playerSettingsDeviceType, bool fails, GraphicsDeviceType[] loaders)
  33. {
  34. m_BuildFails = fails;
  35. m_PlayerSettingsDeviceType = playerSettingsDeviceType;
  36. m_LoadersSupporteDeviceTypes = loaders;
  37. }
  38. [SetUp]
  39. public void SetupPlayerSettings()
  40. {
  41. #if UNITY_EDITOR_WIN
  42. PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneWindows64, new[] { m_PlayerSettingsDeviceType });
  43. #elif UNITY_EDITOR_OSX
  44. PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneOSX, new[] { m_PlayerSettingsDeviceType });
  45. #endif
  46. m_Manager = ScriptableObject.CreateInstance<XRManagerSettings>();
  47. m_Manager.automaticLoading = false;
  48. m_Loaders = new List<XRLoader>();
  49. for (int i = 0; i < m_LoadersSupporteDeviceTypes.Length; i++)
  50. {
  51. DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader;
  52. dl.id = i;
  53. dl.supportedDeviceType = m_LoadersSupporteDeviceTypes[i];
  54. m_Loaders.Add(dl);
  55. m_Manager.loaders.Add(dl);
  56. }
  57. }
  58. [TearDown]
  59. public void TeadDown()
  60. {
  61. Object.DestroyImmediate(m_Manager);
  62. m_Manager = null;
  63. }
  64. [Test]
  65. public void CheckGraphicsAPICompatibilityOnBuild()
  66. {
  67. try
  68. {
  69. XRGeneralBuildProcessor.VerifyGraphicsAPICompatibility(m_Manager, m_PlayerSettingsDeviceType);
  70. }
  71. catch (BuildFailedException)
  72. {
  73. Assert.True(m_BuildFails);
  74. return;
  75. }
  76. Assert.False(m_BuildFails);
  77. }
  78. }
  79. }
  80. #endif //UNITY_EDITOR_WIN || UNITY_EDITOR_OSX