RemoveGroup.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <QTableWidget>
  10. #include <gtest/gtest.h>
  11. #include <Tests/UI/UIFixture.h>
  12. #include <Tests/Matchers.h>
  13. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  14. #include <EMotionFX/Source/AnimGraphManager.h>
  15. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  16. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ParameterWindow.h>
  17. #include <QApplication>
  18. #include <QComboBox>
  19. #include <Editor/ReselectingTreeView.h>
  20. #include <QtTest>
  21. #include <QApplication>
  22. #include <QWidget>
  23. #include <QToolBar>
  24. namespace EMotionFX
  25. {
  26. class RemoveGroupFixture : public UIFixture
  27. {
  28. public:
  29. void SetUp() override
  30. {
  31. UIFixture::SetUp();
  32. // Create empty anim graph and select it.
  33. const AZ::u32 animGraphId = 1;
  34. const AZStd::string command = AZStd::string::format("CreateAnimGraph -animGraphID %d", animGraphId);
  35. AZStd::string commandResult;
  36. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  37. ASSERT_TRUE(animGraphPlugin);
  38. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, commandResult)) << commandResult.c_str();
  39. m_animGraph = GetAnimGraphManager().FindAnimGraphByID(animGraphId);
  40. ASSERT_NE(m_animGraph, nullptr) << "Cannot find the newly created anim graph.";
  41. m_parameterWindow = animGraphPlugin->GetParameterWindow();
  42. ASSERT_TRUE(m_parameterWindow) << "Parameter window was not found";
  43. }
  44. void TearDown() override
  45. {
  46. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  47. delete m_animGraph;
  48. UIFixture::TearDown();
  49. }
  50. public:
  51. AnimGraph* m_animGraph = nullptr;
  52. EMStudio::ParameterWindow* m_parameterWindow = nullptr;
  53. };
  54. TEST_F(RemoveGroupFixture, RemoveNodeGroup)
  55. {
  56. RecordProperty("test_case_id", "C5522320");
  57. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  58. ASSERT_TRUE(animGraphPlugin) << "Anim graph plugin not found.";
  59. // Verify baseline
  60. ASSERT_EQ(m_animGraph->GetNumParameters(), 0) << "No Parameter Groups should exist initially";
  61. EXPECT_EQ(m_animGraph->GetNumValueParameters(), 0) << "No parameters should exist initially";
  62. AZStd::string result;
  63. // Create Parameter Group
  64. AZStd::string command = AZStd::string::format("AnimGraphAddGroupParameter -animGraphID %i -name \"%s\"", m_animGraph->GetID(), "Group0");
  65. ASSERT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, result)) << "Parameter Group could not be created";
  66. // Verify Parameter Group was created
  67. // Verify that we have the group inside the anim graph.
  68. ASSERT_EQ(m_animGraph->GetNumParameters(), 1) << "Group creation failed. We shouldn't have one parameter in the animgraph.";
  69. EXPECT_EQ(m_animGraph->GetNumValueParameters(), 0) << "Expecting no value parameters as we only created a group.";
  70. const Parameter* parameter = m_animGraph->FindParameter(0);
  71. EXPECT_NE(parameter, nullptr) << "The parameter we created should be valid.";
  72. ASSERT_THAT(parameter->GetName(), StrEq("Group0")) << "Group was made with the wrong name";
  73. // Select and remove the parameter group.
  74. m_parameterWindow->SelectParameters({ "Group0" });
  75. m_parameterWindow->OnRemoveSelected();
  76. // Verify that the Parameter group was removed
  77. ASSERT_EQ(m_animGraph->GetNumParameters(), 0) << "No Parameter Groups should exist initially";
  78. }
  79. } // namespace EMotionFX