Program.cs 6.4 KB

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