LyShineTest.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/Component/ComponentApplication.h>
  11. #include <LyShineModule.h>
  12. namespace UnitTest
  13. {
  14. class LyShineTest
  15. : public LeakDetectionFixture
  16. {
  17. protected:
  18. LyShineTest()
  19. : m_application()
  20. , m_systemEntity(nullptr)
  21. {
  22. }
  23. void SetUp() override
  24. {
  25. SetupApplication();
  26. SetupEnvironment();
  27. }
  28. virtual void SetupApplication()
  29. {
  30. AZ::ComponentApplication::Descriptor appDesc;
  31. appDesc.m_memoryBlocksByteSize = 10 * 1024 * 1024;
  32. appDesc.m_recordingMode = AZ::Debug::AllocationRecords::Mode::RECORD_FULL;
  33. m_systemEntity = m_application->Create(appDesc);
  34. m_systemEntity->Init();
  35. m_systemEntity->Activate();
  36. }
  37. virtual void SetupEnvironment()
  38. {
  39. m_env = AZStd::make_unique<StubEnv>();
  40. memset(&m_env->m_stubEnv, 0, sizeof(SSystemGlobalEnvironment));
  41. m_priorEnv = gEnv;
  42. gEnv = &m_env->m_stubEnv;
  43. }
  44. void TearDown() override
  45. {
  46. m_env.reset();
  47. gEnv = m_priorEnv;
  48. m_application->Destroy();
  49. delete m_application;
  50. m_application = nullptr;
  51. }
  52. struct StubEnv
  53. {
  54. SSystemGlobalEnvironment m_stubEnv;
  55. };
  56. AZ::ComponentApplication* m_application = nullptr;
  57. AZ::Entity* m_systemEntity = nullptr;
  58. AZStd::unique_ptr<StubEnv> m_env;
  59. SSystemGlobalEnvironment* m_priorEnv = nullptr;
  60. };
  61. } // namespace UnitTest