GraphCreationTests.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <qpushbutton.h>
  9. #include <GraphCanvas/Components/GridBus.h>
  10. #include <GraphCanvas/Components/Nodes/Group/NodeGroupBus.h>
  11. #include <Editor/Source/EditorAutomationTests/GraphCreationTests.h>
  12. #include <Editor/GraphCanvas/GraphCanvasEditorNotificationBusId.h>
  13. #include <ScriptCanvas/GraphCanvas/MappingBus.h>
  14. #include <ScriptCanvas/Core/Node.h>
  15. #include <ScriptCanvas/Core/NodeBus.h>
  16. #include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
  17. #include <ScriptCanvasDeveloperEditor/EditorAutomation/EditorAutomationStates/GraphStates.h>
  18. namespace ScriptCanvas::Developer
  19. {
  20. ///////////////////////////
  21. // CreateGraphHotKeyState
  22. ///////////////////////////
  23. #if !defined(AZ_COMPILER_MSVC)
  24. #ifndef VK_CONTROL
  25. #define VK_CONTROL 0x11
  26. #endif
  27. #endif
  28. CreateGraphTest::CreateGraphHotKeyState::CreateGraphHotKeyState()
  29. : m_pressControl(VK_CONTROL)
  30. , m_releaseControl(VK_CONTROL)
  31. , m_typeN(QChar('n'))
  32. , m_longProcessEvents(AZStd::chrono::milliseconds(1000))
  33. {
  34. }
  35. void CreateGraphTest::CreateGraphHotKeyState::OnActiveGraphChanged(const AZ::EntityId& graphCanvasId)
  36. {
  37. m_hotKeyGraphId = graphCanvasId;
  38. }
  39. void CreateGraphTest::CreateGraphHotKeyState::OnSetupStateActions(EditorAutomationActionRunner& actionRunner)
  40. {
  41. GraphCanvas::AssetEditorNotificationBus::Handler::BusConnect(ScriptCanvasEditor::AssetEditorId);
  42. actionRunner.AddAction(&m_pressControl);
  43. actionRunner.AddAction(&m_shortProcessEvents);
  44. actionRunner.AddAction(&m_typeN);
  45. actionRunner.AddAction(&m_longProcessEvents);
  46. actionRunner.AddAction(&m_releaseControl);
  47. actionRunner.AddAction(&m_shortProcessEvents);
  48. m_hotKeyGraphId.SetInvalid();
  49. }
  50. void CreateGraphTest::CreateGraphHotKeyState::OnStateActionsComplete()
  51. {
  52. if (!m_hotKeyGraphId.IsValid())
  53. {
  54. ReportError("Failed to create graph using hot key");
  55. }
  56. else
  57. {
  58. GraphCanvas::GraphId activeGraphCanvasId;
  59. ScriptCanvasEditor::GeneralRequestBus::BroadcastResult(activeGraphCanvasId, &ScriptCanvasEditor::GeneralRequests::GetActiveGraphCanvasGraphId);
  60. if (activeGraphCanvasId != m_hotKeyGraphId)
  61. {
  62. ReportError("Active graph is not the newly created graph using hotkey.");
  63. }
  64. }
  65. GraphCanvas::AssetEditorNotificationBus::Handler::BusDisconnect();
  66. }
  67. ////////////////////
  68. // CreateGraphTest
  69. ////////////////////
  70. CreateGraphTest::CreateGraphTest()
  71. : EditorAutomationTest("Create Graph Test")
  72. {
  73. SetHasCustomTransitions(true);
  74. AddState(new CreateRuntimeGraphState());
  75. AddState(new CreateGraphHotKeyState());
  76. AddState(new ForceCloseActiveGraphState());
  77. SetInitialStateId<CreateRuntimeGraphStateId>();
  78. }
  79. void CreateGraphTest::OnTestStarting()
  80. {
  81. m_creationState = CreateRuntimeGraphStateId::StateID();
  82. }
  83. int CreateGraphTest::EvaluateTransition(int stateId)
  84. {
  85. if (stateId == CreateRuntimeGraphState::StateID()
  86. || stateId == CreateGraphHotKeyState::StateID())
  87. {
  88. return ForceCloseActiveGraphState::StateID();
  89. }
  90. else if (stateId == ForceCloseActiveGraphState::StateID())
  91. {
  92. if (m_creationState == CreateRuntimeGraphStateId::StateID())
  93. {
  94. m_creationState = CreateGraphHotKeyState::StateID();
  95. return m_creationState;
  96. }
  97. }
  98. return EditorAutomationState::EXIT_STATE_ID;
  99. }
  100. ///////////////////////
  101. // CreateFunctionTest
  102. ///////////////////////
  103. CreateFunctionTest::CreateFunctionTest()
  104. : EditorAutomationTest("Create Function Test")
  105. {
  106. AddState(new CreateFunctionGraphState());
  107. AddState(new ForceCloseActiveGraphState());
  108. }
  109. }