EditorCompoundShapeComponentTests.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "LmbrCentralReflectionTest.h"
  9. #include "Shape/EditorCompoundShapeComponent.h"
  10. namespace LmbrCentral
  11. {
  12. // Serialized legacy EditorCompoundShapeComponent v1.
  13. const char kEditorCompoundComponentVersion1[] =
  14. R"DELIMITER(<ObjectStream version="3">
  15. <Class name="EditorCompoundShapeComponent" field="element" version="1" type="{837AA0DF-9C14-4311-8410-E7983E1F4B8D}">
  16. <Class name="EditorComponentBase" field="BaseClass1" version="1" type="{D5346BD4-7F20-444E-B370-327ACD03D4A0}">
  17. <Class name="AZ::Component" field="BaseClass1" type="{EDFCB2CF-F75D-43BE-B26B-F35821B29247}">
  18. <Class name="AZ::u64" field="Id" value="10467239283436660413" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  19. </Class>
  20. </Class>
  21. <Class name="CompoundShapeConfiguration" field="Configuration" version="1" type="{4CEB4E5C-4CBD-4A84-88BA-87B23C103F3F}">
  22. <Class name="AZStd::list" field="Child Shape Entities" type="{BD759900-55F5-5687-A98B-FA0515FD4783}">
  23. <Class name="EntityId" field="element" version="1" type="{6383F1D3-BB27-4E6B-A49A-6409B2059EAA}">
  24. <Class name="AZ::u64" field="id" value="9" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  25. </Class>
  26. <Class name="EntityId" field="element" version="1" type="{6383F1D3-BB27-4E6B-A49A-6409B2059EAA}">
  27. <Class name="AZ::u64" field="id" value="0" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  28. </Class>
  29. <Class name="EntityId" field="element" version="1" type="{6383F1D3-BB27-4E6B-A49A-6409B2059EAA}">
  30. <Class name="AZ::u64" field="id" value="2" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  31. </Class>
  32. <Class name="EntityId" field="element" version="1" type="{6383F1D3-BB27-4E6B-A49A-6409B2059EAA}">
  33. <Class name="AZ::u64" field="id" value="1" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  34. </Class>
  35. <Class name="EntityId" field="element" version="1" type="{6383F1D3-BB27-4E6B-A49A-6409B2059EAA}">
  36. <Class name="AZ::u64" field="id" value="0" type="{D6597933-47CD-4FC8-B911-63F3E2B0993A}"/>
  37. </Class>
  38. </Class>
  39. </Class>
  40. </Class>
  41. </ObjectStream>)DELIMITER";
  42. class LoadEditorCompoundShapeComponentFromVersion1
  43. : public LoadEditorComponentTest<EditorCompoundShapeComponent>
  44. {
  45. protected:
  46. const char* GetSourceDataBuffer() const override { return kEditorCompoundComponentVersion1; }
  47. };
  48. TEST_F(LoadEditorCompoundShapeComponentFromVersion1, Application_IsRunning)
  49. {
  50. ASSERT_NE(GetApplication(), nullptr);
  51. }
  52. TEST_F(LoadEditorCompoundShapeComponentFromVersion1, Components_Load)
  53. {
  54. EXPECT_NE(m_object.get(), nullptr);
  55. }
  56. TEST_F(LoadEditorCompoundShapeComponentFromVersion1, EditorComponent_Found)
  57. {
  58. EXPECT_EQ(m_entity->GetComponents().size(), 2);
  59. EXPECT_NE(m_entity->FindComponent(m_object->GetId()), nullptr);
  60. }
  61. TEST_F(LoadEditorCompoundShapeComponentFromVersion1, HasChildId_Succeeds)
  62. {
  63. const AZ::u64 potentialIds[] = { 9,0,2,1,0 };
  64. for (const AZ::u64 id : potentialIds)
  65. {
  66. bool hasReference = false;
  67. LmbrCentral::CompoundShapeComponentHierarchyRequestsBus::EventResult(hasReference, m_entity->GetId(),
  68. &LmbrCentral::CompoundShapeComponentHierarchyRequestsBus::Events::HasChildId, AZ::EntityId(id));
  69. EXPECT_TRUE(hasReference);
  70. }
  71. }
  72. TEST_F(LoadEditorCompoundShapeComponentFromVersion1, HasChildId_Fails)
  73. {
  74. const AZ::u64 potentialIds[] = { 8,6,7,5,3 };
  75. for (const AZ::u64 id : potentialIds)
  76. {
  77. bool hasReference = false;
  78. LmbrCentral::CompoundShapeComponentHierarchyRequestsBus::EventResult(hasReference, m_entity->GetId(),
  79. &LmbrCentral::CompoundShapeComponentHierarchyRequestsBus::Events::HasChildId, AZ::EntityId(id));
  80. EXPECT_FALSE(hasReference);
  81. }
  82. }
  83. TEST_F(LoadEditorCompoundShapeComponentFromVersion1, ValidateChildIds_Succeeds)
  84. {
  85. bool valid = false;
  86. LmbrCentral::CompoundShapeComponentHierarchyRequestsBus::EventResult(valid, m_entity->GetId(),
  87. &LmbrCentral::CompoundShapeComponentHierarchyRequestsBus::Events::ValidateChildIds);
  88. EXPECT_TRUE(valid);
  89. }
  90. }