ProfileDataAPITests.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using NUnit.Framework;
  2. using UnityEditor.Performance.ProfileAnalyzer;
  3. using System.Collections.Generic;
  4. public class ProfileDataAPITests : ProfileAnalyzerBaseTest
  5. {
  6. [Test]
  7. public void ProfileData_AddMarkerName_AddsMarkerAndContainsName()
  8. {
  9. var data = new ProfileData();
  10. var markerNames = new List<string>()
  11. {
  12. "Marker01",
  13. "Marker02",
  14. "Marker03",
  15. "Marker04"
  16. };
  17. var markerList = new List<ProfileMarker>();
  18. for (int i = 0; i < 10; ++i)
  19. {
  20. var marker = new ProfileMarker()
  21. {
  22. msMarkerTotal = 0.5f,
  23. depth = i
  24. };
  25. int expectedIndex = i % markerNames.Count;
  26. data.AddMarkerName(markerNames[expectedIndex], marker);
  27. markerList.Add(marker);
  28. Assert.IsTrue(expectedIndex == marker.nameIndex, "Index mismatch at: " + i + " , " + marker.nameIndex);;
  29. }
  30. for (int i = 0; i < markerList.Count; ++i)
  31. {
  32. var curName = data.GetMarkerName(markerList[i]);
  33. Assert.IsTrue(markerNames.Contains(curName));
  34. }
  35. }
  36. [Test]
  37. public void ProfileData_AddThreadName_AddsThreadAndContainsName()
  38. {
  39. var data = new ProfileData();
  40. var threadNames = new List<string>()
  41. {
  42. "Thread01",
  43. "Thread02",
  44. "Thread03",
  45. "Thread04"
  46. };
  47. var threadDict = new Dictionary<string, ProfileThread>();
  48. for (int i = 0; i < 10; ++i)
  49. {
  50. int expectedIndex = i % threadNames.Count;
  51. string threadName = threadNames[expectedIndex];
  52. ProfileThread thread;
  53. if (!threadDict.TryGetValue(threadName, out thread))
  54. {
  55. thread = new ProfileThread();
  56. threadDict.Add(threadName, thread);
  57. }
  58. var marker = new ProfileMarker()
  59. {
  60. msMarkerTotal = 0.5f,
  61. depth = i
  62. };
  63. thread.markers.Add(marker);
  64. data.AddThreadName(threadName, thread);
  65. Assert.IsTrue(expectedIndex == thread.threadIndex, "Index mismatch at: " + i + " , " + thread.threadIndex);;
  66. }
  67. foreach (var curThread in threadDict)
  68. {
  69. var curName = data.GetThreadName(curThread.Value);
  70. Assert.IsTrue(threadNames.Contains(curName));
  71. }
  72. }
  73. }