DomPatchTests.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/DOM/DomPatch.h>
  9. #include <AzCore/DOM/DomComparison.h>
  10. #include <Tests/DOM/DomFixtures.h>
  11. namespace AZ::Dom::Tests
  12. {
  13. class DomPatchTests : public DomTestFixture
  14. {
  15. public:
  16. void SetUp() override
  17. {
  18. DomTestFixture::SetUp();
  19. m_dataset = Value(Type::Object);
  20. m_dataset["arr"].SetArray();
  21. m_dataset["node"].SetNode("SomeNode");
  22. m_dataset["node"]["int"] = 5;
  23. m_dataset["node"]["null"] = Value();
  24. for (int i = 0; i < 5; ++i)
  25. {
  26. m_dataset["arr"].ArrayPushBack(Value(i));
  27. m_dataset["node"].ArrayPushBack(Value(i * 2));
  28. }
  29. m_dataset["obj"].SetObject();
  30. m_dataset["obj"]["foo"] = true;
  31. m_dataset["obj"]["bar"] = false;
  32. m_deltaDataset = m_dataset;
  33. }
  34. void TearDown() override
  35. {
  36. m_dataset = m_deltaDataset = Value();
  37. DomTestFixture::TearDown();
  38. }
  39. PatchUndoRedoInfo GenerateAndVerifyDelta()
  40. {
  41. PatchUndoRedoInfo info = GenerateHierarchicalDeltaPatch(m_dataset, m_deltaDataset);
  42. auto result = info.m_forwardPatches.Apply(m_dataset);
  43. EXPECT_TRUE(result.IsSuccess());
  44. EXPECT_TRUE(Utils::DeepCompareIsEqual(result.GetValue(), m_deltaDataset));
  45. result = info.m_inversePatches.Apply(result.GetValue());
  46. EXPECT_TRUE(result.IsSuccess());
  47. EXPECT_TRUE(Utils::DeepCompareIsEqual(result.GetValue(), m_dataset));
  48. // Verify serialization of the patches
  49. auto VerifySerialization = [](const Patch& patch)
  50. {
  51. Value serializedPatch = patch.GetDomRepresentation();
  52. auto deserializePatchResult = Patch::CreateFromDomRepresentation(serializedPatch);
  53. EXPECT_TRUE(deserializePatchResult.IsSuccess());
  54. EXPECT_EQ(deserializePatchResult.GetValue(), patch);
  55. };
  56. VerifySerialization(info.m_forwardPatches);
  57. VerifySerialization(info.m_inversePatches);
  58. return info;
  59. }
  60. Value m_dataset;
  61. Value m_deltaDataset;
  62. };
  63. TEST_F(DomPatchTests, AddOperation_InsertInObject_Succeeds)
  64. {
  65. Path p("/obj/baz");
  66. PatchOperation op = PatchOperation::AddOperation(p, Value(42));
  67. auto result = op.Apply(m_dataset);
  68. ASSERT_TRUE(result.IsSuccess());
  69. EXPECT_EQ(result.GetValue()[p].GetInt64(), 42);
  70. }
  71. TEST_F(DomPatchTests, AddOperation_ReplaceInObject_Succeeds)
  72. {
  73. Path p("/obj/foo");
  74. PatchOperation op = PatchOperation::AddOperation(p, Value(false));
  75. auto result = op.Apply(m_dataset);
  76. ASSERT_TRUE(result.IsSuccess());
  77. EXPECT_EQ(result.GetValue()[p].GetBool(), false);
  78. }
  79. TEST_F(DomPatchTests, AddOperation_InsertObjectKeyInArray_Fails)
  80. {
  81. Path p("/arr/key");
  82. PatchOperation op = PatchOperation::AddOperation(p, Value(999));
  83. auto result = op.Apply(m_dataset);
  84. ASSERT_FALSE(result.IsSuccess());
  85. }
  86. TEST_F(DomPatchTests, AddOperation_AppendInArray_Succeeds)
  87. {
  88. Path p("/arr/-");
  89. PatchOperation op = PatchOperation::AddOperation(p, Value(42));
  90. auto result = op.Apply(m_dataset);
  91. ASSERT_TRUE(result.IsSuccess());
  92. EXPECT_EQ(result.GetValue()["arr"][5].GetInt64(), 42);
  93. }
  94. TEST_F(DomPatchTests, AddOperation_InsertKeyInNode_Succeeds)
  95. {
  96. Path p("/node/attr");
  97. PatchOperation op = PatchOperation::AddOperation(p, Value(500));
  98. auto result = op.Apply(m_dataset);
  99. ASSERT_TRUE(result.IsSuccess());
  100. EXPECT_EQ(result.GetValue()[p].GetInt64(), 500);
  101. }
  102. TEST_F(DomPatchTests, AddOperation_ReplaceIndexInNode_Succeeds)
  103. {
  104. Path p("/node/0");
  105. PatchOperation op = PatchOperation::AddOperation(p, Value(42));
  106. auto result = op.Apply(m_dataset);
  107. ASSERT_TRUE(result.IsSuccess());
  108. EXPECT_EQ(result.GetValue()[p].GetInt64(), 42);
  109. }
  110. TEST_F(DomPatchTests, AddOperation_AppendInNode_Succeeds)
  111. {
  112. Path p("/node/-");
  113. PatchOperation op = PatchOperation::AddOperation(p, Value(42));
  114. auto result = op.Apply(m_dataset);
  115. ASSERT_TRUE(result.IsSuccess());
  116. EXPECT_EQ(result.GetValue()["node"][5].GetInt64(), 42);
  117. }
  118. TEST_F(DomPatchTests, AddOperation_InvalidPath_Fails)
  119. {
  120. Path p("/non/existent/path");
  121. PatchOperation op = PatchOperation::AddOperation(p, Value(0));
  122. auto result = op.Apply(m_dataset);
  123. ASSERT_FALSE(result.IsSuccess());
  124. }
  125. TEST_F(DomPatchTests, RemoveOperation_RemoveKeyFromObject_Succeeds)
  126. {
  127. Path p("/obj/foo");
  128. PatchOperation op = PatchOperation::RemoveOperation(p);
  129. auto result = op.Apply(m_dataset);
  130. ASSERT_TRUE(result.IsSuccess());
  131. EXPECT_FALSE(result.GetValue()["obj"].HasMember("foo"));
  132. }
  133. TEST_F(DomPatchTests, RemoveOperation_RemoveIndexFromArray_Succeeds)
  134. {
  135. Path p("/arr/0");
  136. PatchOperation op = PatchOperation::RemoveOperation(p);
  137. auto result = op.Apply(m_dataset);
  138. ASSERT_TRUE(result.IsSuccess());
  139. EXPECT_EQ(result.GetValue()["arr"].ArraySize(), 4);
  140. EXPECT_EQ(result.GetValue()["arr"][0].GetInt64(), 1);
  141. }
  142. TEST_F(DomPatchTests, RemoveOperation_PopArray_Fails)
  143. {
  144. Path p("/arr/-");
  145. PatchOperation op = PatchOperation::RemoveOperation(p);
  146. auto result = op.Apply(m_dataset);
  147. ASSERT_FALSE(result.IsSuccess());
  148. }
  149. TEST_F(DomPatchTests, RemoveOperation_RemoveKeyFromNode_Succeeds)
  150. {
  151. Path p("/node/int");
  152. PatchOperation op = PatchOperation::RemoveOperation(p);
  153. auto result = op.Apply(m_dataset);
  154. ASSERT_TRUE(result.IsSuccess());
  155. EXPECT_FALSE(result.GetValue()["node"].HasMember("int"));
  156. }
  157. TEST_F(DomPatchTests, RemoveOperation_RemoveIndexFromNode_Succeeds)
  158. {
  159. Path p("/node/1");
  160. PatchOperation op = PatchOperation::RemoveOperation(p);
  161. auto result = op.Apply(m_dataset);
  162. ASSERT_TRUE(result.IsSuccess());
  163. EXPECT_EQ(result.GetValue()["node"].ArraySize(), 4);
  164. EXPECT_EQ(result.GetValue()["node"][1].GetInt64(), 4);
  165. }
  166. TEST_F(DomPatchTests, RemoveOperation_PopIndexFromNode_Fails)
  167. {
  168. Path p("/node/-");
  169. PatchOperation op = PatchOperation::RemoveOperation(p);
  170. auto result = op.Apply(m_dataset);
  171. ASSERT_FALSE(result.IsSuccess());
  172. }
  173. TEST_F(DomPatchTests, RemoveOperation_RemoveKeyFromArray_Fails)
  174. {
  175. Path p("/arr/foo");
  176. PatchOperation op = PatchOperation::RemoveOperation(p);
  177. auto result = op.Apply(m_dataset);
  178. ASSERT_FALSE(result.IsSuccess());
  179. }
  180. TEST_F(DomPatchTests, RemoveOperation_InvalidPath_Fails)
  181. {
  182. Path p("/non/existent/path");
  183. PatchOperation op = PatchOperation::RemoveOperation(p);
  184. auto result = op.Apply(m_dataset);
  185. ASSERT_FALSE(result.IsSuccess());
  186. }
  187. TEST_F(DomPatchTests, ReplaceOperation_InsertInObject_Fails)
  188. {
  189. Path p("/obj/baz");
  190. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(42));
  191. auto result = op.Apply(m_dataset);
  192. ASSERT_FALSE(result.IsSuccess());
  193. }
  194. TEST_F(DomPatchTests, ReplaceOperation_ReplaceInObject_Succeeds)
  195. {
  196. Path p("/obj/foo");
  197. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(false));
  198. auto result = op.Apply(m_dataset);
  199. ASSERT_TRUE(result.IsSuccess());
  200. EXPECT_EQ(result.GetValue()[p].GetBool(), false);
  201. }
  202. TEST_F(DomPatchTests, ReplaceOperation_InsertObjectKeyInArray_Fails)
  203. {
  204. Path p("/arr/key");
  205. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(999));
  206. auto result = op.Apply(m_dataset);
  207. ASSERT_FALSE(result.IsSuccess());
  208. }
  209. TEST_F(DomPatchTests, ReplaceOperation_AppendInArray_Fails)
  210. {
  211. Path p("/arr/-");
  212. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(42));
  213. auto result = op.Apply(m_dataset);
  214. ASSERT_FALSE(result.IsSuccess());
  215. }
  216. TEST_F(DomPatchTests, ReplaceOperation_InsertKeyInNode_Fails)
  217. {
  218. Path p("/node/attr");
  219. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(500));
  220. auto result = op.Apply(m_dataset);
  221. ASSERT_FALSE(result.IsSuccess());
  222. }
  223. TEST_F(DomPatchTests, ReplaceOperation_ReplaceIndexInNode_Succeeds)
  224. {
  225. Path p("/node/0");
  226. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(42));
  227. auto result = op.Apply(m_dataset);
  228. ASSERT_TRUE(result.IsSuccess());
  229. EXPECT_EQ(result.GetValue()[p].GetInt64(), 42);
  230. }
  231. TEST_F(DomPatchTests, ReplaceOperation_AppendInNode_Fails)
  232. {
  233. Path p("/node/-");
  234. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(42));
  235. auto result = op.Apply(m_dataset);
  236. ASSERT_FALSE(result.IsSuccess());
  237. }
  238. TEST_F(DomPatchTests, ReplaceOperation_InvalidPath_Fails)
  239. {
  240. Path p("/non/existent/path");
  241. PatchOperation op = PatchOperation::ReplaceOperation(p, Value(0));
  242. auto result = op.Apply(m_dataset);
  243. ASSERT_FALSE(result.IsSuccess());
  244. }
  245. TEST_F(DomPatchTests, CopyOperation_ArrayToObject_Succeeds)
  246. {
  247. Path dest("/obj/arr");
  248. Path src("/arr");
  249. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  250. auto result = op.Apply(m_dataset);
  251. ASSERT_TRUE(result.IsSuccess());
  252. EXPECT_TRUE(Utils::DeepCompareIsEqual(m_dataset[src], result.GetValue()[dest]));
  253. EXPECT_TRUE(Utils::DeepCompareIsEqual(result.GetValue()[src], result.GetValue()[dest]));
  254. }
  255. TEST_F(DomPatchTests, CopyOperation_ObjectToArrayInRange_Succeeds)
  256. {
  257. Path dest("/arr/0");
  258. Path src("/obj");
  259. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  260. auto result = op.Apply(m_dataset);
  261. ASSERT_TRUE(result.IsSuccess());
  262. EXPECT_TRUE(Utils::DeepCompareIsEqual(m_dataset[src], result.GetValue()[dest]));
  263. EXPECT_TRUE(Utils::DeepCompareIsEqual(result.GetValue()[src], result.GetValue()[dest]));
  264. }
  265. TEST_F(DomPatchTests, CopyOperation_ObjectToArrayOutOfRange_Fails)
  266. {
  267. Path dest("/arr/5");
  268. Path src("/obj");
  269. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  270. auto result = op.Apply(m_dataset);
  271. ASSERT_FALSE(result.IsSuccess());
  272. }
  273. TEST_F(DomPatchTests, CopyOperation_ObjectToNodeChildInRange_Succeeds)
  274. {
  275. Path dest("/node/0");
  276. Path src("/obj");
  277. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  278. auto result = op.Apply(m_dataset);
  279. ASSERT_TRUE(result.IsSuccess());
  280. EXPECT_TRUE(Utils::DeepCompareIsEqual(m_dataset[src], result.GetValue()[dest]));
  281. EXPECT_TRUE(Utils::DeepCompareIsEqual(result.GetValue()[src], result.GetValue()[dest]));
  282. }
  283. TEST_F(DomPatchTests, CopyOperation_ObjectToNodeChildOutOfRange_Fails)
  284. {
  285. Path dest("/node/5");
  286. Path src("/obj");
  287. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  288. auto result = op.Apply(m_dataset);
  289. ASSERT_FALSE(result.IsSuccess());
  290. }
  291. TEST_F(DomPatchTests, CopyOperation_InvalidSourcePath_Fails)
  292. {
  293. Path dest("/node/0");
  294. Path src("/invalid/path");
  295. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  296. auto result = op.Apply(m_dataset);
  297. ASSERT_FALSE(result.IsSuccess());
  298. }
  299. TEST_F(DomPatchTests, CopyOperation_InvalidDestinationPath_Fails)
  300. {
  301. Path dest("/invalid/path");
  302. Path src("/arr/0");
  303. PatchOperation op = PatchOperation::CopyOperation(dest, src);
  304. auto result = op.Apply(m_dataset);
  305. ASSERT_FALSE(result.IsSuccess());
  306. }
  307. TEST_F(DomPatchTests, MoveOperation_ArrayToObject_Succeeds)
  308. {
  309. Path dest("/obj/arr");
  310. Path src("/arr");
  311. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  312. auto result = op.Apply(m_dataset);
  313. ASSERT_TRUE(result.IsSuccess());
  314. EXPECT_TRUE(Utils::DeepCompareIsEqual(m_dataset[src], result.GetValue()[dest]));
  315. EXPECT_FALSE(result.GetValue().HasMember("arr"));
  316. }
  317. TEST_F(DomPatchTests, MoveOperation_ObjectToArrayInRange_Succeeds)
  318. {
  319. Path dest("/arr/0");
  320. Path src("/obj");
  321. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  322. auto result = op.Apply(m_dataset);
  323. ASSERT_TRUE(result.IsSuccess());
  324. EXPECT_TRUE(Utils::DeepCompareIsEqual(m_dataset[src], result.GetValue()[dest]));
  325. EXPECT_FALSE(result.GetValue().HasMember("obj"));
  326. }
  327. TEST_F(DomPatchTests, MoveOperation_ObjectToArrayOutOfRange_Fails)
  328. {
  329. Path dest("/arr/5");
  330. Path src("/obj");
  331. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  332. auto result = op.Apply(m_dataset);
  333. ASSERT_FALSE(result.IsSuccess());
  334. }
  335. TEST_F(DomPatchTests, MoveOperation_ObjectToNodeChildInRange_Succeeds)
  336. {
  337. Path dest("/node/0");
  338. Path src("/obj");
  339. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  340. auto result = op.Apply(m_dataset);
  341. ASSERT_TRUE(result.IsSuccess());
  342. EXPECT_TRUE(Utils::DeepCompareIsEqual(m_dataset[src], result.GetValue()[dest]));
  343. EXPECT_FALSE(result.GetValue().HasMember("obj"));
  344. }
  345. TEST_F(DomPatchTests, MoveOperation_ObjectToNodeChildOutOfRange_Fails)
  346. {
  347. Path dest("/node/5");
  348. Path src("/obj");
  349. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  350. auto result = op.Apply(m_dataset);
  351. ASSERT_FALSE(result.IsSuccess());
  352. }
  353. TEST_F(DomPatchTests, MoveOperation_InvalidSourcePath_Fails)
  354. {
  355. Path dest("/node/0");
  356. Path src("/invalid/path");
  357. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  358. auto result = op.Apply(m_dataset);
  359. ASSERT_FALSE(result.IsSuccess());
  360. }
  361. TEST_F(DomPatchTests, MoveOperation_InvalidDestinationPath_Fails)
  362. {
  363. Path dest("/invalid/path");
  364. Path src("/arr/0");
  365. PatchOperation op = PatchOperation::MoveOperation(dest, src);
  366. auto result = op.Apply(m_dataset);
  367. ASSERT_FALSE(result.IsSuccess());
  368. }
  369. TEST_F(DomPatchTests, TestOperation_TestCorrectValue_Succeeds)
  370. {
  371. Path path("/arr/1");
  372. Value value(1);
  373. PatchOperation op = PatchOperation::TestOperation(path, value);
  374. auto result = op.Apply(m_dataset);
  375. ASSERT_TRUE(result.IsSuccess());
  376. }
  377. TEST_F(DomPatchTests, TestOperation_TestIncorrectValue_Fails)
  378. {
  379. Path path("/arr/1");
  380. Value value(55);
  381. PatchOperation op = PatchOperation::TestOperation(path, value);
  382. auto result = op.Apply(m_dataset);
  383. ASSERT_FALSE(result.IsSuccess());
  384. }
  385. TEST_F(DomPatchTests, TestOperation_TestCorrectComplexValue_Succeeds)
  386. {
  387. Path path;
  388. Value value = m_dataset;
  389. PatchOperation op = PatchOperation::TestOperation(path, value);
  390. auto result = op.Apply(m_dataset);
  391. ASSERT_TRUE(result.IsSuccess());
  392. }
  393. TEST_F(DomPatchTests, TestOperation_TestIncorrectComplexValue_Fails)
  394. {
  395. Path path;
  396. Value value = m_dataset;
  397. value["arr"][4] = 9;
  398. PatchOperation op = PatchOperation::TestOperation(path, value);
  399. auto result = op.Apply(m_dataset);
  400. ASSERT_FALSE(result.IsSuccess());
  401. }
  402. TEST_F(DomPatchTests, TestOperation_TestInvalidPath_Fails)
  403. {
  404. Path path("/invalid/path");
  405. Value value;
  406. PatchOperation op = PatchOperation::TestOperation(path, value);
  407. auto result = op.Apply(m_dataset);
  408. ASSERT_FALSE(result.IsSuccess());
  409. }
  410. TEST_F(DomPatchTests, TestOperation_TestInsertArrayPath_Fails)
  411. {
  412. Path path("/arr/-");
  413. Value value(4);
  414. PatchOperation op = PatchOperation::TestOperation(path, value);
  415. auto result = op.Apply(m_dataset);
  416. ASSERT_FALSE(result.IsSuccess());
  417. }
  418. TEST_F(DomPatchTests, TestPatch_ReplaceArrayValue)
  419. {
  420. m_deltaDataset["arr"][0] = 5;
  421. GenerateAndVerifyDelta();
  422. }
  423. TEST_F(DomPatchTests, TestPatch_AppendArrayValue)
  424. {
  425. m_deltaDataset["arr"].ArrayPushBack(Value(7));
  426. auto result = GenerateAndVerifyDelta();
  427. // Ensure the generated patch uses the array append operation
  428. ASSERT_EQ(result.m_forwardPatches.Size(), 1);
  429. EXPECT_TRUE(result.m_forwardPatches[0].GetDestinationPath()[1].IsEndOfArray());
  430. }
  431. TEST_F(DomPatchTests, TestPatch_AppendArrayValues)
  432. {
  433. m_deltaDataset["arr"].ArrayPushBack(Value(7));
  434. m_deltaDataset["arr"].ArrayPushBack(Value(8));
  435. m_deltaDataset["arr"].ArrayPushBack(Value(9));
  436. GenerateAndVerifyDelta();
  437. }
  438. TEST_F(DomPatchTests, TestPatch_InsertArrayValue)
  439. {
  440. auto& arr = m_deltaDataset["arr"].GetMutableArray();
  441. arr.insert(arr.begin(), Value(42));
  442. GenerateAndVerifyDelta();
  443. }
  444. TEST_F(DomPatchTests, TestPatch_InsertObjectKey)
  445. {
  446. m_deltaDataset["obj"]["newKey"].CopyFromString("test");
  447. GenerateAndVerifyDelta();
  448. }
  449. TEST_F(DomPatchTests, TestPatch_DeleteObjectKey)
  450. {
  451. m_deltaDataset["obj"].RemoveMember("foo");
  452. GenerateAndVerifyDelta();
  453. }
  454. TEST_F(DomPatchTests, TestPatch_AppendNodeValues)
  455. {
  456. m_deltaDataset["node"].ArrayPushBack(Value(7));
  457. m_deltaDataset["node"].ArrayPushBack(Value(8));
  458. m_deltaDataset["node"].ArrayPushBack(Value(9));
  459. GenerateAndVerifyDelta();
  460. }
  461. TEST_F(DomPatchTests, TestPatch_InsertNodeValue)
  462. {
  463. auto& node = m_deltaDataset["node"].GetMutableNode();
  464. node.GetChildren().insert(node.GetChildren().begin(), Value(42));
  465. GenerateAndVerifyDelta();
  466. }
  467. TEST_F(DomPatchTests, TestPatch_InsertNodeKey)
  468. {
  469. m_deltaDataset["node"]["newKey"].CopyFromString("test");
  470. GenerateAndVerifyDelta();
  471. }
  472. TEST_F(DomPatchTests, TestPatch_DeleteNodeKey)
  473. {
  474. m_deltaDataset["node"].RemoveMember("int");
  475. GenerateAndVerifyDelta();
  476. }
  477. TEST_F(DomPatchTests, TestPatch_RenameNode)
  478. {
  479. m_deltaDataset["node"].SetNodeName("RenamedNode");
  480. GenerateAndVerifyDelta();
  481. }
  482. TEST_F(DomPatchTests, TestPatch_ReplaceRoot)
  483. {
  484. m_deltaDataset = Value(Type::Array);
  485. m_deltaDataset.ArrayPushBack(Value(2));
  486. m_deltaDataset.ArrayPushBack(Value(4));
  487. m_deltaDataset.ArrayPushBack(Value(6));
  488. GenerateAndVerifyDelta();
  489. }
  490. TEST_F(DomPatchTests, TestPatch_DenormalizeOnApply)
  491. {
  492. m_dataset = Value(Type::Array);
  493. m_dataset.ArrayPushBack(Value(2));
  494. m_deltaDataset = m_dataset;
  495. m_deltaDataset.ArrayPushBack(Value(4));
  496. DeltaPatchGenerationParameters params;
  497. params.m_generateDenormalizedPaths = false;
  498. PatchUndoRedoInfo info = GenerateHierarchicalDeltaPatch(m_dataset, m_deltaDataset, params);
  499. EXPECT_TRUE(info.m_forwardPatches.ContainsNormalizedEntries());
  500. auto result = info.m_forwardPatches.ApplyAndDenormalize(m_dataset);
  501. EXPECT_TRUE(result.IsSuccess());
  502. EXPECT_TRUE(Utils::DeepCompareIsEqual(result.GetValue(), m_deltaDataset));
  503. EXPECT_FALSE(info.m_forwardPatches.ContainsNormalizedEntries());
  504. }
  505. } // namespace AZ::Dom::Tests