DirectCallTest.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 "AzManipulatorTestFrameworkTestFixtures.h"
  9. namespace UnitTest
  10. {
  11. class CustomManipulatorManager : public AzToolsFramework::ManipulatorManager
  12. {
  13. using ManagerBase = AzToolsFramework::ManipulatorManager;
  14. public:
  15. using ManagerBase::ManagerBase;
  16. size_t RegisteredManipulatorCount() const
  17. {
  18. return m_manipulatorIdToPtrMap.size();
  19. }
  20. };
  21. class AzManipulatorTestFrameworkCustomManagerTestFixture : public LinearManipulatorTestFixture
  22. {
  23. protected:
  24. AzManipulatorTestFrameworkCustomManagerTestFixture()
  25. : LinearManipulatorTestFixture(AzToolsFramework::ManipulatorManagerId(AZ::Crc32("TestManipulatorManagerId")))
  26. {
  27. }
  28. void SetUpEditorFixtureImpl() override
  29. {
  30. m_manipulatorManager = AZStd::make_shared<CustomManipulatorManager>(m_manipulatorManagerId);
  31. LinearManipulatorTestFixture::SetUpEditorFixtureImpl();
  32. }
  33. void TearDownEditorFixtureImpl() override
  34. {
  35. LinearManipulatorTestFixture::TearDownEditorFixtureImpl();
  36. m_manipulatorManager.reset();
  37. }
  38. AZStd::shared_ptr<CustomManipulatorManager> m_manipulatorManager;
  39. };
  40. TEST_F(AzManipulatorTestFrameworkCustomManagerTestFixture, RegisterManipulatorWithCustomManager)
  41. {
  42. // Expect the manager to contain one manipulator
  43. EXPECT_EQ(m_manipulatorManager->RegisteredManipulatorCount(), 1);
  44. }
  45. TEST_F(AzManipulatorTestFrameworkCustomManagerTestFixture, ConsumeViewportLeftMouseClick)
  46. {
  47. // consume the mouse down and up events
  48. m_manipulatorManager->ConsumeViewportMousePress(m_interaction);
  49. m_manipulatorManager->ConsumeViewportMouseRelease(m_interaction);
  50. // expect the left mouse down and mouse up sanity flags to be set
  51. EXPECT_TRUE(m_receivedLeftMouseDown);
  52. EXPECT_TRUE(m_receivedLeftMouseUp);
  53. // do not expect the mouse move sanity flag to be set
  54. EXPECT_FALSE(m_receivedMouseMove);
  55. }
  56. TEST_F(AzManipulatorTestFrameworkCustomManagerTestFixture, ConsumeViewportMouseMoveHover)
  57. {
  58. // consume the mouse move event
  59. m_manipulatorManager->ConsumeViewportMouseMove(m_interaction);
  60. // do not expect the manipulator to be performing an action
  61. EXPECT_FALSE(m_linearManipulator->PerformingAction());
  62. EXPECT_FALSE(m_manipulatorManager->Interacting());
  63. // do not expect the left mouse down/up and mouse move sanity flags to be set
  64. EXPECT_FALSE(m_receivedLeftMouseDown);
  65. EXPECT_FALSE(m_receivedMouseMove);
  66. EXPECT_FALSE(m_receivedLeftMouseUp);
  67. }
  68. TEST_F(AzManipulatorTestFrameworkCustomManagerTestFixture, ConsumeViewportMouseMoveActive)
  69. {
  70. // consume the mouse down and mouse move events
  71. m_manipulatorManager->ConsumeViewportMousePress(m_interaction);
  72. m_manipulatorManager->ConsumeViewportMouseMove(m_interaction);
  73. // do not expect the mouse to be hovering over the manipulator
  74. EXPECT_FALSE(m_linearManipulator->MouseOver());
  75. // expect the manipulator to be performing an action
  76. EXPECT_TRUE(m_linearManipulator->PerformingAction());
  77. EXPECT_TRUE(m_manipulatorManager->Interacting());
  78. // consume the mouse up event
  79. m_manipulatorManager->ConsumeViewportMouseRelease(m_interaction);
  80. // expect the left mouse down/up and mouse move sanity flags to be set
  81. EXPECT_TRUE(m_receivedLeftMouseDown);
  82. EXPECT_TRUE(m_receivedMouseMove);
  83. EXPECT_TRUE(m_receivedLeftMouseUp);
  84. }
  85. TEST_F(AzManipulatorTestFrameworkCustomManagerTestFixture, MoveManipulatorAlongAxis)
  86. {
  87. AZ::Vector3 movementAlongAxis = AZ::Vector3::CreateZero();
  88. const AZ::Vector3 expectedPositionAfterMovementAlongAxis = AZ::Vector3(-5.0f, 0.0f, 0.0f);
  89. m_linearManipulator->InstallMouseMoveCallback(
  90. [&movementAlongAxis](const AzToolsFramework::LinearManipulator::Action& action)
  91. {
  92. movementAlongAxis = action.m_current.m_localPositionOffset;
  93. });
  94. // consume the mouse down event
  95. m_manipulatorManager->ConsumeViewportMousePress(m_interaction);
  96. // move the mouse along the -x axis
  97. m_interaction.m_mousePick.m_rayOrigin += expectedPositionAfterMovementAlongAxis;
  98. m_manipulatorManager->ConsumeViewportMouseMove(m_interaction);
  99. // expect the manipulator to be performing an action
  100. EXPECT_TRUE(m_linearManipulator->PerformingAction());
  101. EXPECT_TRUE(m_manipulatorManager->Interacting());
  102. // consume the mouse up event
  103. m_manipulatorManager->ConsumeViewportMouseRelease(m_interaction);
  104. // expect the left mouse down/up sanity flags to be set
  105. EXPECT_TRUE(m_receivedLeftMouseDown);
  106. EXPECT_TRUE(m_receivedLeftMouseUp);
  107. // expect the manipulator movement along the axis to match the mouse movement along the axis
  108. EXPECT_EQ(movementAlongAxis, expectedPositionAfterMovementAlongAxis);
  109. }
  110. } // namespace UnitTest