BoolTrackTest.cpp 3.3 KB

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