TestUtility.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Threading;
  3. using UnityEngine;
  4. namespace Unity.RenderStreaming.RuntimeTest
  5. {
  6. internal class TestUtility
  7. {
  8. const string FileNameWebAppForMac = "webserver_mac";
  9. const string FileNameWebAppForLinux = "webserver";
  10. const string FileNameWebAppForWin = "webserver.exe";
  11. public const int PortNumber = 8081;
  12. public static string GetFileName()
  13. {
  14. switch (Application.platform)
  15. {
  16. case RuntimePlatform.OSXEditor:
  17. case RuntimePlatform.OSXPlayer:
  18. return FileNameWebAppForMac;
  19. case RuntimePlatform.WindowsPlayer:
  20. case RuntimePlatform.WindowsEditor:
  21. return FileNameWebAppForWin;
  22. case RuntimePlatform.LinuxPlayer:
  23. case RuntimePlatform.LinuxEditor:
  24. return FileNameWebAppForLinux;
  25. default:
  26. throw new ArgumentOutOfRangeException($"this platform ({Application.platform} does not support.");
  27. }
  28. }
  29. public static bool Wait(Func<bool> condition, int millisecondsTimeout = 1000, int millisecondsInterval = 100)
  30. {
  31. if (millisecondsTimeout < millisecondsInterval)
  32. {
  33. throw new ArgumentException();
  34. }
  35. int time = 0;
  36. while (!condition() && millisecondsTimeout > time)
  37. {
  38. Thread.Sleep(millisecondsInterval);
  39. time += millisecondsInterval;
  40. }
  41. return millisecondsTimeout > time;
  42. }
  43. public static string GetWebAppLocationFromEnv()
  44. {
  45. var path = Environment.GetEnvironmentVariable("WEBAPP_PATH");
  46. if (!string.IsNullOrEmpty(path))
  47. {
  48. return path;
  49. }
  50. var args = Environment.GetCommandLineArgs();
  51. for (int i = 0; i < args.Length; i++)
  52. {
  53. if (args[i] == "-webapp-path")
  54. {
  55. return args[i + 1];
  56. }
  57. }
  58. return null;
  59. }
  60. }
  61. }