diff --git a/Code/Framework/AzCore/Tests/AZTestShared/Utils/Utils.cpp b/Code/Framework/AzCore/Tests/AZTestShared/Utils/Utils.cpp index a654302da6..d61323f33e 100644 --- a/Code/Framework/AzCore/Tests/AZTestShared/Utils/Utils.cpp +++ b/Code/Framework/AzCore/Tests/AZTestShared/Utils/Utils.cpp @@ -7,9 +7,9 @@ */ #include -#include "AzCore/Component/Entity.h" -#include "AzCore/Asset/AssetManager.h" -#include "AzCore/Slice/SliceComponent.h" +#include +#include +#include namespace UnitTest { diff --git a/Code/Framework/AzFramework/AzFramework/IO/LocalFileIO.cpp b/Code/Framework/AzFramework/AzFramework/IO/LocalFileIO.cpp index 69bf6bb394..96810c20ec 100644 --- a/Code/Framework/AzFramework/AzFramework/IO/LocalFileIO.cpp +++ b/Code/Framework/AzFramework/AzFramework/IO/LocalFileIO.cpp @@ -279,14 +279,11 @@ namespace AZ return SystemFile::Exists(resolvedPath); } - void LocalFileIO::CheckInvalidWrite(const char* path) + void LocalFileIO::CheckInvalidWrite([[maybe_unused]] const char* path) { - (void)path; - #if defined(AZ_ENABLE_TRACING) const char* assetsAlias = GetAlias("@assets@"); - - if (((path) && (assetsAlias) && (azstrnicmp(path, assetsAlias, strlen(assetsAlias)) == 0))) + if (path && assetsAlias && AZ::IO::PathView(path).IsRelativeTo(assetsAlias)) { AZ_Error("FileIO", false, "You may not alter data inside the asset cache. Please check the call stack and consider writing into the source asset folder instead.\n" "Attempted write location: %s", path); diff --git a/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp b/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp index f706ee824d..3b08e04304 100644 --- a/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/ArchiveTests.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace UnitTest { @@ -73,7 +74,7 @@ namespace UnitTest void CreateArchiveFolder( QString archiveFolderName, QStringList fileList ) { - QDir tempPath = QDir(m_tempDir.path()).filePath(archiveFolderName); + QDir tempPath = QDir(m_tempDir.GetDirectory()).filePath(archiveFolderName); for (const auto& thisFile : fileList) { @@ -89,12 +90,12 @@ namespace UnitTest QString GetArchivePath() { - return QDir(m_tempDir.path()).filePath("TestArchive.pak"); + return QDir(m_tempDir.GetDirectory()).filePath("TestArchive.pak"); } QString GetArchiveFolder() { - return QDir(m_tempDir.path()).filePath(GetArchiveFolderName()); + return QDir(m_tempDir.GetDirectory()).filePath(GetArchiveFolderName()); } bool CreateArchive() @@ -115,7 +116,7 @@ namespace UnitTest if (auto fileIoBase = AZ::IO::FileIOBase::GetInstance(); fileIoBase != nullptr) { - fileIoBase->SetAlias("@assets@", m_tempDir.path().toUtf8().data()); + fileIoBase->SetAlias("@assets@", m_tempDir.GetDirectory()); } } @@ -126,16 +127,12 @@ namespace UnitTest } AZStd::unique_ptr m_app; - QTemporaryDir m_tempDir {QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).filePath("ArchiveTests-")}; + UnitTest::ScopedTemporaryDirectory m_tempDir; }; -#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_CreateArchiveBlocking_FilesAtThreeDepths_ArchiveCreated) -#else TEST_F(ArchiveTest, CreateArchiveBlocking_FilesAtThreeDepths_ArchiveCreated) -#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { - EXPECT_TRUE(m_tempDir.isValid()); + EXPECT_TRUE(m_tempDir.IsValid()); CreateArchiveFolder(); bool createResult = CreateArchive(); @@ -143,13 +140,9 @@ namespace UnitTest EXPECT_EQ(createResult, true); } -#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_ListFilesInArchiveBlocking_FilesAtThreeDepths_FilesFound) -#else TEST_F(ArchiveTest, ListFilesInArchiveBlocking_FilesAtThreeDepths_FilesFound) -#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { - EXPECT_TRUE(m_tempDir.isValid()); + EXPECT_TRUE(m_tempDir.IsValid()); CreateArchiveFolder(); EXPECT_EQ(CreateArchive(), true); @@ -161,11 +154,7 @@ namespace UnitTest EXPECT_EQ(fileList.size(), 6); } -#if AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS - TEST_F(ArchiveTest, DISABLED_CreateDeltaCatalog_AssetsNotRegistered_Failure) -#else TEST_F(ArchiveTest, CreateDeltaCatalog_AssetsNotRegistered_Failure) -#endif // AZ_TRAIT_DISABLE_FAILED_ARCHIVE_TESTS { QStringList fileList = CreateArchiveFileList(); @@ -209,7 +198,9 @@ namespace UnitTest } bool catalogCreated{ false }; + AZ_TEST_START_TRACE_SUPPRESSION; AzToolsFramework::AssetBundleCommandsBus::BroadcastResult(catalogCreated, &AzToolsFramework::AssetBundleCommandsBus::Events::CreateDeltaCatalog, GetArchivePath().toStdString().c_str(), true); + AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT; // produces different counts in different platforms EXPECT_EQ(catalogCreated, true); } } diff --git a/Code/Framework/AzToolsFramework/Tests/AssetFileInfoListComparison.cpp b/Code/Framework/AzToolsFramework/Tests/AssetFileInfoListComparison.cpp index 2e4641d818..fea9fa6cc1 100644 --- a/Code/Framework/AzToolsFramework/Tests/AssetFileInfoListComparison.cpp +++ b/Code/Framework/AzToolsFramework/Tests/AssetFileInfoListComparison.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace // anonymous { @@ -57,7 +58,8 @@ namespace UnitTest AZ::IO::FileIOBase::SetInstance(nullptr); AZ::IO::FileIOBase::SetInstance(m_localFileIO); - AZ::IO::FileIOBase::GetInstance()->SetAlias("@assets@", GetTestFolderPath().c_str()); + AZ::IO::FileIOBase::GetInstance()->SetAlias("@assets@", m_tempDir.GetDirectory()); + AZStd::string assetRoot = AzToolsFramework::PlatformAddressedAssetCatalog::GetAssetRootForPlatform(AzFramework::PlatformId::PC); for (int idx = 0; idx < TotalAssets; idx++) @@ -69,9 +71,11 @@ namespace UnitTest assetRegistry.RegisterAsset(m_assets[idx], info); AzFramework::StringFunc::Path::Join(assetRoot.c_str(), info.m_relativePath.c_str(), m_assetsPath[idx]); + AZ_TEST_START_TRACE_SUPPRESSION; if (m_fileStreams[idx].Open(m_assetsPath[idx].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath)) { m_fileStreams[idx].Write(info.m_relativePath.size(), info.m_relativePath.data()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder } else { @@ -115,10 +119,12 @@ namespace UnitTest // Modify contents of asset2 int fileIndex = 2; + AZ_TEST_START_TRACE_SUPPRESSION; if (m_fileStreams[fileIndex].Open(m_assetsPath[fileIndex].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath)) { AZStd::string fileContent = AZStd::string::format("new Asset%d.txt", fileIndex);// changing file content m_fileStreams[fileIndex].Write(fileContent.size(), fileContent.c_str()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder } else { @@ -127,10 +133,12 @@ namespace UnitTest // Modify contents of asset 4 fileIndex = 4; + AZ_TEST_START_TRACE_SUPPRESSION; if (m_fileStreams[fileIndex].Open(m_assetsPath[fileIndex].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath)) { AZStd::string fileContent = AZStd::string::format("new Asset%d.txt", fileIndex);// changing file content m_fileStreams[fileIndex].Write(fileContent.size(), fileContent.c_str()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder } else { @@ -152,7 +160,9 @@ namespace UnitTest { if (fileIO->Exists(TempFiles[idx])) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(TempFiles[idx]); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // deleting from asset cache folder } } @@ -163,14 +173,18 @@ namespace UnitTest m_fileStreams[idx].Close(); if (fileIO->Exists(m_assetsPath[idx].c_str())) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(m_assetsPath[idx].c_str()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // deleting from asset cache folder } } auto pcCatalogFile = AzToolsFramework::PlatformAddressedAssetCatalog::GetCatalogRegistryPathForPlatform(AzFramework::PlatformId::PC); if (fileIO->Exists(pcCatalogFile.c_str())) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(pcCatalogFile.c_str()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // deleting from asset cache folder } delete m_pcCatalog; @@ -728,6 +742,7 @@ namespace UnitTest } ToolsTestApplication* m_application; + UnitTest::ScopedTemporaryDirectory m_tempDir; AzToolsFramework::PlatformAddressedAssetCatalog* m_pcCatalog; AZ::IO::FileIOBase* m_priorFileIO = nullptr; AZ::IO::FileIOBase* m_localFileIO = nullptr; diff --git a/Code/Framework/AzToolsFramework/Tests/AssetSeedManager.cpp b/Code/Framework/AzToolsFramework/Tests/AssetSeedManager.cpp index 52b8cc6a52..9ac53e4702 100644 --- a/Code/Framework/AzToolsFramework/Tests/AssetSeedManager.cpp +++ b/Code/Framework/AzToolsFramework/Tests/AssetSeedManager.cpp @@ -87,10 +87,12 @@ namespace UnitTest for (int idx = 0; idx < s_totalAssets; idx++) { AzFramework::StringFunc::Path::Join(assetRoot.c_str(), m_assetsPath[idx].c_str(), m_assetsPathFull[platformCount][idx]); + 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()); m_fileStreams[platformCount][idx].Close(); + AZ_TEST_STOP_TRACE_SUPPRESSION(thisPlatform == AzFramework::PlatformId::PC ? 1 : 0); // writing to asset cache folder, only invalid for PC } else { @@ -112,7 +114,9 @@ namespace UnitTest m_testDynamicSliceAssetId = testDynamicSliceAsset; m_assetRegistry->RegisterAsset(testDynamicSliceAsset, dynamicSliceAssetInfo); + AZ_TEST_START_TRACE_SUPPRESSION; AZ::IO::FileIOStream dynamicSliceFileIOStream(TestDynamicSliceAssetPath, AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeText); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder AZ::Data::AssetInfo sliceAssetInfo; sliceAssetInfo.m_relativePath = TestSliceAssetPath; @@ -124,7 +128,9 @@ namespace UnitTest secondSliceAssetInfo.m_assetId = secondTestSliceAsset; m_assetRegistry->RegisterAsset(secondTestSliceAsset, secondSliceAssetInfo); + AZ_TEST_START_TRACE_SUPPRESSION; AZ::IO::FileIOStream sliceFileIOStream(TestSliceAssetPath, AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeText); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder // asset0 -> asset1 -> asset2 -> asset4 // --> asset3 @@ -186,7 +192,6 @@ namespace UnitTest AZ::IO::Path assetRoot(AZ::Utils::GetProjectPath()); assetRoot /= "Cache"; AZ::IO::FileIOBase::GetInstance()->SetAlias("@root@", assetRoot.c_str()); - } void TearDown() override @@ -195,7 +200,9 @@ namespace UnitTest if (fileIO->Exists(s_catalogFile)) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(s_catalogFile); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // deleting from asset cache folder } for (size_t platformCount = 0; platformCount < s_totalTestPlatforms; ++platformCount) @@ -206,26 +213,34 @@ namespace UnitTest // 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(platformCount == 0 ? 1 : 0); // deleting from asset cache folder } } } if (fileIO->Exists(TestSliceAssetPath)) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(TestSliceAssetPath); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // deleting from asset cache folder } if (fileIO->Exists(TestDynamicSliceAssetPath)) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(TestDynamicSliceAssetPath); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // deleting from asset cache folder } 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(1); // deleting from asset cache folder } if (fileIO->Exists(androidCatalogFile.c_str())) @@ -629,11 +644,13 @@ namespace UnitTest EXPECT_EQ(assetList1.m_fileInfoList.size(), 1); EXPECT_TRUE(Search(assetList1, assets[fileIndex])); + AZ_TEST_START_TRACE_SUPPRESSION; 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()); m_fileStreams[0][fileIndex].Close(); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder } AzToolsFramework::AssetFileInfoList assetList2 = m_assetSeedManager->GetDependencyList(AzFramework::PlatformId::PC); @@ -660,11 +677,13 @@ namespace UnitTest EXPECT_EQ(assetList1.m_fileInfoList.size(), 1); EXPECT_TRUE(Search(assetList1, assets[fileIndex])); + AZ_TEST_START_TRACE_SUPPRESSION; 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()); m_fileStreams[0][fileIndex].Close(); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder } AzToolsFramework::AssetFileInfoList assetList2 = m_assetSeedManager->GetDependencyList(AzFramework::PlatformId::PC); diff --git a/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp b/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp index 29b48a1f31..3446f854b6 100644 --- a/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/PlatformAddressedAssetCatalogTests.cpp @@ -83,9 +83,11 @@ namespace UnitTest info.m_assetId = m_assets[platformNum][idx]; assetRegistry->RegisterAsset(m_assets[platformNum][idx], info); m_assetsPath[platformNum][idx] = info.m_relativePath; + AZ_TEST_START_TRACE_SUPPRESSION; if (m_fileStreams[platformNum][idx].Open(m_assetsPath[platformNum][idx].c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary | AZ::IO::OpenMode::ModeCreatePath)) { m_fileStreams[platformNum][idx].Write(info.m_relativePath.size(), info.m_relativePath.data()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // writing to asset cache folder } else { @@ -131,7 +133,9 @@ namespace UnitTest m_fileStreams[platformNum][idx].Close(); if (fileIO->Exists(m_assetsPath[platformNum][idx].c_str())) { + AZ_TEST_START_TRACE_SUPPRESSION; fileIO->Remove(m_assetsPath[platformNum][idx].c_str()); + AZ_TEST_STOP_TRACE_SUPPRESSION(1); // removing from asset cache folder } } }