SceneImporterUtilitiesTests.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/std/smart_ptr/make_shared.h>
  9. #include <AzCore/std/smart_ptr/shared_ptr.h>
  10. #include <AzTest/AzTest.h>
  11. #include <SceneAPI/SceneBuilder/Importers/ImporterUtilities.h>
  12. #include <SceneAPI/SceneCore/Containers/Scene.h>
  13. #include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
  14. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  15. #include <SceneAPI/SceneData/GraphData/BoneData.h>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace SceneBuilder
  21. {
  22. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_EmptySceneGraphs_ReturnsTrue)
  23. {
  24. Containers::SceneGraph lhsGraph;
  25. Containers::SceneGraph rhsGraph;
  26. bool sceneGraphsEqual =
  27. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  28. EXPECT_TRUE(sceneGraphsEqual);
  29. }
  30. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_SameNameSingleNodeBothNull_ReturnsTrue)
  31. {
  32. Containers::SceneGraph lhsGraph;
  33. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild");
  34. Containers::SceneGraph rhsGraph;
  35. rhsGraph.AddChild(rhsGraph.GetRoot(), "testChild");
  36. bool sceneGraphsEqual =
  37. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  38. EXPECT_TRUE(sceneGraphsEqual);
  39. }
  40. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_SameNameSingleNodeSameType_ReturnsTrue)
  41. {
  42. Containers::SceneGraph lhsGraph;
  43. AZStd::shared_ptr<DataTypes::IGraphObject> lhsData = AZStd::make_shared<SceneData::GraphData::MeshData>();
  44. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild", AZStd::move(lhsData));
  45. Containers::SceneGraph rhsGraph;
  46. AZStd::shared_ptr<DataTypes::IGraphObject> rhsData = AZStd::make_shared<SceneData::GraphData::MeshData>();
  47. rhsGraph.AddChild(rhsGraph.GetRoot(), "testChild", AZStd::move(rhsData));
  48. bool sceneGraphsEqual =
  49. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  50. EXPECT_TRUE(sceneGraphsEqual);
  51. }
  52. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_SameNameSingleNodeOneNull_ReturnsFalse)
  53. {
  54. Containers::SceneGraph lhsGraph;
  55. AZStd::shared_ptr<DataTypes::IGraphObject> lhsData = AZStd::make_shared<SceneData::GraphData::MeshData>();
  56. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild", AZStd::move(lhsData));
  57. Containers::SceneGraph rhsGraph;
  58. rhsGraph.AddChild(rhsGraph.GetRoot(), "testChild");
  59. bool sceneGraphsEqual =
  60. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  61. EXPECT_FALSE(sceneGraphsEqual);
  62. }
  63. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_SameNameSingleNodeDifferentTypes_ReturnsFalse)
  64. {
  65. Containers::SceneGraph lhsGraph;
  66. AZStd::shared_ptr<DataTypes::IGraphObject> lhsData = AZStd::make_shared<SceneData::GraphData::MeshData>();
  67. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild", AZStd::move(lhsData));
  68. Containers::SceneGraph rhsGraph;
  69. AZStd::shared_ptr<DataTypes::IGraphObject> rhsData = AZStd::make_shared<SceneData::GraphData::BoneData>();
  70. rhsGraph.AddChild(rhsGraph.GetRoot(), "testChild", AZStd::move(rhsData));
  71. bool sceneGraphsEqual =
  72. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  73. EXPECT_FALSE(sceneGraphsEqual);
  74. }
  75. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_SameNameOneEmptyOneSingleNode_ReturnsFalse)
  76. {
  77. Containers::SceneGraph lhsGraph;
  78. AZStd::shared_ptr<DataTypes::IGraphObject> lhsData = AZStd::make_shared<SceneData::GraphData::MeshData>();
  79. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild", AZStd::move(lhsData));
  80. Containers::SceneGraph rhsGraph;
  81. bool sceneGraphsEqual =
  82. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  83. EXPECT_FALSE(sceneGraphsEqual);
  84. }
  85. TEST(SceneImpoterUtilityTests, AreSceneGraphsEqual_DifferentNamesSingleNodeBothNull_ReturnsFalse)
  86. {
  87. Containers::SceneGraph lhsGraph;
  88. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild");
  89. Containers::SceneGraph rhsGraph;
  90. rhsGraph.AddChild(rhsGraph.GetRoot(), "differentName");
  91. bool sceneGraphsEqual =
  92. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  93. EXPECT_FALSE(sceneGraphsEqual);
  94. }
  95. TEST(SceneImporterUtilityTests, AreSceneGraphsEqual_SecondGraphExtraChild_ReturnsFalse)
  96. {
  97. Containers::SceneGraph lhsGraph;
  98. lhsGraph.AddChild(lhsGraph.GetRoot(), "testChild");
  99. lhsGraph.AddChild(lhsGraph.GetRoot(), "extraTestChild");
  100. Containers::SceneGraph rhsGraph;
  101. rhsGraph.AddChild(rhsGraph.GetRoot(), "testChild");
  102. bool sceneGraphsEqual =
  103. (AreSceneGraphsEqual(lhsGraph, rhsGraph) && AreSceneGraphsEqual(rhsGraph, lhsGraph));
  104. EXPECT_FALSE(sceneGraphsEqual);
  105. }
  106. } // namespace SceneBuilder
  107. } // namespace SceneAPI
  108. } // namespace AZ