RemoveParameter.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <gtest/gtest.h>
  9. #include <Tests/UI/UIFixture.h>
  10. #include <EMotionFX/CommandSystem/Source/AnimGraphParameterCommands.h>
  11. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  12. #include <EMotionFX/Source/Actor.h>
  13. #include <EMotionFX/Source/AnimGraphManager.h>
  14. #include <EMotionFX/Source/Parameter/ParameterFactory.h>
  15. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  16. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ParameterWindow.h>
  17. #include <QApplication>
  18. #include <QtTest>
  19. #include "qtestsystem.h"
  20. namespace EMotionFX
  21. {
  22. class RemoveParameterFixture
  23. : public UIFixture
  24. {
  25. public:
  26. void SetUp() override
  27. {
  28. UIFixture::SetUp();
  29. // Create empty anim graph and select it.
  30. const AZStd::string command = AZStd::string::format("CreateAnimGraph -animGraphID %d", m_animGraphId);
  31. AZStd::string commandResult;
  32. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, commandResult)) << commandResult.c_str();
  33. m_animGraph = GetAnimGraphManager().FindAnimGraphByID(m_animGraphId);
  34. EXPECT_NE(m_animGraph, nullptr) << "Cannot find newly created anim graph.";
  35. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  36. EXPECT_NE(animGraphPlugin, nullptr) << "Anim graph plugin not found.";
  37. m_parameterWindow = animGraphPlugin->GetParameterWindow();
  38. EXPECT_NE(m_parameterWindow, nullptr) << "Anim graph parameter window is invalid.";
  39. }
  40. void TearDown() override
  41. {
  42. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  43. delete m_animGraph;
  44. UIFixture::TearDown();
  45. }
  46. public:
  47. const AZ::u32 m_animGraphId = 64;
  48. AnimGraph* m_animGraph = nullptr;
  49. EMStudio::ParameterWindow* m_parameterWindow = nullptr;
  50. };
  51. TEST_F(RemoveParameterFixture, RemoveParameterSimple)
  52. {
  53. AZStd::string commandString;
  54. AZStd::string commandResult;
  55. // Create parameter.
  56. const AZ::TypeId parameterTypeId = EMotionFX::ParameterFactory::GetValueParameterTypes()[0];
  57. AZStd::unique_ptr<Parameter> parameterPrototype(EMotionFX::ParameterFactory::Create(parameterTypeId));
  58. parameterPrototype->SetName("Parameter0");
  59. CommandSystem::ConstructCreateParameterCommand(commandString, m_animGraph, parameterPrototype.get());
  60. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(commandString, commandResult)) << commandResult.c_str();
  61. EXPECT_EQ(m_animGraph->GetNumParameters(), 1);
  62. // Select and remove the parameter.
  63. m_parameterWindow->SelectParameters({parameterPrototype->GetName().c_str()});
  64. m_parameterWindow->OnRemoveSelected();
  65. // Verify that the parameter got correctly removed.
  66. EXPECT_EQ(m_animGraph->GetNumParameters(), 0) << "Removing the parameter failed.";
  67. }
  68. TEST_F(RemoveParameterFixture, RemoveAllSelectedParameters)
  69. {
  70. RecordProperty("test_case_id", "C1559137");
  71. AZStd::string commandString;
  72. AZStd::string commandResult;
  73. AZStd::vector<AZStd::string> parameterNames;
  74. // Create parameter for each of the available types.
  75. const AZStd::vector<AZ::TypeId> parameterTypeIds = EMotionFX::ParameterFactory::GetValueParameterTypes();
  76. for (const AZ::TypeId& parameterTypeId : parameterTypeIds)
  77. {
  78. const AZStd::string parameterName = AZStd::string::format("Parameter (Type=%s)", parameterTypeId.ToString<AZStd::string>().c_str());
  79. parameterNames.emplace_back(parameterName);
  80. AZStd::unique_ptr<Parameter> parameterPrototype(EMotionFX::ParameterFactory::Create(parameterTypeId));
  81. parameterPrototype->SetName(parameterName);
  82. CommandSystem::ConstructCreateParameterCommand(commandString, m_animGraph, parameterPrototype.get());
  83. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(commandString, commandResult)) << commandResult.c_str();
  84. }
  85. EXPECT_EQ(m_animGraph->GetNumParameters(), parameterTypeIds.size());
  86. // Select all parameters and remove them using the remove selected operation.
  87. m_parameterWindow->SelectParameters(parameterNames);
  88. m_parameterWindow->OnRemoveSelected();
  89. // Verify that all parameters got correctly removed.
  90. EXPECT_EQ(m_animGraph->GetNumParameters(), 0) << "Removing the parameter failed.";
  91. }
  92. } // namespace EMotionFX