EditorTest.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEditor;
  6. using UnityEditor.TestTools;
  7. using UnityEngine.TestRunner;
  8. using NUnit.Framework.Interfaces;
  9. [assembly: TestPlayerBuildModifier(typeof(Unity.RenderStreaming.EditorTest.BuildModifier))]
  10. [assembly: TestRunCallback(typeof(Unity.RenderStreaming.EditorTest.TestListener))]
  11. namespace Unity.RenderStreaming.EditorTest
  12. {
  13. class BuildModifier : ITestPlayerBuildModifier
  14. {
  15. const string path = "Packages/com.unity.renderstreaming/Tests/Editor/RenderStreamingSettings.asset";
  16. public BuildPlayerOptions ModifyOptions(BuildPlayerOptions playerOptions)
  17. {
  18. var settings = AssetDatabase.LoadAssetAtPath<RenderStreamingSettings>(path);
  19. RenderStreaming.Settings = settings;
  20. return playerOptions;
  21. }
  22. }
  23. class TestListener : ITestRunCallback
  24. {
  25. const string path = "Packages/com.unity.renderstreaming/Tests/Editor/RenderStreamingSettings.asset";
  26. RenderStreamingSettings temp = null;
  27. public void RunStarted(ITest testsToRun)
  28. {
  29. var settings = AssetDatabase.LoadAssetAtPath<RenderStreamingSettings>(path);
  30. temp = RenderStreaming.Settings;
  31. RenderStreaming.Settings = settings;
  32. }
  33. public void RunFinished(ITestResult testResults)
  34. {
  35. if(temp != null)
  36. RenderStreaming.Settings = temp;
  37. }
  38. public void TestStarted(ITest test)
  39. {
  40. }
  41. public void TestFinished(ITestResult result)
  42. {
  43. }
  44. }
  45. class VideoCodecInfoTest
  46. {
  47. [Test]
  48. public void EqualityOperator()
  49. {
  50. VideoCodecInfo info = null;
  51. Assert.That(info == null, Is.True);
  52. Assert.That(info != null, Is.False);
  53. VideoCodecInfo otherInfo = info;
  54. Assert.That(info == otherInfo, Is.True);
  55. Assert.That(info != otherInfo, Is.False);
  56. info = VideoStreamSender.GetAvailableCodecs().First();
  57. Assert.That(info == otherInfo, Is.False);
  58. Assert.That(info == (object)otherInfo, Is.False);
  59. otherInfo = info;
  60. Assert.That(info == otherInfo, Is.True);
  61. Assert.That(info == (object)otherInfo, Is.True);
  62. }
  63. [Test]
  64. public void HashCode()
  65. {
  66. VideoCodecInfo info = VideoStreamSender.GetAvailableCodecs().First();
  67. VideoCodecInfo otherInfo = info;
  68. Assert.That(info.GetHashCode() == otherInfo.GetHashCode(), Is.True);
  69. otherInfo = VideoStreamSender.GetAvailableCodecs().Last();
  70. Assert.That(info.GetHashCode() == otherInfo.GetHashCode(), Is.False);
  71. }
  72. }
  73. class AudioCodecInfoTest
  74. {
  75. [Test]
  76. public void EqualityOperator()
  77. {
  78. AudioCodecInfo info = null;
  79. Assert.That(info == null, Is.True);
  80. Assert.That(info != null, Is.False);
  81. AudioCodecInfo otherInfo = info;
  82. Assert.That(info == otherInfo, Is.True);
  83. Assert.That(info != otherInfo, Is.False);
  84. info = AudioStreamSender.GetAvailableCodecs().First();
  85. Assert.That(info == otherInfo, Is.False);
  86. Assert.That(info == (object)otherInfo, Is.False);
  87. otherInfo = info;
  88. Assert.That(info == otherInfo, Is.True);
  89. Assert.That(info == (object)otherInfo, Is.True);
  90. }
  91. [Test]
  92. public void HashCode()
  93. {
  94. AudioCodecInfo info = AudioStreamSender.GetAvailableCodecs().First();
  95. AudioCodecInfo otherInfo = info;
  96. Assert.That(info.GetHashCode() == otherInfo.GetHashCode(), Is.True);
  97. otherInfo = AudioStreamSender.GetAvailableCodecs().Last();
  98. Assert.That(info.GetHashCode() == otherInfo.GetHashCode(), Is.False);
  99. }
  100. }
  101. class VideoStreamSenderTest
  102. {
  103. [Test]
  104. public void GetAvailableCodec()
  105. {
  106. var codecs = VideoStreamSender.GetAvailableCodecs();
  107. Assert.That(codecs, Is.Not.Null.Or.Empty);
  108. Assert.That(codecs, Is.Not.Contains(null));
  109. }
  110. }
  111. class VideoStreamReceiverTest
  112. {
  113. [Test]
  114. public void GetAvailableCodec()
  115. {
  116. var codecs = VideoStreamReceiver.GetAvailableCodecs();
  117. Assert.That(codecs, Is.Not.Null.Or.Empty);
  118. Assert.That(codecs, Is.Not.Contains(null));
  119. }
  120. }
  121. class AudioStreamSenderTest
  122. {
  123. [Test]
  124. public void GetAvailableCodec()
  125. {
  126. var codecs = AudioStreamSender.GetAvailableCodecs();
  127. Assert.That(codecs, Is.Not.Null.Or.Empty);
  128. Assert.That(codecs, Is.Not.Contains(null));
  129. }
  130. }
  131. class AudioStreamReceiverTest
  132. {
  133. [Test]
  134. public void GetAvailableCodec()
  135. {
  136. var codecs = AudioStreamReceiver.GetAvailableCodecs();
  137. Assert.That(codecs, Is.Not.Null.Or.Empty);
  138. Assert.That(codecs, Is.Not.Contains(null));
  139. }
  140. }
  141. class RenderStreamingSettingsTest
  142. {
  143. [Test]
  144. public void CheckDefaultSettings()
  145. {
  146. RenderStreamingSettings defaultSettings = AssetDatabase.LoadAssetAtPath<RenderStreamingSettings>(RenderStreaming.DefaultRenderStreamingSettingsPath);
  147. Assert.That(defaultSettings.automaticStreaming, Is.True);
  148. var defaultSignalingSettings = defaultSettings.signalingSettings as WebSocketSignalingSettings;
  149. Assert.That(defaultSignalingSettings, Is.Not.Null);
  150. Assert.That(defaultSignalingSettings.signalingClass, Is.EqualTo(typeof(Signaling.WebSocketSignaling)));
  151. Assert.That(defaultSignalingSettings.url, Is.EqualTo("ws://127.0.0.1:80"));
  152. Assert.That(defaultSignalingSettings.iceServers.ElementAt(0).urls, Is.EquivalentTo(new string[] { "stun:stun.l.google.com:19302" }));
  153. }
  154. }
  155. class SerializeTest
  156. {
  157. [Test]
  158. public void SerializeVideoCodecInfo()
  159. {
  160. IEnumerable<VideoCodecInfo> codecs = VideoStreamSender.GetAvailableCodecs();
  161. var asset = ScriptableObject.CreateInstance<VideoCodecInfoObject>();
  162. asset.info = codecs.First();
  163. string exportPath = "Assets/test.asset";
  164. AssetDatabase.CreateAsset(asset, exportPath);
  165. EditorUtility.SetDirty(asset);
  166. AssetDatabase.SaveAssets();
  167. var otherAsset = AssetDatabase.LoadAssetAtPath<VideoCodecInfoObject>(exportPath);
  168. Assert.That(asset.info, Is.Not.Null);
  169. Assert.That(otherAsset.info, Is.Not.Null);
  170. Assert.That(asset.info, Is.EqualTo(otherAsset.info));
  171. Assert.That(asset.info.Equals(otherAsset.info), Is.True);
  172. AssetDatabase.DeleteAsset(exportPath);
  173. }
  174. [Test]
  175. public void SerializeAudioCodecInfo()
  176. {
  177. IEnumerable<AudioCodecInfo> codecs = AudioStreamSender.GetAvailableCodecs();
  178. var asset = ScriptableObject.CreateInstance<AudioCodecInfoObject>();
  179. asset.info = codecs.First();
  180. string exportPath = "Assets/test.asset";
  181. AssetDatabase.CreateAsset(asset, exportPath);
  182. EditorUtility.SetDirty(asset);
  183. AssetDatabase.SaveAssets();
  184. var otherAsset = AssetDatabase.LoadAssetAtPath<AudioCodecInfoObject>(exportPath);
  185. Assert.That(asset.info, Is.Not.Null);
  186. Assert.That(otherAsset.info, Is.Not.Null);
  187. Assert.That(asset.info, Is.EqualTo(otherAsset.info));
  188. Assert.That(asset.info.Equals(otherAsset.info), Is.True);
  189. AssetDatabase.DeleteAsset(exportPath);
  190. }
  191. [Test]
  192. public void CreateSignalingSettingsObject()
  193. {
  194. var asset = SignalingSettingsObject.Create();
  195. Assert.That(asset, Is.Not.Null);
  196. Assert.That(asset.settings, Is.Not.Null);
  197. Assert.That(asset.settings, Is.TypeOf<WebSocketSignalingSettings>());
  198. }
  199. }
  200. }