Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AdaptivePerformanceBuildUtilsTests.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.IO;
  2. using NUnit.Framework;
  3. using UnityEngine;
  4. namespace UnityEditor.AdaptivePerformance.Editor.Tests
  5. {
  6. public class AdaptivePerformanceBuildUtilsTests
  7. {
  8. string testFolder;
  9. string bootConfig;
  10. [SetUp]
  11. public void SetUp()
  12. {
  13. testFolder = Path.Combine(Application.temporaryCachePath, "APTestBoot");
  14. if (Directory.Exists(testFolder))
  15. Directory.Delete(testFolder, true);
  16. Directory.CreateDirectory(testFolder);
  17. string testBuildPath = Path.Combine(testFolder, "src/main/assets/bin/Data");
  18. Directory.CreateDirectory(testBuildPath);
  19. bootConfig = Path.Combine(testBuildPath, "boot.config");
  20. File.WriteAllLines(bootConfig, new[]
  21. {
  22. "gfx-disable-mt-rendering=1",
  23. "wait-for-native-debugger=0",
  24. "hdr-display-enabled=0",
  25. });
  26. }
  27. [TearDown]
  28. public void TearDown()
  29. {
  30. if (testFolder != null && Directory.Exists(testFolder))
  31. Directory.Delete(testFolder, true);
  32. }
  33. void CheckBootConfigContains(string key, string value)
  34. {
  35. var lines = File.ReadAllLines(bootConfig);
  36. bool found = false;
  37. foreach (var line in lines)
  38. {
  39. if (line.StartsWith(key))
  40. {
  41. Assert.IsFalse(found); // no duplicates allowed
  42. Assert.AreEqual($"{key}={value}", line);
  43. found = true;
  44. }
  45. }
  46. Assert.IsTrue(found);
  47. }
  48. [Test]
  49. public void UpdateBootConfigBoostSetting_WithoutSetting_AddsSetting()
  50. {
  51. AdaptivePerformanceBuildUtils.UpdateBootConfigBoostSetting(testFolder, "adaptive-performance-test", "1");
  52. CheckBootConfigContains("adaptive-performance-test", "1");
  53. }
  54. [Test]
  55. public void UpdateBootConfigBoostSetting_WithCorrectSetting_DoesntChangeFile()
  56. {
  57. File.AppendAllLines(bootConfig, new[] { "adaptive-performance-test=1" });
  58. AdaptivePerformanceBuildUtils.UpdateBootConfigBoostSetting(testFolder, "adaptive-performance-test", "1");
  59. CheckBootConfigContains("adaptive-performance-test", "1");
  60. }
  61. [Test]
  62. public void UpdateBootConfigBoostSetting_WithInorrectSetting_ReplacesSetting()
  63. {
  64. File.AppendAllLines(bootConfig, new[] { "adaptive-performance-test=0" });
  65. AdaptivePerformanceBuildUtils.UpdateBootConfigBoostSetting(testFolder, "adaptive-performance-test", "1");
  66. CheckBootConfigContains("adaptive-performance-test", "1");
  67. }
  68. }
  69. }