/* * 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 #include #include #include #include #include #include #include namespace UnitTest { using namespace AZ; // Expose AssetManagerComponent::Reflect function for testing class MyAssetManagerComponent : public AssetManagerComponent { public: static void Reflect(ReflectContext* reflection) { AssetManagerComponent::Reflect(reflection); } }; SerializeContext* BuilderTestFixture::GetSerializeContext() { return m_context.get(); } JsonRegistrationContext* BuilderTestFixture::GetJsonRegistrationContext() { return m_jsonRegistrationContext.get(); } void BuilderTestFixture::Reflect(ReflectContext* context) { RHI::ReflectSystemComponent::Reflect(context); RPI::RPISystem::Reflect(context); RPI::BuilderComponent::Reflect(context); AZ::Name::Reflect(context); MyAssetManagerComponent::Reflect(context); } void BuilderTestFixture::SetUp() { AllocatorsFixture::SetUp(); //prepare reflection m_context = AZStd::make_unique(); m_jsonRegistrationContext = AZStd::make_unique(); m_jsonSystemComponent = AZStd::make_unique(); m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get()); // Adding this handler to allow utility functions access the serialize context ComponentApplicationBus::Handler::BusConnect(); AZ::Interface::Register(this); // Startup default local FileIO (hits OSAllocator) if not already setup. if (IO::FileIOBase::GetInstance() == nullptr) { IO::FileIOBase::SetInstance(aznew IO::LocalFileIO()); } NameDictionary::Create(); Reflect(m_context.get()); Reflect(m_jsonRegistrationContext.get()); AZ::AllocatorInstance::Create(); AZ::AllocatorInstance::Create(); m_streamer = AZStd::make_unique(AZStd::thread_desc{}, AZ::StreamerComponent::CreateStreamerStack()); Interface::Register(m_streamer.get()); Data::AssetManager::Descriptor desc; Data::AssetManager::Create(desc); AZ::Utils::GetExecutableDirectory(m_currentDir, AZ_MAX_PATH_LEN); } void BuilderTestFixture::TearDown() { Data::AssetManager::Destroy(); Interface::Unregister(m_streamer.get()); m_streamer.reset(); AZ::AllocatorInstance::Destroy(); AZ::AllocatorInstance::Destroy(); delete IO::FileIOBase::GetInstance(); IO::FileIOBase::SetInstance(nullptr); AZ::Interface::Unregister(this); ComponentApplicationBus::Handler::BusDisconnect(); m_jsonRegistrationContext->EnableRemoveReflection(); m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get()); Reflect(m_jsonRegistrationContext.get()); m_jsonRegistrationContext->DisableRemoveReflection(); m_jsonRegistrationContext.reset(); m_jsonSystemComponent.reset(); NameDictionary::Destroy(); m_context.reset(); AllocatorsFixture::TearDown(); } } // namespace UnitTest