RenderStreamingTest.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Linq;
  2. using NUnit.Framework;
  3. using Unity.RenderStreaming.RuntimeTest.Signaling;
  4. using Unity.RenderStreaming.Signaling;
  5. using UnityEngine;
  6. using UnityEngine.TestTools;
  7. #if UNITY_EDITOR
  8. using UnityEditor;
  9. #endif
  10. namespace Unity.RenderStreaming.RuntimeTest
  11. {
  12. class RenderStreamingTest : IPrebuildSetup, IPostBuildCleanup
  13. {
  14. private RenderStreamingSettings temp;
  15. [SetUp]
  16. public void SetUpTest()
  17. {
  18. temp = RenderStreaming.Settings;
  19. }
  20. [TearDown]
  21. public void TearDown()
  22. {
  23. if (temp != null)
  24. {
  25. RenderStreaming.Settings = temp;
  26. }
  27. }
  28. void IPrebuildSetup.Setup()
  29. {
  30. #if UNITY_EDITOR
  31. var defaultSettings = RenderStreaming.Settings;
  32. RenderStreaming.Settings =
  33. AssetDatabase.LoadAssetAtPath<RenderStreamingSettings>(RenderStreaming.DefaultRenderStreamingSettingsPath);
  34. if (defaultSettings != null)
  35. {
  36. EditorBuildSettings.AddConfigObject(RenderStreaming.EditorBuildSettingsConfigKey, defaultSettings, true);
  37. }
  38. #endif
  39. }
  40. void IPostBuildCleanup.Cleanup()
  41. {
  42. #if UNITY_EDITOR
  43. if (EditorBuildSettings.TryGetConfigObject(RenderStreaming.EditorBuildSettingsConfigKey, out RenderStreamingSettings settingsAsset))
  44. {
  45. RenderStreaming.Settings = settingsAsset;
  46. }
  47. else
  48. {
  49. RenderStreaming.Settings =
  50. AssetDatabase.LoadAssetAtPath<RenderStreamingSettings>(RenderStreaming.DefaultRenderStreamingSettingsPath);
  51. }
  52. #endif
  53. }
  54. [Test]
  55. public void Settings()
  56. {
  57. Assert.That(() => RenderStreaming.Settings = null, Throws.ArgumentNullException);
  58. var settings = ScriptableObject.CreateInstance<RenderStreamingSettings>();
  59. settings.signalingSettings = new MockSignalingSettings();
  60. RenderStreaming.Settings = settings;
  61. Assert.That(RenderStreaming.Settings.automaticStreaming, Is.EqualTo(settings.automaticStreaming));
  62. Assert.That(RenderStreaming.Settings.signalingSettings, Is.EqualTo(settings.signalingSettings));
  63. Object.DestroyImmediate(settings);
  64. }
  65. [Test]
  66. public void AutomaticStreaming()
  67. {
  68. var settings = ScriptableObject.CreateInstance<RenderStreamingSettings>();
  69. settings.automaticStreaming = false;
  70. settings.signalingSettings = new WebSocketSignalingSettings();
  71. RenderStreaming.Settings = settings;
  72. RenderStreaming.AutomaticStreaming = true;
  73. var automaticStreaming = Object.FindObjectOfType<AutomaticStreaming>();
  74. Assert.That(automaticStreaming, Is.Not.Null);
  75. RenderStreaming.AutomaticStreaming = false;
  76. automaticStreaming = Object.FindObjectOfType<AutomaticStreaming>();
  77. Assert.That(automaticStreaming, Is.Null);
  78. Object.DestroyImmediate(settings);
  79. }
  80. }
  81. }