MainTools.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/UnitTest/UnitTest.h>
  9. #include <AzCore/UserSettings/UserSettingsComponent.h>
  10. #include <AzQtComponents/Utilities/QtPluginPaths.h>
  11. #include <AzTest/AzTest.h>
  12. #include <AzTest/GemTestEnvironment.h>
  13. #include <QApplication>
  14. #include <Multiplayer/Components/NetBindComponent.h>
  15. #include <UnitTest/ToolsTestApplication.h>
  16. namespace Multiplayer
  17. {
  18. class MultiplayerToolsTestEnvironment : public AZ::Test::GemTestEnvironment
  19. {
  20. AZ::ComponentApplication* CreateApplicationInstance() override
  21. {
  22. return aznew UnitTest::ToolsTestApplication("MultiplayerToolsTest");
  23. }
  24. void AddGemsAndComponents() override
  25. {
  26. AZStd::vector<AZ::ComponentDescriptor*> descriptors({
  27. NetBindComponent::CreateDescriptor()
  28. });
  29. AddComponentDescriptors(descriptors);
  30. }
  31. /// Allows derived environments to override to perform additional steps after the system entity is activated.
  32. void PostSystemEntityActivate() override
  33. {
  34. // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
  35. // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
  36. // in the unit tests.
  37. AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
  38. }
  39. };
  40. } // namespace UnitTest
  41. // Required to support running integration tests with Qt
  42. AZTEST_EXPORT int AZ_UNIT_TEST_HOOK_NAME(int argc, char** argv)
  43. {
  44. ::testing::InitGoogleMock(&argc, argv);
  45. AzQtComponents::PrepareQtPaths();
  46. QApplication app(argc, argv);
  47. AZ::Test::printUnusedParametersWarning(argc, argv);
  48. AZ::Test::addTestEnvironments({new Multiplayer::MultiplayerToolsTestEnvironment});
  49. int result = RUN_ALL_TESTS();
  50. return result;
  51. }