Program.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using System.Diagnostics;
  5. [assembly: InternalsVisibleTo("MBansheeEditor")]
  6. namespace BansheeEngine
  7. {
  8. class Program
  9. {
  10. // TODO: Make this an actual unit test
  11. static void UnitTest1_ManagedSerialization()
  12. {
  13. SceneObject otherSO = new SceneObject("OtherSO");
  14. DbgComponent2 dbgComponent2 = otherSO.AddComponent<DbgComponent2>();
  15. dbgComponent2.a2 = 33;
  16. GUIElementStateStyle dbgStyle = new GUIElementStateStyle();
  17. SceneObject so = new SceneObject("TestSO");
  18. DbgComponent dbgComponent = so.AddComponent<DbgComponent>();
  19. dbgComponent.a = 5;
  20. dbgComponent.b = "SomeTestVal";
  21. dbgComponent.complex.someValue = 19;
  22. dbgComponent.complex.anotherValue = "AnotherValue";
  23. dbgComponent.complex2.someValue2 = 21;
  24. dbgComponent.complex2.anotherValue2 = "AnotherValue2";
  25. dbgComponent.arrA = new int[5];
  26. dbgComponent.arrA[4] = 5;
  27. dbgComponent.arrB = new string[5];
  28. dbgComponent.arrB[4] = "ArrAnotherValue";
  29. dbgComponent.arrComplex = new DbgSerzObj[5];
  30. dbgComponent.arrComplex[4].someValue = 99;
  31. dbgComponent.arrComplex[4].anotherValue = "ArrComplexAnotherValue";
  32. dbgComponent.arrComplex2 = new DbgSerzCls[5];
  33. dbgComponent.arrComplex2[4] = new DbgSerzCls();
  34. dbgComponent.arrComplex2[4].someValue2 = 101;
  35. dbgComponent.arrComplex2[4].anotherValue2 = "ArrComplex2AnotherValue";
  36. dbgComponent.listA = new List<int>();
  37. dbgComponent.listA.Add(5);
  38. dbgComponent.listB = new List<string>();
  39. dbgComponent.listB.Add("ListAnotherValue");
  40. dbgComponent.listB.Add(null);
  41. dbgComponent.listComplex = new List<DbgSerzObj>();
  42. dbgComponent.listComplex.Add(new DbgSerzObj());
  43. dbgComponent.listComplex.Add(new DbgSerzObj(99, "ListComplexAnotherValue"));
  44. dbgComponent.listComplex2 = new List<DbgSerzCls>();
  45. dbgComponent.listComplex2.Add(new DbgSerzCls());
  46. dbgComponent.listComplex2[0].someValue2 = 101;
  47. dbgComponent.listComplex2[0].anotherValue2 = "ListComplexAnotherValue";
  48. dbgComponent.listComplex2.Add(null);
  49. dbgComponent.otherComponent = dbgComponent2;
  50. dbgComponent.otherSO = otherSO;
  51. //dbgComponent.zeArray = new int[5][][];
  52. //dbgComponent.zeList = new List<DbgSerzObj>();
  53. //dbgComponent.zeDict = new Dictionary<string, int>();
  54. //dbgComponent.zeList.Add(new DbgSerzObj());
  55. //dbgComponent.zeList.Add(new DbgSerzObj());
  56. //dbgComponent.zeList.Add(new DbgSerzObj(101, ""));
  57. //dbgComponent.zeList.Add(new DbgSerzObj());
  58. //dbgComponent.zeDict["supSup"] = 10001;
  59. //dbgComponent.zeDict["lolz"] = 696969;
  60. //var enumerator = dbgComponent.zeDict.GetEnumerator();
  61. //int all = 0;
  62. //while (enumerator.MoveNext())
  63. //{
  64. // all += enumerator.Current.Value;
  65. //}
  66. //for (int i = 0; i < dbgComponent.zeArray.Length; i++)
  67. //{
  68. // dbgComponent.zeArray[i] = new int[6][];
  69. // for (int j = 0; j < dbgComponent.zeArray[i].Length; j++)
  70. // dbgComponent.zeArray[i][j] = new int[7];
  71. //}
  72. //dbgComponent.zeArray[4][1][3] = 129;
  73. UnitTest1_GameObjectClone(so);
  74. for (int i = 0; i < so.GetNumChildren(); i++)
  75. {
  76. SceneObject childSO = so.GetChild(i);
  77. DbgComponent otherComponent = childSO.GetComponent<DbgComponent>();
  78. System.Diagnostics.Debug.Assert(otherComponent.a == 5);
  79. System.Diagnostics.Debug.Assert(otherComponent.b == "SomeTestVal");
  80. System.Diagnostics.Debug.Assert(otherComponent.complex.someValue == 19);
  81. System.Diagnostics.Debug.Assert(otherComponent.complex2.anotherValue2 == "AnotherValue2");
  82. System.Diagnostics.Debug.Assert(otherComponent.arrA[4] == 5);
  83. System.Diagnostics.Debug.Assert(otherComponent.arrB[4] == "ArrAnotherValue");
  84. System.Diagnostics.Debug.Assert(otherComponent.arrComplex[4].someValue == 99);
  85. System.Diagnostics.Debug.Assert(otherComponent.arrComplex2[4].anotherValue2 == "ArrComplex2AnotherValue");
  86. System.Diagnostics.Debug.Assert(otherComponent.listA[0] == 5);
  87. System.Diagnostics.Debug.Assert(otherComponent.listB[0] == "ListAnotherValue");
  88. System.Diagnostics.Debug.Assert(otherComponent.listComplex[1].someValue == 99);
  89. System.Diagnostics.Debug.Assert(otherComponent.listComplex2[0].anotherValue2 == "ListComplexAnotherValue");
  90. }
  91. }
  92. [MethodImpl(MethodImplOptions.InternalCall)]
  93. private static extern void UnitTest1_GameObjectClone(SceneObject so);
  94. static void Main()
  95. {
  96. UnitTest1_ManagedSerialization();
  97. //Color newColor = Color.red;
  98. //dbgStyle.textColor = newColor;
  99. //Color myColor = dbgStyle.textColor;
  100. //dbgStyle.textColor = myColor;
  101. SerializableObject obj = new SerializableObject(typeof(DbgSerzCls), new DbgSerzCls());
  102. Debug.Log(obj.fields.Length);
  103. for (int i = 0; i < obj.fields.Length; i++)
  104. {
  105. Debug.Log(i + ". " + obj.fields[i].Name + " - " + obj.fields[i].Type.ToString());
  106. }
  107. SerializableProperty prop = obj.fields[0].GetProperty();
  108. Debug.Log("Old value: " + prop.GetValue<int>());
  109. prop.SetValue<int>(33);
  110. Debug.Log("New value: " + prop.GetValue<int>());
  111. SerializableProperty prop2 = obj.fields[2].GetProperty();
  112. Debug.Log("Old value: " + (prop2.GetValue<DbgSerzCls>() == null));
  113. DbgSerzCls child = new DbgSerzCls();
  114. child.anotherValue2 = "ass";
  115. prop2.SetValue<DbgSerzCls>(child);
  116. if (prop2.GetValue<DbgSerzCls>() == null)
  117. Debug.Log("New value: null");
  118. else
  119. Debug.Log("New value: " + prop2.GetValue<DbgSerzCls>().anotherValue2);
  120. }
  121. }
  122. }