BsEditorTestSuite.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. #include "BsEditorTestSuite.h"
  2. #include "BsSceneObject.h"
  3. #include "BsCmdRecordSO.h"
  4. #include "BsCmdDeleteSO.h"
  5. #include "BsUndoRedo.h"
  6. #include "BsRTTIType.h"
  7. #include "BsGameObjectRTTI.h"
  8. #include "BsBinarySerializer.h"
  9. #include "BsMemorySerializer.h"
  10. #include "BsBinaryDiff.h"
  11. #include "BsPrefab.h"
  12. #include "BsResources.h"
  13. #include "BsPrefabDiff.h"
  14. #include "BsFrameAlloc.h"
  15. namespace BansheeEngine
  16. {
  17. class TestComponentARTTI : public RTTIType<TestComponentA, Component, TestComponentARTTI>
  18. {
  19. private:
  20. HSceneObject& getRef1(TestComponentA* obj) { return obj->ref1; }
  21. void setRef1(TestComponentA* obj, HSceneObject& val) { obj->ref1 = val; }
  22. HComponent& getRef2(TestComponentA* obj) { return obj->ref2; }
  23. void setRef2(TestComponentA* obj, HComponent& val) { obj->ref2 = val; }
  24. public:
  25. TestComponentARTTI()
  26. {
  27. addReflectableField("ref1", 0, &TestComponentARTTI::getRef1, &TestComponentARTTI::setRef1);
  28. addReflectableField("ref2", 1, &TestComponentARTTI::getRef2, &TestComponentARTTI::setRef2);
  29. }
  30. virtual const String& getRTTIName()
  31. {
  32. static String name = "TestComponentA";
  33. return name;
  34. }
  35. virtual UINT32 getRTTIId()
  36. {
  37. return TID_TestComponentA;
  38. }
  39. virtual std::shared_ptr<IReflectable> newRTTIObject()
  40. {
  41. return GameObjectRTTI::createGameObject<TestComponentA>();
  42. }
  43. };
  44. class TestComponentBRTTI : public RTTIType<TestComponentB, Component, TestComponentBRTTI>
  45. {
  46. private:
  47. HSceneObject& getRef1(TestComponentB* obj) { return obj->ref1; }
  48. void setRef1(TestComponentB* obj, HSceneObject& val) { obj->ref1 = val; }
  49. String& getVal1(TestComponentB* obj) { return obj->val1; }
  50. void setVal1(TestComponentB* obj, String& val) { obj->val1 = val; }
  51. public:
  52. TestComponentBRTTI()
  53. {
  54. addReflectableField("ref1", 0, &TestComponentBRTTI::getRef1, &TestComponentBRTTI::setRef1);
  55. addPlainField("val1", 1, &TestComponentBRTTI::getVal1, &TestComponentBRTTI::setVal1);
  56. }
  57. virtual const String& getRTTIName()
  58. {
  59. static String name = "TestComponentB";
  60. return name;
  61. }
  62. virtual UINT32 getRTTIId()
  63. {
  64. return TID_TestComponentB;
  65. }
  66. virtual std::shared_ptr<IReflectable> newRTTIObject()
  67. {
  68. return GameObjectRTTI::createGameObject<TestComponentB>();
  69. }
  70. };
  71. TestComponentA::TestComponentA(const HSceneObject& parent)
  72. :Component(parent)
  73. {}
  74. RTTITypeBase* TestComponentA::getRTTIStatic()
  75. {
  76. return TestComponentARTTI::instance();
  77. }
  78. RTTITypeBase* TestComponentA::getRTTI() const
  79. {
  80. return TestComponentA::getRTTIStatic();
  81. }
  82. TestComponentB::TestComponentB(const HSceneObject& parent)
  83. :Component(parent)
  84. {}
  85. RTTITypeBase* TestComponentB::getRTTIStatic()
  86. {
  87. return TestComponentBRTTI::instance();
  88. }
  89. RTTITypeBase* TestComponentB::getRTTI() const
  90. {
  91. return TestComponentB::getRTTIStatic();
  92. }
  93. struct TestObjectB : IReflectable
  94. {
  95. UINT32 intA = 100;
  96. String strA = "100";
  97. /************************************************************************/
  98. /* RTTI */
  99. /************************************************************************/
  100. public:
  101. friend class TestObjectBRTTI;
  102. static RTTITypeBase* getRTTIStatic();
  103. virtual RTTITypeBase* getRTTI() const;
  104. };
  105. struct TestObjectA : IReflectable
  106. {
  107. TestObjectA()
  108. {
  109. arrStrA = { "10", "11", "12" };
  110. arrStrB = { "13", "14", "15" };
  111. arrStrC = { "16", "17", "18" };
  112. arrObjA = { TestObjectB(), TestObjectB(), TestObjectB() };
  113. arrObjB = { TestObjectB(), TestObjectB(), TestObjectB() };
  114. arrObjPtrA = { bs_shared_ptr<TestObjectB>(), bs_shared_ptr<TestObjectB>(), bs_shared_ptr<TestObjectB>() };
  115. arrObjPtrB = { bs_shared_ptr<TestObjectB>(), bs_shared_ptr<TestObjectB>(), bs_shared_ptr<TestObjectB>() };
  116. }
  117. UINT32 intA = 5;
  118. String strA = "5";
  119. String strB = "7";
  120. TestObjectB objA;
  121. TestObjectB objB;
  122. SPtr<TestObjectB> objPtrA = bs_shared_ptr<TestObjectB>();
  123. SPtr<TestObjectB> objPtrB = bs_shared_ptr<TestObjectB>();
  124. SPtr<TestObjectB> objPtrC = bs_shared_ptr<TestObjectB>();
  125. SPtr<TestObjectB> objPtrD = nullptr;
  126. Vector<String> arrStrA;
  127. Vector<String> arrStrB;
  128. Vector<String> arrStrC;
  129. Vector<TestObjectB> arrObjA;
  130. Vector<TestObjectB> arrObjB;
  131. Vector<SPtr<TestObjectB>> arrObjPtrA;
  132. Vector<SPtr<TestObjectB>> arrObjPtrB;
  133. /************************************************************************/
  134. /* RTTI */
  135. /************************************************************************/
  136. public:
  137. friend class TestObjectARTTI;
  138. static RTTITypeBase* getRTTIStatic();
  139. virtual RTTITypeBase* getRTTI() const;
  140. };
  141. class TestObjectARTTI : public RTTIType < TestObjectA, IReflectable, TestObjectARTTI >
  142. {
  143. private:
  144. BS_PLAIN_MEMBER(intA);
  145. BS_PLAIN_MEMBER(strA);
  146. BS_PLAIN_MEMBER(strB);
  147. BS_REFL_MEMBER(objA);
  148. BS_REFL_MEMBER(objB);
  149. BS_REFLPTR_MEMBER(objPtrA);
  150. BS_REFLPTR_MEMBER(objPtrB);
  151. BS_REFLPTR_MEMBER(objPtrC);
  152. BS_REFLPTR_MEMBER(objPtrD);
  153. BS_PLAIN_MEMBER_VEC(arrStrA);
  154. BS_PLAIN_MEMBER_VEC(arrStrB);
  155. BS_PLAIN_MEMBER_VEC(arrStrC);
  156. BS_REFL_MEMBER_VEC(arrObjA);
  157. BS_REFL_MEMBER_VEC(arrObjB);
  158. BS_REFLPTR_MEMBER_VEC(arrObjPtrA);
  159. BS_REFLPTR_MEMBER_VEC(arrObjPtrB);
  160. public:
  161. TestObjectARTTI()
  162. {
  163. BS_ADD_PLAIN_FIELD(intA, 0);
  164. BS_ADD_PLAIN_FIELD(strA, 1);
  165. BS_ADD_PLAIN_FIELD(strB, 2);
  166. BS_ADD_REFL_FIELD(objA, 3);
  167. BS_ADD_REFL_FIELD(objB, 4);
  168. BS_ADD_REFLPTR_FIELD(objPtrA, 5);
  169. BS_ADD_REFLPTR_FIELD(objPtrB, 6);
  170. BS_ADD_REFLPTR_FIELD(objPtrC, 7);
  171. BS_ADD_REFLPTR_FIELD(objPtrD, 8);
  172. BS_ADD_PLAIN_FIELD_ARR(arrStrA, 9);
  173. BS_ADD_PLAIN_FIELD_ARR(arrStrB, 10);
  174. BS_ADD_PLAIN_FIELD_ARR(arrStrC, 11);
  175. BS_ADD_REFL_FIELD_ARR(arrObjA, 12);
  176. BS_ADD_REFL_FIELD_ARR(arrObjB, 13);
  177. BS_ADD_REFLPTR_FIELD_ARR(arrObjPtrA, 14);
  178. BS_ADD_REFLPTR_FIELD_ARR(arrObjPtrB, 15);
  179. }
  180. virtual const String& getRTTIName()
  181. {
  182. static String name = "TestObjectA";
  183. return name;
  184. }
  185. virtual UINT32 getRTTIId()
  186. {
  187. return TID_TestObjectA;
  188. }
  189. virtual std::shared_ptr<IReflectable> newRTTIObject()
  190. {
  191. return bs_shared_ptr<TestObjectA>();
  192. }
  193. };
  194. class TestObjectBRTTI : public RTTIType < TestObjectB, IReflectable, TestObjectBRTTI >
  195. {
  196. private:
  197. BS_PLAIN_MEMBER(intA);
  198. BS_PLAIN_MEMBER(strA);
  199. public:
  200. TestObjectBRTTI()
  201. {
  202. BS_ADD_PLAIN_FIELD(intA, 0);
  203. BS_ADD_PLAIN_FIELD(strA, 1);
  204. }
  205. virtual const String& getRTTIName()
  206. {
  207. static String name = "TestObjectB";
  208. return name;
  209. }
  210. virtual UINT32 getRTTIId()
  211. {
  212. return TID_TestObjectB;
  213. }
  214. virtual std::shared_ptr<IReflectable> newRTTIObject()
  215. {
  216. return bs_shared_ptr<TestObjectB>();
  217. }
  218. };
  219. RTTITypeBase* TestObjectB::getRTTIStatic()
  220. {
  221. return TestObjectBRTTI::instance();
  222. }
  223. RTTITypeBase* TestObjectB::getRTTI() const
  224. {
  225. return TestObjectB::getRTTIStatic();
  226. }
  227. RTTITypeBase* TestObjectA::getRTTIStatic()
  228. {
  229. return TestObjectARTTI::instance();
  230. }
  231. RTTITypeBase* TestObjectA::getRTTI() const
  232. {
  233. return TestObjectA::getRTTIStatic();
  234. }
  235. class TestComponentC : public Component
  236. {
  237. public:
  238. TestObjectA obj;
  239. /************************************************************************/
  240. /* COMPONENT OVERRIDES */
  241. /************************************************************************/
  242. protected:
  243. friend class SceneObject;
  244. TestComponentC(const HSceneObject& parent)
  245. :Component(parent)
  246. {}
  247. /************************************************************************/
  248. /* RTTI */
  249. /************************************************************************/
  250. public:
  251. friend class TestComponentCRTTI;
  252. static RTTITypeBase* getRTTIStatic();
  253. virtual RTTITypeBase* getRTTI() const;
  254. protected:
  255. TestComponentC() {} // Serialization only
  256. };
  257. class TestComponentD : public Component
  258. {
  259. public:
  260. TestObjectB obj;
  261. /************************************************************************/
  262. /* COMPONENT OVERRIDES */
  263. /************************************************************************/
  264. protected:
  265. friend class SceneObject;
  266. TestComponentD(const HSceneObject& parent)
  267. :Component(parent)
  268. {}
  269. /************************************************************************/
  270. /* RTTI */
  271. /************************************************************************/
  272. public:
  273. friend class TestComponentDRTTI;
  274. static RTTITypeBase* getRTTIStatic();
  275. virtual RTTITypeBase* getRTTI() const;
  276. protected:
  277. TestComponentD() {} // Serialization only
  278. };
  279. class TestComponentCRTTI : public RTTIType < TestComponentC, Component, TestComponentCRTTI >
  280. {
  281. private:
  282. BS_REFL_MEMBER(obj)
  283. public:
  284. TestComponentCRTTI()
  285. {
  286. BS_ADD_REFL_FIELD(obj, 0);
  287. }
  288. virtual const String& getRTTIName()
  289. {
  290. static String name = "TestComponentC";
  291. return name;
  292. }
  293. virtual UINT32 getRTTIId()
  294. {
  295. return TID_TestComponentC;
  296. }
  297. virtual std::shared_ptr<IReflectable> newRTTIObject()
  298. {
  299. return GameObjectRTTI::createGameObject<TestComponentC>();
  300. }
  301. };
  302. class TestComponentDRTTI : public RTTIType < TestComponentD, Component, TestComponentDRTTI >
  303. {
  304. private:
  305. BS_REFL_MEMBER(obj)
  306. public:
  307. TestComponentDRTTI()
  308. {
  309. BS_ADD_REFL_FIELD(obj, 0);
  310. }
  311. virtual const String& getRTTIName()
  312. {
  313. static String name = "TestComponentD";
  314. return name;
  315. }
  316. virtual UINT32 getRTTIId()
  317. {
  318. return TID_TestComponentD;
  319. }
  320. virtual std::shared_ptr<IReflectable> newRTTIObject()
  321. {
  322. return GameObjectRTTI::createGameObject<TestComponentD>();
  323. }
  324. };
  325. RTTITypeBase* TestComponentC::getRTTIStatic()
  326. {
  327. return TestComponentCRTTI::instance();
  328. }
  329. RTTITypeBase* TestComponentC::getRTTI() const
  330. {
  331. return TestComponentC::getRTTIStatic();
  332. }
  333. RTTITypeBase* TestComponentD::getRTTIStatic()
  334. {
  335. return TestComponentDRTTI::instance();
  336. }
  337. RTTITypeBase* TestComponentD::getRTTI() const
  338. {
  339. return TestComponentD::getRTTIStatic();
  340. }
  341. EditorTestSuite::EditorTestSuite()
  342. {
  343. BS_ADD_TEST(EditorTestSuite::SceneObjectRecord_UndoRedo);
  344. BS_ADD_TEST(EditorTestSuite::SceneObjectDelete_UndoRedo);
  345. BS_ADD_TEST(EditorTestSuite::BinaryDiff);
  346. BS_ADD_TEST(EditorTestSuite::TestPrefabDiff);
  347. BS_ADD_TEST(EditorTestSuite::TestFrameAlloc)
  348. }
  349. void EditorTestSuite::SceneObjectRecord_UndoRedo()
  350. {
  351. HSceneObject so0_0 = SceneObject::create("so0_0");
  352. HSceneObject so1_0 = SceneObject::create("so1_0");
  353. HSceneObject so1_1 = SceneObject::create("so1_1");
  354. HSceneObject so2_0 = SceneObject::create("so2_0");
  355. so1_0->setParent(so0_0);
  356. so1_1->setParent(so0_0);
  357. so2_0->setParent(so1_0);
  358. GameObjectHandle<TestComponentA> cmpA1_1 = so1_1->addComponent<TestComponentA>();
  359. GameObjectHandle<TestComponentB> cmpB1_1 = so1_1->addComponent<TestComponentB>();
  360. HSceneObject soExternal = SceneObject::create("soExternal");
  361. GameObjectHandle<TestComponentA> cmpExternal = soExternal->addComponent<TestComponentA>();
  362. cmpA1_1->ref1 = so2_0;
  363. cmpA1_1->ref2 = cmpB1_1;
  364. cmpB1_1->ref1 = soExternal;
  365. cmpB1_1->val1 = "InitialValue";
  366. cmpExternal->ref1 = so1_1;
  367. cmpExternal->ref2 = cmpA1_1;
  368. CmdRecordSO::execute(so0_0);
  369. cmpB1_1->val1 = "ModifiedValue";
  370. UndoRedo::instance().undo();
  371. BS_TEST_ASSERT(!so0_0.isDestroyed());
  372. BS_TEST_ASSERT(!so1_0.isDestroyed());
  373. BS_TEST_ASSERT(!so1_1.isDestroyed());
  374. BS_TEST_ASSERT(!so2_0.isDestroyed());
  375. BS_TEST_ASSERT(!cmpA1_1.isDestroyed());
  376. BS_TEST_ASSERT(!cmpB1_1.isDestroyed());
  377. BS_TEST_ASSERT(!cmpA1_1->ref1.isDestroyed());
  378. BS_TEST_ASSERT(!cmpA1_1->ref2.isDestroyed());
  379. BS_TEST_ASSERT(!cmpB1_1->ref1.isDestroyed());
  380. BS_TEST_ASSERT(!cmpExternal->ref1.isDestroyed());
  381. BS_TEST_ASSERT(!cmpExternal->ref2.isDestroyed());
  382. BS_TEST_ASSERT(cmpB1_1->val1 == "InitialValue");
  383. so0_0->destroy();
  384. }
  385. void EditorTestSuite::SceneObjectDelete_UndoRedo()
  386. {
  387. HSceneObject so0_0 = SceneObject::create("so0_0");
  388. HSceneObject so1_0 = SceneObject::create("so1_0");
  389. HSceneObject so1_1 = SceneObject::create("so1_1");
  390. HSceneObject so2_0 = SceneObject::create("so2_0");
  391. so1_0->setParent(so0_0);
  392. so1_1->setParent(so0_0);
  393. so2_0->setParent(so1_0);
  394. GameObjectHandle<TestComponentA> cmpA1_1 = so1_1->addComponent<TestComponentA>();
  395. GameObjectHandle<TestComponentB> cmpB1_1 = so1_1->addComponent<TestComponentB>();
  396. HSceneObject soExternal = SceneObject::create("soExternal");
  397. GameObjectHandle<TestComponentA> cmpExternal = soExternal->addComponent<TestComponentA>();
  398. cmpA1_1->ref1 = so2_0;
  399. cmpA1_1->ref2 = cmpB1_1;
  400. cmpB1_1->ref1 = soExternal;
  401. cmpB1_1->val1 = "InitialValue";
  402. cmpExternal->ref1 = so1_1;
  403. cmpExternal->ref2 = cmpA1_1;
  404. CmdDeleteSO::execute(so0_0);
  405. UndoRedo::instance().undo();
  406. BS_TEST_ASSERT(!so0_0.isDestroyed());
  407. BS_TEST_ASSERT(!so1_0.isDestroyed());
  408. BS_TEST_ASSERT(!so1_1.isDestroyed());
  409. BS_TEST_ASSERT(!so2_0.isDestroyed());
  410. BS_TEST_ASSERT(!cmpA1_1.isDestroyed());
  411. BS_TEST_ASSERT(!cmpB1_1.isDestroyed());
  412. BS_TEST_ASSERT(!cmpA1_1->ref1.isDestroyed());
  413. BS_TEST_ASSERT(!cmpA1_1->ref2.isDestroyed());
  414. BS_TEST_ASSERT(!cmpB1_1->ref1.isDestroyed());
  415. BS_TEST_ASSERT(!cmpExternal->ref1.isDestroyed());
  416. BS_TEST_ASSERT(!cmpExternal->ref2.isDestroyed());
  417. BS_TEST_ASSERT(cmpB1_1->val1 == "InitialValue");
  418. so0_0->destroy();
  419. }
  420. void EditorTestSuite::BinaryDiff()
  421. {
  422. SPtr<TestObjectA> orgObj = bs_shared_ptr<TestObjectA>();
  423. SPtr<TestObjectA> newObj = bs_shared_ptr<TestObjectA>();
  424. newObj->intA = 995;
  425. newObj->strA = "potato";
  426. newObj->arrStrB = { "orange", "carrot" };
  427. newObj->arrStrC[2] = "banana";
  428. newObj->objB.intA = 9940;
  429. newObj->objPtrB->strA = "kiwi";
  430. newObj->objPtrC = nullptr;
  431. newObj->objPtrD = bs_shared_ptr<TestObjectB>();
  432. newObj->arrObjB[1].strA = "strawberry";
  433. newObj->arrObjPtrB[0]->intA = 99100;
  434. MemorySerializer ms;
  435. UINT32 orgDataLength = 0;
  436. UINT8* orgData = ms.encode(orgObj.get(), orgDataLength, &bs_alloc);
  437. UINT32 newDataLength = 0;
  438. UINT8* newData = ms.encode(newObj.get(), newDataLength, &bs_alloc);
  439. BinarySerializer bs;
  440. SPtr<SerializedObject> orgSerialized = bs._decodeIntermediate(orgData, orgDataLength);
  441. SPtr<SerializedObject> newSerialized = bs._decodeIntermediate(newData, newDataLength);
  442. IDiff& diffHandler = orgObj->getRTTI()->getDiffHandler();
  443. SPtr<SerializedObject> objDiff = diffHandler.generateDiff(orgSerialized, newSerialized);
  444. diffHandler.applyDiff(orgObj, objDiff);
  445. bs_free(orgData);
  446. bs_free(newData);
  447. BS_TEST_ASSERT(orgObj->intA == newObj->intA);
  448. BS_TEST_ASSERT(orgObj->strA == newObj->strA);
  449. BS_TEST_ASSERT(orgObj->strB == newObj->strB);
  450. BS_TEST_ASSERT(orgObj->objA.intA == newObj->objA.intA);
  451. BS_TEST_ASSERT(orgObj->objB.intA == newObj->objB.intA);
  452. BS_TEST_ASSERT(orgObj->objPtrA->strA == newObj->objPtrA->strA);
  453. BS_TEST_ASSERT(orgObj->objPtrB->strA == newObj->objPtrB->strA);
  454. BS_TEST_ASSERT(orgObj->objPtrD->strA == newObj->objPtrD->strA);
  455. BS_TEST_ASSERT(orgObj->objPtrC == newObj->objPtrC);
  456. BS_TEST_ASSERT(orgObj->arrStrA.size() == newObj->arrStrA.size());
  457. for (UINT32 i = 0; i < (UINT32)orgObj->arrStrA.size(); i++)
  458. BS_TEST_ASSERT(orgObj->arrStrA[i] == newObj->arrStrA[i]);
  459. BS_TEST_ASSERT(orgObj->arrStrB.size() == newObj->arrStrB.size());
  460. for (UINT32 i = 0; i < (UINT32)orgObj->arrStrB.size(); i++)
  461. BS_TEST_ASSERT(orgObj->arrStrB[i] == newObj->arrStrB[i]);
  462. BS_TEST_ASSERT(orgObj->arrStrC.size() == newObj->arrStrC.size());
  463. for (UINT32 i = 0; i < (UINT32)orgObj->arrStrC.size(); i++)
  464. BS_TEST_ASSERT(orgObj->arrStrC[i] == newObj->arrStrC[i]);
  465. BS_TEST_ASSERT(orgObj->arrObjA.size() == newObj->arrObjA.size());
  466. for (UINT32 i = 0; i < (UINT32)orgObj->arrObjA.size(); i++)
  467. BS_TEST_ASSERT(orgObj->arrObjA[i].strA == newObj->arrObjA[i].strA);
  468. BS_TEST_ASSERT(orgObj->arrObjB.size() == newObj->arrObjB.size());
  469. for (UINT32 i = 0; i < (UINT32)orgObj->arrObjB.size(); i++)
  470. BS_TEST_ASSERT(orgObj->arrObjB[i].strA == newObj->arrObjB[i].strA);
  471. BS_TEST_ASSERT(orgObj->arrObjPtrA.size() == newObj->arrObjPtrA.size());
  472. for (UINT32 i = 0; i < (UINT32)orgObj->arrObjPtrA.size(); i++)
  473. BS_TEST_ASSERT(orgObj->arrObjPtrA[i]->intA == newObj->arrObjPtrA[i]->intA);
  474. BS_TEST_ASSERT(orgObj->arrObjPtrB.size() == newObj->arrObjPtrB.size());
  475. for (UINT32 i = 0; i < (UINT32)orgObj->arrObjPtrB.size(); i++)
  476. BS_TEST_ASSERT(orgObj->arrObjPtrB[i]->intA == newObj->arrObjPtrB[i]->intA);
  477. }
  478. void EditorTestSuite::TestPrefabDiff()
  479. {
  480. HSceneObject root = SceneObject::create("root");
  481. HSceneObject so0 = SceneObject::create("so0");
  482. HSceneObject so1 = SceneObject::create("so1");
  483. HSceneObject so2 = SceneObject::create("so2");
  484. HSceneObject so0_0 = SceneObject::create("so0_0");
  485. HSceneObject so0_1 = SceneObject::create("so0_1");
  486. HSceneObject so1_0 = SceneObject::create("so1_0");
  487. HSceneObject so1_1 = SceneObject::create("so1_1");
  488. HSceneObject so1_2 = SceneObject::create("so1_2");
  489. HSceneObject so2_0 = SceneObject::create("so2_0");
  490. so0->setParent(root);
  491. so1->setParent(root);
  492. so2->setParent(root);
  493. so0_0->setParent(so0);
  494. so0_1->setParent(so0);
  495. so1_0->setParent(so1);
  496. so1_1->setParent(so1);
  497. so1_2->setParent(so1);
  498. so2_0->setParent(so2);
  499. GameObjectHandle<TestComponentC> cmp0 = so0->addComponent<TestComponentC>();
  500. GameObjectHandle<TestComponentC> cmp0_1_A = so0_1->addComponent<TestComponentC>();
  501. GameObjectHandle<TestComponentD> cmp0_1_B = so0_1->addComponent<TestComponentD>();
  502. GameObjectHandle<TestComponentD> cmp1 = so1->addComponent<TestComponentD>();
  503. GameObjectHandle<TestComponentD> cmp1_2 = so1_2->addComponent<TestComponentD>();
  504. GameObjectHandle<TestComponentD> cmp2 = so2->addComponent<TestComponentD>();
  505. HPrefab prefab = Prefab::create(root);
  506. gResources().save(prefab, "C:\\testprefab.asset", true);
  507. // Perform modifications
  508. GameObjectHandle<TestComponentC> cmp1_3;
  509. GameObjectHandle<TestComponentD> cmp3;
  510. HSceneObject so1_3, so2_1, so3;
  511. {
  512. cmp0->obj.strA = "banana";
  513. so0_0->destroy();
  514. cmp0_1_A->destroy();
  515. so1_3 = SceneObject::create("so1_2");
  516. so1_3->setParent(so1);
  517. cmp1_3 = so1_3->addComponent<TestComponentC>();
  518. cmp1_3->obj.intA = 999;
  519. so1_0->setName("apple");
  520. so1_1->destroy();
  521. cmp1_2->destroy();
  522. cmp1_2 = so1_2->addComponent<TestComponentD>();
  523. cmp1_2->obj.strA = "orange";
  524. so2_1 = SceneObject::create("so2_1");
  525. so2_1->setParent(so2);
  526. so2_0->addComponent<TestComponentD>();
  527. so3 = SceneObject::create("so3");
  528. so3->setParent(root);
  529. cmp3 = so3->addComponent<TestComponentD>();
  530. }
  531. SPtr<PrefabDiff> prefabDiff = PrefabDiff::create(prefab->getRoot(), root);
  532. prefab = gResources().load<Prefab>("C:\\testprefab.asset");
  533. HSceneObject newRoot = prefab->instantiate();
  534. prefabDiff->apply(newRoot);
  535. // Compare and assert
  536. BS_TEST_ASSERT(root->getNumChildren() == newRoot->getNumChildren());
  537. HSceneObject nso0 = newRoot->getChild(0);
  538. GameObjectHandle<TestComponentC> ncmp0 = nso0->getComponent<TestComponentC>();
  539. BS_TEST_ASSERT(cmp0->obj.strA == ncmp0->obj.strA);
  540. BS_TEST_ASSERT(so0->getNumChildren() == nso0->getNumChildren());
  541. HSceneObject nso0_1 = nso0->getChild(0);
  542. GameObjectHandle<TestComponentC> ncmp0_1 = nso0_1->getComponent<TestComponentD>();
  543. BS_TEST_ASSERT(ncmp0_1 != nullptr);
  544. HSceneObject nso1 = newRoot->getChild(1);
  545. BS_TEST_ASSERT(so1->getNumChildren() == nso1->getNumChildren());
  546. HSceneObject nso1_0 = nso1->getChild(0);
  547. BS_TEST_ASSERT(so1_0->getName() == nso1_0->getName());
  548. HSceneObject nso1_2 = nso1->getChild(1);
  549. GameObjectHandle<TestComponentD> ncmp1_2 = nso1_2->getComponent<TestComponentD>();
  550. BS_TEST_ASSERT(cmp1_2->obj.strA == ncmp1_2->obj.strA);
  551. HSceneObject nso1_3 = nso1->getChild(2);
  552. GameObjectHandle<TestComponentC> ncmp1_3 = nso1_3->getComponent<TestComponentC>();
  553. BS_TEST_ASSERT(cmp1_3->obj.intA == ncmp1_3->obj.intA);
  554. HSceneObject nso2 = newRoot->getChild(2);
  555. BS_TEST_ASSERT(so2->getNumChildren() == nso2->getNumChildren());
  556. HSceneObject nso2_0 = nso2->getChild(0);
  557. GameObjectHandle<TestComponentD> ncmp2_0 = nso2_0->getComponent<TestComponentD>();
  558. BS_TEST_ASSERT(ncmp2_0 != nullptr);
  559. HSceneObject nso3 = newRoot->getChild(3);
  560. GameObjectHandle<TestComponentD> ncmp3 = nso3->getComponent<TestComponentD>();
  561. BS_TEST_ASSERT(ncmp3 != nullptr);
  562. root->destroy();
  563. }
  564. void EditorTestSuite::TestFrameAlloc()
  565. {
  566. FrameAlloc alloc(128);
  567. alloc.markFrame();
  568. UINT8* a1 = alloc.alloc(5);
  569. UINT8* a2 = alloc.alloc(10);
  570. UINT8* a3 = alloc.alloc(130);
  571. UINT8* a4 = alloc.alloc(5);
  572. alloc.dealloc(a1);
  573. alloc.dealloc(a2);
  574. alloc.dealloc(a3);
  575. alloc.dealloc(a4);
  576. alloc.clear();
  577. alloc.markFrame();
  578. UINT8* a5 = alloc.alloc(5);
  579. UINT8* a6 = alloc.alloc(10);
  580. UINT8* a7 = alloc.alloc(130);
  581. UINT8* a8 = alloc.alloc(5);
  582. alloc.dealloc(a5);
  583. alloc.dealloc(a6);
  584. alloc.dealloc(a7);
  585. alloc.dealloc(a8);
  586. alloc.markFrame();
  587. UINT8* a9 = alloc.alloc(5);
  588. UINT8* a10 = alloc.alloc(10);
  589. UINT8* a11 = alloc.alloc(130);
  590. UINT8* a12 = alloc.alloc(5);
  591. alloc.dealloc(a9);
  592. alloc.dealloc(a10);
  593. alloc.dealloc(a11);
  594. alloc.dealloc(a12);
  595. alloc.clear();
  596. alloc.clear();
  597. UINT8* a13 = alloc.alloc(5);
  598. alloc.dealloc(a13);
  599. alloc.clear();
  600. }
  601. }