InitSceneAPIFixture.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #pragma once
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. #include <AzCore/std/containers/vector.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <AzCore/Module/DynamicModuleHandle.h>
  13. namespace AZ { class DynamicModuleHandle; }
  14. namespace SceneProcessing
  15. {
  16. class InitSceneAPIFixture
  17. : public UnitTest::LeakDetectionFixture
  18. {
  19. using DynamicModuleHandlePtr = AZStd::unique_ptr<AZ::DynamicModuleHandle>;
  20. protected:
  21. void SetUp() override
  22. {
  23. UnitTest::LeakDetectionFixture::SetUp();
  24. const AZStd::vector<AZStd::string> moduleNames {"SceneCore", "SceneData"};
  25. for (const AZStd::string& moduleName : moduleNames)
  26. {
  27. AZStd::unique_ptr<AZ::DynamicModuleHandle> module = AZ::DynamicModuleHandle::Create(moduleName.c_str());
  28. ASSERT_TRUE(module) << "Scene Processing Gem unit tests failed to create " << moduleName.c_str() << " module.";
  29. const bool loaded = module->Load();
  30. ASSERT_TRUE(loaded) << "Scene Processing Gem unit tests failed to load " << moduleName.c_str() << " module.";
  31. auto init = module->GetFunction<AZ::InitializeDynamicModuleFunction>(AZ::InitializeDynamicModuleFunctionName);
  32. ASSERT_TRUE(init) << "Scene Processing Gem unit tests failed to find the initialization function the " << moduleName.c_str() << " module.";
  33. (*init)();
  34. m_modules.emplace_back(AZStd::move(module));
  35. }
  36. }
  37. ~InitSceneAPIFixture() override
  38. {
  39. for (DynamicModuleHandlePtr& module : m_modules)
  40. {
  41. const auto uninit = module->GetFunction<AZ::UninitializeDynamicModuleFunction>(AZ::UninitializeDynamicModuleFunctionName);
  42. (*uninit)();
  43. module.reset();
  44. }
  45. m_modules.clear();
  46. m_modules.shrink_to_fit();
  47. }
  48. private:
  49. AZStd::vector<DynamicModuleHandlePtr> m_modules;
  50. };
  51. } // namespace SceneProcessing