diff --git a/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp b/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp index d489ac2990..f6a913b61d 100644 --- a/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp +++ b/Gems/PhysX/Code/Tests/PhysXColliderPrefabTests.cpp @@ -13,12 +13,12 @@ #include #include + #include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -26,101 +26,164 @@ #include #include #include -#include -#include -#include -#include namespace PhysX { - class PhysXColliderPrefabTest + class PhysXColliderPrefabTests : public ::testing::Test { protected: - void SetUp() override - { - - } - - void TearDown() override - { - - } - - }; - TEST_F(PhysXColliderPrefabTest, JsonStoreAndLoadPhysicsObjectsWithPrefabTest) + TEST_F(PhysXColliderPrefabTests, StoreAndLoad_DefaultPhysicsTypes_ValuesNotNull) { + //create a prefab for storing data AzToolsFramework::Prefab::PrefabDom prefabDom; //material selection Physics::MaterialSelection materialSelection; - AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), materialSelection); + AZ::JsonSerializationResult::ResultCode result + = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), materialSelection); - AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Material Selection", prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); Physics::MaterialSelection newSelection; - AZ::JsonSerialization::Load(newSelection, prefabDom); + result = AZ::JsonSerialization::Load(newSelection, prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); EXPECT_EQ(materialSelection.GetMaterialId(), newSelection.GetMaterialId()); //collider configuration Physics::ColliderConfiguration colliderConfig; - AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), colliderConfig); + result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), colliderConfig); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); - AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Collider Configuration", prefabDom); Physics::ColliderConfiguration newConfig; - AZ::JsonSerialization::Load(newConfig, prefabDom); + result = AZ::JsonSerialization::Load(newConfig, prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); EXPECT_EQ(colliderConfig.m_collisionLayer, newConfig.m_collisionLayer); + } + + TEST_F(PhysXColliderPrefabTests, StoreAndLoad_DefaultPhysicsTypes_PointersNotNull) + { + //create a prefab for storing data + AzToolsFramework::Prefab::PrefabDom prefabDom; //shared pointer - collider configuration - defaults only auto colliderConfigPtr = AZStd::make_shared(); AZ::JsonSerializationResult::ResultCode result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), colliderConfigPtr); - AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Collider Configuration", prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); colliderConfigPtr = nullptr; - AZ::JsonSerialization::Load(colliderConfigPtr, prefabDom); + result = AZ::JsonSerialization::Load(colliderConfigPtr, prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); EXPECT_NE(nullptr, colliderConfigPtr); + //shared pointer - shape configuration - defaults only + auto shapeConfigPtr = AZStd::make_shared(); + result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), shapeConfigPtr); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + + shapeConfigPtr = nullptr; + result = AZ::JsonSerialization::Load(shapeConfigPtr, prefabDom); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + EXPECT_NE(nullptr, shapeConfigPtr); + + + } + + TEST_F(PhysXColliderPrefabTests, StoreAndLoad_NonDefaultPhysicsTypes_PointersNotNull) + { + //create a prefab for storing data + AzToolsFramework::Prefab::PrefabDom prefabDom; + //shared pointer - collider configuration - non default auto updatedColliderConfigPtr = AZStd::make_shared(); updatedColliderConfigPtr->m_isTrigger = true; - AZ::JsonSerializationResult::ResultCode result2 = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), updatedColliderConfigPtr); + AZ::JsonSerializationResult::ResultCode result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), updatedColliderConfigPtr); - AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Collider Configuration", prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); updatedColliderConfigPtr = nullptr; - AZ::JsonSerialization::Load(updatedColliderConfigPtr, prefabDom); + result = AZ::JsonSerialization::Load(updatedColliderConfigPtr, prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); EXPECT_NE(nullptr, updatedColliderConfigPtr); - //shared pointer - shape configuration - defaults only - auto shapeConfigPtr = AZStd::make_shared(); - AZ::JsonSerializationResult::ResultCode result3 = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), shapeConfigPtr); - - AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Shape Configuration", prefabDom); - - shapeConfigPtr = nullptr; - AZ::JsonSerialization::Load(shapeConfigPtr, prefabDom); - - EXPECT_NE(nullptr, shapeConfigPtr); - //shared pointer - shape configuration - non default auto updatedShapeConfigPtr = AZStd::make_shared(); updatedShapeConfigPtr->m_radius = 2.0f; - AZ::JsonSerializationResult::ResultCode result4 = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), updatedShapeConfigPtr); + result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), updatedShapeConfigPtr); - AzToolsFramework::Prefab::PrefabDomUtils::PrintPrefabDomValue("Shape Configuration", prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); updatedShapeConfigPtr = nullptr; - AZ::JsonSerialization::Load(updatedShapeConfigPtr, prefabDom); + result = AZ::JsonSerialization::Load(updatedShapeConfigPtr, prefabDom); + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); EXPECT_NE(nullptr, updatedColliderConfigPtr); } + + TEST_F(PhysXColliderPrefabTests, StoreAndLoad_DefaultPhysicsColliderComponents_PointersNotNull) + { + //create a prefab for storing data + AzToolsFramework::Prefab::PrefabDom prefabDom; + + //shared pointer - box collider - defaults only + auto boxColliderPtr = AZStd::make_shared(); + AZ::JsonSerializationResult::ResultCode result + = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), boxColliderPtr); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + + boxColliderPtr = nullptr; + result = AZ::JsonSerialization::Load(boxColliderPtr, prefabDom); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + EXPECT_NE(nullptr, boxColliderPtr); + + //shared pointer - sphere collider - defaults only + auto sphereColliderPtr = AZStd::make_shared(); + result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), sphereColliderPtr); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + + sphereColliderPtr = nullptr; + result = AZ::JsonSerialization::Load(sphereColliderPtr, prefabDom); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + EXPECT_NE(nullptr, sphereColliderPtr); + + //shared pointer - capsule collider - defaults only + auto capsuleColliderPtr = AZStd::make_shared(); + result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), capsuleColliderPtr); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + + capsuleColliderPtr = nullptr; + result = AZ::JsonSerialization::Load(capsuleColliderPtr, prefabDom); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + EXPECT_NE(nullptr, capsuleColliderPtr); + + //shared pointer - shape collider - defaults only + auto shapeColliderPtr = AZStd::make_shared(); + result = AZ::JsonSerialization::Store(prefabDom, prefabDom.GetAllocator(), shapeColliderPtr); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + + shapeColliderPtr = nullptr; + result = AZ::JsonSerialization::Load(shapeColliderPtr, prefabDom); + + EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, result.GetProcessing()); + EXPECT_NE(nullptr, shapeColliderPtr); + } }