QtWidgetLimitsTests.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/QtWidgetLimits.h>
  9. #include "IntegerPrimtitiveTestConfig.h"
  10. namespace UnitTest
  11. {
  12. using namespace AzToolsFramework;
  13. template<typename ValueType>
  14. struct QtWidgetLimitsFixture
  15. : public ToolsApplicationFixture<>
  16. {
  17. };
  18. TYPED_TEST_SUITE(QtWidgetLimitsFixture, IntegerPrimtitiveTestConfigs);
  19. TYPED_TEST(QtWidgetLimitsFixture, MinRange)
  20. {
  21. switch (AZ::IntegralTypeCompare<TypeParam, QtWidgetValueType>())
  22. {
  23. // Given an LY widget value type of equal signedness and size to QtWidgetValueType
  24. case AZ::IntegralTypeDiff::LSignedRSignedEqSize:
  25. {
  26. // Expect the minimum range of widget type to equal QtWidgetValueType
  27. EXPECT_EQ(QtWidgetLimits<TypeParam>::Min(), std::numeric_limits<TypeParam>::min());
  28. EXPECT_EQ(QtWidgetLimits<TypeParam>::Min(), std::numeric_limits<QtWidgetValueType>::min());
  29. break;
  30. }
  31. // Given an LY widget type of equal signedness but wider than QtWidgetValueType
  32. case AZ::IntegralTypeDiff::LSignedRSignedLWider:
  33. {
  34. // Expect the minimum range of widget type to be clamped to the range of QtWidgetValueType
  35. EXPECT_NE(QtWidgetLimits<TypeParam>::Min(), std::numeric_limits<TypeParam>::min());
  36. EXPECT_EQ(QtWidgetLimits<TypeParam>::Min(), std::numeric_limits<QtWidgetValueType>::min());
  37. break;
  38. }
  39. // Given an LY widget type with a minimum range greater than the range of QtWidgetValueType
  40. case AZ::IntegralTypeDiff::LSignedRSignedRWider:
  41. case AZ::IntegralTypeDiff::LUnsignedRSignedLWider:
  42. case AZ::IntegralTypeDiff::LUnsignedRSignedEqSize:
  43. case AZ::IntegralTypeDiff::LUnsignedRSignedRWider:
  44. {
  45. // Expect the minimum range of widget type to be greater than the minimum range of QtWidgetValueType
  46. EXPECT_EQ(QtWidgetLimits<TypeParam>::Min(), std::numeric_limits<TypeParam>::min());
  47. EXPECT_NE(QtWidgetLimits<TypeParam>::Min(), std::numeric_limits<QtWidgetValueType>::min());
  48. break;
  49. }
  50. default:
  51. FAIL();
  52. }
  53. }
  54. TYPED_TEST(QtWidgetLimitsFixture, MaxRange)
  55. {
  56. switch (AZ::IntegralTypeCompare<TypeParam, QtWidgetValueType>())
  57. {
  58. // Given an LY widget value type of equal signedness and size to QtWidgetValueType
  59. case AZ::IntegralTypeDiff::LSignedRSignedEqSize:
  60. {
  61. // Expect the maximum range of widget type to equal QtWidgetValueType
  62. EXPECT_EQ(QtWidgetLimits<TypeParam>::Max(), std::numeric_limits<TypeParam>::max());
  63. EXPECT_EQ(QtWidgetLimits<TypeParam>::Max(), std::numeric_limits<QtWidgetValueType>::max());
  64. break;
  65. }
  66. // Given an LY widget type with a maximum range greater than the range of QtWidgetValueType
  67. case AZ::IntegralTypeDiff::LSignedRSignedLWider:
  68. case AZ::IntegralTypeDiff::LUnsignedRSignedLWider:
  69. case AZ::IntegralTypeDiff::LUnsignedRSignedEqSize:
  70. {
  71. // Expect the maximum range of widget type to be clamped to the range of QtWidgetValueType
  72. EXPECT_NE(QtWidgetLimits<TypeParam>::Max(), std::numeric_limits<TypeParam>::max());
  73. EXPECT_EQ(QtWidgetLimits<TypeParam>::Max(), std::numeric_limits<QtWidgetValueType>::max());
  74. break;
  75. }
  76. // Given an LY widget type with a maximum range less than the range of QtWidgetValueType
  77. case AZ::IntegralTypeDiff::LUnsignedRSignedRWider:
  78. case AZ::IntegralTypeDiff::LSignedRSignedRWider:
  79. {
  80. // Expect the maximum range of widget type to be less than the minimum range of QtWidgetValueType
  81. EXPECT_EQ(QtWidgetLimits<TypeParam>::Max(), std::numeric_limits<TypeParam>::max());
  82. EXPECT_NE(QtWidgetLimits<TypeParam>::Max(), std::numeric_limits<QtWidgetValueType>::max());
  83. break;
  84. }
  85. default:
  86. FAIL();
  87. }
  88. }
  89. } // namespace UnitTest