3
0

AnimGraphPreviewMotionTests.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <EMotionFX/CommandSystem/Source/AnimGraphNodeCommands.h>
  10. #include <EMotionFX/Source/AnimGraph.h>
  11. #include <EMotionFX/Source/AnimGraphManager.h>
  12. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  13. #include <EMotionFX/Source/AnimGraphNode.h>
  14. #include <EMotionFX/Source/Motion.h>
  15. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  16. #include <EMotionStudio/Plugins/StandardPlugins/Source/TimeView/TimeViewPlugin.h>
  17. #include <QPushButton>
  18. #include <QAction>
  19. #include <QtTest>
  20. #include <Tests/UI/AnimGraphUIFixture.h>
  21. #include <Tests/ProvidesUI/AnimGraph/PreviewMotionFixture.h>
  22. namespace EMotionFX
  23. {
  24. TEST_F(PreviewMotionFixture, PreviewMotionTests)
  25. {
  26. AnimGraph* animGraph = CreateAnimGraph();
  27. EXPECT_NE(animGraph, nullptr) << "Cannot find newly created anim graph.";
  28. auto nodeGraph = GetActiveNodeGraph();
  29. EXPECT_TRUE(nodeGraph) << "Node graph not found.";
  30. // Serialize motion node members, the motion id for rin_idle.
  31. EMotionFX::AnimGraphMotionNode* tempMotionNode = aznew EMotionFX::AnimGraphMotionNode();
  32. tempMotionNode->SetMotionIds({ "rin_idle" });
  33. AZ::Outcome<AZStd::string> serializedMotionNode = MCore::ReflectionSerializer::SerializeMembersExcept(tempMotionNode, {});
  34. EMotionFX::AnimGraphNode* currentNode = nodeGraph->GetModelIndex().data(EMStudio::AnimGraphModel::ROLE_NODE_POINTER).value<EMotionFX::AnimGraphNode*>();
  35. ASSERT_TRUE(currentNode) << "No current AnimGraphNode found";
  36. CommandSystem::CreateAnimGraphNode(/*commandGroup=*/nullptr, currentNode->GetAnimGraph(), azrtti_typeid<EMotionFX::AnimGraphMotionNode>(), "Motion", currentNode, 0, 0, serializedMotionNode.GetValue());
  37. // Check motion node has been created.
  38. AnimGraphMotionNode* motionNode = static_cast<AnimGraphMotionNode*>(animGraph->GetNode(1));
  39. EXPECT_NE(motionNode, nullptr) << "Cannot find newly created motion node.";
  40. nodeGraph->SelectAllNodes();
  41. const AZStd::vector<EMotionFX::AnimGraphNode*> selectedAnimGraphNodes = nodeGraph->GetSelectedAnimGraphNodes();
  42. m_blendGraphWidget->OnContextMenuEvent(m_blendGraphWidget, QPoint(0, 0), QPoint(0, 0), m_animGraphPlugin, selectedAnimGraphNodes, true, false, m_animGraphPlugin->GetActionFilter());
  43. // Check that Preview Motion action is available in the context menu.
  44. QMenu* selectedNodeContextMenu = m_blendGraphWidget->findChild<QMenu*>("BlendGraphWidget.SelectedNodeMenu");
  45. ASSERT_TRUE(selectedNodeContextMenu) << "Selected node context menu was not found.";
  46. QAction* previewMotionAction = GetNamedAction(selectedNodeContextMenu, QString("Preview rin_idle"));
  47. ASSERT_TRUE(previewMotionAction) << "Preview motion action not found.";
  48. delete tempMotionNode;
  49. }
  50. } // end namespace EMotionFX