/* * 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 namespace UnitTest { // 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(); } template AZ::Component* CreateComponent(AZ::Entity* entity, const Configuration& config) { m_app->RegisterComponentDescriptor(Component::CreateDescriptor()); return entity->CreateComponent(config); } template AZ::Component* CreateComponent(AZ::Entity* entity) { m_app->RegisterComponentDescriptor(Component::CreateDescriptor()); return entity->CreateComponent(); } AZStd::unique_ptr m_app; AZ::Entity* m_systemEntity = nullptr; ImageAssetMockAssetHandler* m_mockHandler = nullptr; }; struct GradientSignalTest : public GradientSignalBaseFixture , public UnitTest::AllocatorsTestFixture { protected: void SetUp() override { UnitTest::AllocatorsTestFixture::SetUp(); SetupCoreSystems(); } void TearDown() override { TearDownCoreSystems(); UnitTest::AllocatorsTestFixture::TearDown(); } void TestFixedDataSampler(const AZStd::vector& expectedOutput, int size, AZ::EntityId gradientEntityId); }; #ifdef HAVE_BENCHMARK class GradientSignalBenchmarkFixture : public GradientSignalBaseFixture , public UnitTest::AllocatorsBenchmarkFixture , public UnitTest::TraceBusRedirector { public: void internalSetUp(const benchmark::State& state) { AZ::Debug::TraceMessageBus::Handler::BusConnect(); UnitTest::AllocatorsBenchmarkFixture::SetUp(state); SetupCoreSystems(); // Create a default test entity with bounds of 256 m x 256 m x 256 m. const float shapeHalfBounds = 128.0f; CreateTestEntity(shapeHalfBounds); } void internalTearDown(const benchmark::State& state) { DestroyTestEntity(); TearDownCoreSystems(); UnitTest::AllocatorsBenchmarkFixture::TearDown(state); AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); } void CreateTestEntity(float shapeHalfBounds); void DestroyTestEntity(); void CreateTestImageGradient(AZ::Entity* entity); void CreateTestPerlinGradient(AZ::Entity* entity); void CreateTestRandomGradient(AZ::Entity* entity); void RunSamplerGetValueBenchmark(benchmark::State& state); void RunSamplerGetValuesBenchmark(benchmark::State& state); void RunEBusGetValueBenchmark(benchmark::State& state); void RunEBusGetValuesBenchmark(benchmark::State& state); protected: void SetUp(const benchmark::State& state) override { internalSetUp(state); } void SetUp(benchmark::State& state) override { internalSetUp(state); } void TearDown(const benchmark::State& state) override { internalTearDown(state); } void TearDown(benchmark::State& state) override { internalTearDown(state); } AZStd::unique_ptr m_testEntity; }; #endif }