627012840d
* Fixed the return value of the ConvertToAbsolutePath function Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added the generated cmake_dependencies.*.setreg files to engine.pak (#5073) * Copied the generated cmake_dependencies.*.setreg file to the Cache directory Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed the platform name from the bootstrap.game.*.setreg Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Update how the project related file paths are determined when not supplied. The project-path determination now goes back to only detecting a "project.json" file. It no longer attempts to detect a "Cache" directory The project-cache-path determination now in addition to checking the project_cache_path key searches for a "Cache" directory. The project-path defaults to executable folder if it cannot be detected. The copying of generated executable folder Registry directory contents to the product cache is now removed after the archive step. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the invocation of the AssetProcessor in Jenkins to supply an absolute path to the project. The project-path is no longer treated as relative to the engine root, but instead relative to the current working directory at application startup. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added constant for the storing the name of Cache directory Fixed typos and grammatical errors in the SettingsRegistryMergeUtils.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated UnitTest prepend the EngineRoot path to "AutomatedTesting" when setting the project path. This is needed now that the project-path isn't treated relative to the EngineRoot if it is not absolute. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix AssetSeedManagerTest and PlatformAddressedAssetCatalogManagerTest Instead of trying to used the AutomatedTesting directory as the project root, the temp directory created during the test is used as the project root. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Moved the setting of the project cache root folder and project asset platform root folder into the `if (!projectCachePath.empty())` block Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removing the scan up logic for the "Cache" directory. This is no longer needed to locate the project cache path in a Project Game Release Layout. Because the project path defaults to the executable directory if, it is not found, the Cache directory will be set to the "Cache" directory within the executable directory. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
267 lines
12 KiB
C++
267 lines
12 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <AzFramework/API/ApplicationAPI.h>
|
|
#include <AzFramework/IO/LocalFileIO.h>
|
|
#include <AzFramework/StringFunc/StringFunc.h>
|
|
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
|
#include <AzToolsFramework/Application/ToolsApplication.h>
|
|
#include <AzToolsFramework/Asset/AssetBundler.h>
|
|
#include <AzCore/IO/Path/Path.h>
|
|
#include <AzCore/Settings/SettingsRegistryImpl.h>
|
|
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
|
#include <AzCore/UserSettings/UserSettingsComponent.h>
|
|
|
|
#include <source/utils/utils.h>
|
|
#include <source/utils/applicationManager.h>
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
#include <tests/main.h>
|
|
|
|
namespace AssetBundler
|
|
{
|
|
const char DummyProjectName[] = "DummyProject";
|
|
|
|
class MockApplicationManagerTest
|
|
: public AssetBundler::ApplicationManager
|
|
{
|
|
public:
|
|
friend class GTEST_TEST_CLASS_NAME_(ApplicationManagerTest, ValidatePlatformFlags_ReadConfigFiles_OK);
|
|
explicit MockApplicationManagerTest(int* argc, char*** argv)
|
|
: ApplicationManager(argc, argv)
|
|
{
|
|
}
|
|
|
|
};
|
|
|
|
class BasicApplicationManagerTest
|
|
: public UnitTest::ScopedAllocatorSetupFixture
|
|
{
|
|
|
|
};
|
|
|
|
class ApplicationManagerTest
|
|
: public UnitTest::ScopedAllocatorSetupFixture
|
|
{
|
|
public:
|
|
|
|
void SetUp() override
|
|
{
|
|
UnitTest::ScopedAllocatorSetupFixture::SetUp();
|
|
m_data = AZStd::make_unique<StaticData>();
|
|
|
|
AZ::SettingsRegistryInterface* registry = nullptr;
|
|
if (!AZ::SettingsRegistry::Get())
|
|
{
|
|
AZ::SettingsRegistry::Register(&m_registry);
|
|
registry = &m_registry;
|
|
}
|
|
else
|
|
{
|
|
registry = AZ::SettingsRegistry::Get();
|
|
}
|
|
auto projectPathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey)
|
|
+ "/project_path";
|
|
AZ::IO::FixedMaxPath enginePath;
|
|
registry->Get(enginePath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
|
|
registry->Set(projectPathKey, (enginePath / "AutomatedTesting").Native());
|
|
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
|
|
|
|
|
|
m_data->m_applicationManager.reset(aznew MockApplicationManagerTest(0, 0));
|
|
|
|
AZ::ComponentApplication::StartupParameters startupParameters;
|
|
// The AssetBundler does not need to load gems
|
|
startupParameters.m_loadDynamicModules = false;
|
|
m_data->m_applicationManager->Start(AzFramework::Application::Descriptor(), startupParameters);
|
|
|
|
// 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
|
|
// in the unit tests.
|
|
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
|
|
|
const char* engineRoot = nullptr;
|
|
AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot);
|
|
ASSERT_TRUE(engineRoot) << "Unable to locate engine root.\n";
|
|
AzFramework::StringFunc::Path::Join(engineRoot, RelativeTestFolder, m_data->m_testEngineRoot);
|
|
|
|
m_data->m_localFileIO = aznew AZ::IO::LocalFileIO();
|
|
m_data->m_priorFileIO = AZ::IO::FileIOBase::GetInstance();
|
|
// we need to set it to nullptr first because otherwise the
|
|
// underneath code assumes that we might be leaking the previous instance
|
|
AZ::IO::FileIOBase::SetInstance(nullptr);
|
|
AZ::IO::FileIOBase::SetInstance(m_data->m_localFileIO);
|
|
|
|
}
|
|
void TearDown() override
|
|
{
|
|
AZ::IO::FileIOBase::SetInstance(nullptr);
|
|
delete m_data->m_localFileIO;
|
|
AZ::IO::FileIOBase::SetInstance(m_data->m_priorFileIO);
|
|
|
|
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
|
if(settingsRegistry == &m_registry)
|
|
{
|
|
AZ::SettingsRegistry::Unregister(settingsRegistry);
|
|
}
|
|
|
|
m_data->m_applicationManager->Stop();
|
|
m_data->m_applicationManager.reset();
|
|
m_data.reset();
|
|
UnitTest::ScopedAllocatorSetupFixture::TearDown();
|
|
}
|
|
|
|
struct StaticData
|
|
{
|
|
AZStd::unique_ptr<MockApplicationManagerTest> m_applicationManager = {};
|
|
AZ::IO::FileIOBase* m_priorFileIO = nullptr;
|
|
AZ::IO::FileIOBase* m_localFileIO = nullptr;
|
|
AZStd::string m_testEngineRoot;
|
|
};
|
|
|
|
AZStd::unique_ptr<StaticData> m_data;
|
|
AZ::SettingsRegistryImpl m_registry;
|
|
};
|
|
|
|
TEST_F(ApplicationManagerTest, ValidatePlatformFlags_ReadConfigFiles_OK)
|
|
{
|
|
AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get();
|
|
ASSERT_NE(nullptr, settingsRegistry);
|
|
|
|
AZStd::unordered_set<AZStd::string> gemsNameMap{ "GemA", "GemB", "GemC" };
|
|
for (AZStd::string& gemName : gemsNameMap)
|
|
{
|
|
auto gemSourcePathKey = AZ::SettingsRegistryInterface::FixedValueString::format("%s/Gems/%s/SourcePaths/0",
|
|
AZ::SettingsRegistryMergeUtils::OrganizationRootKey, gemName.c_str());
|
|
auto gemSourcePath = AZ::IO::Path(m_data->m_testEngineRoot) / "Gems" / gemName;
|
|
settingsRegistry->Set(gemSourcePathKey, gemSourcePath.Native());
|
|
}
|
|
|
|
AzFramework::GetGemsInfo(m_data->m_applicationManager->m_gemInfoList, *settingsRegistry);
|
|
EXPECT_GE(m_data->m_applicationManager->m_gemInfoList.size(), 3);
|
|
for (const AzFramework::GemInfo& gemInfo : m_data->m_applicationManager->m_gemInfoList)
|
|
{
|
|
gemsNameMap.erase(gemInfo.m_gemName);
|
|
}
|
|
|
|
EXPECT_EQ(0, gemsNameMap.size());
|
|
|
|
AzFramework::PlatformFlags platformFlags = GetEnabledPlatformFlags(m_data->m_testEngineRoot.c_str(), m_data->m_testEngineRoot.c_str(), DummyProjectName);
|
|
AzFramework::PlatformFlags hostPlatformFlag = AzFramework::PlatformHelper::GetPlatformFlag(AzToolsFramework::AssetSystem::GetHostAssetPlatform());
|
|
AzFramework::PlatformFlags expectedFlags = AzFramework::PlatformFlags::Platform_ANDROID | AzFramework::PlatformFlags::Platform_IOS | AzFramework::PlatformFlags::Platform_PROVO | hostPlatformFlag;
|
|
ASSERT_EQ(platformFlags, expectedFlags);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeComparisonTypeFromString_InvalidString_Fails)
|
|
{
|
|
auto invalidResult = AssetBundler::ParseComparisonType("notacomparisontype");
|
|
EXPECT_EQ(invalidResult.IsSuccess(), false);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeComparisonTypeFromString_ValidString_Success)
|
|
{
|
|
using namespace AzToolsFramework;
|
|
|
|
auto deltaResult = AssetBundler::ParseComparisonType(AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::Delta)]);
|
|
EXPECT_EQ(deltaResult.IsSuccess(), true);
|
|
EXPECT_EQ(deltaResult.GetValue(), AssetFileInfoListComparison::ComparisonType::Delta);
|
|
|
|
auto unionResult = AssetBundler::ParseComparisonType(AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::Union)]);
|
|
EXPECT_EQ(unionResult.IsSuccess(), true);
|
|
EXPECT_EQ(unionResult.GetValue(), AssetFileInfoListComparison::ComparisonType::Union);
|
|
|
|
auto intersectionResult = AssetBundler::ParseComparisonType(AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::Intersection)]);
|
|
EXPECT_EQ(intersectionResult.IsSuccess(), true);
|
|
EXPECT_EQ(intersectionResult.GetValue(), AssetFileInfoListComparison::ComparisonType::Intersection);
|
|
|
|
auto complementResult = AssetBundler::ParseComparisonType(AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::Complement)]);
|
|
EXPECT_EQ(complementResult.IsSuccess(), true);
|
|
EXPECT_EQ(complementResult.GetValue(), AssetFileInfoListComparison::ComparisonType::Complement);
|
|
|
|
auto filePatternResult = AssetBundler::ParseComparisonType(AssetFileInfoListComparison::ComparisonTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::ComparisonType::FilePattern)]);
|
|
EXPECT_EQ(filePatternResult.IsSuccess(), true);
|
|
EXPECT_EQ(filePatternResult.GetValue(), AssetFileInfoListComparison::ComparisonType::FilePattern);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeComparisonTypeFromInt_InvalidInt_Fails)
|
|
{
|
|
auto invalidResult = AssetBundler::ParseComparisonType("999");
|
|
EXPECT_EQ(invalidResult.IsSuccess(), false);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeComparisonTypeFromInt_ValidInt_Success)
|
|
{
|
|
int unionIndex(aznumeric_cast<int>(AzToolsFramework::AssetFileInfoListComparison::ComparisonType::Union));
|
|
auto unionResult = AssetBundler::ParseComparisonType(AZStd::string::format("%i", unionIndex));
|
|
EXPECT_TRUE(unionResult.IsSuccess());
|
|
EXPECT_EQ(unionResult.GetValue(), AzToolsFramework::AssetFileInfoListComparison::ComparisonType::Union);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeFilePatternTypeFromString_InvalidString_Fails)
|
|
{
|
|
auto invalidResult = AssetBundler::ParseFilePatternType("notafilepatterntype");
|
|
EXPECT_EQ(invalidResult.IsSuccess(), false);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeFilePatternTypeFromString_ValidString_Success)
|
|
{
|
|
using namespace AzToolsFramework;
|
|
|
|
auto wildcardResult = AssetBundler::ParseFilePatternType(AssetFileInfoListComparison::FilePatternTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::FilePatternType::Wildcard)]);
|
|
EXPECT_TRUE(wildcardResult.IsSuccess());
|
|
EXPECT_EQ(wildcardResult.GetValue(), AssetFileInfoListComparison::FilePatternType::Wildcard);
|
|
|
|
auto regexResult = AssetBundler::ParseFilePatternType(AssetFileInfoListComparison::FilePatternTypeNames[aznumeric_cast<AZ::u8>(AssetFileInfoListComparison::FilePatternType::Regex)]);
|
|
EXPECT_TRUE(regexResult.IsSuccess());
|
|
EXPECT_EQ(regexResult.GetValue(), AssetFileInfoListComparison::FilePatternType::Regex);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeFilePatternTypeFromInt_InvalidInt_Fails)
|
|
{
|
|
auto invalidResult = AssetBundler::ParseFilePatternType("555");
|
|
EXPECT_EQ(invalidResult.IsSuccess(), false);
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, IsTokenFile_Empty_ReturnsFalse)
|
|
{
|
|
EXPECT_FALSE(AzToolsFramework::AssetFileInfoListComparison::IsTokenFile(""));
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, IsTokenFile_NonToken_ReturnsFalse)
|
|
{
|
|
EXPECT_FALSE(AzToolsFramework::AssetFileInfoListComparison::IsTokenFile("Somefile"));
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, IsTokenFile_Token_ReturnsTrue)
|
|
{
|
|
EXPECT_TRUE(AzToolsFramework::AssetFileInfoListComparison::IsTokenFile("$SomeToken"));
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, IsOutputPath_Empty_ReturnsFalse)
|
|
{
|
|
EXPECT_FALSE(AzToolsFramework::AssetFileInfoListComparison::IsOutputPath(""));
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, IsOutputPath_NonToken_ReturnsTrue)
|
|
{
|
|
EXPECT_TRUE(AzToolsFramework::AssetFileInfoListComparison::IsOutputPath("Somefile"));
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, IsOutputPath_Token_ReturnsFalse)
|
|
{
|
|
EXPECT_FALSE(AzToolsFramework::AssetFileInfoListComparison::IsOutputPath("$SomeToken"));
|
|
}
|
|
|
|
TEST_F(BasicApplicationManagerTest, ComputeFilePatternTypeFromInt_ValidInt_Success)
|
|
{
|
|
int regexIndex(aznumeric_cast<int>(AzToolsFramework::AssetFileInfoListComparison::FilePatternType::Regex));
|
|
auto regexResult = AssetBundler::ParseFilePatternType(AZStd::string::format("%i", regexIndex));
|
|
EXPECT_TRUE(regexResult.IsSuccess());
|
|
EXPECT_EQ(regexResult.GetValue(), AzToolsFramework::AssetFileInfoListComparison::FilePatternType::Regex);
|
|
}
|
|
}
|