Files
o3de/Gems/AssetValidation/Code/Tests/AssetValidationTestShared.h
T
lumberyard-employee-dm 5fc4551ac0 [LYN-8041] Enable relocation of the Project Game Release Layout (#5380)
* Enable relocation of the Project Game Release Layout

Relocating the Project Game Release Layout to another directory on the file system failed due to the querying of the engine root failing due to the ComponentApplication::m_engineRoot not using the project path stored in the SettingsRegisry if the engine root cannot be detected

Removed the ApplicationRequestBus GetEngineRoot function.
The ComponentApplicationRequestBus has a function of the same name that returns the same path.

Removed the deprecated GetAppRoot function.
The path it returns has no defined value. It was not the engine root or the project root.
Removed unused CFileUtil and CFileUtil_impl functions that were invoking the ApplicationREquestBus GetEngineRoot function.
On the way to update the functions it was discovered that they aren't called

Added a CalculateBranchToken overload that can populate a fixed_string to avoid heap allocations

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Protect against an empty list of artifacts to remove when generating the
engine.pak

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-11-09 12:03:52 -06:00

199 lines
6.3 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
*
*/
#pragma once
#include <AzTest/AzTest.h>
#include <AssetValidationSystemComponent.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <AzFramework/Asset/AssetSeedList.h>
#include <AzFramework/Asset/AssetSystemBus.h>
#include <AzFramework/IO/LocalFileIO.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Settings/SettingsRegistryImpl.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <Tests/FileIOBaseTestTypes.h>
#include <Utils/Utils.h>
constexpr int NumTestAssets = 10;
constexpr char ProjectName[] = "UnitTest";
class MockValidationComponent : public AssetValidation::AssetValidationSystemComponent
, public AZ::Data::AssetCatalogRequestBus::Handler
{
public:
MockValidationComponent()
{
for (int i = 0; i < NumTestAssets; ++i)
{
m_assetIds[i] = AZ::Data::AssetId(AZ::Uuid::CreateRandom(), 0);
}
AZ::Data::AssetCatalogRequestBus::Handler::BusConnect();
AssetValidation::AssetValidationSystemComponent::Activate();
}
~MockValidationComponent()
{
AssetValidation::AssetValidationSystemComponent::Deactivate();
AZ::Data::AssetCatalogRequestBus::Handler::BusDisconnect();
}
void SeedMode() override
{
AssetValidation::AssetValidationSystemComponent::SeedMode();
}
bool IsKnownAsset(const char* fileName) override
{
return AssetValidation::AssetValidationSystemComponent::IsKnownAsset(fileName);
}
bool AddSeedAssetId(AZ::Data::AssetId assetId, AZ::u32 sourceId) override
{
return AssetValidation::AssetValidationSystemComponent::AddSeedAssetId(assetId, sourceId);
}
AZ::Data::AssetInfo GetAssetInfoById(const AZ::Data::AssetId& id) override
{
AZ::Data::AssetInfo result;
for (int slotNum = 0; slotNum < NumTestAssets; ++slotNum)
{
const AZ::Data::AssetId& assetId = m_assetIds[slotNum];
if (assetId == id)
{
result.m_assetId = id;
// Internal paths should be lower cased as from the cache
result.m_relativePath = AZStd::string::format("assetpath%d", slotNum);
break;
}
}
return result;
}
AZ::Outcome<AZStd::vector<AZ::Data::ProductDependency>, AZStd::string> GetAllProductDependencies(const AZ::Data::AssetId& id) override
{
AZStd::vector<AZ::Data::ProductDependency> dependencyList;
bool foundAsset{ false };
for (const AZ::Data::AssetId& assetId : m_assetIds)
{
if (assetId == id)
{
foundAsset = true;
}
else if (foundAsset)
{
AZ::Data::ProductDependency thisDependency;
thisDependency.m_assetId = assetId;
dependencyList.emplace_back(AZ::Data::ProductDependency(assetId, {}));
}
}
if (dependencyList.size())
{
return AZ::Success(dependencyList);
}
return AZ::Failure(AZStd::string("Asset not found"));
}
bool TestAddSeedsFor(const AzFramework::AssetSeedList& seedList, AZ::u32 sourceId)
{
return AddSeedsFor(seedList, sourceId);
}
bool TestRemoveSeedsFor(const AzFramework::AssetSeedList& seedList, AZ::u32 sourceId)
{
return RemoveSeedsFor(seedList, sourceId);
}
bool TestAddSeedList(const char* seedListName)
{
return AddSeedList(seedListName);
}
bool TestRemoveSeedList(const char* seedListName)
{
return RemoveSeedList(seedListName);
}
AZ::Outcome<AzFramework::AssetSeedList, AZStd::string> LoadSeedList(const char* fileName, AZStd::string& seedFilepath) override
{
if (m_validSeedPath == fileName)
{
seedFilepath = fileName;
return AZ::Success(m_validSeedList);
}
return AZ::Failure(AZStd::string("Invalid List"));
}
AzFramework::AssetSeedList m_validSeedList;
AZStd::string m_validSeedPath;
AZ::Data::AssetId m_assetIds[NumTestAssets];
};
struct AssetValidationTest
: UnitTest::ScopedAllocatorSetupFixture,
UnitTest::SetRestoreFileIOBaseRAII,
AzFramework::ApplicationRequests::Bus::Handler
{
AssetValidationTest() : UnitTest::SetRestoreFileIOBaseRAII(m_fileIO)
{
if (!AZ::SettingsRegistry::Get())
{
AZ::SettingsRegistry::Register(&m_registry);
auto projectPathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey)
+ "/project_path";
m_registry.Set(projectPathKey, (AZ::IO::FixedMaxPath(m_tempDir.GetDirectory()) / "AutomatedTesting").Native());
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(m_registry);
// Set the engine root to the temporary directory and re-update the runtime file paths
auto enginePathKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey)
+ "/engine_path";
m_registry.Set(enginePathKey, m_tempDir.GetDirectory());
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(m_registry);
}
}
void NormalizePath(AZStd::string&) override
{
AZ_Assert(false, "Not implemented");
}
void NormalizePathKeepCase(AZStd::string&) override
{
AZ_Assert(false, "Not implemented");
}
void CalculateBranchTokenForEngineRoot([[maybe_unused]] AZStd::string& token) const override
{
AZ_Assert(false, "Not implemented");
}
void SetUp() override
{
using namespace ::testing;
ASSERT_TRUE(m_tempDir.IsValid());
AzFramework::ApplicationRequests::Bus::Handler::BusConnect();
}
void TearDown() override
{
AzFramework::ApplicationRequests::Bus::Handler::BusDisconnect();
}
bool CreateDummyFile(const char* path, const char* seedFileName, AZStd::string_view contents, AZStd::string& subfolderPath) const;
AZ::IO::LocalFileIO m_fileIO;
UnitTest::ScopedTemporaryDirectory m_tempDir;
AZ::SettingsRegistryImpl m_registry;
};