3
0

AddGroup.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <Tests/Matchers.h>
  11. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  12. #include <EMotionFX/Source/AnimGraphManager.h>
  13. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  14. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/ParameterWindow.h>
  15. #include <QApplication>
  16. #include <QComboBox>
  17. namespace EMotionFX
  18. {
  19. class AddGroupFixture
  20. : public UIFixture
  21. {
  22. public:
  23. void SetUp() override
  24. {
  25. UIFixture::SetUp();
  26. // Create empty anim graph and select it.
  27. const AZ::u32 animGraphId = 1;
  28. const AZStd::string command = AZStd::string::format("CreateAnimGraph -animGraphID %d", animGraphId);
  29. AZStd::string commandResult;
  30. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommand(command, commandResult)) << commandResult.c_str();
  31. m_animGraph = GetAnimGraphManager().FindAnimGraphByID(animGraphId);
  32. EXPECT_NE(m_animGraph, nullptr) << "Cannot find the newly created anim graph.";
  33. }
  34. void TearDown() override
  35. {
  36. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  37. delete m_animGraph;
  38. UIFixture::TearDown();
  39. }
  40. public:
  41. AnimGraph* m_animGraph = nullptr;
  42. };
  43. TEST_F(AddGroupFixture, AddGroupParameter)
  44. {
  45. RecordProperty("test_case_id", "C5506441");
  46. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  47. ASSERT_TRUE(animGraphPlugin) << "Anim graph plugin not found.";
  48. // Trigger the window that will let us set a name for the group to add.
  49. EMStudio::ParameterWindow* parameterWindow = animGraphPlugin->GetParameterWindow();
  50. ASSERT_TRUE(parameterWindow) << "Anim graph parameter window is invalid.";
  51. parameterWindow->OnAddGroup();
  52. // Grab a pointer to that dialog that pops up and accept it (basically click the Ok button).
  53. QWidget* groupCreateWidget = FindTopLevelWidget("EMFX.ParameterCreateRenameDialog");
  54. ASSERT_NE(groupCreateWidget, nullptr) << "Cannot find anim graph group create/rename dialog. Is the anim graph selected?";
  55. auto groupCreateWindow = qobject_cast<EMStudio::ParameterCreateRenameWindow*>(groupCreateWidget);
  56. groupCreateWindow->accept();
  57. // Verify that we have the group inside the anim graph.
  58. ASSERT_EQ(m_animGraph->GetNumParameters(), 1) << "Group creation failed. We shouldn't have one parameter in the animgraph.";
  59. EXPECT_EQ(m_animGraph->GetNumValueParameters(), 0) << "Expecting no value parameters as we only created a group.";
  60. const Parameter* parameter = m_animGraph->FindParameter(0);
  61. EXPECT_NE(parameter, nullptr) << "The parameter we created should be valid.";
  62. EXPECT_THAT(parameter->GetName(), StrEq("Group0"));
  63. EXPECT_EQ(parameter->RTTI_GetType(), azrtti_typeid<GroupParameter>()) << "The type of the created parameter isn't a group.";
  64. }
  65. } // namespace EMotionFX