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
|
||||
|
||||
@@ -28,4 +28,18 @@ namespace UnitTest
|
||||
: m_boolProperty(boolProperty)
|
||||
{
|
||||
}
|
||||
|
||||
void PrefabTestComponentWithUnReflectedTypeMember::Reflect(AZ::ReflectContext* reflection)
|
||||
{
|
||||
AZ::SerializeContext* serializeContext = AZ::RttiCast<AZ::SerializeContext*>(reflection);
|
||||
|
||||
// We reflect our member but not its type this will result in missing reflection data
|
||||
// when we try to store or load this field
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<PrefabTestComponentWithUnReflectedTypeMember, AzToolsFramework::Components::EditorComponentBase>()
|
||||
->Field("UnReflectedType", &PrefabTestComponentWithUnReflectedTypeMember::m_unReflectedType)
|
||||
->Field("ReflectedType", &PrefabTestComponentWithUnReflectedTypeMember::m_reflectedType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,22 @@ namespace UnitTest
|
||||
int m_intProperty = 0;
|
||||
AZ::EntityId m_entityIdProperty;
|
||||
};
|
||||
|
||||
class UnReflectedType
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(UnReflectedType, "{FB65262C-CE9A-45CA-99EB-4DDCB19B32DB}");
|
||||
int m_unReflectedInt = 42;
|
||||
};
|
||||
|
||||
class PrefabTestComponentWithUnReflectedTypeMember
|
||||
: public AzToolsFramework::Components::EditorComponentBase
|
||||
{
|
||||
public:
|
||||
AZ_EDITOR_COMPONENT(PrefabTestComponentWithUnReflectedTypeMember, "{726281E1-8E47-46AB-8018-D3F4BA823D74}");
|
||||
static void Reflect(AZ::ReflectContext* reflection);
|
||||
|
||||
UnReflectedType m_unReflectedType;
|
||||
int m_reflectedType = 52;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace UnitTest
|
||||
EXPECT_TRUE(m_instanceToTemplateInterface);
|
||||
|
||||
GetApplication()->RegisterComponentDescriptor(PrefabTestComponent::CreateDescriptor());
|
||||
GetApplication()->RegisterComponentDescriptor(PrefabTestComponentWithUnReflectedTypeMember::CreateDescriptor());
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<ToolsTestApplication> PrefabTestFixture::CreateTestApplication()
|
||||
|
||||
@@ -136,7 +136,10 @@ namespace UnitTest
|
||||
|
||||
PrefabDomValueReference wheelEntityComponentBoolPropertyValue =
|
||||
PrefabDomUtils::FindPrefabDomValue(wheelEntityComponentValue->get(), PrefabTestDomUtils::BoolPropertyName);
|
||||
ASSERT_FALSE(wheelEntityComponentBoolPropertyValue.has_value());
|
||||
|
||||
ASSERT_TRUE(wheelEntityComponentBoolPropertyValue.has_value());
|
||||
ASSERT_TRUE(wheelEntityComponentBoolPropertyValue->get().IsBool());
|
||||
ASSERT_FALSE(wheelEntityComponentBoolPropertyValue->get().GetBool());
|
||||
|
||||
// Validate that the axles under the car have the same DOM as the axle template.
|
||||
PrefabTestDomUtils::ValidatePrefabDomInstances(axleInstanceAliasesUnderCar, carTemplateDom, axleTemplateDom);
|
||||
|
||||
Reference in New Issue
Block a user