3
0

CanDeleteAnimGraphNode.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <QAction>
  11. #include <QtTest>
  12. #include <Tests/UI/AnimGraphUIFixture.h>
  13. #include <EMotionFX/Source/AnimGraphManager.h>
  14. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  15. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  16. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  17. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphWidget.h>
  18. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h>
  19. #include <EMotionFX/Source/AnimGraphBindPoseNode.h>
  20. namespace EMotionFX {
  21. TEST_F(AnimGraphUIFixture, CanDeleteAnimGraphNode)
  22. {
  23. /*
  24. Test Case: C22083484
  25. Can Delete AnimGraph Node.
  26. Tests the UI functionality for deleting an existing AnimGraph Node via the right-click context menu.
  27. */
  28. RecordProperty("test_case_id", "C22083484");
  29. AnimGraph* activeAnimGraph = CreateAnimGraph();
  30. // Create a node to delete later
  31. AnimGraphNode* node = CreateAnimGraphNode(azrtti_typeid<AnimGraphBindPoseNode>().ToString<AZStd::string>(), "-parentName Root -xPos 1 -yPos 1");
  32. ASSERT_TRUE(node) << "Node was not created.";
  33. // Verify no nodes are selecetd yet
  34. EXPECT_EQ(m_blendGraphWidget->CalcNumSelectedNodes(), 0) << "Expected to have exactly zero (0) selected nodes";
  35. EXPECT_EQ(m_blendGraphWidget->GetActiveGraph()->GetSelectedAnimGraphNodes().size(), 0) << "Expected to have zero (0) items selected in selection model";
  36. // Select the new Graph Node (via left mouse click)
  37. QRect nodeRect = m_blendGraphWidget->GetActiveGraph()->FindGraphNode(node)->GetRect();
  38. QPoint localPoint = nodeRect.center();
  39. QTest::mouseClick(m_blendGraphWidget, Qt::LeftButton, Qt::NoModifier, localPoint);
  40. // Verify our node was selected
  41. EXPECT_EQ(m_blendGraphWidget->CalcNumSelectedNodes(), 1) << "Expected to have exactly one (1) selected node";
  42. EXPECT_EQ(m_blendGraphWidget->GetActiveGraph()->GetSelectedAnimGraphNodes().size(), 1) << "Not exactly one selection made";
  43. // Open context menu
  44. m_blendGraphWidget->OnContextMenuEvent(m_blendGraphWidget, localPoint, m_blendGraphWidget->LocalToGlobal(localPoint), m_animGraphPlugin, m_blendGraphWidget->GetActiveGraph()->GetSelectedAnimGraphNodes(), true, false, m_animGraphPlugin->GetActionFilter());
  45. // Find Action for deleting node
  46. QAction* deleteAction = GetNamedAction(m_animGraphPlugin->GetViewWidget(), FromStdString(EMStudio::AnimGraphPlugin::s_deleteSelectedNodesShortcutName));
  47. ASSERT_TRUE(deleteAction) << "Could not find the '" <<
  48. std::string(EMStudio::AnimGraphPlugin::s_deleteSelectedNodesShortcutName.data(), EMStudio::AnimGraphPlugin::s_deleteSelectedNodesShortcutName.size())
  49. << "' action in the context menu";
  50. // Trigger delete
  51. const size_t nodeCount = activeAnimGraph->GetNumNodes();
  52. deleteAction->trigger();
  53. // Verify Result
  54. EXPECT_EQ(nodeCount - 1, activeAnimGraph->GetNumNodes()) << "Delete Action from Context menu did not remove exactly 1 Node from AnimGraph";
  55. EXPECT_EQ(m_blendGraphWidget->CalcNumSelectedNodes(), 0) << "BlendGraphWidget still has the deleted node selected";
  56. EXPECT_EQ(m_blendGraphWidget->GetActiveGraph()->GetSelectedAnimGraphNodes().size(), 0) << "Selection model not cleared";
  57. }
  58. }