From 21f9a789c13d17341be3a04d38360c9d5f06cab9 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Wed, 10 Nov 2021 08:57:39 -0800 Subject: [PATCH] Merged the Editor.Camera.Tests with the Editor.Tests (#5463) * Merged the Edtiror.Camera.Tests witht eh Editor.Tests Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> * Adds dependency to Camera.Editor gem which is used by the test Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> * Inheirts from TraceBusHook instead of adding the default env to the test Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> * makes order consistent between Setup/Teardown Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> * adds missing header for non-unity builds Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> * Removes dependency to Camera gem Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Editor/CMakeLists.txt | 31 +--------- Code/Editor/EditorEnvironment.cpp | 2 +- .../Camera/editor_lib_camera_test_files.cmake | 11 ---- .../Lib/Tests/Camera/test_EditorCamera.cpp | 57 +++++++------------ Code/Editor/Lib/Tests/test_Main.cpp | 11 +++- Code/Editor/editor_lib_test_files.cmake | 1 + .../AzTest/AzTest/GemTestEnvironment.cpp | 5 ++ .../AzTest/AzTest/GemTestEnvironment.h | 2 +- 8 files changed, 39 insertions(+), 81 deletions(-) delete mode 100644 Code/Editor/Lib/Tests/Camera/editor_lib_camera_test_files.cmake diff --git a/Code/Editor/CMakeLists.txt b/Code/Editor/CMakeLists.txt index bdfac373eb..693799e08b 100644 --- a/Code/Editor/CMakeLists.txt +++ b/Code/Editor/CMakeLists.txt @@ -249,38 +249,9 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) RUNTIME_DEPENDENCIES Gem::LmbrCentral ) + ly_add_googletest( NAME Legacy::EditorLib.Tests ) - ly_add_target( - NAME EditorLib.Camera.Tests ${PAL_TRAIT_TEST_TARGET_TYPE} - NAMESPACE Legacy - FILES_CMAKE - Lib/Tests/Camera/editor_lib_camera_test_files.cmake - INCLUDE_DIRECTORIES - PRIVATE - . - BUILD_DEPENDENCIES - PRIVATE - AZ::AzCore - AZ::AzTest - AZ::AzToolsFramework - AZ::AzTestShared - Legacy::EditorLib - Gem::Camera.Editor - Gem::AtomToolsFramework.Static - RUNTIME_DEPENDENCIES - Legacy::EditorLib - ) - - ly_add_source_properties( - SOURCES Lib/Tests/Camera/test_EditorCamera.cpp - PROPERTY COMPILE_DEFINITIONS - VALUES CAMERA_EDITOR_MODULE="$" - ) - - ly_add_googletest( - NAME Legacy::EditorLib.Camera.Tests - ) endif() diff --git a/Code/Editor/EditorEnvironment.cpp b/Code/Editor/EditorEnvironment.cpp index 463fec8d08..2d675275ec 100644 --- a/Code/Editor/EditorEnvironment.cpp +++ b/Code/Editor/EditorEnvironment.cpp @@ -17,7 +17,7 @@ void SetEditorEnvironment(SSystemGlobalEnvironment* pEnv) void AttachEditorAZEnvironment(AZ::EnvironmentInstance azEnv) { - AZ::Environment::Attach(azEnv, true); + AZ::Environment::Attach(azEnv); } void DetachEditorAZEnvironment() diff --git a/Code/Editor/Lib/Tests/Camera/editor_lib_camera_test_files.cmake b/Code/Editor/Lib/Tests/Camera/editor_lib_camera_test_files.cmake deleted file mode 100644 index 69d3e37f2d..0000000000 --- a/Code/Editor/Lib/Tests/Camera/editor_lib_camera_test_files.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# Copyright (c) Contributors to the Open 3D Engine Project. -# For complete copyright and license terms please see the LICENSE at the root of this distribution. -# -# SPDX-License-Identifier: Apache-2.0 OR MIT -# -# - -set(FILES - test_EditorCamera.cpp -) diff --git a/Code/Editor/Lib/Tests/Camera/test_EditorCamera.cpp b/Code/Editor/Lib/Tests/Camera/test_EditorCamera.cpp index 1a44d43370..637b9c44c5 100644 --- a/Code/Editor/Lib/Tests/Camera/test_EditorCamera.cpp +++ b/Code/Editor/Lib/Tests/Camera/test_EditorCamera.cpp @@ -17,43 +17,33 @@ namespace UnitTest { - class EditorCameraTestEnvironment : public AZ::Test::GemTestEnvironment - { - // AZ::Test::GemTestEnvironment overrides ... - void AddGemsAndComponents() override; - }; - - void EditorCameraTestEnvironment::AddGemsAndComponents() - { - AddDynamicModulePaths({ CAMERA_EDITOR_MODULE }); - AddComponentDescriptors({ AzToolsFramework::Components::TransformComponent::CreateDescriptor() }); - } - class EditorCameraFixture : public ::testing::Test { public: + AZ::ComponentApplication* m_application = nullptr; AtomToolsFramework::ModularCameraViewportContext* m_cameraViewportContextView = nullptr; AZStd::unique_ptr m_editorModularViewportCameraComposer; - AZStd::unique_ptr m_editorLibHandle; AzFramework::ViewportControllerListPtr m_controllerList; - AZStd::unique_ptr m_entity; + AZ::Entity* m_entity = nullptr; + AZ::ComponentDescriptor* m_transformComponent = nullptr; static const AzFramework::ViewportId TestViewportId; void SetUp() override { - m_editorLibHandle = AZ::DynamicModuleHandle::Create("EditorLib"); - [[maybe_unused]] const bool loaded = m_editorLibHandle->Load(true); - AZ_Assert(loaded, "EditorLib could not be loaded"); + m_application = aznew AZ::ComponentApplication; + AZ::ComponentApplication::Descriptor appDesc; + m_entity = m_application->Create(appDesc); + m_transformComponent = AzToolsFramework::Components::TransformComponent::CreateDescriptor(); + m_application->RegisterComponentDescriptor(m_transformComponent); - m_controllerList = AZStd::make_shared(); - m_controllerList->RegisterViewportContext(TestViewportId); - - m_entity = AZStd::make_unique(); m_entity->Init(); m_entity->CreateComponent(); m_entity->Activate(); + m_controllerList = AZStd::make_shared(); + m_controllerList->RegisterViewportContext(TestViewportId); + m_editorModularViewportCameraComposer = AZStd::make_unique(TestViewportId); auto controller = m_editorModularViewportCameraComposer->CreateModularViewportCameraController(); @@ -72,8 +62,17 @@ namespace UnitTest { m_editorModularViewportCameraComposer.reset(); m_cameraViewportContextView = nullptr; - m_entity.reset(); - m_editorLibHandle = {}; + + if (m_application) + { + m_application->UnregisterComponentDescriptor(m_transformComponent); + delete m_transformComponent; + m_transformComponent = nullptr; + + m_application->Destroy(); + delete m_application; + m_application = nullptr; + } } }; @@ -211,15 +210,3 @@ namespace UnitTest EXPECT_THAT(currentReferenceFrame, IsClose(AZ::Transform::CreateIdentity())); } } // namespace UnitTest - -// required to support running integration tests with the Camera Gem -AZTEST_EXPORT int AZ_UNIT_TEST_HOOK_NAME(int argc, char** argv) -{ - ::testing::InitGoogleMock(&argc, argv); - AZ::Test::printUnusedParametersWarning(argc, argv); - AZ::Test::addTestEnvironments({ new UnitTest::EditorCameraTestEnvironment() }); - int result = RUN_ALL_TESTS(); - return result; -} - -IMPLEMENT_TEST_EXECUTABLE_MAIN(); diff --git a/Code/Editor/Lib/Tests/test_Main.cpp b/Code/Editor/Lib/Tests/test_Main.cpp index 6250c540db..91369ee8b6 100644 --- a/Code/Editor/Lib/Tests/test_Main.cpp +++ b/Code/Editor/Lib/Tests/test_Main.cpp @@ -9,12 +9,13 @@ #include "EditorDefs.h" #include #include +#include #include #include class EditorLibTestEnvironment - : public AZ::Test::ITestEnvironment + : public ::UnitTest::TraceBusHook { public: ~EditorLibTestEnvironment() override = default; @@ -22,16 +23,20 @@ public: protected: void SetupEnvironment() override { + ::UnitTest::TraceBusHook::SetupEnvironment(); + AZ::Environment::Create(nullptr); - AttachEditorAZEnvironment(AZ::Environment::GetInstance()); AZ::AllocatorInstance::Create(); + AttachEditorAZEnvironment(AZ::Environment::GetInstance()); } void TeardownEnvironment() override { - AZ::AllocatorInstance::Destroy(); DetachEditorAZEnvironment(); + AZ::AllocatorInstance::Destroy(); AZ::Environment::Destroy(); + + ::UnitTest::TraceBusHook::TeardownEnvironment(); } }; diff --git a/Code/Editor/editor_lib_test_files.cmake b/Code/Editor/editor_lib_test_files.cmake index 2ae3d22c19..17f36228db 100644 --- a/Code/Editor/editor_lib_test_files.cmake +++ b/Code/Editor/editor_lib_test_files.cmake @@ -22,6 +22,7 @@ set(FILES Lib/Tests/test_DisplaySettingsPythonBindings.cpp Lib/Tests/test_ViewportManipulatorController.cpp Lib/Tests/test_ModularViewportCameraController.cpp + Lib/Tests/Camera/test_EditorCamera.cpp DisplaySettingsPythonFuncs.cpp DisplaySettingsPythonFuncs.h ) diff --git a/Code/Framework/AzTest/AzTest/GemTestEnvironment.cpp b/Code/Framework/AzTest/AzTest/GemTestEnvironment.cpp index dae1683bd5..de7f8f17c2 100644 --- a/Code/Framework/AzTest/AzTest/GemTestEnvironment.cpp +++ b/Code/Framework/AzTest/AzTest/GemTestEnvironment.cpp @@ -140,6 +140,11 @@ namespace AZ void GemTestEnvironment::TeardownEnvironment() { + for (AZ::ComponentDescriptor* descriptor : m_parameters->m_componentDescriptors) + { + m_application->UnregisterComponentDescriptor(descriptor); + } + const AZ::Entity::ComponentArrayType& components = m_gemEntity->GetComponents(); for (auto itComponent = components.rbegin(); itComponent != components.rend(); ++itComponent) { diff --git a/Code/Framework/AzTest/AzTest/GemTestEnvironment.h b/Code/Framework/AzTest/AzTest/GemTestEnvironment.h index 9008c1ab54..ad495e40c4 100644 --- a/Code/Framework/AzTest/AzTest/GemTestEnvironment.h +++ b/Code/Framework/AzTest/AzTest/GemTestEnvironment.h @@ -18,7 +18,7 @@ namespace AZ /// A test environment which is intended to facilitate writing unit tests which require components from a gem. class GemTestEnvironment - : public UnitTest::TraceBusHook + : public ::UnitTest::TraceBusHook { public: GemTestEnvironment();