From 48b2c2a4f2cb9cbd86b31e674a7a19fab6f9a23d Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:52:43 +0100 Subject: [PATCH 1/3] Surface Materials list unit tests Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- .../Code/Tests/SurfaceMaterialsListTest.cpp | 73 +++++++++++++++++++ Gems/Terrain/Code/terrain_tests_files.cmake | 1 + 2 files changed, 74 insertions(+) create mode 100644 Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp diff --git a/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp b/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp new file mode 100644 index 0000000000..fb70b1366f --- /dev/null +++ b/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp @@ -0,0 +1,73 @@ +/* + * 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 + * + */ + +#include +#include +#include +#include +#include + +using ::testing::NiceMock; +using ::testing::AtLeast; +using ::testing::_; + +namespace UnitTest +{ + class TerrainSurfaceMaterialsListTest : public ::testing::Test + { + protected: + AZ::ComponentApplication m_app; + + void SetUp() override + { + AZ::ComponentApplication::Descriptor appDesc; + appDesc.m_memoryBlocksByteSize = 20 * 1024 * 1024; + appDesc.m_recordingMode = AZ::Debug::AllocationRecords::RECORD_NO_RECORDS; + appDesc.m_stackRecordLevels = 20; + + m_app.Create(appDesc); + } + + AZStd::unique_ptr CreateEntityWithShapeComponents() + { + auto entity = AZStd::make_unique(); + entity->Init(); + + auto shapeComponent = entity->CreateComponent(); + m_app.RegisterComponentDescriptor(shapeComponent->CreateDescriptor()); + + return entity; + } + + Terrain::TerrainSurfaceMaterialsListComponent* AddSurfaceMaterialListComponent(AZ::Entity* entity) + { + auto surfaceMaterialsListComponent = entity->CreateComponent(); + m_app.RegisterComponentDescriptor(surfaceMaterialsListComponent->CreateDescriptor()); + + return surfaceMaterialsListComponent; + } + + void TearDown() override + { + m_app.Destroy(); + } + }; + + TEST_F(TerrainSurfaceMaterialsListTest, SurfaceGradientListActivatesSuccessfully) + { + auto entity = CreateEntityWithShapeComponents(); + + AddSurfaceMaterialListComponent(entity.get()); + + entity->Activate(); + + EXPECT_EQ(entity->GetState(), AZ::Entity::State::Active); + + entity.reset(); + } +} // namespace UnitTest diff --git a/Gems/Terrain/Code/terrain_tests_files.cmake b/Gems/Terrain/Code/terrain_tests_files.cmake index 3ce1d05003..793bc01ac5 100644 --- a/Gems/Terrain/Code/terrain_tests_files.cmake +++ b/Gems/Terrain/Code/terrain_tests_files.cmake @@ -10,5 +10,6 @@ set(FILES Tests/TerrainTest.cpp Tests/TerrainSystemTest.cpp Tests/LayerSpawnerTests.cpp + Tests/SurfaceMaterialsListTest.cpp Tests/MockAxisAlignedBoxShapeComponent.h ) From 68fe604dde986d31c0455813e1e12ca193d13026 Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Mon, 11 Oct 2021 17:18:41 +0100 Subject: [PATCH 2/3] Missing shape test Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- .../Code/Tests/SurfaceMaterialsListTest.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp b/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp index fb70b1366f..cc1af8bf62 100644 --- a/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp +++ b/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp @@ -33,10 +33,16 @@ namespace UnitTest m_app.Create(appDesc); } - AZStd::unique_ptr CreateEntityWithShapeComponents() + AZStd::unique_ptr CreateEntity() { auto entity = AZStd::make_unique(); entity->Init(); + return entity; + } + + AZStd::unique_ptr CreateEntityWithShapeComponents() + { + auto entity = CreateEntity(); auto shapeComponent = entity->CreateComponent(); m_app.RegisterComponentDescriptor(shapeComponent->CreateDescriptor()); @@ -58,6 +64,19 @@ namespace UnitTest } }; + TEST_F(TerrainSurfaceMaterialsListTest, SurfaceGradientListRequiresShapeToActivate) + { + auto entity = CreateEntity(); + + AddSurfaceMaterialListComponent(entity.get()); + + entity->Activate(); + + EXPECT_EQ(entity->GetState(), AZ::Entity::State::Active); + + entity.reset(); + } + TEST_F(TerrainSurfaceMaterialsListTest, SurfaceGradientListActivatesSuccessfully) { auto entity = CreateEntityWithShapeComponents(); From a849008a4857d50ed109d03ad8c087889f44d401 Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Tue, 12 Oct 2021 09:33:36 +0100 Subject: [PATCH 3/3] compile fix and add activation failure test. Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp b/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp index cc1af8bf62..c2c24e300f 100644 --- a/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp +++ b/Gems/Terrain/Code/Tests/SurfaceMaterialsListTest.cpp @@ -10,7 +10,6 @@ #include #include #include -#include using ::testing::NiceMock; using ::testing::AtLeast; @@ -66,14 +65,16 @@ namespace UnitTest TEST_F(TerrainSurfaceMaterialsListTest, SurfaceGradientListRequiresShapeToActivate) { + // Check that the component requires a shape service to activate: trying to Activate the entity will cause the test to fail, so + // use the EvaluateDependenciesGetDetails function to check the dependencies are met. + auto entity = CreateEntity(); AddSurfaceMaterialListComponent(entity.get()); - entity->Activate(); - - EXPECT_EQ(entity->GetState(), AZ::Entity::State::Active); - + const AZ::Entity::DependencySortOutcome sortOutcome = entity->EvaluateDependenciesGetDetails(); + EXPECT_FALSE(sortOutcome.IsSuccess()); + entity.reset(); }