| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963 |
- /*
- * 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 <sstream>
- #include <AzCore/Memory/Memory.h>
- #include <AzCore/UnitTest/TestTypes.h>
- #include <AzCore/std/optional.h>
- #include <AzCore/std/smart_ptr/make_shared.h>
- #include <AzCore/std/string/conversions.h>
- #include <AzCore/std/string/string.h>
- #include <AzFramework/Physics/SystemBus.h>
- #include <EMotionFX/CommandSystem/Source/CommandManager.h>
- #include <EMotionFX/Source/Actor.h>
- #include <EMotionFX/Source/ActorManager.h>
- #include <EMotionFX/Source/Allocators.h>
- #include <EMotionFX/Source/AnimGraph.h>
- #include <EMotionFX/Source/AnimGraphManager.h>
- #include <EMotionFX/Source/AnimGraphNode.h>
- #include <EMotionFX/Source/AnimGraphObjectIds.h>
- #include <EMotionFX/Source/EMotionFXManager.h>
- #include <EMotionFX/Source/Node.h>
- #include <EMotionFX/Source/SimulatedObjectSetup.h>
- #include <EMotionFX/Source/SimulatedObjectBus.h>
- #include <EMotionFX/Source/AnimGraphStateTransition.h>
- #include <EMotionFX/Source/AnimGraphTransitionCondition.h>
- #include <MCore/Source/Command.h>
- #include <MCore/Source/ReflectionSerializer.h>
- #include <Tests/Printers.h>
- #include <Tests/Matchers.h>
- namespace CommandAdjustSimulatedObjectTests
- {
- namespace EMotionFX
- {
- // Import real types from the production namespace
- using ::EMotionFX::AnimGraphConnectionId;
- using ::EMotionFX::AnimGraphNodeId;
- using ::EMotionFX::AnimGraphObject;
- using ::EMotionFX::BlendTreeConnection;
- using ::EMotionFX::ValueParameter;
- using ::EMotionFX::CommandAllocator;
- using ::EMotionFX::AnimGraphAllocator;
- using ::EMotionFX::PhysicsSetup;
- using ::EMotionFX::SimulatedObjectNotificationBus;
- // Forward-declare types that will be mocked
- class Actor;
- class ActorManager;
- class AnimGraph;
- class AnimGraphInstance;
- class AnimGraphManager;
- class AnimGraphNode;
- class AnimGraphStateTransition;
- class EMotionFXManager;
- class GroupParameter;
- class Parameter;
- class SimulatedJoint;
- class SimulatedObject;
- class SimulatedObjectSetup;
- } // namespace EMotionFX
- namespace EMotionFX
- {
- typedef AZStd::vector<GroupParameter*> GroupParameterVector;
- typedef AZStd::vector<Parameter*> ParameterVector;
- typedef AZStd::vector<ValueParameter*> ValueParameterVector;
- }
- #include <Tests/Mocks/Parameter.h>
- #include <Tests/Mocks/GroupParameter.h>
- #include <Tests/Mocks/Actor.h>
- #include <Tests/Mocks/ActorManager.h>
- #include <Tests/Mocks/AnimGraphTransitionCondition.h>
- #include <Tests/Mocks/AnimGraph.h>
- #include <Tests/Mocks/AnimGraphInstance.h>
- #include <Tests/Mocks/AnimGraphManager.h>
- #include <Tests/Mocks/AnimGraphNode.h>
- #include <Tests/Mocks/AnimGraphStateTransition.h>
- #include <Tests/Mocks/EMotionFXManager.h>
- #include <Tests/Mocks/SimulatedJoint.h>
- #include <Tests/Mocks/SimulatedObject.h>
- #include <Tests/Mocks/SimulatedObjectSetup.h>
- #include <EMotionFX/CommandSystem/Source/ParameterMixins_Interface.inl>
- #include <EMotionFX/CommandSystem/Source/ParameterMixins_Impl.inl>
- #include <EMotionFX/CommandSystem/Source/SimulatedObjectCommands_Interface.inl>
- #include <EMotionFX/CommandSystem/Source/SimulatedObjectCommands_Impl.inl>
- } // namespace CommandAdjustSimulatedObjectTests
- namespace EMotionFX
- {
- namespace UnderTest
- {
- using namespace ::CommandAdjustSimulatedObjectTests::EMotionFX;
- } // namespace UnderTest
- ///////////////////////////////////////////////////////////////////////////
- // CommandAdjustSimulatedObject tests
- ///////////////////////////////////////////////////////////////////////////
- struct CommandAdjustSimulatedObjectTestsParam
- {
- AZStd::optional<std::string> objectName;
- AZStd::optional<float> gravityFactor;
- AZStd::optional<float> stiffnessFactor;
- AZStd::optional<float> dampingFactor;
- AZStd::optional<std::vector<std::string>> colliderTags;
- void (*setExecuteExpectations)(UnderTest::SimulatedObject*);
- void (*setUndoExpectations)(UnderTest::SimulatedObject*);
- };
- class CommandAdjustSimulatedObjectTestsFixture
- : public UnitTest::LeakDetectionFixture
- , public ::testing::WithParamInterface<::testing::tuple<bool, bool, CommandAdjustSimulatedObjectTestsParam>>
- {
- public:
- static std::string buildCommandLineFromTestParam(const CommandAdjustSimulatedObjectTestsParam& param)
- {
- std::string string;
- std::stringstream stream(string);
- if (param.objectName.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedObject::s_objectNameParameterName << ' ' << param.objectName.value();
- }
- if (param.gravityFactor.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedObject::s_gravityFactorParameterName << ' ' << param.gravityFactor.value();
- }
- if (param.stiffnessFactor.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedObject::s_stiffnessFactorParameterName << ' ' << param.stiffnessFactor.value();
- }
- if (param.dampingFactor.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedObject::s_dampingFactorParameterName << ' ' << param.dampingFactor.value();
- }
- if (param.colliderTags.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedObject::s_colliderTagsParameterName << ' ';
- for (const std::string& val : *param.colliderTags)
- {
- stream << val;
- if (&val != std::addressof(*(param.colliderTags->end() - 1)))
- {
- stream << ";";
- }
- }
- }
- return stream.str();
- }
- };
- TEST_P(CommandAdjustSimulatedObjectTestsFixture, TestExecute)
- {
- using ::testing::Return;
- using ::testing::ReturnRef;
- const AZStd::string nameString {"Old name"};
- UnderTest::EMotionFXManager& manager = UnderTest::GetEMotionFX();
- UnderTest::ActorManager actorManager;
- UnderTest::Actor actor;
- auto simulatedObjectSetup = AZStd::make_shared<UnderTest::SimulatedObjectSetup>();
- UnderTest::SimulatedObject simulatedObject;
- EXPECT_CALL(manager, GetActorManager())
- .WillRepeatedly(Return(&actorManager));
- EXPECT_CALL(actorManager, FindActorByID(0))
- .WillRepeatedly(Return(&actor));
- EXPECT_CALL(actor, GetSimulatedObjectSetup())
- .WillRepeatedly(ReturnRef(simulatedObjectSetup));
- EXPECT_CALL(actor, GetDirtyFlag())
- .WillOnce(Return(false));
- EXPECT_CALL(*simulatedObjectSetup, GetSimulatedObject(0))
- .WillRepeatedly(Return(&simulatedObject));
- EXPECT_CALL(*simulatedObjectSetup, IsSimulatedObjectNameUnique(StrEq("New name"), &simulatedObject))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*simulatedObjectSetup, IsSimulatedObjectNameUnique(StrEq("Old name"), &simulatedObject))
- .WillRepeatedly(Return(true));
- // GetName returns a reference, so the return value for it has to be
- // defined in a place where that reference will exist
- EXPECT_CALL(simulatedObject, GetName())
- .WillRepeatedly(::testing::ReturnRef(nameString));
- AZStd::vector<AZStd::string> defaultColliderTags;
- EXPECT_CALL(simulatedObject, GetColliderTags())
- .WillRepeatedly(testing::ReturnRef(defaultColliderTags));
- const bool doExecuteOnly = ::testing::get<0>(GetParam());
- const bool useCommandString = ::testing::get<1>(GetParam());
- const CommandAdjustSimulatedObjectTestsParam& testParams = ::testing::get<2>(GetParam());
- if (doExecuteOnly)
- {
- EXPECT_CALL(actor, SetDirtyFlag(true));
- testParams.setExecuteExpectations(&simulatedObject);
- }
- else
- {
- {
- testing::InSequence sequence;
- EXPECT_CALL(actor, SetDirtyFlag(true))
- .RetiresOnSaturation();
- EXPECT_CALL(actor, SetDirtyFlag(false))
- .RetiresOnSaturation();
- }
- testParams.setUndoExpectations(&simulatedObject);
- }
- AZStd::string paramString {"-actorId 0 -objectIndex 0"};
- paramString += AZStd::string(buildCommandLineFromTestParam(testParams).c_str());
- MCore::CommandLine parameters(paramString);
- AZStd::string outResult;
- UnderTest::CommandAdjustSimulatedObject command(/*actorId=*/0, /*objectIndex=*/0);
- if (useCommandString)
- {
- EXPECT_TRUE(command.SetCommandParameters(parameters));
- }
- else
- {
- if (testParams.objectName)
- {
- command.SetObjectName(AZStd::string(testParams.objectName->c_str(), testParams.objectName->size()));
- }
- command.SetGravityFactor(testParams.gravityFactor);
- command.SetStiffnessFactor(testParams.stiffnessFactor);
- command.SetDampingFactor(testParams.dampingFactor);
- if (testParams.colliderTags)
- {
- AZStd::vector<AZStd::string> value;
- for (const std::string& stdstring : testParams.colliderTags.value())
- {
- value.emplace_back(stdstring.c_str(), stdstring.size());
- }
- command.SetColliderTags(value);
- }
- }
- EXPECT_TRUE(command.Execute(parameters, outResult)) << outResult.c_str();
- if (!doExecuteOnly)
- {
- EXPECT_TRUE(command.Undo(parameters, outResult)) << outResult.c_str();
- }
- }
- INSTANTIATE_TEST_CASE_P(TestCommandAdjustSimulatedObject, CommandAdjustSimulatedObjectTestsFixture,
- ::testing::Combine(
- ::testing::Bool(), // Test execute or test undo
- ::testing::Bool(), // Use command strings or not
- ::testing::ValuesIn({
- CommandAdjustSimulatedObjectTestsParam
- {
- "New name",
- AZStd::nullopt,
- AZStd::nullopt,
- AZStd::nullopt,
- AZStd::nullopt,
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- EXPECT_CALL(*simulatedObject, SetName(StrEq("New name")))
- .Times(1);
- },
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, SetName(StrEq("New name")))
- .Times(1);
- EXPECT_CALL(*simulatedObject, SetName(StrEq("Old name")))
- .Times(1);
- }
- },
- CommandAdjustSimulatedObjectTestsParam
- {
- AZStd::nullopt,
- 2.2f,
- AZStd::nullopt,
- AZStd::nullopt,
- AZStd::nullopt,
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, GetGravityFactor())
- .Times(1)
- .WillOnce(::testing::Return(1.2f));
- EXPECT_CALL(*simulatedObject, SetGravityFactor(::testing::FloatEq(2.2f)))
- .Times(1);
- },
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, GetGravityFactor())
- .Times(1)
- .WillOnce(::testing::Return(1.2f));
- EXPECT_CALL(*simulatedObject, SetGravityFactor(::testing::FloatEq(2.2f)))
- .Times(1);
- EXPECT_CALL(*simulatedObject, SetGravityFactor(::testing::FloatEq(1.2f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedObjectTestsParam
- {
- AZStd::nullopt,
- AZStd::nullopt,
- 3.2f,
- AZStd::nullopt,
- AZStd::nullopt,
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, GetStiffnessFactor())
- .Times(1)
- .WillOnce(::testing::Return(2.2f));
- EXPECT_CALL(*simulatedObject, SetStiffnessFactor(::testing::FloatEq(3.2f)))
- .Times(1);
- },
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, GetStiffnessFactor())
- .Times(1)
- .WillOnce(::testing::Return(2.2f));
- EXPECT_CALL(*simulatedObject, SetStiffnessFactor(::testing::FloatEq(3.2f)))
- .Times(1);
- EXPECT_CALL(*simulatedObject, SetStiffnessFactor(::testing::FloatEq(2.2f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedObjectTestsParam
- {
- AZStd::nullopt,
- AZStd::nullopt,
- AZStd::nullopt,
- 4.2f,
- AZStd::nullopt,
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, GetDampingFactor())
- .Times(1)
- .WillOnce(::testing::Return(3.2f));
- EXPECT_CALL(*simulatedObject, SetDampingFactor(::testing::FloatEq(4.2f)))
- .Times(1);
- },
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, GetDampingFactor())
- .Times(1)
- .WillOnce(::testing::Return(3.2f));
- EXPECT_CALL(*simulatedObject, SetDampingFactor(::testing::FloatEq(4.2f)))
- .Times(1);
- EXPECT_CALL(*simulatedObject, SetDampingFactor(::testing::FloatEq(3.2f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedObjectTestsParam
- {
- AZStd::nullopt,
- AZStd::nullopt,
- AZStd::nullopt,
- AZStd::nullopt,
- std::vector<std::string>{"left_knee", "right_knee"},
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- EXPECT_CALL(*simulatedObject, SetColliderTags(::testing::Pointwise(StrEq(), std::vector<std::string> {"left_knee", "right_knee"})))
- .Times(1);
- },
- [](UnderTest::SimulatedObject* simulatedObject)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedObject, SetColliderTags(::testing::Pointwise(StrEq(), std::vector<std::string> {"left_knee", "right_knee"})))
- .Times(1);
- EXPECT_CALL(*simulatedObject, SetColliderTags(::testing::Pointwise(StrEq(), std::vector<std::string> {})))
- .Times(1);
- }
- },
- })
- ),
- [](const ::testing::TestParamInfo<::testing::tuple<bool, bool, CommandAdjustSimulatedObjectTestsParam>>& info)
- {
- std::string cmdline =
- (::testing::get<0>(info.param) ? std::string {"Execute_"} : std::string {"Undo_"})
- + (::testing::get<1>(info.param) ? std::string {"UseCommandString"} : std::string {"UseSetters"})
- + CommandAdjustSimulatedObjectTestsFixture::buildCommandLineFromTestParam(::testing::get<2>(info.param));
- std::replace(cmdline.begin(), cmdline.end(), ' ', '_');
- std::replace(cmdline.begin(), cmdline.end(), ';', '_');
- cmdline.erase(std::remove(cmdline.begin(), cmdline.end(), '-'), cmdline.end());
- cmdline.erase(std::remove(cmdline.begin(), cmdline.end(), '.'), cmdline.end());
- return cmdline;
- }
- );
- ///////////////////////////////////////////////////////////////////////////
- // CommandAdjustSimulatedJoint tests
- ///////////////////////////////////////////////////////////////////////////
- struct CommandAdjustSimulatedJointTestsParam
- {
- AZStd::optional<float> coneAngleLimit;
- AZStd::optional<float> mass;
- AZStd::optional<float> stiffness;
- AZStd::optional<float> damping;
- AZStd::optional<float> gravityFactor;
- AZStd::optional<float> friction;
- AZStd::optional<bool> pinned;
- AZStd::optional<std::vector<std::string>> colliderExclusionTags;
- AZStd::optional<SimulatedJoint::AutoExcludeMode> autoExcludeMode;
- AZStd::optional<bool> geometricAutoExclusion;
- void (*setExecuteExpectations)(UnderTest::SimulatedJoint*);
- void (*setUndoExpectations)(UnderTest::SimulatedJoint*);
- };
- class CommandAdjustSimulatedJointTestsFixture
- : public UnitTest::LeakDetectionFixture
- , public ::testing::WithParamInterface<::testing::tuple<bool, bool, CommandAdjustSimulatedJointTestsParam>>
- {
- public:
- static std::string buildCommandLineFromTestParam(const CommandAdjustSimulatedJointTestsParam& param)
- {
- std::string string;
- std::stringstream stream(string);
- if (param.coneAngleLimit.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_coneAngleLimitParameterName << ' ' << param.coneAngleLimit.value();
- }
- if (param.mass.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_massParameterName << ' ' << param.mass.value();
- }
- if (param.stiffness.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_stiffnessParameterName << ' ' << param.stiffness.value();
- }
- if (param.damping.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_dampingParameterName << ' ' << param.damping.value();
- }
- if (param.gravityFactor.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_gravityFactorParameterName << ' ' << param.gravityFactor.value();
- }
- if (param.friction.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_frictionParameterName << ' ' << param.friction.value();
- }
- if (param.pinned.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_pinnedParameterName << ' ' << (param.pinned.value() ? "true" : "false");
- }
- if (param.colliderExclusionTags.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_colliderExclusionTagsParameterName << ' ';
- for (const std::string& val : *param.colliderExclusionTags)
- {
- stream << val;
- if (&val != std::addressof(*(param.colliderExclusionTags->end() - 1)))
- {
- stream << ";";
- }
- }
- }
- if (param.autoExcludeMode.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_autoExcludeModeParameterName << ' ';
- switch (param.autoExcludeMode.value())
- {
- case SimulatedJoint::AutoExcludeMode::None:
- stream << "None";
- break;
- case SimulatedJoint::AutoExcludeMode::Self:
- stream << "Self";
- break;
- case SimulatedJoint::AutoExcludeMode::SelfAndNeighbors:
- stream << "SelfAndNeighbors";
- break;
- case SimulatedJoint::AutoExcludeMode::All:
- stream << "All";
- break;
- };
- }
- if (param.geometricAutoExclusion.has_value())
- {
- stream << " -" << UnderTest::CommandAdjustSimulatedJoint::s_geometricAutoExclusionParameterName << ' ' << (param.geometricAutoExclusion.value() ? "true" : "false");
- }
- return stream.str();
- }
- };
- TEST_P(CommandAdjustSimulatedJointTestsFixture, TestExecute)
- {
- using ::testing::Return;
- using ::testing::ReturnRef;
- UnderTest::EMotionFXManager& manager = UnderTest::GetEMotionFX();
- UnderTest::ActorManager actorManager;
- UnderTest::Actor actor;
- auto simulatedObjectSetup = AZStd::make_shared<UnderTest::SimulatedObjectSetup>();
- UnderTest::SimulatedObject simulatedObject;
- UnderTest::SimulatedJoint simulatedJoint;
- EXPECT_CALL(manager, GetActorManager())
- .WillRepeatedly(Return(&actorManager));
- EXPECT_CALL(actorManager, FindActorByID(0))
- .WillRepeatedly(Return(&actor));
- EXPECT_CALL(actor, GetSimulatedObjectSetup())
- .WillRepeatedly(ReturnRef(simulatedObjectSetup));
- EXPECT_CALL(actor, GetDirtyFlag())
- .WillOnce(Return(false));
- EXPECT_CALL(*simulatedObjectSetup, GetSimulatedObject(0))
- .WillRepeatedly(Return(&simulatedObject));
- EXPECT_CALL(simulatedObject, GetSimulatedJoint(0))
- .WillRepeatedly(Return(&simulatedJoint));
- AZStd::vector<AZStd::string> defaultColliderExclusionTags;
- EXPECT_CALL(simulatedJoint, GetColliderExclusionTags())
- .WillRepeatedly(testing::ReturnRef(defaultColliderExclusionTags));
- const bool doExecuteOnly = ::testing::get<0>(GetParam());
- const bool useCommandString = ::testing::get<1>(GetParam());
- const auto& testParams = ::testing::get<2>(GetParam());
- if (doExecuteOnly)
- {
- EXPECT_CALL(actor, SetDirtyFlag(true));
- testParams.setExecuteExpectations(&simulatedJoint);
- }
- else
- {
- {
- testing::InSequence sequence;
- EXPECT_CALL(actor, SetDirtyFlag(true))
- .RetiresOnSaturation();
- EXPECT_CALL(actor, SetDirtyFlag(false))
- .RetiresOnSaturation();
- }
- testParams.setUndoExpectations(&simulatedJoint);
- }
- AZStd::string paramString {"-actorId 0 -objectIndex 0 -jointIndex 0"};
- paramString += AZStd::string(buildCommandLineFromTestParam(testParams).c_str());
- MCore::CommandLine parameters(paramString);
- AZStd::string outResult;
- UnderTest::CommandAdjustSimulatedJoint command(/*actorId=*/0, /*objectIndex=*/0, /*jointIndex=*/0);
- if (useCommandString)
- {
- EXPECT_TRUE(command.SetCommandParameters(parameters));
- }
- else
- {
- if (testParams.coneAngleLimit.has_value())
- {
- command.SetConeAngleLimit(testParams.coneAngleLimit.value());
- }
- if (testParams.mass.has_value())
- {
- command.SetMass(testParams.mass.value());
- }
- if (testParams.stiffness.has_value())
- {
- command.SetStiffness(testParams.stiffness.value());
- }
- if (testParams.damping.has_value())
- {
- command.SetDamping(testParams.damping.value());
- }
- if (testParams.gravityFactor.has_value())
- {
- command.SetGravityFactor(testParams.gravityFactor.value());
- }
- if (testParams.friction.has_value())
- {
- command.SetFriction(testParams.friction.value());
- }
- if (testParams.pinned.has_value())
- {
- command.SetPinned(testParams.pinned.value());
- }
- if (testParams.colliderExclusionTags.has_value())
- {
- AZStd::vector<AZStd::string> value;
- for (const std::string& stdstring : testParams.colliderExclusionTags.value())
- {
- value.emplace_back(stdstring.c_str(), stdstring.size());
- }
- command.SetColliderExclusionTags(value);
- }
- if (testParams.autoExcludeMode.has_value())
- {
- command.SetAutoExcludeMode(testParams.autoExcludeMode.value());
- }
- if (testParams.geometricAutoExclusion.has_value())
- {
- command.SetGeometricAutoExclusion(testParams.geometricAutoExclusion.has_value());
- }
- }
- EXPECT_TRUE(command.Execute(parameters, outResult)) << outResult.c_str();
- if (!doExecuteOnly)
- {
- EXPECT_TRUE(command.Undo(parameters, outResult)) << outResult.c_str();
- }
- }
- INSTANTIATE_TEST_CASE_P(TestCommandAdjustSimulatedJoint, CommandAdjustSimulatedJointTestsFixture,
- ::testing::Combine(
- ::testing::Bool(), // Test execute or test undo
- ::testing::Bool(), // Use command strings or not
- ::testing::ValuesIn(
- {
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ 0.3f,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetConeAngleLimit())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetConeAngleLimit(::testing::FloatEq(0.3f)))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetConeAngleLimit())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetConeAngleLimit(::testing::FloatEq(0.3f)))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetConeAngleLimit(::testing::FloatEq(0.8f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ 0.3f,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetMass())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetMass(::testing::FloatEq(0.3f)))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetMass())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetMass(::testing::FloatEq(0.3f)))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetMass(::testing::FloatEq(0.8f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ 0.3f,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetStiffness())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetStiffness(::testing::FloatEq(0.3f)))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetStiffness())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetStiffness(::testing::FloatEq(0.3f)))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetStiffness(::testing::FloatEq(0.8f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ 0.3f,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetDamping())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetDamping(::testing::FloatEq(0.3f)))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetDamping())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetDamping(::testing::FloatEq(0.3f)))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetDamping(::testing::FloatEq(0.8f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ 0.3f,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetGravityFactor())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetGravityFactor(::testing::FloatEq(0.3f)))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetGravityFactor())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetGravityFactor(::testing::FloatEq(0.3f)))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetGravityFactor(::testing::FloatEq(0.8f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ 0.3f,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetFriction())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetFriction(::testing::FloatEq(0.3f)))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetFriction())
- .Times(1)
- .WillOnce(::testing::Return(0.8f));
- EXPECT_CALL(*simulatedJoint, SetFriction(::testing::FloatEq(0.3f)))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetFriction(::testing::FloatEq(0.8f)))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ true,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, IsPinned())
- .Times(1)
- .WillOnce(::testing::Return(false));
- EXPECT_CALL(*simulatedJoint, SetPinned(true))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint* simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, IsPinned())
- .Times(1)
- .WillOnce(::testing::Return(false));
- EXPECT_CALL(*simulatedJoint, SetPinned(true))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetPinned(false))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ std::vector<std::string>{"left_knee", "right_knee"},
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint * simulatedJoint)
- {
- EXPECT_CALL(*simulatedJoint, SetColliderExclusionTags(::testing::Pointwise(StrEq(), std::vector<std::string> {"left_knee", "right_knee"})))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint * simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, SetColliderExclusionTags(::testing::Pointwise(StrEq(), std::vector<std::string> {"left_knee", "right_knee"})))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetColliderExclusionTags(::testing::Pointwise(StrEq(), std::vector<std::string> {})))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ SimulatedJoint::AutoExcludeMode::All,
- /* geometricAutoExclusion = */ AZStd::nullopt,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint * simulatedJoint)
- {
- EXPECT_CALL(*simulatedJoint, GetAutoExcludeMode())
- .Times(1)
- .WillOnce(::testing::Return(SimulatedJoint::AutoExcludeMode::None));
- EXPECT_CALL(*simulatedJoint, SetAutoExcludeMode(SimulatedJoint::AutoExcludeMode::All))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint * simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, GetAutoExcludeMode())
- .Times(1)
- .WillOnce(::testing::Return(SimulatedJoint::AutoExcludeMode::None));
- EXPECT_CALL(*simulatedJoint, SetAutoExcludeMode(SimulatedJoint::AutoExcludeMode::All))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetAutoExcludeMode(SimulatedJoint::AutoExcludeMode::None))
- .Times(1);
- }
- },
- CommandAdjustSimulatedJointTestsParam
- {
- /* coneAngleLimit = */ AZStd::nullopt,
- /* mass = */ AZStd::nullopt,
- /* stiffness = */ AZStd::nullopt,
- /* damping = */ AZStd::nullopt,
- /* gravityFactor = */ AZStd::nullopt,
- /* friction = */ AZStd::nullopt,
- /* pinned = */ AZStd::nullopt,
- /* colliderExclusionTags = */ AZStd::nullopt,
- /* autoExcludeMode = */ AZStd::nullopt,
- /* geometricAutoExclusion = */ true,
- /* setExecuteExpectations = */ [](UnderTest::SimulatedJoint * simulatedJoint)
- {
- EXPECT_CALL(*simulatedJoint, IsGeometricAutoExclusion())
- .Times(1)
- .WillOnce(::testing::Return(false));
- EXPECT_CALL(*simulatedJoint, SetGeometricAutoExclusion(true))
- .Times(1);
- },
- /* setUndoExpectations = */ [](UnderTest::SimulatedJoint * simulatedJoint)
- {
- ::testing::InSequence sequence;
- EXPECT_CALL(*simulatedJoint, IsGeometricAutoExclusion())
- .Times(1)
- .WillOnce(::testing::Return(false));
- EXPECT_CALL(*simulatedJoint, SetGeometricAutoExclusion(true))
- .Times(1);
- EXPECT_CALL(*simulatedJoint, SetGeometricAutoExclusion(false))
- .Times(1);
- }
- },
- })
- ),
- [](const ::testing::TestParamInfo<::testing::tuple<bool, bool, CommandAdjustSimulatedJointTestsParam>>& info)
- {
- std::string cmdline =
- (::testing::get<0>(info.param) ? std::string {"Execute_"} : std::string {"Undo_"})
- + (::testing::get<1>(info.param) ? std::string {"UseCommandString"} : std::string {"UseSetters"})
- + CommandAdjustSimulatedJointTestsFixture::buildCommandLineFromTestParam(::testing::get<2>(info.param));
- std::replace(cmdline.begin(), cmdline.end(), ' ', '_');
- std::replace(cmdline.begin(), cmdline.end(), ';', '_');
- cmdline.erase(std::remove(cmdline.begin(), cmdline.end(), '-'), cmdline.end());
- cmdline.erase(std::remove(cmdline.begin(), cmdline.end(), '.'), cmdline.end());
- return cmdline;
- }
- );
- } // namespace EMotionFX
|