AnimGraphParameterConditionTests.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "EMotionFX/CommandSystem/Source/AnimGraphParameterCommands.h"
  9. #include <AzCore/RTTI/TypeInfo.h>
  10. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  11. #include <EMotionFX/Source/AnimGraphBindPoseNode.h>
  12. #include <EMotionFX/Source/AnimGraphParameterCondition.h>
  13. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  14. #include <EMotionFX/Source/AnimGraphStateTransition.h>
  15. #include <EMotionFX/Source/Parameter/FloatSliderParameter.h>
  16. #include <Tests/SystemComponentFixture.h>
  17. #include <Tests/TestAssetCode/AnimGraphFactory.h>
  18. namespace EMotionFX
  19. {
  20. class ParamConditionAnimGraph
  21. : public EmptyAnimGraph
  22. {
  23. public:
  24. AZ_CLASS_ALLOCATOR(ParamConditionAnimGraph, AnimGraphAllocator)
  25. ParamConditionAnimGraph()
  26. {
  27. AddParameter(aznew FloatSliderParameter("P0"));
  28. AddParameter(aznew FloatSliderParameter("P1"));
  29. auto bindPoseNode1 = aznew EMotionFX::AnimGraphBindPoseNode();
  30. auto bindPoseNode2 = aznew EMotionFX::AnimGraphBindPoseNode();
  31. m_parameterCondition = aznew AnimGraphParameterCondition("P1");
  32. AnimGraphStateTransition* node1ToNode2 = aznew AnimGraphStateTransition(bindPoseNode1, bindPoseNode2, {m_parameterCondition});
  33. GetRootStateMachine()->AddChildNode(bindPoseNode1);
  34. GetRootStateMachine()->AddChildNode(bindPoseNode2);
  35. GetRootStateMachine()->AddTransition(node1ToNode2);
  36. GetRootStateMachine()->SetEntryState(bindPoseNode1);
  37. InitAfterLoading();
  38. }
  39. AnimGraphParameterCondition* GetParameterCondition() const
  40. {
  41. return m_parameterCondition;
  42. }
  43. private:
  44. AnimGraphParameterCondition* m_parameterCondition;
  45. };
  46. class AnimGraphParameterConditionRemoveParameterFixture
  47. : public SystemComponentFixture
  48. {
  49. public:
  50. void SetUp() override
  51. {
  52. SystemComponentFixture::SetUp();
  53. m_animGraph = AnimGraphFactory::Create<ParamConditionAnimGraph>();
  54. }
  55. void TearDown() override
  56. {
  57. m_animGraph.reset();
  58. SystemComponentFixture::TearDown();
  59. }
  60. ParamConditionAnimGraph* GetAnimGraph() const
  61. {
  62. return m_animGraph.get();
  63. }
  64. private:
  65. AZStd::unique_ptr<ParamConditionAnimGraph> m_animGraph;
  66. };
  67. TEST_F(AnimGraphParameterConditionRemoveParameterFixture, ParameterIndexIsUpdatedWhenParameterIsRemoved)
  68. {
  69. CommandSystem::CommandManager manager;
  70. // GetParameterType is a proxy to check that cached m_parameterIndex is updated properly.
  71. const AnimGraphParameterCondition* condition = GetAnimGraph()->GetParameterCondition();
  72. EXPECT_EQ(condition->GetParameterType(), azrtti_typeid<EMotionFX::FloatSliderParameter>());
  73. EXPECT_TRUE(CommandSystem::BuildRemoveParametersCommandGroup(GetAnimGraph(), {"P0"}));
  74. EXPECT_EQ(condition->GetParameterType(), azrtti_typeid<EMotionFX::FloatSliderParameter>());
  75. EXPECT_TRUE(CommandSystem::BuildRemoveParametersCommandGroup(GetAnimGraph(), {"P1"}));
  76. EXPECT_EQ(condition->GetParameterType(), AZ::TypeId::CreateNull());
  77. {
  78. AZStd::string result;
  79. EXPECT_TRUE(manager.Undo(result)) << result.c_str();
  80. }
  81. EXPECT_EQ(condition->GetParameterType(), azrtti_typeid<EMotionFX::FloatSliderParameter>());
  82. }
  83. } // namespace EMotionFX