Main.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <AzCore/Component/ComponentApplication.h>
  9. #include <AzCore/Component/ComponentApplicationLifecycle.h>
  10. #include <AzCore/IO/Path/Path.h>
  11. #include <AzCore/Memory/AllocatorManager.h>
  12. #include <AzCore/Memory/SystemAllocator.h>
  13. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  14. #include <AzCore/std/smart_ptr/unique_ptr.h>
  15. #include <AzQtComponents/Components/StyleManager.h>
  16. #include <AzTest/AzTest.h>
  17. #include <QApplication>
  18. // Handle asserts
  19. class ToolsFrameworkHook
  20. : public AZ::Test::ITestEnvironment
  21. {
  22. public:
  23. void SetupEnvironment() override
  24. {
  25. }
  26. void TeardownEnvironment() override
  27. {
  28. }
  29. };
  30. AZTEST_EXPORT int AZ_UNIT_TEST_HOOK_NAME(int argc, char** argv)
  31. {
  32. ::testing::InitGoogleMock(&argc, argv);
  33. QApplication app(argc, argv);
  34. auto styleManager = AZStd::make_unique<AzQtComponents::StyleManager>(&app);
  35. AZ::IO::FixedMaxPath engineRootPath;
  36. {
  37. AZ::ComponentApplication componentApplication(argc, argv);
  38. auto settingsRegistry = AZ::SettingsRegistry::Get();
  39. settingsRegistry->Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
  40. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SystemComponentsDeactivated");
  41. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "ConsoleUnavailable");
  42. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SettingsRegistryUnavailable");
  43. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SystemAllocatorPendingDestruction");
  44. }
  45. AZ::AllocatorManager::Instance().GarbageCollect();
  46. styleManager->initialize(&app, engineRootPath);
  47. AZ::Test::printUnusedParametersWarning(argc, argv);
  48. AZ::Test::addTestEnvironments({ DEFAULT_UNIT_TEST_ENV, new ToolsFrameworkHook });
  49. int result = RUN_ALL_TESTS();
  50. styleManager.release();
  51. return result;
  52. }
  53. #if defined(HAVE_BENCHMARK)
  54. AZ_BENCHMARK_HOOK();
  55. #else
  56. IMPLEMENT_TEST_EXECUTABLE_MAIN();
  57. #endif