CanRemoveMotionFromMotionSet.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <QPushButton>
  10. #include <QAction>
  11. #include <QtTest>
  12. #include <QHeaderView>
  13. #include <QMessageBox>
  14. #include <Tests/UI/AnimGraphUIFixture.h>
  15. #include <Tests/UI/ModalPopupHandler.h>
  16. #include <EMotionFX/Source/AnimGraphReferenceNode.h>
  17. #include <EMotionFX/Source/AnimGraphManager.h>
  18. #include <EMotionFX/Source/AnimGraphObject.h>
  19. #include <EMotionFX/Source/AnimGraphObjectFactory.h>
  20. #include <EMotionStudio/Plugins/StandardPlugins/Source/MotionSetsWindow/MotionSetsWindowPlugin.h>
  21. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  22. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h>
  23. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h>
  24. namespace EMotionFX
  25. {
  26. TEST_F(UIFixture, CanRemoveMotionFromMotionSet)
  27. {
  28. RecordProperty("test_case_id", "C24255734");
  29. auto motionSetPlugin = static_cast<EMStudio::MotionSetsWindowPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::MotionSetsWindowPlugin::CLASS_ID));
  30. ASSERT_TRUE(motionSetPlugin) << "No motion sets plugin found";
  31. EMStudio::MotionSetManagementWindow* managementWindow = motionSetPlugin->GetManagementWindow();
  32. ASSERT_TRUE(managementWindow) << "No motion sets management window found";
  33. EMStudio::MotionSetWindow* motionSetWindow = motionSetPlugin->GetMotionSetWindow();
  34. ASSERT_TRUE(motionSetWindow) << "No motion set window found";
  35. // Check if only the default motion set is there.
  36. const size_t numOldMotionSets = EMotionFX::GetMotionManager().GetNumMotionSets();
  37. EXPECT_EQ(numOldMotionSets, 1);
  38. // Find the action to create a new motion set and press it.
  39. QWidget* addMotionSetButton = GetWidgetWithNameFromNamedToolbar(managementWindow, "MotionSetManagementWindow.ToolBar", "MotionSetManagementWindow.ToolBar.AddNewMotionSet");
  40. ASSERT_TRUE(addMotionSetButton);
  41. QTest::mouseClick(addMotionSetButton, Qt::LeftButton);
  42. // Check there is now a motion set.
  43. const size_t numMotionSetsAfterCreate = EMotionFX::GetMotionManager().GetNumMotionSets();
  44. ASSERT_EQ(numMotionSetsAfterCreate, numOldMotionSets + 1);
  45. EMotionFX::MotionSet* motionSet = EMotionFX::GetMotionManager().GetMotionSet(numOldMotionSets);
  46. // Ensure new motion set is selected.
  47. motionSetPlugin->SetSelectedSet(motionSet);
  48. // It should be empty at the moment.
  49. const size_t numMotions = motionSet->GetNumMotionEntries();
  50. EXPECT_EQ(numMotions, 0);
  51. // Find the action to add a motion to the set and press it.
  52. QWidget* addMotionButton = GetWidgetWithNameFromNamedToolbar(motionSetWindow, "MotionSetWindow.ToolBar", "MotionSetWindow.ToolBar.AddANewEntry");
  53. ASSERT_TRUE(addMotionButton);
  54. QTest::mouseClick(addMotionButton, Qt::LeftButton);
  55. // There should now be a motion.
  56. const size_t numMotionsAfterCreate = motionSet->GetNumMotionEntries();
  57. ASSERT_EQ(numMotionsAfterCreate, 1);
  58. AZStd::unordered_map<AZStd::string, MotionSet::MotionEntry*> motions = motionSet->GetMotionEntries();
  59. // The newly created motion should be called "<undefined>".
  60. MotionSet::MotionEntry* motion = motions["<undefined>"];
  61. ASSERT_TRUE(motion) << "no \"<undefined>\" motion found";
  62. // Ensure the new motion is added to the table.
  63. motionSetWindow->ReInit();
  64. // Now we need to remove it again.
  65. EMStudio::MotionSetTableWidget* table = motionSetWindow->findChild< EMStudio::MotionSetTableWidget*>("EMFX.MotionSetWindow.TableWidget");
  66. ASSERT_TRUE(table);
  67. ASSERT_EQ(table->rowCount(), 1);
  68. // Select the motion in the table.
  69. QList<QTableWidgetItem *> items = table->findItems("<undefined>", Qt::MatchExactly);
  70. items[0]->setSelected(true);
  71. // Set up a watcher to press the ok button in the Really Delete dialog.
  72. ModalPopupHandler reallyDeletehandler;
  73. reallyDeletehandler.WaitForPopupPressSpecificButton<QMessageBox*>("EMFX.MotionSet.RemoveMotionMessageBox.YesButton");
  74. // Pop up the context menu and select the Remove action.
  75. ModalPopupHandler menuHandler;
  76. menuHandler.ShowContextMenuAndTriggerAction(motionSetWindow, "EMFX.MotionSetTableWidget.RemoveSelectedMotionsAction", 3000, nullptr);
  77. // Make sure any changes filter through to the widget.
  78. motionSetWindow->ReInit();
  79. // The motion should now be gone.
  80. items = table->findItems("<undefined>", Qt::MatchExactly);
  81. ASSERT_EQ(table->rowCount(), 0);
  82. motions = motionSet->GetMotionEntries();
  83. ASSERT_EQ(table->rowCount(), 0);
  84. }
  85. TEST_F(UIFixture, CanRemoveSingleMotionFromMotionSetWithMultipleMotions)
  86. {
  87. RecordProperty("test_case_id", "C15105117");
  88. auto motionSetPlugin = static_cast<EMStudio::MotionSetsWindowPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::MotionSetsWindowPlugin::CLASS_ID));
  89. ASSERT_TRUE(motionSetPlugin) << "No motion sets plugin found";
  90. EMStudio::MotionSetManagementWindow* managementWindow = motionSetPlugin->GetManagementWindow();
  91. ASSERT_TRUE(managementWindow) << "No motion sets management window found";
  92. EMStudio::MotionSetWindow* motionSetWindow = motionSetPlugin->GetMotionSetWindow();
  93. ASSERT_TRUE(motionSetWindow) << "No motion set window found";
  94. // There should be only the default motion set.
  95. const size_t oldNumMotionSets = EMotionFX::GetMotionManager().GetNumMotionSets();
  96. // Find the action to create a new motion set and press it.
  97. QWidget* addMotionSetButton = GetWidgetWithNameFromNamedToolbar(managementWindow, "MotionSetManagementWindow.ToolBar", "MotionSetManagementWindow.ToolBar.AddNewMotionSet");
  98. ASSERT_TRUE(addMotionSetButton);
  99. QTest::mouseClick(addMotionSetButton, Qt::LeftButton);
  100. // Check there is now an additional motion set.
  101. ASSERT_EQ(EMotionFX::GetMotionManager().GetNumMotionSets(), oldNumMotionSets + 1);
  102. EMotionFX::MotionSet* motionSet = EMotionFX::GetMotionManager().GetMotionSet(oldNumMotionSets);
  103. // Ensure new motion set is selected.
  104. motionSetPlugin->SetSelectedSet(motionSet);
  105. // It should be empty at the moment.
  106. const size_t numMotions = motionSet->GetNumMotionEntries();
  107. EXPECT_EQ(numMotions, 0);
  108. // Find the action to add a motion to the set and press it twice.
  109. QWidget* addMotionButton = GetWidgetWithNameFromNamedToolbar(motionSetWindow, "MotionSetWindow.ToolBar", "MotionSetWindow.ToolBar.AddANewEntry");
  110. ASSERT_TRUE(addMotionButton);
  111. QTest::mouseClick(addMotionButton, Qt::LeftButton);
  112. QTest::mouseClick(addMotionButton, Qt::LeftButton);
  113. // There should now be two motion.
  114. const size_t numMotionsAfterCreate = motionSet->GetNumMotionEntries();
  115. ASSERT_EQ(numMotionsAfterCreate, 2);
  116. AZStd::unordered_map<AZStd::string, MotionSet::MotionEntry*> motions = motionSet->GetMotionEntries();
  117. // The newly created motions should be called "<undefined>".
  118. MotionSet::MotionEntry* motion = motions["<undefined>"];
  119. ASSERT_TRUE(motion) << "no \"<undefined>\" motion found";
  120. // Ensure the new motion is added to the table.
  121. motionSetWindow->ReInit();
  122. // Now we need to remove one of them.
  123. EMStudio::MotionSetTableWidget* table = motionSetWindow->findChild< EMStudio::MotionSetTableWidget*>("EMFX.MotionSetWindow.TableWidget");
  124. ASSERT_TRUE(table);
  125. ASSERT_EQ(table->rowCount(), 2);
  126. // Select the motion in the table.
  127. QList<QTableWidgetItem *> items = table->findItems("<undefined>", Qt::MatchExactly);
  128. items[0]->setSelected(true);
  129. // Set up a watcher to press the ok button in the Really Delete dialog.
  130. ModalPopupHandler reallyDeletehandler;
  131. reallyDeletehandler.WaitForPopupPressSpecificButton<QMessageBox*>("EMFX.MotionSet.RemoveMotionMessageBox.YesButton");
  132. // Pop up the context menu and select the Remove action.
  133. ModalPopupHandler menuHandler;
  134. menuHandler.ShowContextMenuAndTriggerAction(motionSetWindow, "EMFX.MotionSetTableWidget.RemoveSelectedMotionsAction", 3000, nullptr);
  135. // Make sure any changes filter through to the widget.
  136. motionSetWindow->ReInit();
  137. // The motion should now be gone leaving the other.
  138. items = table->findItems("<undefined>", Qt::MatchExactly);
  139. ASSERT_EQ(table->rowCount(), 1);
  140. motions = motionSet->GetMotionEntries();
  141. ASSERT_EQ(table->rowCount(), 1);
  142. }
  143. } // namespace EMotionFX