123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AzTest/AzTest.h>
- #include <AzCore/UnitTest/UnitTest.h>
- #include <AnimKey.h>
- #include <Maestro/Types/AssetBlendKey.h>
- #include <Cinematics/AnimTrack.h>
- namespace AnimTrackTest
- {
- struct ITestKey
- : public IKey
- {
- public:
- AZ_RTTI(ITestKey, "{0C84DBF1-C88E-4C76-8282-601EE30D1AFF}", IKey);
- ITestKey() {}
- ITestKey(bool isSelected, bool isSortMarker)
- {
- if (isSelected)
- {
- flags |= AKEY_SELECTED;
- }
- if (isSortMarker)
- {
- flags |= AKEY_SORT_MARKER;
- }
- }
- };
- class CTestTrack
- : public TAnimTrack<ITestKey>
- {
- public:
- AZ_RTTI(CTestTrack, "{78041EDD-872C-4AB9-81DD-605413810C7E}", IAnimTrack);
- CTestTrack() {}
- void GetKeyInfo([[maybe_unused]] int index, [[maybe_unused]] const char*& description, [[maybe_unused]] float& duration) {}
- void SerializeKey([[maybe_unused]] ITestKey& key, [[maybe_unused]] XmlNodeRef& keyNode, [[maybe_unused]] bool bLoading) {};
- };
- class TAnimTrackTest
- : public ::testing::Test
- {
- public:
- TAnimTrackTest() {}
- void SetUp() override
- {
- // Init Test Track A
- int keyIndex = 0;
- m_testKeyA_0.time = 1.0f;
- m_testTrackA.CreateKey(m_testKeyA_0.time);
- m_testTrackA.SetKey(keyIndex++, &m_testKeyA_0);
- m_testKeyA_1 = ITestKey(/*is selected*/ true, /*is sort marker*/ false);
- m_testKeyA_1.time = 2.0f;
- m_testTrackA.CreateKey(m_testKeyA_1.time);
- m_testTrackA.SetKey(keyIndex++, &m_testKeyA_1);
- m_testKeyA_2 = ITestKey(/*is selected*/ false, /*is sort marker*/ true);
- m_testKeyA_2.time = 5.0f;
- m_testTrackA.CreateKey(m_testKeyA_2.time);
- m_testTrackA.SetKey(keyIndex++, &m_testKeyA_2);
- }
- CTestTrack m_emptyTrack;
- CTestTrack m_testTrackA;
- ITestKey m_testKeyA_0;
- ITestKey m_testKeyA_1;
- ITestKey m_testKeyA_2;
- };
- //------------------------------------------------------------------------------
- // Unit Tests
- //------------------------------------------------------------------------------
- TEST_F(TAnimTrackTest, IsKeySelected_InvalidKey_ExpectAssert)
- {
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.IsKeySelected(-1);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, IsKeySelected_UnselectedKey_ExpectFalse)
- {
- bool result = true;
- result = m_testTrackA.IsKeySelected(2);
- EXPECT_FALSE(result);
- }
- TEST_F(TAnimTrackTest, IsKeySelected_SelectedKey_ExpectTrue)
- {
- bool result = true;
- result = m_testTrackA.IsKeySelected(1);
- EXPECT_TRUE(result);
- }
- TEST_F(TAnimTrackTest, SelectKey_InvalidKey)
- {
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.SelectKey(-1, true);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, SelectKey_UnselectedKey_Select)
- {
- bool result = false;
- m_testTrackA.SelectKey(0, true);
- result = m_testTrackA.IsKeySelected(0);
- EXPECT_TRUE(result);
- }
- TEST_F(TAnimTrackTest, SelectKey_SelectedKey_Select)
- {
- bool result = false;
- m_testTrackA.SelectKey(1, true);
- result = m_testTrackA.IsKeySelected(1);
- EXPECT_TRUE(result);
- }
- TEST_F(TAnimTrackTest, SelectKey_UnselectedKey_UnSelect)
- {
- bool result = true;
- m_testTrackA.SelectKey(0, false);
- result = m_testTrackA.IsKeySelected(0);
- EXPECT_FALSE(result);
- }
- TEST_F(TAnimTrackTest, SelectKey_SelectedKey_UnSelect)
- {
- bool result = true;
- m_testTrackA.SelectKey(1, false);
- result = m_testTrackA.IsKeySelected(1);
- EXPECT_FALSE(result);
- }
- TEST_F(TAnimTrackTest, IsSortMarkerKey_InvalidKey)
- {
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.IsSortMarkerKey(5);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, IsSortMarkerKey_UnmarkedKey_ExpectFalse)
- {
- bool result = true;
- result = m_testTrackA.IsSortMarkerKey(0);
- EXPECT_FALSE(result);
- }
- TEST_F(TAnimTrackTest, IsSortMarkerKey_MarkedKey_ExpectTrue)
- {
- bool result = false;
- result = m_testTrackA.IsSortMarkerKey(2);
- EXPECT_TRUE(result);
- }
- TEST_F(TAnimTrackTest, SetSortMarkerKey_InvalidKey)
- {
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.SetSortMarkerKey(5, true);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, SetSortMarkerKey_UnsetKey_Set)
- {
- m_testTrackA.SetSortMarkerKey(0, true);
- EXPECT_TRUE(m_testTrackA.IsSortMarkerKey(0));
- }
- TEST_F(TAnimTrackTest, SetSortMarkerKey_UnsetKey_Unset)
- {
- m_testTrackA.SetSortMarkerKey(0, false);
- EXPECT_FALSE(m_testTrackA.IsSortMarkerKey(0));
- }
- TEST_F(TAnimTrackTest, SetSortMarkerKey_SetKey_Set)
- {
- m_testTrackA.SetSortMarkerKey(2, true);
- EXPECT_TRUE(m_testTrackA.IsSortMarkerKey(2));
- }
- TEST_F(TAnimTrackTest, SetSortMarkerKey_SetKey_Unset)
- {
- m_testTrackA.SetSortMarkerKey(2, false);
- EXPECT_FALSE(m_testTrackA.IsSortMarkerKey(2));
- }
- TEST_F(TAnimTrackTest, RemoveKey_RemoveFirstKey)
- {
- m_testTrackA.RemoveKey(0);
- IKey result;
- m_testTrackA.GetKey(0, &result);
- EXPECT_EQ(m_testTrackA.GetNumKeys(), 2);
- EXPECT_EQ(result.time, 2.0f);
- }
- TEST_F(TAnimTrackTest, RemoveKey_RemoveMiddleKey)
- {
- m_testTrackA.RemoveKey(1);
- EXPECT_EQ(m_testTrackA.GetNumKeys(), 2);
- IKey result;
- m_testTrackA.GetKey(0, &result);
- EXPECT_EQ(result.time, 1.0f);
- m_testTrackA.GetKey(1, &result);
- EXPECT_EQ(result.time, 5.0f);
- }
- TEST_F(TAnimTrackTest, RemoveKey_RemoveLastKey)
- {
- m_testTrackA.RemoveKey(2);
- EXPECT_EQ(m_testTrackA.GetNumKeys(), 2);
- }
- TEST_F(TAnimTrackTest, GetKey_InvalidIndex_ExpectAssert)
- {
- IKey result;
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.GetKey(-1, &result);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, GetKey_ValidInputs_ExpectSuccess)
- {
- IKey result;
- m_testTrackA.GetKey(0, &result);
- EXPECT_EQ(result.time, m_testKeyA_0.time);
- }
- TEST_F(TAnimTrackTest, SetKey_InvalidIndex_ExpectAssert)
- {
- ITestKey testKey;
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.SetKey(-1, &testKey);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, SetKey_ValidKey_ExpectSuccess)
- {
- ITestKey testKey;
- testKey.time = 3.0f;
- m_testTrackA.SetKey(2, &testKey);
- EXPECT_EQ(m_testTrackA.GetKeyTime(2), 3.0f);
- EXPECT_EQ(m_testTrackA.GetNumKeys(), 3);
- EXPECT_FALSE(m_testTrackA.IsSortMarkerKey(2));
- }
- TEST_F(TAnimTrackTest, GetKeyTime_InvalidIndex_ExpectAssert)
- {
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.GetKeyTime(-1);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, GetKeyTime_ValidInputs_ExpectSuccess)
- {
- EXPECT_EQ(m_testTrackA.GetKeyTime(0), m_testKeyA_0.time);
- EXPECT_EQ(m_testTrackA.GetKeyTime(1), m_testKeyA_1.time);
- EXPECT_EQ(m_testTrackA.GetKeyTime(2), m_testKeyA_2.time);
- }
- TEST_F(TAnimTrackTest, SetKeyTime_InvalidIndex_ExpectAssert)
- {
- AZ_TEST_START_TRACE_SUPPRESSION;
- m_testTrackA.SetKeyTime(-1, 5.0f);
- // We are expecting 2 asserts as the function does not early-out, so the bad input asserts in both
- // the TrackView code and the AZStd code that gets called. Early-outs should probably be added in the future.
- AZ_TEST_STOP_TRACE_SUPPRESSION(2);
- }
- TEST_F(TAnimTrackTest, SetKeyTime)
- {
- m_testTrackA.SetKeyTime(2, 6.0f);
- EXPECT_EQ(m_testTrackA.GetKeyTime(0), m_testKeyA_0.time);
- EXPECT_EQ(m_testTrackA.GetKeyTime(1), m_testKeyA_1.time);
- EXPECT_EQ(m_testTrackA.GetKeyTime(2), 6.0f);
- }
- TEST_F(TAnimTrackTest, FindKey_IncorrectInput_NoKeysFound)
- {
- int result = m_testTrackA.FindKey(4.0f);
- EXPECT_EQ(result, -1);
- }
- TEST_F(TAnimTrackTest, FindKey_ExactInputs_ExpectKeysFound)
- {
- int result = m_testTrackA.FindKey(1.0f);
- EXPECT_EQ(m_testTrackA.GetKeyTime(result), m_testKeyA_0.time);
- result = m_testTrackA.FindKey(2.0f);
- EXPECT_EQ(m_testTrackA.GetKeyTime(result), m_testKeyA_1.time);
- result = m_testTrackA.FindKey(5.0f);
- EXPECT_EQ(m_testTrackA.GetKeyTime(result), m_testKeyA_2.time);
- }
- TEST_F(TAnimTrackTest, CreateKey)
- {
- m_testTrackA.CreateKey(7.0f);
- EXPECT_EQ(m_testTrackA.GetNumKeys(), 4);
- EXPECT_EQ(m_testTrackA.GetKeyTime(3), 7.0f);
- }
- TEST_F(TAnimTrackTest, CloneKey)
- {
- m_testTrackA.CloneKey(2);
- EXPECT_EQ(m_testTrackA.GetNumKeys(), 4);
- EXPECT_EQ(m_testTrackA.GetKeyTime(3), m_testKeyA_2.time);
- }
- TEST_F(TAnimTrackTest, CopyKey)
- {
- m_emptyTrack.CopyKey(&m_testTrackA, 1);
- EXPECT_EQ(m_emptyTrack.GetNumKeys(), 1);
- EXPECT_EQ(m_emptyTrack.GetKeyTime(0), m_testKeyA_1.time);
- }
- TEST_F(TAnimTrackTest, GetActiveKey_NullKey)
- {
- int i = m_testTrackA.GetActiveKey(0.0f, NULL);
- EXPECT_EQ(i, -1);
- }
- TEST_F(TAnimTrackTest, GetActiveKey_EmptyTrack)
- {
- ITestKey tempKey;
- int i = m_emptyTrack.GetActiveKey(5.0f, &tempKey);
- EXPECT_EQ(i, -1);
- }
- TEST_F(TAnimTrackTest, GetActiveKey_TimeIsBeforeFirstKey_RegularTrack_ExpectInvalid)
- {
- ITestKey tempKey;
- int i = m_testTrackA.GetActiveKey(0.5f, &tempKey);
- EXPECT_EQ(i, -1);
- }
- TEST_F(TAnimTrackTest, GetActiveKey_TimeIsBeforeCurrentKey_ExpectValid)
- {
- ITestKey tempKey;
- int i = m_testTrackA.GetActiveKey(3.0f, &tempKey);
- EXPECT_EQ(i, 1);
- i = m_testTrackA.GetActiveKey(1.5f, &tempKey);
- EXPECT_EQ(i, 0);
- }
- TEST_F(TAnimTrackTest, GetActiveKey_TimeIsAfterCurrentKey_ExpectValid)
- {
- ITestKey tempKey;
- int i = m_testTrackA.GetActiveKey(1.5f, &tempKey);
- EXPECT_EQ(i, 0);
- }
- TEST_F(TAnimTrackTest, GetActiveKey_TimeIsAfterLastKey_ExpectValid)
- {
- ITestKey tempKey;
- int i = m_testTrackA.GetActiveKey(6.0f, &tempKey);
- EXPECT_EQ(i, 2);
- }
- } //namespace AnimTrackTest
|