TestsMain.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzTest/AzTest.h>
  9. #include <AzCore/Module/DynamicModuleHandle.h>
  10. #include <AzCore/Memory/SystemAllocator.h>
  11. class SceneBuilderTestEnvironment
  12. : public AZ::Test::ITestEnvironment
  13. {
  14. public:
  15. virtual ~SceneBuilderTestEnvironment()
  16. {}
  17. protected:
  18. void SetupEnvironment() override
  19. {
  20. sceneCoreModule = AZ::DynamicModuleHandle::Create("SceneCore");
  21. AZ_Assert(sceneCoreModule, "SceneBuilder unit tests failed to create SceneCore module.");
  22. [[maybe_unused]] bool loaded = sceneCoreModule->Load();
  23. AZ_Assert(loaded, "SceneBuilder unit tests failed to load SceneCore module.");
  24. auto init = sceneCoreModule->GetFunction<AZ::InitializeDynamicModuleFunction>(AZ::InitializeDynamicModuleFunctionName);
  25. AZ_Assert(init, "SceneBuilder unit tests failed to find the initialization function the SceneCore module.");
  26. (*init)();
  27. sceneDataModule = AZ::DynamicModuleHandle::Create("SceneData");
  28. AZ_Assert(sceneDataModule, "SceneData unit tests failed to create SceneData module.");
  29. loaded = sceneDataModule->Load();
  30. AZ_Assert(loaded, "SceneBuilder unit tests failed to load SceneData module.");
  31. init = sceneDataModule->GetFunction<AZ::InitializeDynamicModuleFunction>(AZ::InitializeDynamicModuleFunctionName);
  32. AZ_Assert(init, "SceneBuilder unit tests failed to find the initialization function the SceneData module.");
  33. (*init)();
  34. }
  35. void TeardownEnvironment() override
  36. {
  37. auto uninit = sceneDataModule->GetFunction<AZ::UninitializeDynamicModuleFunction>(AZ::UninitializeDynamicModuleFunctionName);
  38. AZ_Assert(uninit, "SceneBuilder unit tests failed to find the uninitialization function the SceneData module.");
  39. (*uninit)();
  40. sceneDataModule.reset();
  41. uninit = sceneCoreModule->GetFunction<AZ::UninitializeDynamicModuleFunction>(AZ::UninitializeDynamicModuleFunctionName);
  42. AZ_Assert(uninit, "SceneBuilder unit tests failed to find the uninitialization function the SceneCore module.");
  43. (*uninit)();
  44. sceneCoreModule.reset();
  45. }
  46. private:
  47. AZStd::unique_ptr<AZ::DynamicModuleHandle> sceneCoreModule;
  48. AZStd::unique_ptr<AZ::DynamicModuleHandle> sceneDataModule;
  49. };
  50. AZ_UNIT_TEST_HOOK(new SceneBuilderTestEnvironment);