/* * 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 namespace EMotionFX { template class CanSetParameterToDefaultValueWhenInGroupFixture : public CommandRunnerFixture { public: using TestParameterT = T; template ValueType GetExpectedValue(); template <> AZ::Quaternion GetExpectedValue() { return AZ::Quaternion::CreateRotationX(0.5f); } template <> AZStd::string GetExpectedValue() { return "New default value for a string"; } template <> AZ::Vector4 GetExpectedValue() { return AZ::Vector4(2.0f, 3.0f, 4.0f, 5.0f); } template <> AZ::Vector3 GetExpectedValue() { return AZ::Vector3(2.0f, 3.0f, 4.0f); } template <> AZ::Vector2 GetExpectedValue() { return AZ::Vector2(2.0f, 3.0f); } template void TestEquality(const ValueType& lhs, const ValueType& rhs) { EXPECT_THAT(lhs, IsClose(rhs)); } template <> void TestEquality(const AZStd::string& lhs, const AZStd::string& rhs) { EXPECT_EQ(lhs, rhs); } template void TestInequality(const ValueType& lhs, const ValueType& rhs) { EXPECT_THAT(lhs, ::testing::Not(IsClose(rhs))); } template <> void TestInequality(const AZStd::string& lhs, const AZStd::string& rhs) { EXPECT_NE(lhs, rhs); } }; template class TestParameterT { public: using ParameterT = ParameterType; using AttributeT = AttributeType; // Use the return type from the attribute's GetValue method as the type // that this attribute contains using ValueT = AZStd::remove_const_t().GetValue())>>; }; using RotationParameterT = TestParameterT; using StringParameterT = TestParameterT; using Vector2ParameterT = TestParameterT; using Vector3ParameterT = TestParameterT; using Vector4ParameterT = TestParameterT; using TypesToTest = ::testing::Types< RotationParameterT, StringParameterT, Vector2ParameterT, Vector3ParameterT, Vector4ParameterT >; TYPED_TEST_CASE(CanSetParameterToDefaultValueWhenInGroupFixture, TypesToTest); TYPED_TEST(CanSetParameterToDefaultValueWhenInGroupFixture, CanSetParameterToDefaultValueWhenInGroup) { using ParameterT = typename TestFixture::TestParameterT::ParameterT; using AttributeT = typename TestFixture::TestParameterT::AttributeT; using ValueT = typename TestFixture::TestParameterT::ValueT; ActorUniquePtr actor = ActorFactory::CreateAndInit(1); ActorInstance* actorInstance = ActorInstance::Create(actor.get()); this->ExecuteCommands({ R"(Select -actorInstanceID )" + std::to_string(actorInstance->GetID()), R"(CreateMotionSet -name CanSetParameterToDefaultValueWhenInGroupMotionSet -motionSetID 0)", R"(CreateAnimGraph -animGraphID 0)", R"(AnimGraphAddGroupParameter -animGraphID 0 -name GroupParam)", R"(AnimGraphCreateParameter -animGraphID 0 -parent GroupParam -name Param -type )" + azrtti_typeid().template ToString(), R"(ActivateAnimGraph -animGraphID 0 -motionSetID 0 -actorInstanceID )" + std::to_string(actorInstance->GetID()), }); AnimGraph* animGraph = GetEMotionFX().GetAnimGraphManager()->FindAnimGraphByID(0); const ValueParameter* valueParameter = animGraph->FindValueParameter(0); const ParameterT* defaultValueParameter = azdynamic_cast(valueParameter); ASSERT_TRUE(defaultValueParameter) << "Found parameter does not inherit from DefaultValueParameter"; const ValueT expectedValue = this->template GetExpectedValue(); this->TestInequality(defaultValueParameter->GetDefaultValue(), expectedValue); AnimGraphInstance* animGraphInstance = animGraph->GetAnimGraphInstance(0); auto instanceValue = static_cast(animGraphInstance->GetParameterValue(animGraph->FindValueParameterIndex(valueParameter).GetValue())); ASSERT_EQ(instanceValue->GetType(), AttributeT::TYPE_ID); // Set the parameter's current value instanceValue->SetValue(expectedValue); auto animGraphPlugin = static_cast(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID)); ASSERT_TRUE(animGraphPlugin) << "Expected to find the AnimGraph plugin. Is it loaded?"; QTreeWidget* treeWidget = animGraphPlugin->GetParameterWindow()->findChild("AnimGraphParamWindow"); ASSERT_TRUE(treeWidget) << "Expected to find the QTreeWidget inside the AnimGraph plugin's parameter window"; const QTreeWidgetItem* groupParameterItem = treeWidget->topLevelItem(0); const QTreeWidgetItem* valueParameterItem = groupParameterItem->child(0); treeWidget->setItemSelected(valueParameterItem, true); // Make the current value of the parameter from the current animgraph the parameter's default value animGraphPlugin->GetParameterWindow()->OnMakeDefaultValue(); this->TestEquality(defaultValueParameter->GetDefaultValue(), expectedValue); } } // namespace EMotionFX