/* * 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 "qtestsystem.h" namespace EMotionFX { class RemoveParameterFixture : public UIFixture { public: void SetUp() override { UIFixture::SetUp(); // Create empty anim graph and select it. const AZStd::string command = AZStd::string::format("CreateAnimGraph -animGraphID %d", m_animGraphId); AZStd::string commandResult; EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, commandResult)) << commandResult.c_str(); m_animGraph = GetAnimGraphManager().FindAnimGraphByID(m_animGraphId); EXPECT_NE(m_animGraph, nullptr) << "Cannot find newly created anim graph."; auto animGraphPlugin = static_cast(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID)); EXPECT_NE(animGraphPlugin, nullptr) << "Anim graph plugin not found."; m_parameterWindow = animGraphPlugin->GetParameterWindow(); EXPECT_NE(m_parameterWindow, nullptr) << "Anim graph parameter window is invalid."; } void TearDown() override { QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); delete m_animGraph; UIFixture::TearDown(); } public: const AZ::u32 m_animGraphId = 64; AnimGraph* m_animGraph = nullptr; EMStudio::ParameterWindow* m_parameterWindow = nullptr; }; TEST_F(RemoveParameterFixture, RemoveParameterSimple) { AZStd::string commandString; AZStd::string commandResult; // Create parameter. const AZ::TypeId parameterTypeId = EMotionFX::ParameterFactory::GetValueParameterTypes()[0]; AZStd::unique_ptr parameterPrototype(EMotionFX::ParameterFactory::Create(parameterTypeId)); parameterPrototype->SetName("Parameter0"); CommandSystem::ConstructCreateParameterCommand(commandString, m_animGraph, parameterPrototype.get()); EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(commandString, commandResult)) << commandResult.c_str(); EXPECT_EQ(m_animGraph->GetNumParameters(), 1); // Select and remove the parameter. m_parameterWindow->SelectParameters({parameterPrototype->GetName().c_str()}); m_parameterWindow->OnRemoveSelected(); // Verify that the parameter got correctly removed. EXPECT_EQ(m_animGraph->GetNumParameters(), 0) << "Removing the parameter failed."; } TEST_F(RemoveParameterFixture, RemoveAllSelectedParameters) { RecordProperty("test_case_id", "C1559137"); AZStd::string commandString; AZStd::string commandResult; AZStd::vector parameterNames; // Create parameter for each of the available types. const AZStd::vector parameterTypeIds = EMotionFX::ParameterFactory::GetValueParameterTypes(); for (const AZ::TypeId& parameterTypeId : parameterTypeIds) { const AZStd::string parameterName = AZStd::string::format("Parameter (Type=%s)", parameterTypeId.ToString().c_str()); parameterNames.emplace_back(parameterName); AZStd::unique_ptr parameterPrototype(EMotionFX::ParameterFactory::Create(parameterTypeId)); parameterPrototype->SetName(parameterName); CommandSystem::ConstructCreateParameterCommand(commandString, m_animGraph, parameterPrototype.get()); EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(commandString, commandResult)) << commandResult.c_str(); } EXPECT_EQ(m_animGraph->GetNumParameters(), parameterTypeIds.size()); // Select all parameters and remove them using the remove selected operation. m_parameterWindow->SelectParameters(parameterNames); m_parameterWindow->OnRemoveSelected(); // Verify that all parameters got correctly removed. EXPECT_EQ(m_animGraph->GetNumParameters(), 0) << "Removing the parameter failed."; } } // namespace EMotionFX