EditorFocusModeSelectionTests.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <Tests/FocusMode/EditorFocusModeSelectionFixture.h>
  9. namespace UnitTest
  10. {
  11. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnLevel)
  12. {
  13. // Click on Car Entity
  14. ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
  15. // Verify entity is selected
  16. auto selectedEntitiesAfter = GetSelectedEntities();
  17. EXPECT_EQ(selectedEntitiesAfter.size(), 1);
  18. EXPECT_EQ(selectedEntitiesAfter.front(), m_entityMap[CarEntityName]);
  19. }
  20. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnAncestor)
  21. {
  22. // Set the focus on the Street Entity (parent of the test entity)
  23. m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]);
  24. // Click on Car Entity
  25. ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
  26. // Verify entity is selected
  27. auto selectedEntitiesAfter = GetSelectedEntities();
  28. EXPECT_EQ(selectedEntitiesAfter.size(), 1);
  29. EXPECT_EQ(selectedEntitiesAfter.front(), m_entityMap[CarEntityName]);
  30. }
  31. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnItself)
  32. {
  33. // Set the focus on the Car Entity (test entity)
  34. m_focusModeInterface->SetFocusRoot(m_entityMap[CarEntityName]);
  35. // Click on Car Entity
  36. ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
  37. // Verify entity is selected
  38. auto selectedEntitiesAfter = GetSelectedEntities();
  39. EXPECT_EQ(selectedEntitiesAfter.size(), 1);
  40. EXPECT_EQ(selectedEntitiesAfter.front(), m_entityMap[CarEntityName]);
  41. }
  42. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnSibling)
  43. {
  44. // Set the focus on the SportsCar Entity (sibling of the test entity)
  45. m_focusModeInterface->SetFocusRoot(m_entityMap[SportsCarEntityName]);
  46. // Click on Car Entity
  47. ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
  48. // Verify entity is selected
  49. auto selectedEntitiesAfter = GetSelectedEntities();
  50. EXPECT_EQ(selectedEntitiesAfter.size(), 0);
  51. }
  52. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionSelectEntityWithFocusOnDescendant)
  53. {
  54. // Set the focus on the Passenger1 Entity (child of the entity)
  55. m_focusModeInterface->SetFocusRoot(m_entityMap[Passenger1EntityName]);
  56. // Click on Car Entity
  57. ClickAtWorldPositionOnViewport(s_worldCarEntityPosition);
  58. // Verify entity is selected
  59. auto selectedEntitiesAfter = GetSelectedEntities();
  60. EXPECT_EQ(selectedEntitiesAfter.size(), 0);
  61. }
  62. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionBoxSelectWithFocusOnLevel)
  63. {
  64. // Do a box select that includes all entities in the fixture
  65. BoxSelectOnViewport();
  66. // Entities are selected
  67. using ::testing::UnorderedElementsAre;
  68. auto selectedEntitiesAfter = GetSelectedEntities();
  69. EXPECT_THAT(selectedEntitiesAfter,
  70. UnorderedElementsAre(
  71. m_entityMap[CityEntityName],
  72. m_entityMap[StreetEntityName],
  73. m_entityMap[CarEntityName],
  74. m_entityMap[Passenger1EntityName],
  75. m_entityMap[SportsCarEntityName],
  76. m_entityMap[Passenger2EntityName]
  77. )
  78. );
  79. }
  80. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionBoxSelectWithFocusOnChild)
  81. {
  82. // Set the focus on the Passenger1 Entity (child of the entity)
  83. m_focusModeInterface->SetFocusRoot(m_entityMap[StreetEntityName]);
  84. // Do a box select that includes all entities in the fixture
  85. BoxSelectOnViewport();
  86. // Entities are selected
  87. using ::testing::UnorderedElementsAre;
  88. auto selectedEntitiesAfter = GetSelectedEntities();
  89. EXPECT_THAT(selectedEntitiesAfter,
  90. UnorderedElementsAre(
  91. m_entityMap[StreetEntityName],
  92. m_entityMap[CarEntityName],
  93. m_entityMap[Passenger1EntityName],
  94. m_entityMap[SportsCarEntityName],
  95. m_entityMap[Passenger2EntityName]
  96. )
  97. );
  98. }
  99. TEST_F(EditorFocusModeSelectionFixture, EditorFocusModeSelectionBoxSelectWithFocusOnLeaf)
  100. {
  101. // Set the focus on the Passenger1 Entity (child of the entity)
  102. m_focusModeInterface->SetFocusRoot(m_entityMap[Passenger1EntityName]);
  103. // Do a box select that includes all entities in the fixture
  104. BoxSelectOnViewport();
  105. // Entities are selected
  106. using ::testing::UnorderedElementsAre;
  107. auto selectedEntitiesAfter = GetSelectedEntities();
  108. EXPECT_THAT(selectedEntitiesAfter,
  109. UnorderedElementsAre(
  110. m_entityMap[Passenger1EntityName]
  111. )
  112. );
  113. }
  114. } // namespace UnitTest