PropertyIntCtrlCommonTests.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <AzToolsFramework/UI/PropertyEditor/PropertyIntCtrlCommon.h>
  9. #include <AzToolsFramework/UI/PropertyEditor/QtWidgetLimits.h>
  10. #include <Tests/IntegerPrimtitiveTestConfig.h>
  11. namespace UnitTest
  12. {
  13. using namespace AzToolsFramework;
  14. template<typename ValueType>
  15. struct PropertyIntCtrlCommonFixture
  16. : public ToolsApplicationFixture<>
  17. {
  18. };
  19. TYPED_TEST_SUITE(PropertyIntCtrlCommonFixture, IntegerPrimtitiveTestConfigs);
  20. TYPED_TEST(PropertyIntCtrlCommonFixture, ValidMinValue_ExpectSafeValueEqualToOriginalValue)
  21. {
  22. // Given a valid value for the minimum attribute
  23. AZ::s64 value = aznumeric_cast<AZ::s64>(QtWidgetLimits<TypeParam>::Min());
  24. // Attempt to get a safe value in the Qt range
  25. AZ::s64 result = GetSafeAttributeValue<TypeParam>(value, "Test Property", "Test Attribute");
  26. // Expect the result to be equal the original value
  27. EXPECT_EQ(result, value);
  28. }
  29. TYPED_TEST(PropertyIntCtrlCommonFixture, InvalidMinValue_ExpectSafeValueEqualToValueTypeMinLimit)
  30. {
  31. // Given an invalid value for the minimum attribute
  32. AZ::s64 value = aznumeric_cast<AZ::s64>(QtWidgetLimits<TypeParam>::Min()) - 1;
  33. // Attempt to get a safe value in the Qt range
  34. AZ::s64 result = GetSafeAttributeValue<TypeParam>(value, "Test Property", "Test Attribute");
  35. // Expect the result to be equal to the limit for this value type
  36. EXPECT_EQ(result, QtWidgetLimits<TypeParam>::Min());
  37. }
  38. TYPED_TEST(PropertyIntCtrlCommonFixture, ValidMaxValue_ExpectSafeValueEqualToOriginalValue)
  39. {
  40. // Given a valid value for the maximum attribute
  41. AZ::s64 value = aznumeric_cast<AZ::s64>(QtWidgetLimits<TypeParam>::Max());
  42. // Attempt to get a safe value in the Qt range
  43. AZ::s64 result = GetSafeAttributeValue<TypeParam>(value, "Test Property", "Test Attribute");
  44. // Expect the result to be equal the original value
  45. EXPECT_EQ(result, value);
  46. }
  47. TYPED_TEST(PropertyIntCtrlCommonFixture, InvalidMaxValue_ExpectSafeValueEqualToValueTypeMinLimit)
  48. {
  49. // Given an invalid value for the maximum attribute
  50. AZ::s64 value = aznumeric_cast<AZ::s64>(QtWidgetLimits<TypeParam>::Min()) - 1;
  51. // Attempt to get a safe value in the Qt range
  52. AZ::s64 result = GetSafeAttributeValue<TypeParam>(value, "Test Property", "Test Attribute");
  53. // Expect the result to be equal to the limit for this value type
  54. EXPECT_EQ(result, QtWidgetLimits<TypeParam>::Min());
  55. }
  56. } // namespace UnitTest