Fixed AzToolsFramework tests (#2887)
* Fixed AzToolsFramework unit tests. Signed-off-by: moraaar <moraaar@amazon.com> * Include missing header. Signed-off-by: moraaar <moraaar@amazon.com> * Using util's class to generate temp directory, instead of qt. Signed-off-by: moraaar <moraaar@amazon.com> * Added empty line Signed-off-by: moraaar <moraaar@amazon.com> * Fixed warning in MessageTest fixture that CacheProjectRootFolder was not set Signed-off-by: moraaar <moraaar@amazon.com> * Additional checks in CreateDefaultEditorEntity helper function. Signed-off-by: moraaar <moraaar@amazon.com> * Updated the AzToolsFrameworkTest logic to set the project cache path The Project Cache Path and Project Path is set through the CommandLine functionality of the ComponentApplication. This allows those Project Cache Path and Project Path to be set within the Settings Registry during the ComponentApplication constructor Removed the explicitly calls to delete the temporary directory and fixed the ScopedTemporaryDirectory class to recursively delete the temporary directory Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Setup correctly @assets@ alias for PlatformAddressedAssetCatalogManagerTest and AssetSeedManagerTest fixtures. - These 2 test fixtures need to manually set the @asset@ alias to not include the platform at the end (which it does by default), because they are looping over platforms in their setup. - Also initializing pointers to nullptr, so if setup fail in the future the teardown doesn't crash trying to delete garbage. Signed-off-by: moraaar <moraaar@amazon.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
@@ -23,11 +23,12 @@
|
||||
#include <AzCore/UserSettings/UserSettingsComponent.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzTest/Utils.h>
|
||||
#include <Utils/Utils.h>
|
||||
|
||||
namespace // anonymous
|
||||
{
|
||||
static const int s_totalAssets = 12;
|
||||
static const int s_totalTestPlatforms = 2;
|
||||
const char* s_catalogFile = "AssetCatalog.xml";
|
||||
|
||||
AZ::Data::AssetId assets[s_totalAssets];
|
||||
const char TestSliceAssetPath[] = "test.slice";
|
||||
@@ -55,18 +56,30 @@ namespace UnitTest
|
||||
void SetUp() override
|
||||
{
|
||||
using namespace AZ::Data;
|
||||
m_application = new ToolsTestApplication("AssetSeedManagerTest");
|
||||
constexpr size_t MaxCommandArgsCount = 128;
|
||||
using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
|
||||
using ArgumentContainer = AZStd::fixed_vector<char*, MaxCommandArgsCount>;
|
||||
// The first command line argument is assumed to be the executable name so add a blank entry for it
|
||||
ArgumentContainer argContainer{ {} };
|
||||
|
||||
// Append Command Line override for the Project Cache Path
|
||||
AZ::IO::Path cacheProjectRootFolder{ m_tempDir.GetDirectory() };
|
||||
auto projectCachePathOverride = FixedValueString::format(R"(--project-cache-path="%s")", cacheProjectRootFolder.c_str());
|
||||
auto projectPathOverride = FixedValueString{ R"(--project-path=AutomatedTesting)" };
|
||||
argContainer.push_back(projectCachePathOverride.data());
|
||||
argContainer.push_back(projectPathOverride.data());
|
||||
m_application = new ToolsTestApplication("AssetSeedManagerTest", aznumeric_caster(argContainer.size()), argContainer.data());
|
||||
m_assetSeedManager = new AzToolsFramework::AssetSeedManager();
|
||||
m_assetRegistry = new AzFramework::AssetRegistry();
|
||||
|
||||
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());
|
||||
|
||||
// By default @assets@ is setup to include the platform at the end. But this test is going to
|
||||
// loop over platforms and it will be included as part of the relative path of the file.
|
||||
// So the asset folder for these tests have to point to the cache project root folder, which
|
||||
// doesn't include the platform.
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@assets@", cacheProjectRootFolder.c_str());
|
||||
|
||||
for (int idx = 0; idx < s_totalAssets; idx++)
|
||||
{
|
||||
assets[idx] = AssetId(AZ::Uuid::CreateRandom(), 0);
|
||||
@@ -83,17 +96,18 @@ namespace UnitTest
|
||||
int platformCount = 0;
|
||||
for(auto thisPlatform : m_testPlatforms)
|
||||
{
|
||||
AZStd::string assetRoot = AzToolsFramework::PlatformAddressedAssetCatalog::GetAssetRootForPlatform(thisPlatform);
|
||||
AZ::IO::Path assetRoot = AzToolsFramework::PlatformAddressedAssetCatalog::GetAssetRootForPlatform(thisPlatform);
|
||||
|
||||
for (int idx = 0; idx < s_totalAssets; idx++)
|
||||
{
|
||||
AzFramework::StringFunc::Path::Join(assetRoot.c_str(), m_assetsPath[idx].c_str(), m_assetsPathFull[platformCount][idx]);
|
||||
m_assetsPathFull[platformCount][idx] = (assetRoot / m_assetsPath[idx]).Native();
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
if (m_fileStreams[platformCount][idx].Open(m_assetsPathFull[platformCount][idx].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath))
|
||||
{
|
||||
m_fileStreams[platformCount][idx].Write(m_assetsPath[idx].size(), m_assetsPath[idx].data());
|
||||
AZ::IO::SizeType bytesWritten = m_fileStreams[platformCount][idx].Write(m_assetsPath[idx].size(), m_assetsPath[idx].data());
|
||||
EXPECT_EQ(bytesWritten, m_assetsPath[idx].size());
|
||||
m_fileStreams[platformCount][idx].Close();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, only invalid for PC, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,7 +131,7 @@ namespace UnitTest
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
AZ::IO::FileIOStream dynamicSliceFileIOStream(TestDynamicSliceAssetPath, AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeText);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder
|
||||
|
||||
AZ::Data::AssetInfo sliceAssetInfo;
|
||||
sliceAssetInfo.m_relativePath = TestSliceAssetPath;
|
||||
@@ -131,7 +145,7 @@ namespace UnitTest
|
||||
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
AZ::IO::FileIOStream sliceFileIOStream(TestSliceAssetPath, AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeText);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder
|
||||
|
||||
// asset0 -> asset1 -> asset2 -> asset4
|
||||
// --> asset3
|
||||
@@ -197,58 +211,6 @@ namespace UnitTest
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
|
||||
|
||||
if (fileIO->Exists(s_catalogFile))
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
fileIO->Remove(s_catalogFile);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // deleting from asset cache folder, not invalid in Jenkins
|
||||
}
|
||||
|
||||
for (size_t platformCount = 0; platformCount < s_totalTestPlatforms; ++platformCount)
|
||||
{
|
||||
// Deleting all the temporary files
|
||||
for (int idx = 0; idx < s_totalAssets; idx++)
|
||||
{
|
||||
// we need to close the handle before we try to remove the file
|
||||
if (fileIO->Exists(m_assetsPathFull[platformCount][idx].c_str()))
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
fileIO->Remove(m_assetsPathFull[platformCount][idx].c_str());
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // deleting from asset cache folder, not invalid in Jenkins
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileIO->Exists(TestSliceAssetPath))
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
fileIO->Remove(TestSliceAssetPath);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // deleting from asset cache folder, not invalid in Jenkins
|
||||
}
|
||||
|
||||
if (fileIO->Exists(TestDynamicSliceAssetPath))
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
fileIO->Remove(TestDynamicSliceAssetPath);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // deleting from asset cache folder, not invalid in Jenkins
|
||||
}
|
||||
|
||||
auto pcCatalogFile = AzToolsFramework::PlatformAddressedAssetCatalog::GetCatalogRegistryPathForPlatform(AzFramework::PlatformId::PC);
|
||||
auto androidCatalogFile = AzToolsFramework::PlatformAddressedAssetCatalog::GetCatalogRegistryPathForPlatform(AzFramework::PlatformId::ANDROID_ID);
|
||||
if (fileIO->Exists(pcCatalogFile.c_str()))
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
fileIO->Remove(pcCatalogFile.c_str());
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // deleting from asset cache folder, not invalid in Jenkins
|
||||
}
|
||||
|
||||
if (fileIO->Exists(androidCatalogFile.c_str()))
|
||||
{
|
||||
fileIO->Remove(androidCatalogFile.c_str());
|
||||
}
|
||||
|
||||
delete m_assetSeedManager;
|
||||
delete m_assetRegistry;
|
||||
delete m_pcCatalog;
|
||||
@@ -284,7 +246,7 @@ namespace UnitTest
|
||||
// Attempt to save to the same file. Should not be allowed.
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
EXPECT_FALSE(m_assetSeedManager->Save(filePath));
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // One error expected
|
||||
|
||||
// Clean up the test environment
|
||||
AZ::IO::SystemFile::SetWritable(filePath.c_str(), true);
|
||||
@@ -310,7 +272,7 @@ namespace UnitTest
|
||||
// Attempt to save to the same file. Should not be allowed.
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
EXPECT_FALSE(m_assetSeedManager->SaveAssetFileInfo(filePath, AzFramework::PlatformFlags::Platform_PC, {}));
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // One error expected
|
||||
|
||||
// Clean up the test environment
|
||||
AZ::IO::SystemFile::SetWritable(filePath.c_str(), true);
|
||||
@@ -379,7 +341,7 @@ namespace UnitTest
|
||||
// Step we are testing
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
m_assetSeedManager->AddPlatformToAllSeeds(AzFramework::PlatformId::ANDROID_ID);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // One error expected
|
||||
|
||||
// Verification
|
||||
AzFramework::PlatformFlags expectedPlatformFlags = AzFramework::PlatformFlags::Platform_PC | AzFramework::PlatformFlags::Platform_ANDROID;
|
||||
@@ -649,9 +611,10 @@ namespace UnitTest
|
||||
if (m_fileStreams[0][fileIndex].Open(m_assetsPathFull[0][fileIndex].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath))
|
||||
{
|
||||
AZStd::string fileContent = AZStd::string::format("asset%d.txt", fileIndex);
|
||||
m_fileStreams[0][fileIndex].Write(fileContent.size(), fileContent.c_str());
|
||||
AZ::IO::SizeType bytesWritten = m_fileStreams[0][fileIndex].Write(fileContent.size(), fileContent.c_str());
|
||||
EXPECT_EQ(bytesWritten, fileContent.size());
|
||||
m_fileStreams[0][fileIndex].Close();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder
|
||||
}
|
||||
|
||||
AzToolsFramework::AssetFileInfoList assetList2 = m_assetSeedManager->GetDependencyList(AzFramework::PlatformId::PC);
|
||||
@@ -682,9 +645,10 @@ namespace UnitTest
|
||||
if (m_fileStreams[0][fileIndex].Open(m_assetsPathFull[0][fileIndex].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath))
|
||||
{
|
||||
AZStd::string fileContent = AZStd::string::format("asset%d.txt", fileIndex + 1);// changing file content
|
||||
m_fileStreams[0][fileIndex].Write(fileContent.size(), fileContent.c_str());
|
||||
AZ::IO::SizeType bytesWritten = m_fileStreams[0][fileIndex].Write(fileContent.size(), fileContent.c_str());
|
||||
EXPECT_EQ(bytesWritten, fileContent.size());
|
||||
m_fileStreams[0][fileIndex].Close();
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // writing to asset cache folder, not invalid in Jenkins
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder
|
||||
}
|
||||
|
||||
AzToolsFramework::AssetFileInfoList assetList2 = m_assetSeedManager->GetDependencyList(AzFramework::PlatformId::PC);
|
||||
@@ -790,16 +754,17 @@ namespace UnitTest
|
||||
|
||||
}
|
||||
|
||||
AzToolsFramework::AssetSeedManager* m_assetSeedManager;
|
||||
AzFramework::AssetRegistry* m_assetRegistry;
|
||||
ToolsTestApplication* m_application;
|
||||
AzToolsFramework::PlatformAddressedAssetCatalog* m_pcCatalog;
|
||||
AzToolsFramework::PlatformAddressedAssetCatalog* m_androidCatalog;
|
||||
AzToolsFramework::AssetSeedManager* m_assetSeedManager = nullptr;
|
||||
AzFramework::AssetRegistry* m_assetRegistry = nullptr;
|
||||
ToolsTestApplication* m_application = nullptr;
|
||||
AzToolsFramework::PlatformAddressedAssetCatalog* m_pcCatalog = nullptr;
|
||||
AzToolsFramework::PlatformAddressedAssetCatalog* m_androidCatalog = nullptr;
|
||||
AZ::IO::FileIOStream m_fileStreams[s_totalTestPlatforms][s_totalAssets];
|
||||
AzFramework::PlatformId m_testPlatforms[s_totalTestPlatforms];
|
||||
AZStd::string m_assetsPath[s_totalAssets];
|
||||
AZStd::string m_assetsPathFull[s_totalTestPlatforms][s_totalAssets];
|
||||
AZ::Data::AssetId m_testDynamicSliceAssetId;
|
||||
UnitTest::ScopedTemporaryDirectory m_tempDir;
|
||||
};
|
||||
|
||||
TEST_F(AssetSeedManagerTest, AssetSeedManager_SaveSeedListFile_FileIsReadOnly)
|
||||
|
||||
Reference in New Issue
Block a user