fec77632ef
* Fix issues with seedlist for AutomatedTesting Fixes error reporting so it will show the file hint in the tool. Removes any missing assets from the .seed file. Remove an unnecessary dependency from AutomatedTesting dependencies file. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Make ArchiveComponent use AZ::IO::IArchive Initial changes that will get the sychronous calls in ArchiveComponent to use IArchive interface rather than external zip/7z tools. Some of the asynchronous api are still in place, anything that wasn't being used has been removed for now. This may change later if we move towards all the api being asynchronous. Until then, we can't remove the reliance upon the external archive tools completely. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Updates AZStd::thread constructors Adds a variadic constructor which forwards args to the functor. Because of our thread_desc extension, there was confusion on the arugments, so the args were reordered to take the thread_desc first, before the functor and args. Also the thread_desc is taken as reference rather than by pointer. Update callsites to account for this change. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Async operation of ArchiveComponent api This sets up the ArchiveComponent to operate asynchronously. It uses promise/future to transfer results to caller. This is still broken, there's a few things that need to get fixed up, but this is a good checkpoint for the work as it solidifies the api, cleans up a bunch of unused code, and compiles. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the platform-specific ArchiveComponen These are no longer needed, as they control the direct interaction with host OS tools like 7za.exe or /bin/zip. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the platform-specific files from cmake Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the 7za.exe (and legal notice) This tool is no longer needed in the repo. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fixes usage of IArchive::GetFullPath() This changed to return a PathView, updated to reflect that. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix promises and threads Make sure promises are only set exactly once. This meant reworking some of the initial error checking. Detach threads when created. Adds [[nodiscard]] to the functions that return a future. Since threads are detached, the future is the main way to get communication from the thread. Clean up interface, add comments. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * More edits to thread creation Changes to thread construction to account for parameter change. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix some remaining issues with ArchiveComponent Put created threads inside a container, then join them at Deactivate. Fix asset bundler case when injecting a file with no working directory. Fix thread constructor that applies args to a function. Fix lambdas to take string args by value rather than reference. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fixes some remaining bugs in ArchiveComponent Open archive as read-only during extract & list operations. Fixes paths issues. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix initialize of opaque thread handle in thread_UnixLike.h Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unused variable in AssetBundleComponent.cpp to fix compiler warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix some issues with archives File paths in the CDR and the local headers need to match, but there were issues with path separators and case that made it possible to get invalid headers errors in some archives. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Adds some new ArchiveComponent unit tests Adds new tests for extraction of archive and adding files from a file list to an archive. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix file data offset issues when opening archives When opening an INestedArchive it would run through the CDR headers to create file entries in the zip cache. The offsets to the compressed data were being calculated incorrectly because they were using the CDR headers rather than jumping to the local file headers and getting offsets from those sizes. Removed and refactored some archive validation flow and zip cache factory init methods to either init default or init w/ additional validation checks. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Addresses PR feedback Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address more points of feedback in PR Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address additional PR feedback Fixes up some error checks and uses of strings vs paths. Enable archive component tests on Linux so we can see if they will pass. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address PR feedback Change the INestedArchive interface to list files as AZ::IO::Path. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Disabling the ArchiveComponent tests on Linux They failed so we will revisit them to attempt a fix. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Rename a member variable to be more accurate Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address feedback on PR Bump version of Archive Components for serialize context. Improve error messages during archive open and validation. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Revert recent changes Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> Co-authored-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("@assets@", 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);
|
|
}
|
|
}
|
|
|
|
}
|