From e54963f0a9f177ff88becc61ebe13ecaf8677191 Mon Sep 17 00:00:00 2001 From: amzn-sj Date: Fri, 21 May 2021 11:00:50 -0700 Subject: [PATCH] Set project_path in the SettingsRegistry in the test SetUp() functions for tests that require a project to be set --- .../Tests/PlatformAddressedAssetCatalogTests.cpp | 10 ++++++++++ Code/Framework/Tests/ArchiveCompressionTests.cpp | 8 ++++++++ Code/Framework/Tests/ArchiveTests.cpp | 9 +++++++++ .../tests/AssetCatalog/AssetCatalogUnitTests.cpp | 3 +++ .../AssetProcessor/native/tests/AssetProcessorTest.cpp | 8 +++++++- .../tests/assetmanager/AssetProcessorManagerTest.cpp | 3 +++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp b/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp index 328bf5dea5..4cc98106d6 100644 --- a/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp @@ -10,6 +10,8 @@ * */ +#include +#include #include #include #include @@ -49,6 +51,14 @@ namespace UnitTest using namespace AZ::Data; m_application = new ToolsTestApplication("AddressedAssetCatalogManager"); // Shorter name because Setting Registry // specialization are 32 characters max. + + AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); + + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + registry->Set(projectPathKey, "AutomatedTesting"); + AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); + m_application->Start(AzFramework::Application::Descriptor()); // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash diff --git a/Code/Framework/Tests/ArchiveCompressionTests.cpp b/Code/Framework/Tests/ArchiveCompressionTests.cpp index fb6beca0b5..c648262599 100644 --- a/Code/Framework/Tests/ArchiveCompressionTests.cpp +++ b/Code/Framework/Tests/ArchiveCompressionTests.cpp @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -40,6 +41,13 @@ namespace UnitTest void SetUp() override { + AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); + + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + registry->Set(projectPathKey, "AutomatedTesting"); + AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); + m_application->Start({}); // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash diff --git a/Code/Framework/Tests/ArchiveTests.cpp b/Code/Framework/Tests/ArchiveTests.cpp index aaca043c4b..6dc081ee72 100644 --- a/Code/Framework/Tests/ArchiveTests.cpp +++ b/Code/Framework/Tests/ArchiveTests.cpp @@ -16,6 +16,7 @@ #include #include // for max path decl +#include #include #include #include // for function<> in the find files callback. @@ -42,6 +43,14 @@ namespace UnitTest { AZ::ComponentApplication::Descriptor descriptor; descriptor.m_stackRecordLevels = 30; + + AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); + + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + registry->Set(projectPathKey, "AutomatedTesting"); + AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); + m_application->Start(descriptor); // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash diff --git a/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp b/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp index e92e9afba5..3d9ecd3f5e 100644 --- a/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp +++ b/Code/Tools/AssetProcessor/native/tests/AssetCatalog/AssetCatalogUnitTests.cpp @@ -130,6 +130,9 @@ namespace AssetProcessor auto cacheRootKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_cache_path"; settingsRegistry->Set(cacheRootKey, m_data->m_temporarySourceDir.absoluteFilePath("Cache").toUtf8().constData()); + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + settingsRegistry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*settingsRegistry); AssetUtilities::ComputeProjectCacheRoot(m_data->m_cacheRootDir); QString normalizedCacheRoot = AssetUtilities::NormalizeDirectoryPath(m_data->m_cacheRootDir.absolutePath()); diff --git a/Code/Tools/AssetProcessor/native/tests/AssetProcessorTest.cpp b/Code/Tools/AssetProcessor/native/tests/AssetProcessorTest.cpp index d04e13aef2..7b88321ad9 100644 --- a/Code/Tools/AssetProcessor/native/tests/AssetProcessorTest.cpp +++ b/Code/Tools/AssetProcessor/native/tests/AssetProcessorTest.cpp @@ -12,7 +12,7 @@ #include "AssetProcessorTest.h" - +#include #include #include "BaseAssetProcessorTest.h" @@ -67,6 +67,12 @@ namespace AssetProcessor static char processName[] = {"AssetProcessorBatch"}; static char* namePtr = &processName[0]; static char** paramStringArray = &namePtr; + + auto registry = AZ::SettingsRegistry::Get(); + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + registry->Set(projectPathKey, "AutomatedTesting"); + AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); m_application.reset(new UnitTestAppManager(&numParams, ¶mStringArray)); ASSERT_EQ(m_application->BeforeRun(), ApplicationManager::Status_Success); diff --git a/Code/Tools/AssetProcessor/native/tests/assetmanager/AssetProcessorManagerTest.cpp b/Code/Tools/AssetProcessor/native/tests/assetmanager/AssetProcessorManagerTest.cpp index 07d1e48229..d592ecb012 100644 --- a/Code/Tools/AssetProcessor/native/tests/assetmanager/AssetProcessorManagerTest.cpp +++ b/Code/Tools/AssetProcessor/native/tests/assetmanager/AssetProcessorManagerTest.cpp @@ -204,6 +204,9 @@ void AssetProcessorManagerTest::SetUp() auto cacheRootKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_cache_path"; registry->Set(cacheRootKey, tempPath.absoluteFilePath("Cache").toUtf8().constData()); + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + registry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); m_data->m_databaseLocationListener.BusConnect();