Merge branch 'development' into Prefab/DestroyGameEntitySupport

Signed-off-by: srikappa-amzn <srikappa@amazon.com>
This commit is contained in:
srikappa-amzn
2021-09-28 06:57:38 -07:00
1501 changed files with 34384 additions and 17743 deletions
@@ -68,7 +68,7 @@ namespace UnitTest
return false;
}
if (!archive->OpenPack(path, AZ::IO::IArchive::FLAGS_PATH_REAL))
if (!archive->OpenPack(path))
{
return false;
}
@@ -94,7 +94,7 @@ namespace UnitTest
fileIo->Remove(testArchivePath.c_str());
// ------------ BASIC TEST: Create and read Empty Archive ------------
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
pArchive.reset();
EXPECT_TRUE(IsPackValid(testArchivePath.c_str()));
@@ -122,7 +122,7 @@ namespace UnitTest
checkSums[pos] = static_cast<uint8_t>(pos % 256);
}
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
// the strategy here is to find errors related to file sizes, alignment, overwrites
@@ -143,7 +143,7 @@ namespace UnitTest
// --------------------------------------------- read it back and verify
pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, openFlags);
pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, openFlags);
EXPECT_NE(nullptr, pArchive);
for (int j = 0; j < iterations; ++j)
@@ -241,7 +241,7 @@ namespace UnitTest
// -------------------------------------------------------------------------------------------
// read it back and verify
pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, openFlags);
pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, openFlags);
EXPECT_NE(nullptr, pArchive);
for (int j = 0; j < iterations; ++j)
@@ -298,7 +298,7 @@ namespace UnitTest
}
// first, reset the pack to the original state:
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
auto pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
for (int j = 0; j < iterations; ++j)
@@ -382,7 +382,7 @@ namespace UnitTest
// -------------------------------------------------------------------------------------------
// read it back and verify
pArchive = archive->OpenArchive(testArchivePath.c_str(), nullptr, openFlags);
pArchive = archive->OpenArchive(testArchivePath.c_str(), {}, openFlags);
EXPECT_NE(nullptr, pArchive);
writeCount = 0;
+44 -222
View File
@@ -30,16 +30,17 @@ namespace UnitTest
: public ScopedAllocatorSetupFixture
{
public:
// Use an Immediately invoked function to initlaize the m_stackRecordLevels value of the AZ::SystemAllocator::Descriptor class
ArchiveTestFixture()
: m_application{ AZStd::make_unique<AzFramework::Application>() }
: ScopedAllocatorSetupFixture(
[]() { AZ::SystemAllocator::Descriptor desc; desc.m_stackRecordLevels = 30; return desc; }()
)
, m_application{ AZStd::make_unique<AzFramework::Application>() }
{
}
void SetUp() override
{
AZ::ComponentApplication::Descriptor descriptor;
descriptor.m_stackRecordLevels = 30;
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
auto projectPathKey =
@@ -47,7 +48,7 @@ namespace UnitTest
registry->Set(projectPathKey, "AutomatedTesting");
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
m_application->Start(descriptor);
m_application->Start({});
// 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.
@@ -68,7 +69,7 @@ namespace UnitTest
return false;
}
return archive->OpenPack(path, AZ::IO::IArchive::FLAGS_PATH_REAL) && archive->ClosePack(path);
return archive->OpenPack(path) && archive->ClosePack(path);
}
template <class Function>
@@ -116,7 +117,7 @@ namespace UnitTest
{
// Canary tests first
AZ::IO::HandleType fileHandle = archive->FOpen(testFilePath, "rb", 0);
AZ::IO::HandleType fileHandle = archive->FOpen(testFilePath, "rb");
ASSERT_NE(AZ::IO::InvalidHandle, fileHandle);
@@ -136,9 +137,9 @@ namespace UnitTest
// open already open file and call FGetCachedFileData
fileSize = 0;
{
AZ::IO::HandleType fileHandle2 = archive->FOpen(testFilePath, "rb", 0);
AZ::IO::HandleType fileHandle2 = archive->FOpen(testFilePath, "rb");
char* pFileBuffer3 = (char*)archive->FGetCachedFileData(fileHandle2, fileSize);
ASSERT_NE(nullptr,pFileBuffer3);
ASSERT_NE(nullptr, pFileBuffer3);
EXPECT_EQ(dataLen, fileSize);
EXPECT_EQ(0, memcmp(pFileBuffer3, testData, dataLen));
archive->FClose(fileHandle2);
@@ -174,7 +175,7 @@ namespace UnitTest
// Multithreaded Test #2 reading from the same file concurrently
auto concurrentArchiveFileReadFunc = [archive, testFilePath, dataLen, testData]()
{
AZ::IO::HandleType threadFileHandle = archive->FOpen(testFilePath, "rb", 0);
AZ::IO::HandleType threadFileHandle = archive->FOpen(testFilePath, "rb");
if (threadFileHandle == AZ::IO::InvalidHandle)
{
@@ -255,7 +256,7 @@ namespace UnitTest
fileIo->CreatePath("@usercache@/levels/test");
// setup test archive and file
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withSubfolders.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withSubfolders.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile(fileInArchiveFile, dataString.data(), dataString.size(), AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_FASTEST));
pArchive.reset();
@@ -290,7 +291,7 @@ namespace UnitTest
archive->ClosePack(filePath.c_str());
fileIo->Remove(filePath.c_str());
auto pArchive = archive->OpenArchive(filePath.c_str(), nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
auto pArchive = archive->OpenArchive(filePath.c_str(), {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
pArchive.reset();
archive->ClosePack(filePath.c_str());
@@ -305,7 +306,7 @@ namespace UnitTest
// open and fetch the opened pak file using a *.pak
AZStd::vector<AZ::IO::FixedMaxPathString> fullPaths;
archive->OpenPacks("@usercache@/*.pak", AZ::IO::IArchive::EPathResolutionRules::FLAGS_PATH_REAL, &fullPaths);
archive->OpenPacks("@usercache@/*.pak", &fullPaths);
EXPECT_TRUE(AZStd::any_of(fullPaths.cbegin(), fullPaths.cend(), [](auto& path) { return path.ends_with("one.pak"); }));
EXPECT_TRUE(AZStd::any_of(fullPaths.cbegin(), fullPaths.cend(), [](auto& path) { return path.ends_with("two.pak"); }));
}
@@ -477,7 +478,7 @@ namespace UnitTest
bool found_mylevel_file{};
bool found_mylevel_folder{};
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withMountPoint, nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath_withMountPoint, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile("levelinfo.xml", dataString.data(), dataString.size(), AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_FASTEST));
pArchive.reset();
@@ -628,7 +629,7 @@ namespace UnitTest
normalFileHandle = InvalidHandle;
EXPECT_TRUE(cpfio.Exists("@log@/unittesttemp/realfileforunittest.xml"));
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(genericArchiveFileName, nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(genericArchiveFileName, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile("testfile.xml", dataString, aznumeric_cast<uint32_t>(dataLen), AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_FASTEST));
pArchive.reset();
@@ -712,13 +713,16 @@ namespace UnitTest
EXPECT_TRUE(cpfio.Exists("@log@/unittesttemp/copiedfile2.xml"));
// find files test.
AZ::IO::FixedMaxPath resolvedTestFilePath;
EXPECT_TRUE(cpfio.ResolvePath(resolvedTestFilePath, AZ::IO::PathView("@assets@/testfile.xml")));
bool foundIt = false;
// note that this file exists only in the archive.
cpfio.FindFiles("@assets@", "*.xml", [&foundIt](const char* foundName)
cpfio.FindFiles("@assets@", "*.xml", [&foundIt, &cpfio, &resolvedTestFilePath](const char* foundName)
{
AZ::IO::FixedMaxPath resolvedFoundPath;
EXPECT_TRUE(cpfio.ResolvePath(resolvedFoundPath, AZ::IO::PathView(foundName)));
// according to the contract stated in the FileIO.h file, we expect full paths. (Aliases are full paths)
if (azstricmp(foundName, "@assets@/testfile.xml") == 0)
if (resolvedTestFilePath == resolvedFoundPath)
{
foundIt = true;
return false;
@@ -769,7 +773,7 @@ namespace UnitTest
fileIo->Remove(testArchivePath);
// ------------ BASIC TEST: Create and read Empty Archive ------------
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath, nullptr, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
AZStd::intrusive_ptr<AZ::IO::INestedArchive> pArchive = archive->OpenArchive(testArchivePath, {}, AZ::IO::INestedArchive::FLAGS_CREATE_NEW);
EXPECT_NE(nullptr, pArchive);
EXPECT_EQ(0, pArchive->UpdateFile("foundit.dat", const_cast<char*>("test"), 4, AZ::IO::INestedArchive::METHOD_COMPRESS, AZ::IO::INestedArchive::LEVEL_BEST));
@@ -803,40 +807,49 @@ namespace UnitTest
EXPECT_TRUE(archive->ClosePack(realNameBuf));
}
TEST_F(ArchiveTestFixture, IResourceList_Add_EmptyFileName_DoesNotCrash)
TEST_F(ArchiveTestFixture, IResourceList_Add_EmptyFileName_DoesNotInsert)
{
AZ::IO::IResourceList* reslist = AZ::Interface<AZ::IO::IArchive>::Get()->GetResourceList(AZ::IO::IArchive::RFOM_EngineStartup);
ASSERT_NE(nullptr, reslist);
reslist->Clear();
reslist->Add("");
EXPECT_STREQ(reslist->GetFirst(), "");
reslist->Clear();
EXPECT_EQ(nullptr, reslist->GetFirst());
}
TEST_F(ArchiveTestFixture, IResourceList_Add_RegularFileName_NormalizesAppropriately)
TEST_F(ArchiveTestFixture, IResourceList_Add_RegularFileName_ResolvesAppropriately)
{
AZ::IO::IResourceList* reslist = AZ::Interface<AZ::IO::IArchive>::Get()->GetResourceList(AZ::IO::IArchive::RFOM_EngineStartup);
ASSERT_NE(nullptr, reslist);
AZ::IO::FileIOBase* ioBase = AZ::IO::FileIOBase::GetInstance();
ASSERT_NE(nullptr, ioBase);
AZ::IO::FixedMaxPath resolvedTestPath;
EXPECT_TRUE(ioBase->ResolvePath(resolvedTestPath, "blah/blah/abcde"));
reslist->Clear();
reslist->Add("blah\\blah/AbCDE");
// it normalizes the string, so the slashes flip and everything is lowercased.
EXPECT_STREQ(reslist->GetFirst(), "blah/blah/abcde");
AZ::IO::FixedMaxPath resolvedAddedPath;
EXPECT_TRUE(ioBase->ResolvePath(resolvedAddedPath, reslist->GetFirst()));
EXPECT_EQ(resolvedTestPath, resolvedAddedPath);
reslist->Clear();
}
TEST_F(ArchiveTestFixture, IResourceList_Add_ReallyShortFileName_NormalizesAppropriately)
TEST_F(ArchiveTestFixture, IResourceList_Add_ReallyShortFileName_ResolvesAppropriately)
{
AZ::IO::IResourceList* reslist = AZ::Interface<AZ::IO::IArchive>::Get()->GetResourceList(AZ::IO::IArchive::RFOM_EngineStartup);
ASSERT_NE(nullptr, reslist);
AZ::IO::FileIOBase* ioBase = AZ::IO::FileIOBase::GetInstance();
ASSERT_NE(nullptr, ioBase);
AZ::IO::FixedMaxPath resolvedTestPath;
EXPECT_TRUE(ioBase->ResolvePath(resolvedTestPath, "a"));
reslist->Clear();
reslist->Add("A");
// it normalizes the string, so the slashes flip and everything is lowercased.
EXPECT_STREQ(reslist->GetFirst(), "a");
AZ::IO::FixedMaxPath resolvedAddedPath;
EXPECT_TRUE(ioBase->ResolvePath(resolvedAddedPath, reslist->GetFirst()));
EXPECT_EQ(resolvedTestPath, resolvedAddedPath);
reslist->Clear();
}
@@ -848,7 +861,7 @@ namespace UnitTest
AZ::IO::FileIOBase* ioBase = AZ::IO::FileIOBase::GetInstance();
ASSERT_NE(nullptr, ioBase);
const char *assetsPath = ioBase->GetAlias("@assets@");
const char* assetsPath = ioBase->GetAlias("@assets@");
ASSERT_NE(nullptr, assetsPath);
auto stringToAdd = AZ::IO::Path(assetsPath) / "textures" / "test.dds";
@@ -864,195 +877,4 @@ namespace UnitTest
EXPECT_EQ(resolvedAddedPath, resolvedResourcePath);
reslist->Clear();
}
class ArchiveUnitTestsWithAllocators
: public ScopedAllocatorSetupFixture
{
protected:
void SetUp() override
{
m_localFileIO = aznew AZ::IO::LocalFileIO();
AZ::IO::FileIOBase::SetDirectInstance(m_localFileIO);
m_localFileIO->SetAlias(m_firstAlias.c_str(), m_firstAliasPath.c_str());
m_localFileIO->SetAlias(m_secondAlias.c_str(), m_secondAliasPath.c_str());
}
void TearDown() override
{
AZ::IO::FileIOBase::SetDirectInstance(nullptr);
delete m_localFileIO;
m_localFileIO = nullptr;
}
AZ::IO::FileIOBase* m_localFileIO = nullptr;
AZStd::string m_firstAlias = "@devassets@";
AZStd::string m_firstAliasPath = "devassets_absolutepath";
AZStd::string m_secondAlias = "@assets@";
AZStd::string m_secondAliasPath = "assets_absolutepath";
};
// ConvertAbsolutePathToAliasedPath tests are built to verify existing behavior doesn't change.
// It's a legacy function and the actual intended behavior is unknown, so these are black box unit tests.
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_NullString_ReturnsSuccess)
{
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(nullptr);
EXPECT_TRUE(conversionResult);
EXPECT_TRUE(conversionResult->empty());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_NoAliasInSource_ReturnsSource)
{
AZStd::string sourceString("NoAlias");
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(sourceString.c_str());
EXPECT_TRUE(conversionResult);
// ConvertAbsolutePathToAliasedPath returns sourceString if there is no alias in the source.
EXPECT_STREQ(sourceString.c_str(), conversionResult->c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_NullAliasToLookFor_ReturnsSource)
{
AZStd::string sourceString("NoAlias");
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(sourceString.c_str(), nullptr);
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(sourceString.c_str(), conversionResult->c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_NullAliasToReplaceWith_ReturnsSource)
{
AZStd::string sourceString("NoAlias");
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(sourceString.c_str(), "@SomeAlias", nullptr);
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(sourceString.c_str(), conversionResult->c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_NullAliases_ReturnsSource)
{
AZStd::string sourceString("NoAlias");
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(sourceString.c_str(), nullptr, nullptr);
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(sourceString.c_str(), conversionResult->c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_AbsPathInSource_ReturnsReplacedAlias)
{
// ConvertAbsolutePathToAliasedPath only replaces data if GetDirectInstance is valid.
EXPECT_TRUE(AZ::IO::FileIOBase::GetDirectInstance() != nullptr);
const char* fullPath = AZ::IO::FileIOBase::GetDirectInstance()->GetAlias(m_firstAlias.c_str());
AZStd::string sourceString = AZStd::string::format("%s" AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING "SomeStringWithAlias", fullPath);
AZStd::string expectedResult = AZStd::string::format("%s" AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING "somestringwithalias", m_secondAlias.c_str());
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(
sourceString.c_str(),
m_firstAlias.c_str(), // find any instance of FirstAlias in sourceString
m_secondAlias.c_str()); // replace it with SecondAlias
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(conversionResult->c_str(), expectedResult.c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_AliasInSource_ReturnsReplacedAlias)
{
// ConvertAbsolutePathToAliasedPath only replaces data if GetDirectInstance is valid.
EXPECT_TRUE(AZ::IO::FileIOBase::GetDirectInstance() != nullptr);
AZStd::string sourceString = AZStd::string::format("%s" AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING "SomeStringWithAlias", m_firstAlias.c_str());
AZStd::string expectedResult = AZStd::string::format("%s" AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING "somestringwithalias", m_secondAlias.c_str());
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(
sourceString.c_str(),
m_firstAlias.c_str(), // find any instance of FirstAlias in sourceString
m_secondAlias.c_str()); // replace it with SecondAlias
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(conversionResult->c_str(), expectedResult.c_str());
}
#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_AbsPathInSource_DOSSlashInSource_ReturnsReplacedAlias)
{
// ConvertAbsolutePathToAliasedPath only replaces data if GetDirectInstance is valid.
EXPECT_TRUE(AZ::IO::FileIOBase::GetDirectInstance() != nullptr);
const char* fullPath = AZ::IO::FileIOBase::GetDirectInstance()->GetAlias(m_firstAlias.c_str());
AZStd::string sourceString = AZStd::string::format("%s" AZ_WRONG_DATABASE_SEPARATOR_STRING "SomeStringWithAlias", fullPath);
AZStd::string expectedResult = AZStd::string::format("%s" AZ_CORRECT_FILESYSTEM_SEPARATOR_STRING "somestringwithalias", m_secondAlias.c_str());
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(
sourceString.c_str(),
m_firstAlias.c_str(), // find any instance of FirstAlias in sourceString
m_secondAlias.c_str()); // replace it with SecondAlias
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(conversionResult->c_str(), expectedResult.c_str());
}
#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_AbsPathInSource_UNIXSlashInSource_ReturnsReplacedAlias)
{
// ConvertAbsolutePathToAliasedPath only replaces data if GetDirectInstance is valid.
EXPECT_TRUE(AZ::IO::FileIOBase::GetDirectInstance() != nullptr);
const char* fullPath = AZ::IO::FileIOBase::GetDirectInstance()->GetAlias(m_firstAlias.c_str());
AZStd::string sourceString = AZStd::string::format("%s" AZ_CORRECT_DATABASE_SEPARATOR_STRING "SomeStringWithAlias", fullPath);
AZStd::string expectedResult = AZStd::string::format("%s" AZ_CORRECT_DATABASE_SEPARATOR_STRING "somestringwithalias", m_secondAlias.c_str());
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(
sourceString.c_str(),
m_firstAlias.c_str(), // find any instance of FirstAlias in sourceString
m_secondAlias.c_str()); // replace it with SecondAlias
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(conversionResult->c_str(), expectedResult.c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_AliasInSource_DOSSlashInSource_ReturnsReplacedAlias)
{
// ConvertAbsolutePathToAliasedPath only replaces data if GetDirectInstance is valid.
EXPECT_TRUE(AZ::IO::FileIOBase::GetDirectInstance() != nullptr);
AZStd::string sourceString = AZStd::string::format("%s" AZ_WRONG_DATABASE_SEPARATOR_STRING "SomeStringWithAlias", m_firstAlias.c_str());
AZStd::string expectedResult = AZStd::string::format("%s" AZ_WRONG_DATABASE_SEPARATOR_STRING "somestringwithalias", m_secondAlias.c_str());
// sourceString is now (firstAlias)SomeStringWithAlias
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(
sourceString.c_str(),
m_firstAlias.c_str(), // find any instance of FirstAlias in sourceString
m_secondAlias.c_str()); // replace it with SecondAlias
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(conversionResult->c_str(), expectedResult.c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_AliasInSource_UNIXSlashInSource_ReturnsReplacedAlias)
{
// ConvertAbsolutePathToAliasedPath only replaces data if GetDirectInstance is valid.
EXPECT_TRUE(AZ::IO::FileIOBase::GetDirectInstance() != nullptr);
AZStd::string sourceString = AZStd::string::format("%s" AZ_CORRECT_DATABASE_SEPARATOR_STRING "SomeStringWithAlias", m_firstAlias.c_str());
AZStd::string expectedResult = AZStd::string::format("%s" AZ_CORRECT_DATABASE_SEPARATOR_STRING "somestringwithalias", m_secondAlias.c_str());
// sourceString is now (firstAlias)SomeStringWithAlias
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(
sourceString.c_str(),
m_firstAlias.c_str(), // find any instance of FirstAlias in sourceString
m_secondAlias.c_str()); // replace it with SecondAlias
EXPECT_TRUE(conversionResult);
EXPECT_STREQ(conversionResult->c_str(), expectedResult.c_str());
}
TEST_F(ArchiveUnitTestsWithAllocators, ConvertAbsolutePathToAliasedPath_SourceLongerThanMaxPath_ReturnsFailure)
{
const int longPathArraySize = AZ::IO::MaxPathLength + 2;
char longPath[longPathArraySize];
memset(longPath, 'a', sizeof(char) * longPathArraySize);
longPath[longPathArraySize - 1] = '\0';
AZ_TEST_START_TRACE_SUPPRESSION;
auto conversionResult = AZ::IO::ArchiveInternal::ConvertAbsolutePathToAliasedPath(longPath);
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
EXPECT_FALSE(conversionResult);
}
class ArchivePathCompareTestFixture
: public ScopedAllocatorSetupFixture
, public ::testing::WithParamInterface<AZStd::tuple<AZStd::string_view, AZStd::string_view>>
{
};
}
@@ -20,8 +20,7 @@ namespace Benchmark
class BM_Octree
: public benchmark::Fixture
{
public:
void SetUp([[maybe_unused]] const ::benchmark::State& state) override
void internalSetUp()
{
// Create the SystemAllocator if not available
if (!AZ::AllocatorInstance<AZ::SystemAllocator>::IsReady())
@@ -72,7 +71,7 @@ namespace Benchmark
});
}
void TearDown([[maybe_unused]] const ::benchmark::State& state) override
void internalTearDown()
{
m_octreeSystemComponent->DestroyVisibilityScene(m_visScene);
delete m_octreeSystemComponent;
@@ -91,6 +90,25 @@ namespace Benchmark
}
}
public:
void SetUp(const benchmark::State&) override
{
internalSetUp();
}
void SetUp(benchmark::State&) override
{
internalSetUp();
}
void TearDown(const benchmark::State&) override
{
internalTearDown();
}
void TearDown(benchmark::State&) override
{
internalTearDown();
}
void InsertEntries(uint32_t entryCount)
{
for (uint32_t i = 0; i < entryCount; ++i)
@@ -0,0 +1,122 @@
/*
* 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/std/containers/array.h>
#include <AzFramework/Spawnable/SpawnableEntitiesInterface.h>
#include <AzTest/AzTest.h>
namespace UnitTest
{
//
// SpawnableEntityContainerView
//
class SpawnableEntityContainerViewTest : public ::testing::Test
{
protected:
AZStd::array<AZ::Entity*, 4> m_values{ reinterpret_cast<AZ::Entity*>(1), reinterpret_cast<AZ::Entity*>(2),
reinterpret_cast<AZ::Entity*>(3), reinterpret_cast<AZ::Entity*>(4) };
AzFramework::SpawnableEntityContainerView m_view{ m_values.begin(), m_values.end() };
};
TEST_F(SpawnableEntityContainerViewTest, begin_Get_MatchesBeginOfArray)
{
EXPECT_EQ(m_view.begin(), m_values.begin());
}
TEST_F(SpawnableEntityContainerViewTest, end_Get_MatchesEndOfArray)
{
EXPECT_EQ(m_view.end(), m_values.end());
}
TEST_F(SpawnableEntityContainerViewTest, cbegin_Get_MatchesBeginOfArray)
{
EXPECT_EQ(m_view.cbegin(), m_values.cbegin());
}
TEST_F(SpawnableEntityContainerViewTest, cend_Get_MatchesEndOfArray)
{
EXPECT_EQ(m_view.cend(), m_values.cend());
}
TEST_F(SpawnableEntityContainerViewTest, IndexOperator_Get_MatchesThirdElement)
{
EXPECT_EQ(m_view[2], m_values[2]);
}
TEST_F(SpawnableEntityContainerViewTest, Size_Get_MatchesSizeOfArray)
{
EXPECT_EQ(m_view.size(), m_values.size());
}
TEST_F(SpawnableEntityContainerViewTest, empty_GetFromFilledArray_ReturnsFalse)
{
EXPECT_FALSE(m_view.empty());
}
TEST_F(SpawnableEntityContainerViewTest, empty_GetFromEmtpyView_ReturnsTrue)
{
AzFramework::SpawnableEntityContainerView view{ nullptr, nullptr };
EXPECT_TRUE(view.empty());
}
//
// SpawnableConstEntityContainerView
//
class SpawnableConstEntityContainerViewTest : public ::testing::Test
{
protected:
AZStd::array<AZ::Entity*, 4> m_values{ reinterpret_cast<AZ::Entity*>(1), reinterpret_cast<AZ::Entity*>(2),
reinterpret_cast<AZ::Entity*>(3), reinterpret_cast<AZ::Entity*>(4) };
AzFramework::SpawnableConstEntityContainerView m_view{ m_values.begin(), m_values.end() };
};
TEST_F(SpawnableConstEntityContainerViewTest, begin_Get_MatchesBeginOfArray)
{
EXPECT_EQ(m_view.begin(), m_values.begin());
}
TEST_F(SpawnableConstEntityContainerViewTest, end_Get_MatchesEndOfArray)
{
EXPECT_EQ(m_view.end(), m_values.end());
}
TEST_F(SpawnableConstEntityContainerViewTest, cbegin_Get_MatchesBeginOfArray)
{
EXPECT_EQ(m_view.cbegin(), m_values.cbegin());
}
TEST_F(SpawnableConstEntityContainerViewTest, cend_Get_MatchesEndOfArray)
{
EXPECT_EQ(m_view.cend(), m_values.cend());
}
TEST_F(SpawnableConstEntityContainerViewTest, IndexOperator_Get_MatchesThirdElement)
{
EXPECT_EQ(m_view[2], m_values[2]);
}
TEST_F(SpawnableConstEntityContainerViewTest, size_Get_MatchesSizeOfArray)
{
EXPECT_EQ(m_view.size(), m_values.size());
}
TEST_F(SpawnableConstEntityContainerViewTest, empty_GetFromFilledArray_ReturnsFalse)
{
EXPECT_FALSE(m_view.empty());
}
TEST_F(SpawnableConstEntityContainerViewTest, empty_GetFromEmtpyView_ReturnsTrue)
{
AzFramework::SpawnableConstEntityContainerView view{ nullptr, nullptr };
EXPECT_TRUE(view.empty());
}
} // namespace UnitTest
@@ -8,6 +8,7 @@
set(FILES
../../AzCore/Tests/Main.cpp
Spawnable/SpawnableEntitiesInterfaceTests.cpp
Spawnable/SpawnableEntitiesManagerTests.cpp
ArchiveCompressionTests.cpp
ArchiveTests.cpp