Merge branch 'development' into cmake/SPEC-2513_w4267
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
#include <random>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
using namespace AZ;
|
||||
@@ -727,6 +728,153 @@ namespace UnitTest
|
||||
|
||||
};
|
||||
|
||||
class GroupTestComponent : public AZ::Component
|
||||
{
|
||||
public:
|
||||
AZ_COMPONENT(GroupTestComponent, "{C088C81D-D59D-43F1-85F8-B2E591BABA36}")
|
||||
|
||||
GroupTestComponent() = default;
|
||||
|
||||
struct SubData
|
||||
{
|
||||
AZ_TYPE_INFO(SubData, "{983316B5-17C0-476E-9CEB-CA749B3ABE5D}");
|
||||
AZ_CLASS_ALLOCATOR(SubData, AZ::SystemAllocator, 0);
|
||||
|
||||
SubData() {}
|
||||
explicit SubData(int v) : m_int(v) {}
|
||||
explicit SubData(bool b) : m_bool(b) {}
|
||||
explicit SubData(float f) : m_float(f) {}
|
||||
~SubData() = default;
|
||||
|
||||
float m_float = 0.f;
|
||||
int m_int = 0;
|
||||
bool m_bool = true;
|
||||
};
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<SubData>()
|
||||
->Version(1)
|
||||
->Field("SubInt", &SubData::m_int)
|
||||
->Field("SubToggle", &SubData::m_bool)
|
||||
->Field("SubFloat", &SubData::m_float)
|
||||
;
|
||||
|
||||
serializeContext->Class<GroupTestComponent, AZ::Component>()
|
||||
->Version(1)
|
||||
->Field("Float", &GroupTestComponent::m_float)
|
||||
->Field("GroupToggle", &GroupTestComponent::m_groupToggle)
|
||||
->Field("GroupFloat", &GroupTestComponent::m_groupFloat)
|
||||
->Field("ToggleGroupInt", &GroupTestComponent::m_toggleGroupInt)
|
||||
->Field("SubDataNormal", &GroupTestComponent::m_subGroupForNormal)
|
||||
->Field("SubDataToggle", &GroupTestComponent::m_subGroupForToggle)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* edit = serializeContext->GetEditContext())
|
||||
{
|
||||
edit->Class<GroupTestComponent>("Group Test Component", "Testing normal groups and toggle groups")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->DataElement(0, &GroupTestComponent::m_float, "Float Field", "A float field")
|
||||
->ClassElement(AZ::Edit::ClassElements::Group, "Normal Group")
|
||||
->DataElement(0, &GroupTestComponent::m_groupFloat, "Float Field", "A float field")
|
||||
->DataElement(0, &GroupTestComponent::m_subGroupForNormal, "Struct Field", "A sub data type")
|
||||
->GroupElementToggle("Group Toggle", &GroupTestComponent::m_groupToggle)
|
||||
->DataElement(0, &GroupTestComponent::m_toggleGroupInt, "Normal Integer", "An Integer")
|
||||
->DataElement(0, &GroupTestComponent::m_subGroupForToggle, "Struct Field", "A sub data type")
|
||||
;
|
||||
|
||||
edit->Class<SubData>("SubGroup Test Component", "Testing nested normal groups and toggle groups")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->ClassElement(AZ::Edit::ClassElements::Group, "Normal SubGroup")
|
||||
->DataElement(0, &SubData::m_int, "SubGroup Int Field", "An int")
|
||||
->GroupElementToggle("SubGroup Toggle", &SubData::m_bool)
|
||||
->DataElement(0, &SubData::m_float, "SubGroup Float Field", "An int")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Activate() override
|
||||
{
|
||||
}
|
||||
|
||||
void Deactivate() override
|
||||
{
|
||||
}
|
||||
|
||||
float m_float = 0.f;
|
||||
float m_groupFloat = 0.f;
|
||||
int m_toggleGroupInt = 0;
|
||||
AZStd::string m_string;
|
||||
bool m_groupToggle = false;
|
||||
|
||||
SubData m_subGroupForNormal;
|
||||
SubData m_subGroupForToggle;
|
||||
};
|
||||
|
||||
class InstanceDataHierarchyGroupTestFixture : public AllocatorsFixture
|
||||
{
|
||||
public:
|
||||
InstanceDataHierarchyGroupTestFixture() = default;
|
||||
|
||||
AZStd::unique_ptr<SerializeContext> m_serializeContext;
|
||||
AZStd::unique_ptr<AZ::Entity> testEntity1;
|
||||
AzToolsFramework::InstanceDataHierarchy* instanceDataHierarchy;
|
||||
AzToolsFramework::InstanceDataNode* componentNode1 = nullptr;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
AllocatorsFixture::SetUp();
|
||||
|
||||
using AzToolsFramework::InstanceDataHierarchy;
|
||||
using AzToolsFramework::InstanceDataNode;
|
||||
|
||||
AZ::AllocatorInstance<AZ::PoolAllocator>::Create();
|
||||
|
||||
m_serializeContext.reset(aznew AZ::SerializeContext());
|
||||
m_serializeContext.get()->CreateEditContext();
|
||||
Entity::Reflect(m_serializeContext.get());
|
||||
GroupTestComponent::Reflect(m_serializeContext.get());
|
||||
|
||||
testEntity1.reset(new AZ::Entity());
|
||||
testEntity1->CreateComponent<GroupTestComponent>();
|
||||
|
||||
instanceDataHierarchy = aznew InstanceDataHierarchy();
|
||||
instanceDataHierarchy->AddRootInstance(testEntity1.get());
|
||||
instanceDataHierarchy->Build(m_serializeContext.get(), 0);
|
||||
|
||||
// Adding the nodes to a node stack
|
||||
auto rootNode = instanceDataHierarchy->GetRootNode();
|
||||
AZStd::stack<InstanceDataNode*> nodeStack;
|
||||
nodeStack.push(rootNode);
|
||||
while (!nodeStack.empty())
|
||||
{
|
||||
InstanceDataNode* node = nodeStack.top();
|
||||
nodeStack.pop();
|
||||
if (node->GetClassMetadata()->m_typeId == AZ::AzTypeInfo<GroupTestComponent>::Uuid())
|
||||
{
|
||||
componentNode1 = node;
|
||||
break;
|
||||
}
|
||||
for (InstanceDataNode& child : node->GetChildren())
|
||||
{
|
||||
nodeStack.push(&child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_serializeContext.reset();
|
||||
testEntity1.reset();
|
||||
delete instanceDataHierarchy;
|
||||
AZ::AllocatorInstance<AZ::PoolAllocator>::Destroy();
|
||||
AllocatorsFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
class InstanceDataHierarchyKeyedContainerTest
|
||||
: public AllocatorsFixture
|
||||
{
|
||||
@@ -1315,4 +1463,108 @@ namespace UnitTest
|
||||
run();
|
||||
}
|
||||
|
||||
// Test to validate that the only ClassElement::Group nodes are ToggleGroups
|
||||
TEST_F(InstanceDataHierarchyGroupTestFixture, GroupToggleIsClassElementGroup)
|
||||
{
|
||||
using AzToolsFramework::InstanceDataHierarchy;
|
||||
using AzToolsFramework::InstanceDataNode;
|
||||
|
||||
for (auto child : componentNode1->GetChildren())
|
||||
{
|
||||
AZStd::string childName(child.GetElementMetadata()->m_name);
|
||||
if (childName.compare("GroupToggle") == 0)
|
||||
{
|
||||
EXPECT_EQ(child.GetElementEditMetadata()->m_elementId, AZ::Edit::ClassElements::Group);
|
||||
}
|
||||
if ((childName.compare("SubDataNormal") == 0) || (childName.compare("SubDataToggle") == 0))
|
||||
{
|
||||
for (auto subChild : child.GetChildren())
|
||||
{
|
||||
childName = subChild.GetElementMetadata()->m_name;
|
||||
if (childName.compare("SubToggle") == 0)
|
||||
{
|
||||
EXPECT_EQ(subChild.GetElementEditMetadata()->m_elementId, AZ::Edit::ClassElements::Group);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_NE(subChild.GetElementEditMetadata()->m_elementId, AZ::Edit::ClassElements::Group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test to ensure that each node has been assigned under the proper group and the group hierarchy is structured correctly
|
||||
TEST_F(InstanceDataHierarchyGroupTestFixture, ValidatingGroupAndSubGroupHierarchy)
|
||||
{
|
||||
using AzToolsFramework::InstanceDataHierarchy;
|
||||
using AzToolsFramework::InstanceDataNode;
|
||||
|
||||
for (auto child : componentNode1->GetChildren())
|
||||
{
|
||||
AZStd::string childName(child.GetElementMetadata()->m_name);
|
||||
if (childName.compare("GroupFloat") == 0)
|
||||
{
|
||||
EXPECT_EQ(child.GetGroupElementMetadata()->m_description, "Normal Group");
|
||||
}
|
||||
if (childName.compare("ToggleGroupInt") == 0)
|
||||
{
|
||||
EXPECT_EQ(child.GetGroupElementMetadata()->m_description, "Group Toggle");
|
||||
}
|
||||
if ((childName.compare("SubDataNormal") == 0) || (childName.compare("SubDataToggle") == 0))
|
||||
{
|
||||
for (auto subChild : child.GetChildren())
|
||||
{
|
||||
childName = subChild.GetElementMetadata()->m_name;
|
||||
if (childName.compare("SubInt") == 0)
|
||||
{
|
||||
EXPECT_EQ(subChild.GetGroupElementMetadata()->m_description, "Normal SubGroup");
|
||||
}
|
||||
if (childName.compare("SubFloat") == 0)
|
||||
{
|
||||
EXPECT_EQ(subChild.GetGroupElementMetadata()->m_description, "SubGroup Toggle");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class InstanceDataHierarchyGroupTestFixtureParameterized
|
||||
: public InstanceDataHierarchyGroupTestFixture
|
||||
, public ::testing::WithParamInterface<const char*>
|
||||
{
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
InstanceDataHierarchyGroupTestFixture,
|
||||
InstanceDataHierarchyGroupTestFixtureParameterized,
|
||||
::testing::Values("GroupFloat", "GroupToggle", "ToggleGroupInt", "SubInt", "SubToggle", "SubFloat"));
|
||||
|
||||
// Test to validate that each node in a group and Subgroup has the correct parent
|
||||
TEST_P(InstanceDataHierarchyGroupTestFixtureParameterized, ValidatingGroupAndSubGroupParents)
|
||||
{
|
||||
using AzToolsFramework::InstanceDataHierarchy;
|
||||
using AzToolsFramework::InstanceDataNode;
|
||||
|
||||
const char* paramName = GetParam();
|
||||
for (auto child : componentNode1->GetChildren())
|
||||
{
|
||||
AZStd::string childName(child.GetElementMetadata()->m_name);
|
||||
if (childName.compare(paramName) == 0)
|
||||
{
|
||||
EXPECT_EQ(child.GetParent()->GetClassMetadata()->m_name, "GroupTestComponent");
|
||||
}
|
||||
if ((childName.compare("SubDataNormal") == 0) || (childName.compare("SubDataToggle") == 0))
|
||||
{
|
||||
for (auto subChild : child.GetChildren())
|
||||
{
|
||||
childName = subChild.GetElementMetadata()->m_name;
|
||||
if (childName.compare(paramName) == 0)
|
||||
{
|
||||
EXPECT_EQ(subChild.GetParent()->GetClassMetadata()->m_name, "SubData");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
Reference in New Issue
Block a user