Files
o3de/Gems/Maestro/Code/Tests/Tracks/AnimTrackTest.cpp
T
Esteban Papp 1f9b284de2 Merge branch 'development' into cmake/SPEC-7179
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

# Conflicts:
#	Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h
#	Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h
#	Code/Editor/Plugins/EditorCommon/stdafx.cpp
#	Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h
#	Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h
#	Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h
#	Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h
#	Code/Tools/AssetProcessor/native/precompiled.h
#	Code/Tools/Standalone/StandaloneTools_precompiled.h
#	Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h
#	Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h
#	Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h
#	Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h
#	Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake
#	Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h
#	Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h
#	Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h
#	Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp
#	Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake
#	Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h
#	Gems/Blast/Code/Source/StdAfx.cpp
#	Gems/Camera/Code/Source/Camera_precompiled.h
#	Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h
#	Gems/FastNoise/Code/Source/FastNoise_precompiled.h
#	Gems/Gestures/Code/Source/Gestures_precompiled.h
#	Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h
#	Gems/GraphCanvas/Code/precompiled.h
#	Gems/ImGui/Code/Source/ImGui_precompiled.h
#	Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h
#	Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h
#	Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp
#	Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h
#	Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h
#	Gems/LyShine/Code/Source/LyShine_precompiled.h
#	Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h
#	Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h
#	Gems/Maestro/Code/Source/Maestro_precompiled.h
#	Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h
#	Gems/Metastream/Code/Source/Metastream_precompiled.h
#	Gems/Microphone/Code/Source/Microphone_precompiled.h
#	Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h
#	Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h
#	Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h
#	Gems/PhysX/Code/Source/PhysX_precompiled.h
#	Gems/PhysX/Code/physx_unsupported_files.cmake
#	Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h
#	Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h
#	Gems/ScriptCanvas/Code/Editor/precompiled.h
#	Gems/ScriptCanvas/Code/Source/precompiled.h
#	Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h
#	Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h
#	Gems/ScriptEvents/Code/Source/precompiled.h
#	Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp
#	Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h
#	Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h
#	Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h
#	Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h
#	Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h
#	Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h
#	Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h
#	Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h
#	Gems/Twitch/Code/Source/Twitch_precompiled.h
#	Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h
#	Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
2021-07-16 15:42:37 -07:00

400 lines
12 KiB
C++

/*
* 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