3
0

CanRemoveMotionSet.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <QApplication>
  10. #include <QWidget>
  11. #include <QWidgetList>
  12. #include <QAction>
  13. #include <QtTest>
  14. #include <QTreeWidget>
  15. #include <QMessageBox>
  16. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  17. #include <EMotionStudio/Plugins/StandardPlugins/Source/MotionSetsWindow/MotionSetsWindowPlugin.h>
  18. #include <EMotionStudio/Plugins/StandardPlugins/Source/MotionSetsWindow/MotionSetManagementWindow.h>
  19. #include <Tests/UI/UIFixture.h>
  20. #include <Tests/UI/ModalPopupHandler.h>
  21. namespace EMotionFX
  22. {
  23. TEST_F(UIFixture, CanRemoveMotionSet)
  24. {
  25. RecordProperty("test_case_id", "C24255735");
  26. const size_t oldNumMotionSets = GetMotionManager().GetNumMotionSets();
  27. // Select the motion set.
  28. MotionSet* motionSet = GetMotionManager().GetMotionSet(0);
  29. motionSet->SetDirtyFlag(false);
  30. auto motionSetsPlugin = static_cast<EMStudio::MotionSetsWindowPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::MotionSetsWindowPlugin::CLASS_ID));
  31. ASSERT_TRUE(motionSetsPlugin) << "Motion Sets Plugin could not be found";
  32. EMStudio::MotionSetManagementWindow* motionSetWindow = motionSetsPlugin->GetManagementWindow();
  33. motionSetWindow->ReInit();
  34. motionSetsPlugin->SetSelectedSet(motionSet);
  35. // Get the rect of the selected motion set tree widget item.
  36. ASSERT_TRUE(motionSetWindow) << "Expected a valid motion set management window.";
  37. const QTreeWidget* treeWidget = motionSetWindow->findChild<QTreeWidget*>("EMFX.MotionSetManagementWindow.MotionSetsTree");
  38. ASSERT_TRUE(treeWidget) << "Expected a valid motion set tree widget.";
  39. QTreeWidgetItem* motionSetItem = treeWidget->invisibleRootItem()->child(0);
  40. EXPECT_TRUE(motionSetItem) << "Tree widget item for motion set not found.";
  41. const QRect rect = treeWidget->visualItemRect(motionSetItem);
  42. // Bring up context menu for the selected motion set.
  43. BringUpContextMenu(treeWidget, rect);
  44. QMenu* contextMenu = motionSetWindow->findChild<QMenu*>("EMFX.MotionSetManagementWindow.ContextMenu");
  45. EXPECT_TRUE(contextMenu) << "No context menu available";
  46. // Remove selected motion sets.
  47. QAction* removeSelectedAction = nullptr;
  48. EXPECT_TRUE(UIFixture::GetActionFromContextMenu(removeSelectedAction, contextMenu, "Remove selected"))
  49. << "Cannot find remove selected motion set context menu entry.";
  50. // Modal pop-up window requesting to remove the motions from the project entirely or only from the motion set comes up.
  51. {
  52. ModalPopupHandler messageBoxPopupHandler;
  53. messageBoxPopupHandler.WaitForPopupPressDialogButton<QMessageBox*>(QDialogButtonBox::Yes);
  54. removeSelectedAction->trigger();
  55. }
  56. motionSetWindow->ReInit();
  57. // Data verification.
  58. EXPECT_EQ(GetMotionManager().GetNumMotionSets(), oldNumMotionSets - 1);
  59. EXPECT_EQ(treeWidget->topLevelItemCount(), 0) << "Expected an empty tree widget.";
  60. }
  61. } // namespace EMotionFX