f648cb1fd8
* Update the FileIOAlias naming to make the cache, project root and engine root paths more clear The alias of `@root@`, `@assets@`, and `@projectplatformcache@` has been collapsed to `@projectproductassets@` The alias of `@devroot@` and `@engroot@` has been collapsed to `@engroot@` The alias of `@devassets@` and `@projectroot@` has been collapsed to `@projectroot@` Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated use of devassets and devroot properties in python Those properties now use projectroot and engroot Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updating the alias @engroot@ alias path comment in each platform specific LocalFileIO_*.cpp file Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed hardcoded size of 9 for the product asset alias. The ResolvePath function now just appends the @projectproductassets@ alias with the input path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove duplicate @projectproductassets@ check in ProcessFileTreeRequest Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix for typos in Hydra python test Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated LocalFileIO::Copy call on Windows to use the Unicode aware CopyFileW API Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the AWSMetreicsGemAllocatorFixture to properly suppress asset cache write errors for Test file creation. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unneeded call to set the @projectproductasstes@ alias at the bottom of the AssetSeedManagerTest SetUp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added a deprecated alias map to the FileIO System When a deprecated alias is accessed, the FileIO System logs an AZ_Error and indicates the alias that should be used Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated python test scripts to use the projectroot binding Retrieving the AutomatedTesting project path based on "<devroot>/AutomatedTesting" has been removed. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated references to devroot and devgame within the codebase The GetAbsoluteDevGameFolderPath functions has been replaced with direct call to AZ::Utils::GetProjectPath The GetAbsoluteDevRootFolderPath functions has been replaced with direct calls to AZ::Utils::GetEnginePath Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated <engroot>/AutomatedTesting references to projectroot Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced references that assumes the project path is <engroot>/AutomatedTesting with <projectroot> in the AutomatedTesting python test Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Correct casing in emfxworkspace file Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed newly added AppendPathParts function Removed the Path constructors which accepts a PathIterable instance The PathIterable isn't safe to return to a user of the Path class as it might be referencing temporary paths supplied via PathView arguments Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed unused parameter warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Undid change to the LexicallyProximate function to set the path result to the base path. It needs to return the *this path if the pathResult is empty Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Moved the LocalFileIO ConvertToAbsolutePath implementations to AZ::Utils Fixed the ConvertToAbsolutePath implementation for Unix platforms to use a buffer that is size PATH_MAX(4096 on all our supported Unix platforms). Because the buffer before was AZ::IO::MaxPathLength which as a size of 1024, this was resulting in the Unix `realpath` function smashing the stack when it converts a path to an absolute path that is longer than 1024 characters Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the EditorCore.Tests to attach the AZ Environment to the EditorCore shared library that is statically loaded on launch. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed for DeprecatedAlaisesKeyVisitor Visit function causing the non string_view overloads being hidden causing a hidden base class function warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Changed the AWSMetricsGemMock to use a temporary for writing test assets Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the LocalFileIO::ResolvePath function to use HasRootPath to determine if a path starts with a root path such as "D:", "D:/" or "/" IsAbsolute was not the corect check as the path of "D:" is a relative path. To be absolute according to the Windows the path must have a root directory. i.e "D:/" or "D:\" Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed absolute path comment from LocalFile_UnixLike.cpp and LocalFile_Android.cpp FindFiles implementations Updated the ConvertToAlias to supply an AZ::IO::FixedMaxPath Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced usage of the @projectproductassets@ alias with @engroot@ when referring to the LmbrCentral source folder in the CopyDependencyBuilderTest and the SeedBuilderTests Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the ScriptCanvas Upgrade Tool to output backed up files to the Project User Path instead of the engine root Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed whitespacing issues in Application.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove unnecessary creation of a FixedMaxPath in the UpgradeTool.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Modified testSeedFolder variable in the SeedBuilderTests to use the @engroot@ alias instead of @projectproductassets@/.. alias when referring to the LmbrCentral Gem source path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated references to the Project Asset Cache in the PythonTests. Those tests no longer use the logic `azlmbr.paths.projectroot / "Cache" / "pc"` to retrieve a path to the cache root but instead the `azlmbr.paths.projectproductassets` constant Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed the FileIO Deprecated Alias test on Windows Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removing @projectsourceassets@ alias, as it is only used once. Updated the PhysX EditorSystemComponent.cpp to query the ProjectPath form the SettingsRegistry. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced @projectproductassets@ alias with @products@ Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Rollback changes to the PhysX EditorSystemComponent.cpp The changes to use the ProjectPath from the SettingsRegistry has been implemented in PR #4497 Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
304 lines
12 KiB
C++
304 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 <AzCore/UnitTest/TestTypes.h>
|
|
#include <AzCore/Asset/AssetManagerBus.h>
|
|
#include <AzCore/Math/Uuid.h>
|
|
#include <AzCore/Memory/Memory.h>
|
|
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
|
#include <AzCore/UserSettings/UserSettingsComponent.h>
|
|
#include <AzCore/IO/FileIO.h>
|
|
#include <Tests/AZTestShared/Utils/Utils.h>
|
|
#include <AzToolsFramework/Archive/ArchiveAPI.h>
|
|
#include <AzFramework/StringFunc/StringFunc.h>
|
|
#include <AzToolsFramework/Archive/ArchiveAPI.h>
|
|
#include <AzToolsFramework/AssetBundle/AssetBundleAPI.h>
|
|
#include <AzToolsFramework/UnitTest/ToolsTestApplication.h>
|
|
#include <QString>
|
|
#include <QDir>
|
|
#include <QFileInfo>
|
|
#include <QStandardPaths>
|
|
#include <QTemporaryDir>
|
|
#include <QTextStream>
|
|
#include <Utils/Utils.h>
|
|
|
|
namespace UnitTest
|
|
{
|
|
namespace
|
|
{
|
|
bool CreateDummyFile(const QString& fullPathToFile, const QString& tempStr = {})
|
|
{
|
|
QFileInfo fi(fullPathToFile);
|
|
QDir fp(fi.path());
|
|
fp.mkpath(".");
|
|
QFile writer(fullPathToFile);
|
|
if (!writer.open(QFile::ReadWrite))
|
|
{
|
|
return false;
|
|
}
|
|
{
|
|
QTextStream stream(&writer);
|
|
stream << tempStr << Qt::endl;
|
|
}
|
|
writer.close();
|
|
return true;
|
|
}
|
|
|
|
class ArchiveComponentTest :
|
|
public ::testing::Test
|
|
{
|
|
|
|
public:
|
|
QStringList CreateArchiveFileList()
|
|
{
|
|
QStringList returnList;
|
|
returnList.append("basicfile.txt");
|
|
returnList.append("basicfile2.txt");
|
|
returnList.append("testfolder/folderfile.txt");
|
|
returnList.append("testfolder2/sharedfolderfile.txt");
|
|
returnList.append("testfolder2/sharedfolderfile2.txt");
|
|
returnList.append("testfolder3/testfolder4/depthfile.bat");
|
|
|
|
return returnList;
|
|
}
|
|
|
|
QString GetArchiveFolderName()
|
|
{
|
|
return "Archive";
|
|
}
|
|
|
|
QString GetExtractFolderName()
|
|
{
|
|
return "Extracted";
|
|
}
|
|
|
|
void CreateArchiveFolder(QString archiveFolderName, QStringList fileList)
|
|
{
|
|
QDir tempPath = QDir(m_tempDir.GetDirectory()).filePath(archiveFolderName);
|
|
|
|
for (const auto& thisFile : fileList)
|
|
{
|
|
QString absoluteTestFilePath = tempPath.absoluteFilePath(thisFile);
|
|
EXPECT_TRUE(CreateDummyFile(absoluteTestFilePath));
|
|
}
|
|
}
|
|
|
|
QString CreateArchiveListTextFile()
|
|
{
|
|
QString listFilePath = QDir(m_tempDir.GetDirectory()).absoluteFilePath("FileList.txt");
|
|
QString textContent = CreateArchiveFileList().join("\n");
|
|
EXPECT_TRUE(CreateDummyFile(listFilePath, textContent));
|
|
return listFilePath;
|
|
}
|
|
|
|
void CreateArchiveFolder()
|
|
{
|
|
CreateArchiveFolder(GetArchiveFolderName(), CreateArchiveFileList());
|
|
}
|
|
|
|
QString GetArchivePath()
|
|
{
|
|
return QDir(m_tempDir.GetDirectory()).filePath("TestArchive.pak");
|
|
}
|
|
|
|
QString GetArchiveFolder()
|
|
{
|
|
return QDir(m_tempDir.GetDirectory()).filePath(GetArchiveFolderName());
|
|
}
|
|
|
|
QString GetExtractFolder()
|
|
{
|
|
return QDir(m_tempDir.GetDirectory()).filePath(GetExtractFolderName());
|
|
}
|
|
|
|
bool CreateArchive()
|
|
{
|
|
std::future<bool> createResult;
|
|
AzToolsFramework::ArchiveCommandsBus::BroadcastResult(createResult,
|
|
&AzToolsFramework::ArchiveCommandsBus::Events::CreateArchive,
|
|
GetArchivePath().toUtf8().constData(), GetArchiveFolder().toUtf8().constData());
|
|
bool result = createResult.get();
|
|
return result;
|
|
}
|
|
|
|
void SetUp() override
|
|
{
|
|
m_app.reset(aznew ToolsTestApplication("ArchiveComponentTest"));
|
|
m_app->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
|
|
// in the unit tests.
|
|
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
|
|
|
if (auto fileIoBase = AZ::IO::FileIOBase::GetInstance(); fileIoBase != nullptr)
|
|
{
|
|
fileIoBase->SetAlias("@products@", m_tempDir.GetDirectory());
|
|
}
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
m_app->Stop();
|
|
m_app.reset();
|
|
}
|
|
|
|
AZStd::unique_ptr<ToolsTestApplication> m_app;
|
|
UnitTest::ScopedTemporaryDirectory m_tempDir;
|
|
};
|
|
|
|
#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
TEST_F(ArchiveComponentTest, DISABLED_CreateArchive_FilesAtThreeDepths_ArchiveCreated)
|
|
#else
|
|
TEST_F(ArchiveComponentTest, CreateArchive_FilesAtThreeDepths_ArchiveCreated)
|
|
#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
{
|
|
EXPECT_TRUE(m_tempDir.IsValid());
|
|
CreateArchiveFolder();
|
|
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
bool createResult = CreateArchive();
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
|
|
EXPECT_TRUE(createResult);
|
|
}
|
|
|
|
#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
TEST_F(ArchiveComponentTest, DISABLED_ListFilesInArchive_FilesAtThreeDepths_FilesFound)
|
|
#else
|
|
TEST_F(ArchiveComponentTest, ListFilesInArchive_FilesAtThreeDepths_FilesFound)
|
|
#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
{
|
|
EXPECT_TRUE(m_tempDir.IsValid());
|
|
CreateArchiveFolder();
|
|
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
EXPECT_EQ(CreateArchive(), true);
|
|
|
|
AZStd::vector<AZStd::string> fileList;
|
|
bool listResult{ false };
|
|
AzToolsFramework::ArchiveCommandsBus::BroadcastResult(listResult,
|
|
&AzToolsFramework::ArchiveCommandsBus::Events::ListFilesInArchive,
|
|
GetArchivePath().toUtf8().constData(), fileList);
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
|
|
EXPECT_TRUE(listResult);
|
|
EXPECT_EQ(fileList.size(), 6);
|
|
}
|
|
|
|
#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
TEST_F(ArchiveComponentTest, DISABLED_CreateDeltaCatalog_AssetsNotRegistered_Failure)
|
|
#else
|
|
TEST_F(ArchiveComponentTest, CreateDeltaCatalog_AssetsNotRegistered_Failure)
|
|
#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
{
|
|
QStringList fileList = CreateArchiveFileList();
|
|
|
|
CreateArchiveFolder(GetArchiveFolderName(), fileList);
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
bool createResult = CreateArchive();
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
|
|
EXPECT_EQ(createResult, true);
|
|
|
|
bool catalogCreated{ true };
|
|
AZ::Test::AssertAbsorber assertAbsorber;
|
|
AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated,
|
|
&AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toUtf8().constData(), true);
|
|
|
|
EXPECT_EQ(catalogCreated, false);
|
|
}
|
|
|
|
#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
TEST_F(ArchiveComponentTest, DISABLED_AddFilesToArchive_FromListFile_Success)
|
|
#else
|
|
TEST_F(ArchiveComponentTest, AddFilesToArchive_FromListFile_Success)
|
|
#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
{
|
|
QString listFile = CreateArchiveListTextFile();
|
|
CreateArchiveFolder(GetArchiveFolderName(), CreateArchiveFileList());
|
|
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
std::future<bool> addResult;
|
|
AzToolsFramework::ArchiveCommandsBus::BroadcastResult(
|
|
addResult, &AzToolsFramework::ArchiveCommandsBus::Events::AddFilesToArchive, GetArchivePath().toUtf8().constData(),
|
|
GetArchiveFolder().toUtf8().constData(), listFile.toUtf8().constData());
|
|
bool result = addResult.get();
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
|
|
EXPECT_TRUE(result);
|
|
}
|
|
|
|
#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
TEST_F(ArchiveComponentTest, DISABLED_ExtractArchive_AllFiles_Success)
|
|
#else
|
|
TEST_F(ArchiveComponentTest, ExtractArchive_AllFiles_Success)
|
|
#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
{
|
|
CreateArchiveFolder();
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
bool createResult = CreateArchive();
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
EXPECT_TRUE(createResult);
|
|
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
std::future<bool> extractResult;
|
|
AzToolsFramework::ArchiveCommandsBus::BroadcastResult(
|
|
extractResult, &AzToolsFramework::ArchiveCommandsBus::Events::ExtractArchive, GetArchivePath().toUtf8().constData(),
|
|
GetExtractFolder().toUtf8().constData());
|
|
bool result = extractResult.get();
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
|
|
EXPECT_TRUE(result);
|
|
|
|
QStringList archiveFiles = CreateArchiveFileList();
|
|
for (const auto& file : archiveFiles)
|
|
{
|
|
QString fullFilePath = QDir(GetExtractFolder()).absoluteFilePath(file);
|
|
QFileInfo fi(fullFilePath);
|
|
EXPECT_TRUE(fi.exists());
|
|
}
|
|
}
|
|
|
|
#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
TEST_F(ArchiveComponentTest, DISABLED_CreateDeltaCatalog_ArchiveWithoutCatalogAssetsRegistered_Success)
|
|
#else
|
|
TEST_F(ArchiveComponentTest, CreateDeltaCatalog_ArchiveWithoutCatalogAssetsRegistered_Success)
|
|
#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS
|
|
{
|
|
QStringList fileList = CreateArchiveFileList();
|
|
|
|
CreateArchiveFolder(GetArchiveFolderName(), fileList);
|
|
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
bool createResult = CreateArchive();
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
|
|
|
|
EXPECT_EQ(createResult, true);
|
|
|
|
for (const auto& thisPath : fileList)
|
|
{
|
|
AZ::Data::AssetInfo newInfo;
|
|
newInfo.m_relativePath = thisPath.toUtf8().constData();
|
|
newInfo.m_assetType = AZ::Uuid::CreateRandom();
|
|
newInfo.m_sizeBytes = 100; // Arbitrary
|
|
AZ::Data::AssetId generatedID(AZ::Uuid::CreateRandom());
|
|
newInfo.m_assetId = generatedID;
|
|
|
|
AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequestBus::Events::RegisterAsset, generatedID, newInfo);
|
|
}
|
|
|
|
bool catalogCreated{ false };
|
|
AZ_TEST_START_TRACE_SUPPRESSION;
|
|
AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated, &AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toUtf8().constData(), true);
|
|
AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // produces different counts in different platforms
|
|
EXPECT_EQ(catalogCreated, true);
|
|
}
|
|
}
|
|
|
|
}
|