/* * 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 * */ #pragma once #include #include #include namespace UnitTest { // The GradientSignal unit tests need to use the GemTestEnvironment to load the LmbrCentral Gem so that Shape components can be used // in the unit tests and benchmarks. class GradientSignalTestEnvironment : public AZ::Test::GemTestEnvironment { public: void AddGemsAndComponents() override; }; #ifdef HAVE_BENCHMARK //! The Benchmark environment is used for one time setup and tear down of shared resources class GradientSignalBenchmarkEnvironment : public AZ::Test::BenchmarkEnvironmentBase , public GradientSignalTestEnvironment { protected: void SetUpBenchmark() override { SetupEnvironment(); } void TearDownBenchmark() override { TeardownEnvironment(); } }; #endif // Base test fixture used for GradientSignal unit tests and benchmark tests class GradientSignalBaseFixture { public: void SetupCoreSystems(); void TearDownCoreSystems(); AZStd::unique_ptr CreateEntity() { return AZStd::make_unique(); } void ActivateEntity(AZ::Entity* entity) { entity->Init(); entity->Activate(); } // Create a mock SurfaceDataSystem that will respond to requests for surface points with mock responses for points inside // the given input box. AZStd::unique_ptr CreateMockSurfaceDataSystem(const AZ::Aabb& spawnerBox); // Create an entity with a mock shape and a transform. It won't be activated yet though, because we expect a gradient component // to also get added to it first before activation. AZStd::unique_ptr CreateTestEntity(float shapeHalfBounds); // Create and activate an entity with a gradient component of the requested type, initialized with test data. AZStd::unique_ptr BuildTestConstantGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestImageGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestPerlinGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestRandomGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestShapeAreaFalloffGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestDitherGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestInvertGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestLevelsGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestMixedGradient( float shapeHalfBounds, const AZ::EntityId& baseGradientId, const AZ::EntityId& mixedGradientId); AZStd::unique_ptr BuildTestPosterizeGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestReferenceGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestSmoothStepGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestThresholdGradient(float shapeHalfBounds, const AZ::EntityId& inputGradientId); AZStd::unique_ptr BuildTestSurfaceAltitudeGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestSurfaceMaskGradient(float shapeHalfBounds); AZStd::unique_ptr BuildTestSurfaceSlopeGradient(float shapeHalfBounds); UnitTest::ImageAssetMockAssetHandler* m_mockHandler = nullptr; }; struct GradientSignalTest : public GradientSignalBaseFixture , public ::testing::Test { protected: void SetUp() override { SetupCoreSystems(); } void TearDown() override { TearDownCoreSystems(); } void TestFixedDataSampler(const AZStd::vector& expectedOutput, int size, AZ::EntityId gradientEntityId); }; #ifdef HAVE_BENCHMARK class GradientSignalBenchmarkFixture : public GradientSignalBaseFixture , public ::benchmark::Fixture { public: void internalSetUp() { SetupCoreSystems(); } void internalTearDown() { TearDownCoreSystems(); } protected: void SetUp([[maybe_unused]] const benchmark::State& state) override { internalSetUp(); } void SetUp([[maybe_unused]] benchmark::State& state) override { internalSetUp(); } void TearDown([[maybe_unused]] const benchmark::State& state) override { internalTearDown(); } void TearDown([[maybe_unused]] benchmark::State& state) override { internalTearDown(); } }; #endif }