/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace EMotionFX { TEST_F(UIFixture, CanRemoveMotionFromMotionSet) { RecordProperty("test_case_id", "C24255734"); auto motionSetPlugin = static_cast(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 there aren't any motion sets yet. const uint32 numMotionSets = EMotionFX::GetMotionManager().GetNumMotionSets(); EXPECT_EQ(numMotionSets, 0); // 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 int numMotionSetsAfterCreate = EMotionFX::GetMotionManager().GetNumMotionSets(); ASSERT_EQ(numMotionSetsAfterCreate, 1); EMotionFX::MotionSet* motionSet = EMotionFX::GetMotionManager().GetMotionSet(0); // Ensure new motion set is selected. motionSetPlugin->SetSelectedSet(motionSet); // It should be empty at the moment. const int 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 int numMotionsAfterCreate = motionSet->GetNumMotionEntries(); ASSERT_EQ(numMotionsAfterCreate, 1); AZStd::unordered_map motions = motionSet->GetMotionEntries(); // The newly created motion should be called "". MotionSet::MotionEntry* motion = motions[""]; ASSERT_TRUE(motion) << "no \"\" 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 items = table->findItems("", Qt::MatchExactly); items[0]->setSelected(true); // Set up a watcher to press the ok button in the Really Delete dialog. ModalPopupHandler reallyDeletehandler; reallyDeletehandler.WaitForPopupPressSpecificButton("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("", 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::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 there aren't any motion sets yet. const uint32 numMotionSets = EMotionFX::GetMotionManager().GetNumMotionSets(); EXPECT_EQ(numMotionSets, 0); // 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 int numMotionSetsAfterCreate = EMotionFX::GetMotionManager().GetNumMotionSets(); ASSERT_EQ(numMotionSetsAfterCreate, 1); EMotionFX::MotionSet* motionSet = EMotionFX::GetMotionManager().GetMotionSet(0); // Ensure new motion set is selected. motionSetPlugin->SetSelectedSet(motionSet); // It should be empty at the moment. const int 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 int numMotionsAfterCreate = motionSet->GetNumMotionEntries(); ASSERT_EQ(numMotionsAfterCreate, 2); AZStd::unordered_map motions = motionSet->GetMotionEntries(); // The newly created motions should be called "". MotionSet::MotionEntry* motion = motions[""]; ASSERT_TRUE(motion) << "no \"\" 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 items = table->findItems("", Qt::MatchExactly); items[0]->setSelected(true); // Set up a watcher to press the ok button in the Really Delete dialog. ModalPopupHandler reallyDeletehandler; reallyDeletehandler.WaitForPopupPressSpecificButton("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("", Qt::MatchExactly); ASSERT_EQ(table->rowCount(), 1); motions = motionSet->GetMotionEntries(); ASSERT_EQ(table->rowCount(), 1); } } // namespace EMotionFX