RemoveTransition.cpp 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <Tests/UI/UIFixture.h>
  10. #include <EMotionFX/CommandSystem/Source/CommandManager.h>
  11. #include <EMotionFX/Source/AnimGraphManager.h>
  12. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  13. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  14. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/AnimGraphPlugin.h>
  15. #include <EMotionStudio/Plugins/StandardPlugins/Source/AnimGraph/BlendGraphViewWidget.h>
  16. #include <QApplication>
  17. #include <QtTest>
  18. #include "qtestsystem.h"
  19. namespace EMotionFX
  20. {
  21. class RemoveTransitionFixture
  22. : public UIFixture
  23. {
  24. public:
  25. void SetUp() override
  26. {
  27. UIFixture::SetUp();
  28. AZStd::string commandResult;
  29. MCore::CommandGroup group;
  30. // Create empty anim graph, add a motion node and a blend tree.
  31. group.AddCommandString(AZStd::string::format("CreateAnimGraph -animGraphID %d", m_animGraphId));
  32. group.AddCommandString(AZStd::string::format("AnimGraphCreateNode -animGraphID %d -type %s -parentName Root -xPos 100 -yPos 100 -name testMotion",
  33. m_animGraphId, azrtti_typeid<AnimGraphMotionNode>().ToString<AZStd::string>().c_str()));
  34. group.AddCommandString(AZStd::string::format("AnimGraphCreateNode -animGraphID %d -type %s -parentName Root -xPos 200 -yPos 100 -name testBlendTree",
  35. m_animGraphId, azrtti_typeid<BlendTree>().ToString<AZStd::string>().c_str()));
  36. group.AddCommandString(AZStd::string::format("AnimGraphCreateConnection -animGraphID %d -transitionType %s -sourceNode testMotion -targetNode testBlendTree",
  37. m_animGraphId, azrtti_typeid<AnimGraphStateTransition>().ToString<AZStd::string>().c_str()));
  38. EXPECT_TRUE(CommandSystem::GetCommandManager()->ExecuteCommandGroup(group, commandResult)) << commandResult.c_str();
  39. m_animGraph = GetAnimGraphManager().FindAnimGraphByID(m_animGraphId);
  40. EXPECT_NE(m_animGraph, nullptr) << "Cannot find newly created anim graph.";
  41. }
  42. void TearDown() override
  43. {
  44. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  45. delete m_animGraph;
  46. UIFixture::TearDown();
  47. }
  48. public:
  49. const AZ::u32 m_animGraphId = 64;
  50. AnimGraph* m_animGraph = nullptr;
  51. };
  52. TEST_F(RemoveTransitionFixture, RemoveTransition)
  53. {
  54. RecordProperty("test_case_id", "C15031141");
  55. auto animGraphPlugin = static_cast<EMStudio::AnimGraphPlugin*>(EMStudio::GetPluginManager()->FindActivePlugin(EMStudio::AnimGraphPlugin::CLASS_ID));
  56. ASSERT_TRUE(animGraphPlugin) << "Anim graph plugin not found.";
  57. EMStudio::AnimGraphModel& animGraphModel = animGraphPlugin->GetAnimGraphModel();
  58. // Find the transition between the motion node and the blend tree.
  59. AnimGraphStateTransition* transition = m_animGraph->GetRootStateMachine()->GetTransition(0);
  60. ASSERT_TRUE(transition) << "Anim graph transition not found.";
  61. // Select the transition in the anim graph model.
  62. const QModelIndex& modelIndex = animGraphModel.FindFirstModelIndex(transition);
  63. ASSERT_TRUE(modelIndex.isValid()) << "Anim graph transition has an invalid model index.";
  64. animGraphModel.GetSelectionModel().select(QItemSelection(modelIndex, modelIndex), QItemSelectionModel::Current | QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
  65. EMStudio::BlendGraphViewWidget* blendGraphViewWidget = animGraphPlugin->GetViewWidget();
  66. blendGraphViewWidget->GetAction(EMStudio::BlendGraphViewWidget::EDIT_DELETE)->trigger();
  67. // Check if the transition get deleted.
  68. ASSERT_EQ(0, m_animGraph->GetRootStateMachine()->GetNumTransitions()) << " Anim Graph transition should be removed";
  69. }
  70. } // namespace EMotionFX