EditorEntityHelpersTests.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <AzTest/AzTest.h>
  9. #include <AzToolsFramework/Application/ToolsApplication.h>
  10. #include <AzToolsFramework/Entity/EditorEntityHelpers.h>
  11. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  12. namespace UnitTest
  13. {
  14. class EditorEntityHelpersTest
  15. : public ToolsApplicationFixture<>
  16. {
  17. void SetUpEditorFixtureImpl() override
  18. {
  19. m_parent1 = CreateDefaultEditorEntity("Parent1");
  20. m_child1 = CreateDefaultEditorEntity("Child1");
  21. m_child2 = CreateDefaultEditorEntity("Child2");
  22. m_grandChild1 = CreateDefaultEditorEntity("GrandChild1");
  23. m_parent2 = CreateDefaultEditorEntity("Parent2");
  24. AZ::TransformBus::Event(m_child1, &AZ::TransformBus::Events::SetParent, m_parent1);
  25. AZ::TransformBus::Event(m_child2, &AZ::TransformBus::Events::SetParent, m_parent1);
  26. AZ::TransformBus::Event(m_grandChild1, &AZ::TransformBus::Events::SetParent, m_child1);
  27. }
  28. public:
  29. AZ::EntityId m_parent1;
  30. AZ::EntityId m_child1;
  31. AZ::EntityId m_child2;
  32. AZ::EntityId m_grandChild1;
  33. AZ::EntityId m_parent2;
  34. };
  35. TEST_F(EditorEntityHelpersTest, EditorEntityHelpersTests_GetCulledEntityHierarchy)
  36. {
  37. AzToolsFramework::EntityIdList testEntityIds{ m_parent1, m_child1, m_child2, m_grandChild1, m_parent2 };
  38. AzToolsFramework::EntityIdSet culledSet = AzToolsFramework::GetCulledEntityHierarchy(testEntityIds);
  39. // There should only be two EntityIds returned (m_parent1, and m_parent2),
  40. // since all the others should be culled out since they have a common ancestor
  41. // in the list already
  42. using ::testing::UnorderedElementsAre;
  43. EXPECT_THAT(culledSet, UnorderedElementsAre(m_parent1, m_parent2));
  44. }
  45. }