Update storage of Prefab Dom info to be best effort (#2862)
* Update storage of Prefab Dom info to be best effort Signed-off-by: sconel <sconel@amazon.com> * Update IssueReporter to Skipped instead of PartialSkip Signed-off-by: sconel <sconel@amazon.com> * Address PR feedback Signed-off-by: sconel <sconel@amazon.com> * Fix failing Prefab Unit Test that expected default values to be stripped Signed-off-by: sconel <sconel@amazon.com>
This commit is contained in:
+93
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <Prefab/PrefabTestDomUtils.h>
|
||||
#include <Prefab/PrefabTestFixture.h>
|
||||
#include <Prefab/PrefabTestComponent.h>
|
||||
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Component/ComponentApplicationBus.h>
|
||||
@@ -18,6 +19,98 @@ namespace UnitTest
|
||||
{
|
||||
using PrefabInstanceToTemplateTests = PrefabTestFixture;
|
||||
|
||||
TEST_F(PrefabInstanceToTemplateTests, GenerateEntityDom_InvalidType_InvalidTypeSkipped)
|
||||
{
|
||||
const char* newEntityName = "New Entity";
|
||||
AZ::Entity* newEntity = CreateEntity(newEntityName, false);
|
||||
ASSERT_TRUE(newEntity);
|
||||
|
||||
// Add a component with a member that is missing reflection info
|
||||
// and a member that is properly reflected
|
||||
PrefabTestComponentWithUnReflectedTypeMember* newComponent =
|
||||
newEntity->CreateComponent<PrefabTestComponentWithUnReflectedTypeMember>();
|
||||
|
||||
ASSERT_TRUE(newComponent);
|
||||
|
||||
AZStd::unique_ptr<Instance> prefabInstance = m_prefabSystemComponent->CreatePrefab({ newEntity }, {}, "test/path");
|
||||
ASSERT_TRUE(prefabInstance);
|
||||
|
||||
PrefabDom entityDom;
|
||||
m_instanceToTemplateInterface->GenerateDomForEntity(entityDom, *newEntity);
|
||||
|
||||
auto componentListDom = entityDom.FindMember("Components");
|
||||
|
||||
// Confirm that there is only one component in the entityDom
|
||||
ASSERT_NE(componentListDom, entityDom.MemberEnd());
|
||||
ASSERT_TRUE(componentListDom->value.IsObject());
|
||||
ASSERT_EQ(componentListDom->value.MemberCount(), 1);
|
||||
|
||||
auto testComponentDom = componentListDom->value.MemberBegin();
|
||||
ASSERT_TRUE(testComponentDom->value.IsObject());
|
||||
|
||||
// Confirm that the componentDom does not contained the invalid UnReflectedType
|
||||
// We want to skip over it and produce a best effort entityDom
|
||||
auto unReflectedTypeDom = testComponentDom->value.FindMember("UnReflectedType");
|
||||
ASSERT_EQ(unReflectedTypeDom, testComponentDom->value.MemberEnd());
|
||||
|
||||
// Confirm the presence of the valid ReflectedType
|
||||
auto reflectedTypeDom = testComponentDom->value.FindMember("ReflectedType");
|
||||
ASSERT_NE(reflectedTypeDom, testComponentDom->value.MemberEnd());
|
||||
|
||||
// Confirm the reflected type has the correct type and value
|
||||
ASSERT_TRUE(reflectedTypeDom->value.IsInt());
|
||||
EXPECT_EQ(reflectedTypeDom->value.GetInt(), newComponent->m_reflectedType);
|
||||
}
|
||||
|
||||
TEST_F(PrefabInstanceToTemplateTests, GenerateInstanceDom_InvalidType_InvalidTypeSkipped)
|
||||
{
|
||||
const char* newEntityName = "New Entity";
|
||||
AZ::Entity* newEntity = CreateEntity(newEntityName, false);
|
||||
ASSERT_TRUE(newEntity);
|
||||
|
||||
// Add a component with a member that is missing reflection info
|
||||
// and a member that is properly reflected
|
||||
PrefabTestComponentWithUnReflectedTypeMember* newComponent =
|
||||
newEntity->CreateComponent<PrefabTestComponentWithUnReflectedTypeMember>();
|
||||
|
||||
ASSERT_TRUE(newComponent);
|
||||
|
||||
AZStd::unique_ptr<Instance> prefabInstance = m_prefabSystemComponent->CreatePrefab({ newEntity }, {}, "test/path");
|
||||
ASSERT_TRUE(prefabInstance);
|
||||
|
||||
PrefabDom instanceDom;
|
||||
m_instanceToTemplateInterface->GenerateDomForInstance(instanceDom, *prefabInstance);
|
||||
|
||||
// Acquire the entity out of the instanceDom
|
||||
auto entitiesDom = instanceDom.FindMember(PrefabDomUtils::EntitiesName);
|
||||
ASSERT_NE(entitiesDom, instanceDom.MemberEnd());
|
||||
ASSERT_EQ(entitiesDom->value.MemberCount(), 1);
|
||||
|
||||
auto entityDom = entitiesDom->value.MemberBegin();
|
||||
auto componentListDom = entityDom->value.FindMember("Components");
|
||||
|
||||
// Confirm that there is only one component in the entityDom
|
||||
ASSERT_NE(componentListDom, entityDom->value.MemberEnd());
|
||||
ASSERT_TRUE(componentListDom->value.IsObject());
|
||||
ASSERT_EQ(componentListDom->value.MemberCount(), 1);
|
||||
|
||||
auto testComponentDom = componentListDom->value.MemberBegin();
|
||||
ASSERT_TRUE(testComponentDom->value.IsObject());
|
||||
|
||||
// Confirm that the componentDom does not contained the invalid UnReflectedType
|
||||
// We want to skip over it and produce a best effort entityDom
|
||||
auto unReflectedTypeDom = testComponentDom->value.FindMember("UnReflectedType");
|
||||
ASSERT_EQ(unReflectedTypeDom, testComponentDom->value.MemberEnd());
|
||||
|
||||
// Confirm the presence of the valid ReflectedType
|
||||
auto reflectedTypeDom = testComponentDom->value.FindMember("ReflectedType");
|
||||
ASSERT_NE(reflectedTypeDom, testComponentDom->value.MemberEnd());
|
||||
|
||||
// Confirm the reflected type has the correct type and value
|
||||
ASSERT_TRUE(reflectedTypeDom->value.IsInt());
|
||||
EXPECT_EQ(reflectedTypeDom->value.GetInt(), newComponent->m_reflectedType);
|
||||
}
|
||||
|
||||
TEST_F(PrefabInstanceToTemplateTests, PrefabUpdateTemplate_UpdateEntityOnInstance)
|
||||
{
|
||||
//create template with single entity
|
||||
|
||||
Reference in New Issue
Block a user