Added basic unit test for relative path function
Moved asset system stub to RPI utils Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
@@ -160,6 +160,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
Gem::Atom_RPI.Public
|
||||
Gem::Atom_RHI.Public
|
||||
Gem::Atom_RPI.Edit
|
||||
Gem::Atom_Utils.Editor.Static
|
||||
)
|
||||
ly_add_googletest(
|
||||
NAME Gem::Atom_RPI.Tests
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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 <Common/AssetSystemStub.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
void AssetSystemStub::Activate()
|
||||
{
|
||||
m_sourceInfoMap.clear();
|
||||
BusConnect();
|
||||
}
|
||||
|
||||
void AssetSystemStub::Deactivate()
|
||||
{
|
||||
m_sourceInfoMap.clear();
|
||||
BusDisconnect();
|
||||
}
|
||||
|
||||
void AssetSystemStub::RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetId& assetId)
|
||||
{
|
||||
AZ::Data::AssetInfo assetInfo;
|
||||
assetInfo.m_assetId = assetId;
|
||||
RegisterSourceInfo(sourcePath, assetInfo, "");
|
||||
}
|
||||
|
||||
void AssetSystemStub::RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetInfo& assetInfo, const AZStd::string& watchFolder)
|
||||
{
|
||||
SourceInfo sourceInfo{ assetInfo , watchFolder };
|
||||
|
||||
// Because GetSourceInfoBySourcePath should always return 0 for the sub-id, since it's about the source file not product file.
|
||||
sourceInfo.m_assetInfo.m_assetId.m_subId = 0;
|
||||
|
||||
AZStd::string normalizedSourcePath = sourcePath;
|
||||
AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
|
||||
m_sourceInfoMap.emplace(normalizedSourcePath, sourceInfo);
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
|
||||
{
|
||||
AZStd::string normalizedSourcePath = sourcePath;
|
||||
AzFramework::StringFunc::Path::Normalize(normalizedSourcePath);
|
||||
|
||||
auto iter = m_sourceInfoMap.find(normalizedSourcePath);
|
||||
|
||||
if (iter != m_sourceInfoMap.end())
|
||||
{
|
||||
assetInfo = iter->second.m_assetInfo;
|
||||
watchFolder = iter->second.m_watchFolder;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetRelativeProductPathFromFullSourceOrProductPath([[maybe_unused]] const AZStd::string& fullPath, [[maybe_unused]] AZStd::string& relativeProductPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GenerateRelativeSourcePath(
|
||||
[[maybe_unused]] const AZStd::string& sourcePath, [[maybe_unused]] AZStd::string& relativePath,
|
||||
[[maybe_unused]] AZStd::string& watchFolder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetFullSourcePathFromRelativeProductPath(
|
||||
[[maybe_unused]] const AZStd::string& relPath, [[maybe_unused]] AZStd::string& fullSourcePath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetAssetInfoById([[maybe_unused]] const AZ::Data::AssetId& assetId, [[maybe_unused]] const AZ::Data::AssetType& assetType, [[maybe_unused]] const AZStd::string& platformName, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& rootFilePath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetSourceInfoBySourceUUID([[maybe_unused]] const AZ::Uuid& sourceUuid, [[maybe_unused]] AZ::Data::AssetInfo& assetInfo, [[maybe_unused]] AZStd::string& watchFolder)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetScanFolders([[maybe_unused]] AZStd::vector<AZStd::string>& scanFolders)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetAssetSafeFolders([[maybe_unused]] AZStd::vector<AZStd::string>& assetSafeFolders)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::IsAssetPlatformEnabled(const char* /*platform*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int AssetSystemStub::GetPendingAssetsForPlatform(const char* /*platform*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AssetSystemStub::GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo)
|
||||
{
|
||||
productsAssetInfo.clear();
|
||||
for (AZStd::pair<AZStd::string, SourceInfo> element : m_sourceInfoMap)
|
||||
{
|
||||
if (element.second.m_assetInfo.m_assetId.m_guid == sourceUuid)
|
||||
{
|
||||
productsAssetInfo.push_back(element.second.m_assetInfo);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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 <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
/**
|
||||
* This class can stub out the asset system to enable the RPI's AssetUtils class to look up test assets.
|
||||
* This is included in the RPITestFixture class. To use it, first create a test asset using AssetManager::Create()
|
||||
* or one of the RPI's AssetCreators. This will register the asset with the asset database. Example:
|
||||
*
|
||||
* Data::Asset<MaterialAsset> myTestMaterialAsset1;
|
||||
* MaterialAssetCreator creator;
|
||||
* creator.Begin(...);
|
||||
* // set some stuff
|
||||
* creator.End(myTestMaterialAsset1);
|
||||
*
|
||||
* Then call RegisterSourceInfo for whatever test assets you want to be able to access via AssetUtils.
|
||||
* This associates an AssetInfo object with some dummy source file name. No source file is actually created;
|
||||
* it just allows AssetUtils to find the desired AssetInfo when looking up a source file name that your unit
|
||||
* test provides. Example:
|
||||
*
|
||||
* m_assetSystemStub.RegisterSourceInfo("MyTestMaterial1.material", Data::AssetInfo{ myTestMaterialAsset1.GetId() }, "");
|
||||
* m_assetSystemStub.RegisterSourceInfo("MyTestMaterial2.material", Data::AssetInfo{ myTestMaterialAsset2.GetId() }, "");
|
||||
*
|
||||
* Now the RPI should be able to use AssetUtils like normal to access your test assets. Example:
|
||||
*
|
||||
* RPI::AssetUtils::LoadAsset("MyTestMaterial1.material"); // Returns myTestMaterialAsset1
|
||||
*/
|
||||
class AssetSystemStub : public AzToolsFramework::AssetSystemRequestBus::Handler
|
||||
{
|
||||
public:
|
||||
|
||||
void Activate();
|
||||
void Deactivate();
|
||||
|
||||
void RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetId& assetId);
|
||||
void RegisterSourceInfo(const char* sourcePath, const AZ::Data::AssetInfo& assetInfo, const AZStd::string& watchFolder);
|
||||
|
||||
private:
|
||||
struct SourceInfo
|
||||
{
|
||||
AZ::Data::AssetInfo m_assetInfo;
|
||||
AZStd::string m_watchFolder;
|
||||
};
|
||||
|
||||
AZStd::unordered_map<AZStd::string, SourceInfo> m_sourceInfoMap;
|
||||
|
||||
bool GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder) override;
|
||||
bool GetRelativeProductPathFromFullSourceOrProductPath(const AZStd::string& fullPath, AZStd::string& relativeProductPath) override;
|
||||
bool GenerateRelativeSourcePath(
|
||||
const AZStd::string& sourcePath, AZStd::string& relativePath, AZStd::string& watchFolder) override;
|
||||
bool GetFullSourcePathFromRelativeProductPath(const AZStd::string& relPath, AZStd::string& fullSourcePath) override;
|
||||
bool GetAssetInfoById(const AZ::Data::AssetId& assetId, const AZ::Data::AssetType& assetType, const AZStd::string& platformName, AZ::Data::AssetInfo& assetInfo, AZStd::string& rootFilePath) override;
|
||||
bool GetSourceInfoBySourceUUID(const AZ::Uuid& sourceUuid, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder) override;
|
||||
bool GetScanFolders(AZStd::vector<AZStd::string>& scanFolders) override;
|
||||
bool GetAssetSafeFolders(AZStd::vector<AZStd::string>& assetSafeFolders) override;
|
||||
bool IsAssetPlatformEnabled(const char* platform) override;
|
||||
int GetPendingAssetsForPlatform(const char* platform) override;
|
||||
bool GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo) override;
|
||||
};
|
||||
} // namespace UnitTest
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <Common/AssetManagerTestFixture.h>
|
||||
#include <Common/RHI/Stubs.h>
|
||||
#include <Common/RHI/Factory.h>
|
||||
#include <Common/AssetSystemStub.h>
|
||||
#include <Atom/Utils/AssetSystemStub.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ set(FILES
|
||||
Tests/Buffer/BufferTests.cpp
|
||||
Tests/Common/AssetManagerTestFixture.cpp
|
||||
Tests/Common/AssetManagerTestFixture.h
|
||||
Tests/Common/AssetSystemStub.cpp
|
||||
Tests/Common/AssetSystemStub.h
|
||||
Tests/Common/ErrorMessageFinder.cpp
|
||||
Tests/Common/ErrorMessageFinder.h
|
||||
Tests/Common/ErrorMessageFinderTests.cpp
|
||||
|
||||
Reference in New Issue
Block a user