test_TrackViewPythonBindings.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. AZ::ComponentApplication::StartupParameters startupParameters;
  31. startupParameters.m_loadSettingsRegistry = false;
  32. m_app.Start(appDesc, startupParameters);
  33. // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
  34. // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
  35. // in the unit tests.
  36. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
  37. m_app.RegisterComponentDescriptor(AzToolsFramework::TrackViewFuncsHandler::CreateDescriptor());
  38. }
  39. void TearDown() override
  40. {
  41. m_app.Stop();
  42. }
  43. };
  44. TEST_F(TrackViewPythonBindingsFixture, TrackViewEditorCommands_ApiExists)
  45. {
  46. AZ::BehaviorContext* behaviorContext = m_app.GetBehaviorContext();
  47. ASSERT_TRUE(behaviorContext);
  48. EXPECT_TRUE(behaviorContext->m_methods.find("set_recording") != behaviorContext->m_methods.end());
  49. EXPECT_TRUE(behaviorContext->m_methods.find("new_sequence") != behaviorContext->m_methods.end());
  50. EXPECT_TRUE(behaviorContext->m_methods.find("delete_sequence") != behaviorContext->m_methods.end());
  51. EXPECT_TRUE(behaviorContext->m_methods.find("set_current_sequence") != behaviorContext->m_methods.end());
  52. EXPECT_TRUE(behaviorContext->m_methods.find("get_num_sequences") != behaviorContext->m_methods.end());
  53. EXPECT_TRUE(behaviorContext->m_methods.find("get_sequence_name") != behaviorContext->m_methods.end());
  54. EXPECT_TRUE(behaviorContext->m_methods.find("get_sequence_time_range") != behaviorContext->m_methods.end());
  55. EXPECT_TRUE(behaviorContext->m_methods.find("set_sequence_time_range") != behaviorContext->m_methods.end());
  56. EXPECT_TRUE(behaviorContext->m_methods.find("play_sequence") != behaviorContext->m_methods.end());
  57. EXPECT_TRUE(behaviorContext->m_methods.find("stop_sequence") != behaviorContext->m_methods.end());
  58. EXPECT_TRUE(behaviorContext->m_methods.find("set_time") != behaviorContext->m_methods.end());
  59. EXPECT_TRUE(behaviorContext->m_methods.find("add_node") != behaviorContext->m_methods.end());
  60. EXPECT_TRUE(behaviorContext->m_methods.find("add_selected_entities") != behaviorContext->m_methods.end());
  61. EXPECT_TRUE(behaviorContext->m_methods.find("add_layer_node") != behaviorContext->m_methods.end());
  62. EXPECT_TRUE(behaviorContext->m_methods.find("delete_node") != behaviorContext->m_methods.end());
  63. EXPECT_TRUE(behaviorContext->m_methods.find("add_track") != behaviorContext->m_methods.end());
  64. EXPECT_TRUE(behaviorContext->m_methods.find("delete_track") != behaviorContext->m_methods.end());
  65. EXPECT_TRUE(behaviorContext->m_methods.find("get_num_nodes") != behaviorContext->m_methods.end());
  66. EXPECT_TRUE(behaviorContext->m_methods.find("get_node_name") != behaviorContext->m_methods.end());
  67. EXPECT_TRUE(behaviorContext->m_methods.find("get_num_track_keys") != behaviorContext->m_methods.end());
  68. EXPECT_TRUE(behaviorContext->m_methods.find("get_key_value") != behaviorContext->m_methods.end());
  69. EXPECT_TRUE(behaviorContext->m_methods.find("get_interpolated_value") != behaviorContext->m_methods.end());
  70. }
  71. class TrackViewComponentFixture
  72. : public UnitTest::LeakDetectionFixture
  73. {
  74. public:
  75. AzToolsFramework::ToolsApplication m_app;
  76. void SetUp() override
  77. {
  78. AzFramework::Application::Descriptor appDesc;
  79. AZ::ComponentApplication::StartupParameters startupParameters;
  80. startupParameters.m_loadSettingsRegistry = false;
  81. m_app.Start(appDesc, startupParameters);
  82. m_app.RegisterComponentDescriptor(AzToolsFramework::TrackViewComponent::CreateDescriptor());
  83. // Disable saving global user settings to prevent failure due to detecting file updates
  84. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
  85. }
  86. void TearDown() override
  87. {
  88. m_app.Stop();
  89. }
  90. };
  91. TEST_F(TrackViewComponentFixture, TrackViewComponent_ApiExists)
  92. {
  93. AZ::BehaviorContext* behaviorContext = m_app.GetBehaviorContext();
  94. ASSERT_TRUE(behaviorContext);
  95. auto itTrackViewBus = behaviorContext->m_ebuses.find("TrackViewBus");
  96. if (itTrackViewBus != behaviorContext->m_ebuses.end())
  97. {
  98. AZ::BehaviorEBus* behaviorBus = itTrackViewBus->second;
  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("AddNode") != behaviorBus->m_events.end());
  104. EXPECT_TRUE(behaviorBus->m_events.find("AddTrack") != behaviorBus->m_events.end());
  105. EXPECT_TRUE(behaviorBus->m_events.find("AddLayerNode") != behaviorBus->m_events.end());
  106. EXPECT_TRUE(behaviorBus->m_events.find("AddSelectedEntities") != behaviorBus->m_events.end());
  107. EXPECT_TRUE(behaviorBus->m_events.find("DeleteNode") != behaviorBus->m_events.end());
  108. EXPECT_TRUE(behaviorBus->m_events.find("DeleteTrack") != behaviorBus->m_events.end());
  109. EXPECT_TRUE(behaviorBus->m_events.find("DeleteSequence") != behaviorBus->m_events.end());
  110. EXPECT_TRUE(behaviorBus->m_events.find("GetInterpolatedValue") != behaviorBus->m_events.end());
  111. EXPECT_TRUE(behaviorBus->m_events.find("GetKeyValue") != behaviorBus->m_events.end());
  112. EXPECT_TRUE(behaviorBus->m_events.find("GetNodeName") != behaviorBus->m_events.end());
  113. EXPECT_TRUE(behaviorBus->m_events.find("GetNumNodes") != behaviorBus->m_events.end());
  114. EXPECT_TRUE(behaviorBus->m_events.find("GetNumSequences") != behaviorBus->m_events.end());
  115. EXPECT_TRUE(behaviorBus->m_events.find("GetNumTrackKeys") != behaviorBus->m_events.end());
  116. EXPECT_TRUE(behaviorBus->m_events.find("GetSequenceName") != behaviorBus->m_events.end());
  117. EXPECT_TRUE(behaviorBus->m_events.find("GetSequenceTimeRange") != behaviorBus->m_events.end());
  118. EXPECT_TRUE(behaviorBus->m_events.find("NewSequence") != behaviorBus->m_events.end());
  119. EXPECT_TRUE(behaviorBus->m_events.find("PlaySequence") != behaviorBus->m_events.end());
  120. EXPECT_TRUE(behaviorBus->m_events.find("SetCurrentSequence") != behaviorBus->m_events.end());
  121. EXPECT_TRUE(behaviorBus->m_events.find("SetRecording") != behaviorBus->m_events.end());
  122. EXPECT_TRUE(behaviorBus->m_events.find("SetSequenceTimeRange") != behaviorBus->m_events.end());
  123. EXPECT_TRUE(behaviorBus->m_events.find("SetTime") != behaviorBus->m_events.end());
  124. EXPECT_TRUE(behaviorBus->m_events.find("StopSequence") != behaviorBus->m_events.end());
  125. }
  126. }
  127. }