| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <gtest/gtest.h>
- #include <QPushButton>
- #include <QAction>
- #include <QtTest>
- #include <QHeaderView>
- #include <QMessageBox>
- #include <Tests/UI/AnimGraphUIFixture.h>
- #include <Tests/UI/ModalPopupHandler.h>
- #include <EMotionFX/Source/AnimGraphReferenceNode.h>
- #include <EMotionFX/Source/AnimGraphManager.h>
- #include <EMotionFX/Source/AnimGraphObject.h>
- #include <EMotionFX/Source/AnimGraphObjectFactory.h>
- #include <EMotionStudio/Plugins/StandardPlugins/Source/MotionSetsWindow/MotionSetsWindowPlugin.h>
- #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
- #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h>
- #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h>
- namespace EMotionFX
- {
- TEST_F(UIFixture, CanRemoveMotionFromMotionSet)
- {
- RecordProperty("test_case_id", "C24255734");
- auto motionSetPlugin = static_cast<EMStudio::MotionSetsWindowPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::MotionSetsWindowPlugin::CLASS_ID));
- ASSERT_TRUE(motionSetPlugin) << "No motion sets plugin found";
- EMStudio::MotionSetManagementWindow* managementWindow = motionSetPlugin->GetManagementWindow();
- ASSERT_TRUE(managementWindow) << "No motion sets management window found";
- EMStudio::MotionSetWindow* motionSetWindow = motionSetPlugin->GetMotionSetWindow();
- ASSERT_TRUE(motionSetWindow) << "No motion set window found";
- // Check if only the default motion set is there.
- const size_t numOldMotionSets = EMotionFX::GetMotionManager().GetNumMotionSets();
- EXPECT_EQ(numOldMotionSets, 1);
- // Find the action to create a new motion set and press it.
- QWidget* addMotionSetButton = GetWidgetWithNameFromNamedToolbar(managementWindow, "MotionSetManagementWindow.ToolBar", "MotionSetManagementWindow.ToolBar.AddNewMotionSet");
- ASSERT_TRUE(addMotionSetButton);
- QTest::mouseClick(addMotionSetButton, Qt::LeftButton);
- // Check there is now a motion set.
- const size_t numMotionSetsAfterCreate = EMotionFX::GetMotionManager().GetNumMotionSets();
- ASSERT_EQ(numMotionSetsAfterCreate, numOldMotionSets + 1);
- EMotionFX::MotionSet* motionSet = EMotionFX::GetMotionManager().GetMotionSet(numOldMotionSets);
- // Ensure new motion set is selected.
- motionSetPlugin->SetSelectedSet(motionSet);
- // It should be empty at the moment.
- const size_t numMotions = motionSet->GetNumMotionEntries();
- EXPECT_EQ(numMotions, 0);
- // Find the action to add a motion to the set and press it.
- QWidget* addMotionButton = GetWidgetWithNameFromNamedToolbar(motionSetWindow, "MotionSetWindow.ToolBar", "MotionSetWindow.ToolBar.AddANewEntry");
- ASSERT_TRUE(addMotionButton);
- QTest::mouseClick(addMotionButton, Qt::LeftButton);
- // There should now be a motion.
- const size_t numMotionsAfterCreate = motionSet->GetNumMotionEntries();
- ASSERT_EQ(numMotionsAfterCreate, 1);
- AZStd::unordered_map<AZStd::string, MotionSet::MotionEntry*> motions = motionSet->GetMotionEntries();
- // The newly created motion should be called "<undefined>".
- MotionSet::MotionEntry* motion = motions["<undefined>"];
- ASSERT_TRUE(motion) << "no \"<undefined>\" motion found";
- // Ensure the new motion is added to the table.
- motionSetWindow->ReInit();
- // Now we need to remove it again.
- EMStudio::MotionSetTableWidget* table = motionSetWindow->findChild< EMStudio::MotionSetTableWidget*>("EMFX.MotionSetWindow.TableWidget");
- ASSERT_TRUE(table);
- ASSERT_EQ(table->rowCount(), 1);
- // Select the motion in the table.
- QList<QTableWidgetItem *> items = table->findItems("<undefined>", Qt::MatchExactly);
- items[0]->setSelected(true);
- // Set up a watcher to press the ok button in the Really Delete dialog.
- ModalPopupHandler reallyDeletehandler;
- reallyDeletehandler.WaitForPopupPressSpecificButton<QMessageBox*>("EMFX.MotionSet.RemoveMotionMessageBox.YesButton");
- // Pop up the context menu and select the Remove action.
- ModalPopupHandler menuHandler;
- menuHandler.ShowContextMenuAndTriggerAction(motionSetWindow, "EMFX.MotionSetTableWidget.RemoveSelectedMotionsAction", 3000, nullptr);
- // Make sure any changes filter through to the widget.
- motionSetWindow->ReInit();
- // The motion should now be gone.
- items = table->findItems("<undefined>", Qt::MatchExactly);
- ASSERT_EQ(table->rowCount(), 0);
- motions = motionSet->GetMotionEntries();
- ASSERT_EQ(table->rowCount(), 0);
- }
- TEST_F(UIFixture, CanRemoveSingleMotionFromMotionSetWithMultipleMotions)
- {
- RecordProperty("test_case_id", "C15105117");
- auto motionSetPlugin = static_cast<EMStudio::MotionSetsWindowPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::MotionSetsWindowPlugin::CLASS_ID));
- ASSERT_TRUE(motionSetPlugin) << "No motion sets plugin found";
- EMStudio::MotionSetManagementWindow* managementWindow = motionSetPlugin->GetManagementWindow();
- ASSERT_TRUE(managementWindow) << "No motion sets management window found";
- EMStudio::MotionSetWindow* motionSetWindow = motionSetPlugin->GetMotionSetWindow();
- ASSERT_TRUE(motionSetWindow) << "No motion set window found";
- // There should be only the default motion set.
- const size_t oldNumMotionSets = EMotionFX::GetMotionManager().GetNumMotionSets();
- // Find the action to create a new motion set and press it.
- QWidget* addMotionSetButton = GetWidgetWithNameFromNamedToolbar(managementWindow, "MotionSetManagementWindow.ToolBar", "MotionSetManagementWindow.ToolBar.AddNewMotionSet");
- ASSERT_TRUE(addMotionSetButton);
- QTest::mouseClick(addMotionSetButton, Qt::LeftButton);
- // Check there is now an additional motion set.
- ASSERT_EQ(EMotionFX::GetMotionManager().GetNumMotionSets(), oldNumMotionSets + 1);
- EMotionFX::MotionSet* motionSet = EMotionFX::GetMotionManager().GetMotionSet(oldNumMotionSets);
- // Ensure new motion set is selected.
- motionSetPlugin->SetSelectedSet(motionSet);
- // It should be empty at the moment.
- const size_t numMotions = motionSet->GetNumMotionEntries();
- EXPECT_EQ(numMotions, 0);
- // Find the action to add a motion to the set and press it twice.
- QWidget* addMotionButton = GetWidgetWithNameFromNamedToolbar(motionSetWindow, "MotionSetWindow.ToolBar", "MotionSetWindow.ToolBar.AddANewEntry");
- ASSERT_TRUE(addMotionButton);
- QTest::mouseClick(addMotionButton, Qt::LeftButton);
- QTest::mouseClick(addMotionButton, Qt::LeftButton);
- // There should now be two motion.
- const size_t numMotionsAfterCreate = motionSet->GetNumMotionEntries();
- ASSERT_EQ(numMotionsAfterCreate, 2);
- AZStd::unordered_map<AZStd::string, MotionSet::MotionEntry*> motions = motionSet->GetMotionEntries();
- // The newly created motions should be called "<undefined>".
- MotionSet::MotionEntry* motion = motions["<undefined>"];
- ASSERT_TRUE(motion) << "no \"<undefined>\" motion found";
- // Ensure the new motion is added to the table.
- motionSetWindow->ReInit();
- // Now we need to remove one of them.
- EMStudio::MotionSetTableWidget* table = motionSetWindow->findChild< EMStudio::MotionSetTableWidget*>("EMFX.MotionSetWindow.TableWidget");
- ASSERT_TRUE(table);
- ASSERT_EQ(table->rowCount(), 2);
- // Select the motion in the table.
- QList<QTableWidgetItem *> items = table->findItems("<undefined>", Qt::MatchExactly);
- items[0]->setSelected(true);
- // Set up a watcher to press the ok button in the Really Delete dialog.
- ModalPopupHandler reallyDeletehandler;
- reallyDeletehandler.WaitForPopupPressSpecificButton<QMessageBox*>("EMFX.MotionSet.RemoveMotionMessageBox.YesButton");
- // Pop up the context menu and select the Remove action.
- ModalPopupHandler menuHandler;
- menuHandler.ShowContextMenuAndTriggerAction(motionSetWindow, "EMFX.MotionSetTableWidget.RemoveSelectedMotionsAction", 3000, nullptr);
- // Make sure any changes filter through to the widget.
- motionSetWindow->ReInit();
- // The motion should now be gone leaving the other.
- items = table->findItems("<undefined>", Qt::MatchExactly);
- ASSERT_EQ(table->rowCount(), 1);
- motions = motionSet->GetMotionEntries();
- ASSERT_EQ(table->rowCount(), 1);
- }
- } // namespace EMotionFX
|