test_TrackViewPythonBindings.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "EditorDefs.h"
  9. #include <AzTest/AzTest.h>
  10. #include <Util/EditorUtils.h>
  11. #include <AzCore/base.h>
  12. #include <AzCore/Memory/SystemAllocator.h>
  13. #include <AzCore/Debug/TraceMessageBus.h>
  14. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  15. #include <AzCore/UnitTest/TestTypes.h>
  16. #include <AzCore/UserSettings/UserSettingsComponent.h>
  17. #include <AzToolsFramework/Application/ToolsApplication.h>
  18. #include <TrackView/TrackViewPythonFuncs.h>
  19. #include <AzCore/RTTI/BehaviorContext.h>
  20. namespace TrackViewPythonBindingsUnitTests
  21. {
  22. class TrackViewPythonBindingsFixture
  23. : public UnitTest::LeakDetectionFixture
  24. {
  25. public:
  26. AzToolsFramework::ToolsApplication m_app;
  27. void SetUp() override
  28. {
  29. AzFramework::Application::Descriptor appDesc;
  30. m_app.Start(appDesc);
  31. // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
  32. // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
  33. // in the unit tests.
  34. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
  35. m_app.RegisterComponentDescriptor(AzToolsFramework::TrackViewFuncsHandler::CreateDescriptor());
  36. }
  37. void TearDown() override
  38. {
  39. m_app.Stop();
  40. }
  41. };
  42. TEST_F(TrackViewPythonBindingsFixture, TrackViewEditorCommands_ApiExists)
  43. {
  44. AZ::BehaviorContext* behaviorContext = m_app.GetBehaviorContext();
  45. ASSERT_TRUE(behaviorContext);
  46. EXPECT_TRUE(behaviorContext->m_methods.find("set_recording") != behaviorContext->m_methods.end());
  47. EXPECT_TRUE(behaviorContext->m_methods.find("new_sequence") != behaviorContext->m_methods.end());
  48. EXPECT_TRUE(behaviorContext->m_methods.find("delete_sequence") != behaviorContext->m_methods.end());
  49. EXPECT_TRUE(behaviorContext->m_methods.find("set_current_sequence") != behaviorContext->m_methods.end());
  50. EXPECT_TRUE(behaviorContext->m_methods.find("get_num_sequences") != behaviorContext->m_methods.end());
  51. EXPECT_TRUE(behaviorContext->m_methods.find("get_sequence_name") != behaviorContext->m_methods.end());
  52. EXPECT_TRUE(behaviorContext->m_methods.find("get_sequence_time_range") != behaviorContext->m_methods.end());
  53. EXPECT_TRUE(behaviorContext->m_methods.find("set_sequence_time_range") != behaviorContext->m_methods.end());
  54. EXPECT_TRUE(behaviorContext->m_methods.find("play_sequence") != behaviorContext->m_methods.end());
  55. EXPECT_TRUE(behaviorContext->m_methods.find("stop_sequence") != behaviorContext->m_methods.end());
  56. EXPECT_TRUE(behaviorContext->m_methods.find("set_time") != behaviorContext->m_methods.end());
  57. EXPECT_TRUE(behaviorContext->m_methods.find("add_node") != behaviorContext->m_methods.end());
  58. EXPECT_TRUE(behaviorContext->m_methods.find("add_selected_entities") != behaviorContext->m_methods.end());
  59. EXPECT_TRUE(behaviorContext->m_methods.find("add_layer_node") != behaviorContext->m_methods.end());
  60. EXPECT_TRUE(behaviorContext->m_methods.find("delete_node") != behaviorContext->m_methods.end());
  61. EXPECT_TRUE(behaviorContext->m_methods.find("add_track") != behaviorContext->m_methods.end());
  62. EXPECT_TRUE(behaviorContext->m_methods.find("delete_track") != behaviorContext->m_methods.end());
  63. EXPECT_TRUE(behaviorContext->m_methods.find("get_num_nodes") != behaviorContext->m_methods.end());
  64. EXPECT_TRUE(behaviorContext->m_methods.find("get_node_name") != behaviorContext->m_methods.end());
  65. EXPECT_TRUE(behaviorContext->m_methods.find("get_num_track_keys") != behaviorContext->m_methods.end());
  66. EXPECT_TRUE(behaviorContext->m_methods.find("get_key_value") != behaviorContext->m_methods.end());
  67. EXPECT_TRUE(behaviorContext->m_methods.find("get_interpolated_value") != behaviorContext->m_methods.end());
  68. }
  69. class TrackViewComponentFixture
  70. : public UnitTest::LeakDetectionFixture
  71. {
  72. public:
  73. AzToolsFramework::ToolsApplication m_app;
  74. void SetUp() override
  75. {
  76. AzFramework::Application::Descriptor appDesc;
  77. m_app.Start(appDesc);
  78. m_app.RegisterComponentDescriptor(AzToolsFramework::TrackViewComponent::CreateDescriptor());
  79. // Disable saving global user settings to prevent failure due to detecting file updates
  80. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
  81. }
  82. void TearDown() override
  83. {
  84. m_app.Stop();
  85. }
  86. };
  87. TEST_F(TrackViewComponentFixture, TrackViewComponent_ApiExists)
  88. {
  89. AZ::BehaviorContext* behaviorContext = m_app.GetBehaviorContext();
  90. ASSERT_TRUE(behaviorContext);
  91. auto itTrackViewBus = behaviorContext->m_ebuses.find("TrackViewBus");
  92. if (itTrackViewBus != behaviorContext->m_ebuses.end())
  93. {
  94. AZ::BehaviorEBus* behaviorBus = itTrackViewBus->second;
  95. EXPECT_TRUE(behaviorBus->m_events.find("AddNode") != behaviorBus->m_events.end());
  96. EXPECT_TRUE(behaviorBus->m_events.find("AddTrack") != behaviorBus->m_events.end());
  97. EXPECT_TRUE(behaviorBus->m_events.find("AddLayerNode") != behaviorBus->m_events.end());
  98. EXPECT_TRUE(behaviorBus->m_events.find("AddSelectedEntities") != behaviorBus->m_events.end());
  99. EXPECT_TRUE(behaviorBus->m_events.find("AddNode") != behaviorBus->m_events.end());
  100. EXPECT_TRUE(behaviorBus->m_events.find("AddTrack") != behaviorBus->m_events.end());
  101. EXPECT_TRUE(behaviorBus->m_events.find("AddLayerNode") != behaviorBus->m_events.end());
  102. EXPECT_TRUE(behaviorBus->m_events.find("AddSelectedEntities") != behaviorBus->m_events.end());
  103. EXPECT_TRUE(behaviorBus->m_events.find("DeleteNode") != behaviorBus->m_events.end());
  104. EXPECT_TRUE(behaviorBus->m_events.find("DeleteTrack") != behaviorBus->m_events.end());
  105. EXPECT_TRUE(behaviorBus->m_events.find("DeleteSequence") != behaviorBus->m_events.end());
  106. EXPECT_TRUE(behaviorBus->m_events.find("GetInterpolatedValue") != behaviorBus->m_events.end());
  107. EXPECT_TRUE(behaviorBus->m_events.find("GetKeyValue") != behaviorBus->m_events.end());
  108. EXPECT_TRUE(behaviorBus->m_events.find("GetNodeName") != behaviorBus->m_events.end());
  109. EXPECT_TRUE(behaviorBus->m_events.find("GetNumNodes") != behaviorBus->m_events.end());
  110. EXPECT_TRUE(behaviorBus->m_events.find("GetNumSequences") != behaviorBus->m_events.end());
  111. EXPECT_TRUE(behaviorBus->m_events.find("GetNumTrackKeys") != behaviorBus->m_events.end());
  112. EXPECT_TRUE(behaviorBus->m_events.find("GetSequenceName") != behaviorBus->m_events.end());
  113. EXPECT_TRUE(behaviorBus->m_events.find("GetSequenceTimeRange") != behaviorBus->m_events.end());
  114. EXPECT_TRUE(behaviorBus->m_events.find("NewSequence") != behaviorBus->m_events.end());
  115. EXPECT_TRUE(behaviorBus->m_events.find("PlaySequence") != behaviorBus->m_events.end());
  116. EXPECT_TRUE(behaviorBus->m_events.find("SetCurrentSequence") != behaviorBus->m_events.end());
  117. EXPECT_TRUE(behaviorBus->m_events.find("SetRecording") != behaviorBus->m_events.end());
  118. EXPECT_TRUE(behaviorBus->m_events.find("SetSequenceTimeRange") != behaviorBus->m_events.end());
  119. EXPECT_TRUE(behaviorBus->m_events.find("SetTime") != behaviorBus->m_events.end());
  120. EXPECT_TRUE(behaviorBus->m_events.find("StopSequence") != behaviorBus->m_events.end());
  121. }
  122. }
  123. }