BoolTrackTest.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #if !defined(_RELEASE)
  9. #include <AzTest/AzTest.h>
  10. #include <AnimKey.h>
  11. #include <Maestro/Types/AssetBlendKey.h>
  12. #include <Cinematics/BoolTrack.h>
  13. namespace Maestro
  14. {
  15. class CBoolTrackTest : public ::testing::Test
  16. {
  17. public:
  18. CBoolTrackTest()
  19. {
  20. }
  21. void SetUp()
  22. {
  23. m_complexBoolTrack.SetDefaultValue(false);
  24. int keyIndex = 0;
  25. // Single Key, track default TRUE
  26. m_singleKey.time = KEY_TIME;
  27. m_singleKeyBoolTrack.CreateKey(m_singleKey.time);
  28. m_singleKeyBoolTrack.SetKey(keyIndex, &m_singleKey);
  29. // Key 1, track default FALSE
  30. m_key1.time = KEY_TIME;
  31. m_complexBoolTrack.CreateKey(m_key1.time);
  32. m_complexBoolTrack.SetKey(keyIndex++, &m_key1);
  33. // Key 2, track default FALSE
  34. m_key2.time = KEY_TIME * 2.0f;
  35. m_complexBoolTrack.CreateKey(m_key2.time);
  36. m_complexBoolTrack.SetKey(keyIndex++, &m_key2);
  37. // Key 3, track default FALSE
  38. m_key3.time = KEY_TIME * 5.0f;
  39. m_complexBoolTrack.CreateKey(m_key3.time);
  40. m_complexBoolTrack.SetKey(keyIndex++, &m_key3);
  41. }
  42. CBoolTrack m_emptyBoolTrack;
  43. CBoolTrack m_singleKeyBoolTrack;
  44. CBoolTrack m_complexBoolTrack;
  45. AZ::IAssetBlendKey m_singleKey;
  46. AZ::IAssetBlendKey m_key1;
  47. AZ::IAssetBlendKey m_key2;
  48. AZ::IAssetBlendKey m_key3;
  49. static constexpr float KEY_TIME = 1.0f;
  50. };
  51. TEST_F(CBoolTrackTest, GetValue_NoKeys_ExpectDefault)
  52. {
  53. bool result = false;
  54. m_emptyBoolTrack.GetValue(KEY_TIME, result);
  55. // default value of m_emptyBoolTrack is true
  56. EXPECT_TRUE(result) << "The track is not at default value, even though there are no keys";
  57. }
  58. TEST_F(CBoolTrackTest, GetValue_OneKey_BeforeKey_ExpectDefault)
  59. {
  60. bool result = false;
  61. m_singleKeyBoolTrack.GetValue(KEY_TIME - 0.5f, result);
  62. // default value of m_singleKeyBoolTrack is true
  63. EXPECT_TRUE(result) << "The track is not at default value, even though no keys have been hit yet";
  64. }
  65. TEST_F(CBoolTrackTest, GetValue_OneKey_AfterKey_ExpectNotDefault)
  66. {
  67. bool result = false;
  68. m_singleKeyBoolTrack.GetValue(KEY_TIME, result);
  69. // default value of m_singleKeyBoolTrack is true
  70. EXPECT_FALSE(result) << "Hitting a Key did not change the default value";
  71. }
  72. TEST_F(CBoolTrackTest, GetValue_EvenKeys_ExpectDefault)
  73. {
  74. bool result = false;
  75. m_complexBoolTrack.GetValue(m_key1.time, result);
  76. EXPECT_TRUE(result);
  77. m_complexBoolTrack.GetValue(m_key2.time, result);
  78. // default value of m_complexBoolTrack is false
  79. EXPECT_FALSE(result);
  80. }
  81. TEST_F(CBoolTrackTest, GetValue_OddKeys_ExpectNotDefault)
  82. {
  83. bool result = false;
  84. m_complexBoolTrack.GetValue(m_key3.time, result);
  85. // default value of m_complexBoolTrack is false
  86. EXPECT_TRUE(result);
  87. }
  88. TEST_F(CBoolTrackTest, SetValue_SetDefault_ExpectChange)
  89. {
  90. m_emptyBoolTrack.SetValue(0.0f, /*value*/ false, /*set default?*/ true);
  91. bool result = true;
  92. m_emptyBoolTrack.GetValue(0.0f, result);
  93. EXPECT_FALSE(result);
  94. }
  95. TEST_F(CBoolTrackTest, SetValue_DoNotSetDefault_NoChange)
  96. {
  97. m_singleKeyBoolTrack.SetValue(0.0f, /*value*/ false, /*set default?*/ false);
  98. bool result = false;
  99. m_singleKeyBoolTrack.GetValue(0.0f, result);
  100. EXPECT_TRUE(result);
  101. }
  102. } // namespace Maestro
  103. #endif