EditorTubeShapeComponentTests.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <AzCore/UnitTest/TestTypes.h>
  9. #include <AzTest/AzTest.h>
  10. #include <Source/Shape/EditorTubeShapeComponentMode.h>
  11. namespace AZ
  12. {
  13. void PrintTo(const AZ::SplineAddress& splineAddress, std::ostream* os)
  14. {
  15. *os << "SplineAddress { segmentIndex: " << splineAddress.m_segmentIndex << ", segmentFraction: " << splineAddress.m_segmentFraction
  16. << " }";
  17. }
  18. } // namespace AZ
  19. namespace UnitTest
  20. {
  21. class EditorTubeShapeFixture
  22. : public LeakDetectionFixture
  23. , public ::testing::WithParamInterface<bool>
  24. {
  25. };
  26. // test both open and closed versions of the spline
  27. INSTANTIATE_TEST_CASE_P(GenerateTubeManipulatorStates, EditorTubeShapeFixture, ::testing::Values(true, false));
  28. TEST_P(EditorTubeShapeFixture, GenerateTubeManipulatorStates_returns_no_TubeManipulatorStates_when_spline_is_empty)
  29. {
  30. using ::testing::Eq;
  31. // given (an empty spline)
  32. AZ::BezierSpline spline;
  33. spline.SetClosed(GetParam());
  34. // when (tube manipulator states are attempted to be created)
  35. const auto tubeManipulatorStates = LmbrCentral::GenerateTubeManipulatorStates(spline);
  36. // then (none are returned)
  37. EXPECT_THAT(tubeManipulatorStates.empty(), Eq(true));
  38. }
  39. TEST_P(EditorTubeShapeFixture, GenerateTubeManipulatorStates_returns_one_TubeManipulatorStates_when_spline_has_one_vertex)
  40. {
  41. using ::testing::Eq;
  42. // given (an empty spline)
  43. AZ::BezierSpline spline;
  44. spline.SetClosed(GetParam());
  45. spline.m_vertexContainer.AddVertex(AZ::Vector3::CreateZero());
  46. // when (tube manipulator states are attempted to be created)
  47. const auto tubeManipulatorStates = LmbrCentral::GenerateTubeManipulatorStates(spline);
  48. // then (one is returned)
  49. EXPECT_THAT(tubeManipulatorStates.size(), Eq(1));
  50. EXPECT_THAT(tubeManipulatorStates[0].m_splineAddress, Eq(AZ::SplineAddress(0, 0.0f)));
  51. EXPECT_THAT(tubeManipulatorStates[0].m_vertIndex, Eq(0));
  52. }
  53. TEST_P(EditorTubeShapeFixture, GenerateTubeManipulatorStates_returns_two_TubeManipulatorStates_when_spline_has_two_vertices)
  54. {
  55. using ::testing::Eq;
  56. // given (an empty spline)
  57. AZ::BezierSpline spline;
  58. spline.SetClosed(GetParam());
  59. spline.m_vertexContainer.AddVertex(AZ::Vector3::CreateZero());
  60. spline.m_vertexContainer.AddVertex(AZ::Vector3::CreateAxisX(1.0f));
  61. // when (tube manipulator states are attempted to be created)
  62. const auto tubeManipulatorStates = LmbrCentral::GenerateTubeManipulatorStates(spline);
  63. // then (two are returned)
  64. EXPECT_THAT(tubeManipulatorStates.size(), Eq(2));
  65. EXPECT_THAT(tubeManipulatorStates[0].m_splineAddress, Eq(AZ::SplineAddress(0, 0.0f)));
  66. EXPECT_THAT(tubeManipulatorStates[0].m_vertIndex, Eq(0));
  67. EXPECT_THAT(tubeManipulatorStates[1].m_splineAddress, Eq(AZ::SplineAddress(0, 1.0f)));
  68. EXPECT_THAT(tubeManipulatorStates[1].m_vertIndex, Eq(1));
  69. }
  70. TEST_P(EditorTubeShapeFixture, GenerateTubeManipulatorStates_returns_three_TubeManipulatorStates_when_spline_has_three_vertices)
  71. {
  72. using ::testing::Eq;
  73. // given (an empty spline)
  74. AZ::BezierSpline spline;
  75. spline.SetClosed(GetParam());
  76. spline.m_vertexContainer.AddVertex(AZ::Vector3::CreateAxisX(-1.0f));
  77. spline.m_vertexContainer.AddVertex(AZ::Vector3::CreateZero());
  78. spline.m_vertexContainer.AddVertex(AZ::Vector3::CreateAxisX(1.0f));
  79. // when (tube manipulator states are attempted to be created)
  80. const auto tubeManipulatorStates = LmbrCentral::GenerateTubeManipulatorStates(spline);
  81. // then (three are returned)
  82. EXPECT_THAT(tubeManipulatorStates.size(), Eq(3));
  83. EXPECT_THAT(tubeManipulatorStates[0].m_splineAddress, Eq(AZ::SplineAddress(0, 0.0f)));
  84. EXPECT_THAT(tubeManipulatorStates[0].m_vertIndex, Eq(0));
  85. EXPECT_THAT(tubeManipulatorStates[1].m_splineAddress, Eq(AZ::SplineAddress(1, 0.0f)));
  86. EXPECT_THAT(tubeManipulatorStates[1].m_vertIndex, Eq(1));
  87. EXPECT_THAT(tubeManipulatorStates[2].m_splineAddress, Eq(AZ::SplineAddress(1, 1.0f)));
  88. EXPECT_THAT(tubeManipulatorStates[2].m_vertIndex, Eq(2));
  89. }
  90. } // namespace UnitTest