3
0

ParameterGroupEdit.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <AzToolsFramework/UI/PropertyEditor/PropertyStringLineEditCtrl.hxx>
  18. #include <QApplication>
  19. #include <QComboBox>
  20. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ParameterCreateEditWidget.h>
  21. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ParameterEditor/ParameterEditorFactory.h>
  22. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ParameterEditor/ValueParameterEditor.h>
  23. #include <EMotionFX/Source/AnimGraphNodeGroup.h>
  24. #include <Editor/ReselectingTreeView.h>
  25. #include <QtTest>
  26. #include <QApplication>
  27. #include <QWidget>
  28. #include <QToolBar>
  29. #include <AzToolsFramework/UI/PropertyEditor/PropertyRowWidget.hxx>
  30. namespace EMotionFX
  31. {
  32. class EditGroupFixture
  33. : public UIFixture
  34. {
  35. public:
  36. void SetUp() override
  37. {
  38. UIFixture::SetUp();
  39. // Create empty anim graph and select it.
  40. const AZ::u32 animGraphId = 1;
  41. const AZStd::string command = AZStd::string::format("CreateAnimGraph -animGraphID %d", animGraphId);
  42. AZStd::string commandResult;
  43. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, commandResult)) << commandResult.c_str();
  44. m_animGraph = GetAnimGraphManager().FindAnimGraphByID(animGraphId);
  45. EXPECT_NE(m_animGraph, nullptr) << "Cannot find the newly created anim graph.";
  46. }
  47. void TearDown() override
  48. {
  49. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  50. delete m_animGraph;
  51. UIFixture::TearDown();
  52. }
  53. public:
  54. AnimGraph* m_animGraph = nullptr;
  55. };
  56. TEST_F(EditGroupFixture, CanEditParameterGroup)
  57. {
  58. RecordProperty("test_case_id", "C5522320");
  59. using WidgetMap = AZStd::unordered_map<AzToolsFramework::InstanceDataNode*, AzToolsFramework::PropertyRowWidget*>;
  60. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  61. ASSERT_TRUE(animGraphPlugin) << "Anim graph plugin not found.";
  62. // Verify baseline
  63. ASSERT_EQ(m_animGraph->GetNumParameters(), 0) << "No Parameter Groups should exist initially";
  64. EXPECT_EQ(m_animGraph->GetNumValueParameters(), 0) << "No parameters should exist initially";
  65. AZStd::string result;
  66. // Create Parameter Group
  67. AZStd::string command = AZStd::string::format("AnimGraphAddGroupParameter -animGraphID %i -name \"%s\"", m_animGraph->GetID(), "Group0");
  68. ASSERT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, result)) << "Parameter Group could not be created" << result.c_str();
  69. // Verify Parameter Group was created
  70. // Verify that we have the group inside the anim graph.
  71. ASSERT_EQ(m_animGraph->GetNumParameters(), 1) << "Group creation failed. We shouldn't have one parameter in the animgraph.";
  72. EXPECT_EQ(m_animGraph->GetNumValueParameters(), 0) << "Expecting no value parameters as we only created a group.";
  73. const Parameter* parameter = m_animGraph->FindParameter(0);
  74. EXPECT_NE(parameter, nullptr) << "The parameter we created should be valid.";
  75. ASSERT_THAT(parameter->GetName(), StrEq("Group0"));
  76. // Edit name of Parameter group
  77. EMStudio::ParameterWindow* parameterWindow = animGraphPlugin->GetParameterWindow();
  78. ASSERT_TRUE(parameterWindow) << "Anim graph parameter window is invalid.";
  79. parameterWindow->SelectParameters({ "Group0" });
  80. parameterWindow->OnEditSelected();
  81. auto groupEditWidget = static_cast<EMStudio::ParameterCreateEditWidget*>(FindTopLevelWidget("ParameterCreateEditWidget"));
  82. ASSERT_NE(groupEditWidget, nullptr) << "Cannot find anim graph group edit dialog";
  83. auto propertyEditor = groupEditWidget->findChild<AzToolsFramework::ReflectedPropertyEditor*>("EMFX.ParameterCreateEditWidget.ReflectedPropertyEditor.ParameterEditorWidget");
  84. // Get list of all PropertyRowWidgets (and their InstanceDataNodes)
  85. const WidgetMap& list = propertyEditor->GetWidgets();
  86. ASSERT_GT(list.size(), 0) << "Did not find any PropertyRowWidgets";
  87. // Look for PropertyRowWidget for "Name"
  88. const auto propertyRowIt = AZStd::find_if(list.begin(), list.end(), [](const WidgetMap::value_type& item) {
  89. return item.second->objectName() == "Name";
  90. });
  91. ASSERT_NE(propertyRowIt, list.end());
  92. const AzToolsFramework::PropertyRowWidget* propertyRow = propertyRowIt->second;
  93. // Set the text for the textbox to edit AnimGraph Node name
  94. auto lineEdit = static_cast<AzToolsFramework::PropertyStringLineEditCtrl*>(propertyRow->GetChildWidget());
  95. QString newName = "DiffGroup";
  96. lineEdit->UpdateValue(newName);
  97. groupEditWidget->accept();
  98. // Verify that name was changed
  99. ASSERT_THAT(parameter->GetName(), StrEq("DiffGroup"));
  100. }
  101. } // namespace EMotionFX