ViewportInteractionTest.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #include <AzManipulatorTestFramework/ViewportInteraction.h>
  10. namespace UnitTest
  11. {
  12. class AValidViewportInteraction : public ToolsApplicationFixture<>
  13. {
  14. public:
  15. AValidViewportInteraction()
  16. : m_viewportInteraction(
  17. AZStd::make_unique<AzManipulatorTestFramework::ViewportInteraction>(AZStd::make_shared<NullDebugDisplayRequests>()))
  18. {
  19. }
  20. protected:
  21. void SetUpEditorFixtureImpl() override
  22. {
  23. m_cameraState = AzFramework::CreateIdentityDefaultCamera(AZ::Vector3::CreateZero(), AzFramework::ScreenSize(800, 600));
  24. }
  25. public:
  26. AZStd::unique_ptr<AzManipulatorTestFramework::ViewportInteraction> m_viewportInteraction;
  27. AzFramework::CameraState m_cameraState;
  28. };
  29. TEST_F(AValidViewportInteraction, HasViewportId1234)
  30. {
  31. EXPECT_EQ(m_viewportInteraction->GetViewportId(), 1234);
  32. }
  33. TEST_F(AValidViewportInteraction, CanSetAndGetCameraState)
  34. {
  35. m_viewportInteraction->SetCameraState(m_cameraState);
  36. const auto cameraState = m_viewportInteraction->GetCameraState();
  37. EXPECT_EQ(cameraState.m_position, m_cameraState.m_position);
  38. EXPECT_EQ(cameraState.m_forward, m_cameraState.m_forward);
  39. }
  40. TEST_F(AValidViewportInteraction, CanEnableGridSnapping)
  41. {
  42. bool snapping = false;
  43. m_viewportInteraction->SetGridSnapping(true);
  44. AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
  45. snapping, m_viewportInteraction->GetViewportId(),
  46. &AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::GridSnappingEnabled);
  47. EXPECT_TRUE(snapping);
  48. }
  49. TEST_F(AValidViewportInteraction, CanDisableGridSnapping)
  50. {
  51. bool snapping = true;
  52. m_viewportInteraction->SetGridSnapping(false);
  53. AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
  54. snapping, m_viewportInteraction->GetViewportId(),
  55. &AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::GridSnappingEnabled);
  56. EXPECT_FALSE(snapping);
  57. }
  58. TEST_F(AValidViewportInteraction, CanGetAndSetGridSize)
  59. {
  60. float gridSize = 0.0f;
  61. const float expectedGridSize = 50.0f;
  62. m_viewportInteraction->SetGridSize(expectedGridSize);
  63. m_viewportInteraction->SetGridSnapping(false);
  64. AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
  65. gridSize, m_viewportInteraction->GetViewportId(),
  66. &AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::GridSize);
  67. EXPECT_EQ(gridSize, expectedGridSize);
  68. }
  69. TEST_F(AValidViewportInteraction, CanEnableAngularSnapping)
  70. {
  71. bool snapping = false;
  72. m_viewportInteraction->SetAngularSnapping(true);
  73. AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
  74. snapping, m_viewportInteraction->GetViewportId(),
  75. &AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::AngleSnappingEnabled);
  76. EXPECT_TRUE(snapping);
  77. }
  78. TEST_F(AValidViewportInteraction, CanDisableAngularSnapping)
  79. {
  80. bool snapping = true;
  81. m_viewportInteraction->SetAngularSnapping(false);
  82. AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
  83. snapping, m_viewportInteraction->GetViewportId(),
  84. &AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::AngleSnappingEnabled);
  85. EXPECT_FALSE(snapping);
  86. }
  87. TEST_F(AValidViewportInteraction, CanGetAndSetAngleStep)
  88. {
  89. float angularStep = 0.0f;
  90. const float expectedAngularStep = 50.0f;
  91. m_viewportInteraction->SetAngularStep(expectedAngularStep);
  92. AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::EventResult(
  93. angularStep, m_viewportInteraction->GetViewportId(),
  94. &AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Events::AngleStep);
  95. EXPECT_EQ(angularStep, expectedAngularStep);
  96. }
  97. TEST_F(AValidViewportInteraction, HasAValidGetDebugDisplay)
  98. {
  99. AzFramework::DebugDisplayRequests& debugDisplay = m_viewportInteraction->GetDebugDisplay();
  100. EXPECT_NE(nullptr, &debugDisplay);
  101. }
  102. } // namespace UnitTest