AssetProcessorTest.h 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <AzTest/AzTest.h>
  10. #include <AzCore/Memory/Memory.h>
  11. #include <AzCore/Memory/SystemAllocator.h>
  12. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  13. #include <AzFramework/Application/Application.h>
  14. #include <native/utilities/assetUtils.h>
  15. #include <native/unittests/UnitTestUtils.h> // for the assert absorber.
  16. #include <AssetManager/FileStateCache.h>
  17. #include <AzCore/Component/ComponentApplicationLifecycle.h>
  18. #include <tests/ApplicationManagerTests.h>
  19. #include "UnitTestUtilities.h"
  20. namespace AssetProcessor
  21. {
  22. struct IUnitTestAppManager
  23. {
  24. AZ_RTTI(IUnitTestAppManager, "{37578207-790A-4928-BD47-B9C4F4B49C3A}");
  25. virtual PlatformConfiguration& GetConfig() = 0;
  26. };
  27. // This is an utility class for Asset Processor Tests
  28. // Any gmock based fixture class can derived from this class and this will automatically do system allocation and teardown for you
  29. // It is important to note that if you are overriding Setup and Teardown functions of your fixture class than please call the base class functions.
  30. class AssetProcessorTest
  31. : public ::UnitTest::LeakDetectionFixture
  32. {
  33. protected:
  34. AZStd::unique_ptr<UnitTestUtils::AssertAbsorber> m_errorAbsorber{};
  35. AZStd::unique_ptr<FileStatePassthrough> m_fileStateCache{};
  36. void SetUp() override
  37. {
  38. m_errorAbsorber = AZStd::make_unique<UnitTestUtils::AssertAbsorber>();
  39. m_application = AZStd::make_unique<AzFramework::Application>();
  40. m_fileStateCache = AZStd::make_unique<FileStatePassthrough>();
  41. // Inject the AutomatedTesting project as a project path into test fixture
  42. using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
  43. constexpr auto projectPathKey = FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey)
  44. + "/project_path";
  45. if(auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  46. {
  47. AZ::IO::FixedMaxPath enginePath;
  48. settingsRegistry->Get(enginePath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
  49. settingsRegistry->Set(projectPathKey, (enginePath / "AutomatedTesting").Native());
  50. AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*settingsRegistry);
  51. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SystemComponentsActivated");
  52. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SystemComponentsDeactivated");
  53. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "ReflectionManagerAvailable");
  54. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "ReflectionManagerUnavailable");
  55. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SystemAllocatorCreated");
  56. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SystemAllocatorPendingDestruction");
  57. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SettingsRegistryAvailable");
  58. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "SettingsRegistryUnavailable");
  59. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "ConsoleAvailable");
  60. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "ConsoleUnavailable");
  61. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "GemsLoaded");
  62. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "GemsUnloaded");
  63. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "FileIOAvailable");
  64. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "FileIOUnavailable");
  65. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "LegacySystemInterfaceCreated");
  66. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "CriticalAssetsCompiled");
  67. AZ::ComponentApplicationLifecycle::RegisterEvent(*settingsRegistry, "LegacyCommandLineProcessed");
  68. }
  69. }
  70. void TearDown() override
  71. {
  72. AssetUtilities::ResetAssetRoot();
  73. m_fileStateCache.reset();
  74. m_application.reset();
  75. m_errorAbsorber.reset();
  76. }
  77. AZStd::unique_ptr<AzFramework::Application> m_application;
  78. };
  79. }