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>
This commit is contained in:
@@ -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="$<TARGET_FILE_BASE_NAME:Camera.Editor>"
|
||||
)
|
||||
|
||||
ly_add_googletest(
|
||||
NAME Legacy::EditorLib.Camera.Tests
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -17,7 +17,7 @@ void SetEditorEnvironment(SSystemGlobalEnvironment* pEnv)
|
||||
|
||||
void AttachEditorAZEnvironment(AZ::EnvironmentInstance azEnv)
|
||||
{
|
||||
AZ::Environment::Attach(azEnv, true);
|
||||
AZ::Environment::Attach(azEnv);
|
||||
}
|
||||
|
||||
void DetachEditorAZEnvironment()
|
||||
|
||||
@@ -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
|
||||
)
|
||||
@@ -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<SandboxEditor::EditorModularViewportCameraComposer> m_editorModularViewportCameraComposer;
|
||||
AZStd::unique_ptr<AZ::DynamicModuleHandle> m_editorLibHandle;
|
||||
AzFramework::ViewportControllerListPtr m_controllerList;
|
||||
AZStd::unique_ptr<AZ::Entity> 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<AzFramework::ViewportControllerList>();
|
||||
m_controllerList->RegisterViewportContext(TestViewportId);
|
||||
|
||||
m_entity = AZStd::make_unique<AZ::Entity>();
|
||||
m_entity->Init();
|
||||
m_entity->CreateComponent<AzToolsFramework::Components::TransformComponent>();
|
||||
m_entity->Activate();
|
||||
|
||||
m_controllerList = AZStd::make_shared<AzFramework::ViewportControllerList>();
|
||||
m_controllerList->RegisterViewportContext(TestViewportId);
|
||||
|
||||
m_editorModularViewportCameraComposer = AZStd::make_unique<SandboxEditor::EditorModularViewportCameraComposer>(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();
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
#include "EditorDefs.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
#include <AzCore/UnitTest/UnitTest.h>
|
||||
#include <EditorEnvironment.h>
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
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<AZ::SystemAllocator>::Create();
|
||||
AttachEditorAZEnvironment(AZ::Environment::GetInstance());
|
||||
}
|
||||
|
||||
void TeardownEnvironment() override
|
||||
{
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
|
||||
DetachEditorAZEnvironment();
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
|
||||
AZ::Environment::Destroy();
|
||||
|
||||
::UnitTest::TraceBusHook::TeardownEnvironment();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user