/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include namespace EMotionFX { class AnimGraphConditionCommandTestFixture : public AnimGraphFixture { public: void ConstructGraph() override { AnimGraphFixture::ConstructGraph(); AnimGraphStateMachine* node1 = aznew AnimGraphStateMachine(); m_rootStateMachine->AddChildNode(node1); m_rootStateMachine->SetEntryState(node1); AnimGraphStateMachine* node2 = aznew AnimGraphStateMachine(); m_rootStateMachine->AddChildNode(node2); m_transition = AddTransition(node1, node2, 1.0f); } public: AnimGraphStateTransition* m_transition = nullptr; }; TEST_F(AnimGraphConditionCommandTestFixture, AdjustConditionCommandTests) { AZStd::string result; CommandSystem::CommandManager commandManager; // Add time condition. CommandSystem::CommandAddTransitionCondition* addConditionCommand = aznew CommandSystem::CommandAddTransitionCondition( m_animGraph->GetID(), m_transition->GetId(), azrtti_typeid()); EXPECT_TRUE(commandManager.ExecuteCommand(addConditionCommand, result)) << result.c_str(); EXPECT_EQ(m_transition->GetNumConditions(), 1) << "There should be a single condition."; const AZ::u32 conditionIndex = 0; AnimGraphTimeCondition* timeCondition = azdynamic_cast(m_transition->GetCondition(conditionIndex)); EXPECT_EQ(timeCondition->GetCountDownTime(), 1.0f) << "Condition should have the default value for the count-down time."; // 1. Adjust attribute of the time condition. const AZStd::string attributesString = AZStd::string::format("-countDownTime %f", 2.0f); CommandSystem::CommandAdjustTransitionCondition* adjustConditionCommand = aznew CommandSystem::CommandAdjustTransitionCondition( m_animGraph->GetID(), m_transition->GetId(), conditionIndex, attributesString); EXPECT_TRUE(commandManager.ExecuteCommand(adjustConditionCommand, result)); // 2. Undo. EXPECT_TRUE(commandManager.Undo(result)) << result.c_str(); EXPECT_EQ(timeCondition->GetCountDownTime(), 1.0f) << "Condition should be back at the default count-down time."; // 3. Redo. EXPECT_TRUE(commandManager.Redo(result)) << result.c_str(); EXPECT_EQ(timeCondition->GetCountDownTime(), 2.0f) << "Condition should hold the adjusted count-down time."; } } // namespace EMotionFX