PrefabLinkDomTests.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <Prefab/PrefabTestDomUtils.h>
  9. #include <Prefab/Link/PrefabLinkDomTestFixture.h>
  10. namespace UnitTest
  11. {
  12. using PrefabLinkDomTest = PrefabLinkDomTestFixture;
  13. // Mock patches to use for validating tests.
  14. static constexpr const AZStd::string_view patchesValue = R"(
  15. [
  16. {
  17. "op": "add",
  18. "path": "Entities/Entity1/Components/ComponentA/IntValue",
  19. "value": 10
  20. },
  21. {
  22. "op": "remove",
  23. "path": "Entities/Entity2/Components/ComponentB/FloatValue"
  24. },
  25. {
  26. "op": "replace",
  27. "path": "Entities/Entity1/Components/ComponentC/StringValue",
  28. "value": "replacedString"
  29. }
  30. ])";
  31. TEST_F(PrefabLinkDomTest, GetLinkDomRetainsPatchOrder)
  32. {
  33. PrefabDom newLinkDom;
  34. newLinkDom.Parse(R"(
  35. {
  36. "Source": "PathToSourceTemplate"
  37. })");
  38. PrefabDom patchesCopy;
  39. patchesCopy.Parse(patchesValue.data());
  40. newLinkDom.AddMember(rapidjson::StringRef(PrefabDomUtils::PatchesName), AZStd::move(patchesCopy), newLinkDom.GetAllocator());
  41. m_link->SetLinkDom(newLinkDom);
  42. // Get the link DOM and verify that it matches the DOM used for SetLinkDom().
  43. PrefabDom fetchedLinkDom;
  44. m_link->GetLinkDom(fetchedLinkDom, fetchedLinkDom.GetAllocator());
  45. EXPECT_EQ(AZ::JsonSerialization::Compare(newLinkDom, fetchedLinkDom), AZ::JsonSerializerCompareResult::Equal);
  46. }
  47. TEST_F(PrefabLinkDomTest, AddPatchesToLinkRetainsPatchOrder)
  48. {
  49. PrefabDom newLinkDom;
  50. newLinkDom.Parse(R"(
  51. {
  52. "Source": "PathToSourceTemplate"
  53. })");
  54. PrefabDom patchesCopy;
  55. patchesCopy.Parse(patchesValue.data());
  56. m_link->SetLinkPatches(patchesCopy);
  57. newLinkDom.AddMember(rapidjson::StringRef(PrefabDomUtils::PatchesName), AZStd::move(patchesCopy), newLinkDom.GetAllocator());
  58. // Get the link DOM and verify that it matches the DOM used for AddPatchesToLink().
  59. PrefabDom fetchedLinkDom;
  60. m_link->GetLinkDom(fetchedLinkDom, fetchedLinkDom.GetAllocator());
  61. EXPECT_EQ(AZ::JsonSerialization::Compare(newLinkDom, fetchedLinkDom), AZ::JsonSerializerCompareResult::Equal);
  62. }
  63. } // namespace UnitTest