/* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace AnimGraphParameterCommandsTests { namespace AZStd { using namespace ::AZStd; } // namespace AZStd namespace AZ { using namespace ::AZ; } // namespace AZ namespace MCore { using ::MCore::Command; using ::MCore::CommandGroup; using ::MCore::CommandLine; using ::MCore::CommandSyntax; using ::MCore::MCORE_MEMCATEGORY_COMMANDSYSTEM; using ::MCore::MCORE_DEFAULT_ALIGNMENT; using ::MCore::AlignedAllocate; using ::MCore::AlignedFree; using ::MCore::GetStringIdPool; using ::MCore::ReflectionSerializer; using ::MCore::LogWarning; using ::MCore::Array; } // namespace MCore namespace EMotionFX { // Import real implementations that are not mocked using ::EMotionFX::AnimGraphNodeId; using ::EMotionFX::AnimGraphConnectionId; // Forward declare types that will be mocked class Actor; class AnimGraph; class AnimGraphInstance; class AnimGraphNode; class AnimGraphObject; class AnimGraphObjectData; class AnimGraphStateTransition; class AnimGraphTransitionCondition; class GroupParameter; class Parameter; class ParameterFactory; class ValueParameter; class BlendTreeConnection; using ParameterVector = AZStd::vector; using ValueParameterVector = AZStd::vector; using GroupParameterVector = AZStd::vector; } // namespace EMotionFX namespace CommandSystem { using ::CommandSystem::SelectionList; void DeleteNodeConnection(MCore::CommandGroup* commandGroup, const EMotionFX::AnimGraphNode* targetNode, const EMotionFX::BlendTreeConnection* connection, bool updateUniqueData = true) {} } // namespace CommandSystem #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class TestParameter : public EMotionFX::ValueParameter { public: AZ_RTTI(TestParameter, "{6C91B0BE-EFCF-4270-A356-28B1C4612CCE}", EMotionFX::ValueParameter); }; class AnimGraphParameterCommandsFixture : public UnitTest::AllocatorsTestFixture { public: void SetUp() override { UnitTest::AllocatorsTestFixture::SetUp(); ::MCore::Initializer::Init(); // create the MCoreSystem object for MCore containers } void TearDown() override { ::MCore::Initializer::Shutdown(); UnitTest::AllocatorsTestFixture::TearDown(); } }; TEST_F(AnimGraphParameterCommandsFixture, CreatingAParameterUpdatesObjectsAfterParameterIsAddedToInstances) { EMotionFX::EMotionFXManager& manager = EMotionFX::GetEMotionFX(); EMotionFX::AnimGraphManager animGraphManager; EMotionFX::AnimGraph animGraph; EMotionFX::AnimGraphInstance animGraphInstance0; EMotionFX::BlendTreeParameterNode parameterNode; TestParameter parameter; EXPECT_CALL(manager, GetAnimGraphManager()) .WillRepeatedly(testing::Return(&animGraphManager)); EXPECT_CALL(animGraph, GetID()) .WillRepeatedly(testing::Return(0)); EXPECT_CALL(animGraph, GetNumParameters()) .WillOnce(testing::Return(0)); EXPECT_CALL(animGraph, AddParameter(¶meter, nullptr)) .WillOnce(testing::Return(true)); EXPECT_CALL(animGraph, FindParameterByName(StrEq("testParameter"))) .WillOnce(testing::Return(nullptr)); EXPECT_CALL(animGraph, FindParameterIndex(¶meter)) .WillOnce(testing::Return(AZ::Success(0))); EXPECT_CALL(animGraph, FindParameter(0)) .WillOnce(testing::Return(¶meter)); EXPECT_CALL(animGraph, FindValueParameterIndex(¶meter)) .WillOnce(testing::Return(AZ::Success(0))); EXPECT_CALL(animGraph, GetNumAnimGraphInstances()) .WillRepeatedly(testing::Return(1)); EXPECT_CALL(animGraph, GetAnimGraphInstance(0)) .WillRepeatedly(testing::Return(&animGraphInstance0)); AZStd::vector objectsAffectedByParameterChanges {¶meterNode}; EXPECT_CALL(animGraph, RecursiveCollectObjectsOfType(azrtti_typeid(), testing::_)) .WillRepeatedly(testing::SetArgReferee<1>(objectsAffectedByParameterChanges)); EXPECT_CALL(animGraph, GetDirtyFlag()) .WillOnce(testing::Return(false)); EXPECT_CALL(animGraph, SetDirtyFlag(true)); EXPECT_CALL(animGraphManager, FindAnimGraphByID(animGraph.GetID())) .WillRepeatedly(testing::Return(&animGraph)); EXPECT_CALL(animGraphManager, RecursiveCollectObjectsAffectedBy(&animGraph, testing::_)); EXPECT_CALL(*EMotionFX::Internal::GetParameterFactory(), CreateImpl(azrtti_typeid())) .WillOnce(testing::Return(¶meter)); EXPECT_CALL(parameter, SetName(StrEq("testParameter"))); EXPECT_CALL(parameter, SetDescription(StrEq("The Test Parameter Description"))); { testing::InSequence sequence; // AnimGraphInstance::InsertParameterValue must be called before // AnimGraphNode::ParameterAdded EXPECT_CALL(animGraphInstance0, InsertParameterValue(0)); EXPECT_CALL(parameterNode, ParameterAdded(StrEq("testParameter"))); } MCore::CommandLine parameters(R"(-name testParameter -animGraphID 0 -type "{6C91B0BE-EFCF-4270-A356-28B1C4612CCE}" -description "The Test Parameter Description")"); AZStd::string outResult; CommandSystem::CommandAnimGraphCreateParameter command; EXPECT_TRUE(command.Execute(parameters, outResult)) << outResult.c_str(); } } // namespace AnimGraphParameterCommandsTests