From c9c505a8f61a0d164e1aab5298c311d5f9dbfc5a Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 30 Nov 2020 04:57:11 +0100 Subject: [PATCH] #5108: Fix unit tests after TestContext API change --- radiantcore/settings/GameManager.cpp | 1 + test/MapSavingLoading.cpp | 25 +++++++++++++------------ test/VFS.cpp | 12 ++++++------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/radiantcore/settings/GameManager.cpp b/radiantcore/settings/GameManager.cpp index c94e5240c8..50b4b1b17f 100644 --- a/radiantcore/settings/GameManager.cpp +++ b/radiantcore/settings/GameManager.cpp @@ -58,6 +58,7 @@ const StringSet& Manager::getDependencies() const _dependencies.insert(MODULE_VIRTUALFILESYSTEM); _dependencies.insert(MODULE_COMMANDSYSTEM); _dependencies.insert(MODULE_PREFERENCESYSTEM); + _dependencies.insert(MODULE_FILETYPES); } return _dependencies; diff --git a/test/MapSavingLoading.cpp b/test/MapSavingLoading.cpp index 681ea36de1..c368a8c66b 100644 --- a/test/MapSavingLoading.cpp +++ b/test/MapSavingLoading.cpp @@ -91,7 +91,7 @@ class MapFileTestBase : // The copy will be removed in the TearDown() method fs::path createMapCopyInModMapsPath(const std::string& mapToCopy, const std::string& newFilename) { - fs::path targetPath = _context.getTestResourcePath(); + fs::path targetPath = _context.getTestProjectPath(); targetPath /= "maps/"; targetPath /= newFilename; @@ -101,7 +101,7 @@ class MapFileTestBase : private: fs::path createMapCopy(const std::string& mapToCopy, const fs::path& targetPath) { - fs::path mapPath = _context.getTestResourcePath(); + fs::path mapPath = _context.getTestProjectPath(); mapPath /= "maps/"; mapPath /= mapToCopy; @@ -240,7 +240,7 @@ TEST_F(MapLoadingTest, openMapFromModRelativePath) std::string modRelativePath = "maps/altar.map"; // The map is located in maps/altar.map folder, check that it physically exists - fs::path mapPath = _context.getTestResourcePath(); + fs::path mapPath = _context.getTestProjectPath(); mapPath /= modRelativePath; EXPECT_TRUE(os::fileOrDirExists(mapPath)); @@ -258,7 +258,7 @@ TEST_F(MapLoadingTest, openMapFromMapsFolder) std::string mapName = "altar.map"; // The map is located in maps/altar.map folder, check that it physically exists - fs::path mapPath = _context.getTestResourcePath(); + fs::path mapPath = _context.getTestProjectPath(); mapPath /= "maps"; mapPath /= mapName; EXPECT_TRUE(os::fileOrDirExists(mapPath)); @@ -277,7 +277,7 @@ TEST_F(MapLoadingTest, openMapFromModPak) std::string modRelativePath = "maps/altar_in_pk4.map"; // The map is located in maps/ folder within the altar.pk4, check that it doesn't physically exist - fs::path mapPath = _context.getTestResourcePath(); + fs::path mapPath = _context.getTestProjectPath(); mapPath /= modRelativePath; EXPECT_FALSE(os::fileOrDirExists(mapPath)); @@ -291,7 +291,7 @@ TEST_F(MapLoadingTest, openMapFromModPak) TEST_F(MapLoadingTest, openMapFromArchive) { - auto pakPath = fs::path(_context.getTestResourcePath()) / ".." / "map_loading_test.pk4"; + auto pakPath = fs::path(_context.getTestResourcePath()) / "map_loading_test.pk4"; std::string archiveRelativePath = "maps/altar_packed.map"; GlobalCommandSystem().executeCommand("OpenMapFromArchive", pakPath.string(), archiveRelativePath); @@ -302,7 +302,7 @@ TEST_F(MapLoadingTest, openMapFromArchive) TEST_F(MapLoadingTest, openMapFromArchiveWithoutInfoFile) { - auto pakPath = fs::path(_context.getTestResourcePath()) / ".." / "map_loading_test.pk4"; + auto pakPath = fs::path(_context.getTestResourcePath()) / "map_loading_test.pk4"; std::string archiveRelativePath = "maps/altar_packed_without_dr_file.map"; GlobalCommandSystem().executeCommand("OpenMapFromArchive", pakPath.string(), archiveRelativePath); @@ -337,7 +337,7 @@ TEST_F(MapLoadingTest, openWithInvalidPath) TEST_F(MapLoadingTest, openWithInvalidPathInsideMod) { // Pass a directory name to it - GlobalCommandSystem().executeCommand("OpenMap", _context.getTestResourcePath()); + GlobalCommandSystem().executeCommand("OpenMap", _context.getTestProjectPath()); // No worldspawn in this map, it should be empty EXPECT_FALSE(algorithm::getEntityByName(GlobalMapModule().getRoot(), "world")); @@ -448,12 +448,12 @@ TEST_F(MapSavingTest, saveMapClearsModifiedFlag) TEST_F(MapSavingTest, saveMapDoesntChangeMap) { // Create a copy of the map file in the mod-relative maps/ folder - fs::path mapPath = _context.getTestResourcePath(); + fs::path mapPath = _context.getTestProjectPath(); mapPath /= "maps/altar.map"; // The map is located in maps/altar.map folder, check that it physically exists std::string modRelativePath = "maps/altar_saveMapDoesntChangeMap.map"; - fs::path copiedMap = _context.getTestResourcePath(); + fs::path copiedMap = _context.getTestProjectPath(); copiedMap /= modRelativePath; fs::remove(copiedMap); @@ -594,8 +594,9 @@ TEST_F(MapSavingTest, saveAs) std::string modRelativePath = "maps/altar.map"; // The map is located in maps/altar.map folder, check that it physically exists - fs::path mapPath = _context.getTestResourcePath(); + fs::path mapPath = _context.getTestProjectPath(); mapPath /= modRelativePath; + EXPECT_TRUE(os::fileOrDirExists(mapPath)); GlobalCommandSystem().executeCommand("OpenMap", modRelativePath); checkAltarScene(); @@ -885,7 +886,7 @@ TEST_F(MapSavingTest, saveArchivedMapWillAskForFilename) { // A map that has been loaded from an archive file is not writeable // the map saving algorithm should detect this and ask for a new file location - auto pakPath = fs::path(_context.getTestResourcePath()) / ".." / "map_loading_test.pk4"; + auto pakPath = fs::path(_context.getTestResourcePath()) / "map_loading_test.pk4"; std::string archiveRelativePath = "maps/altar_packed.map"; GlobalCommandSystem().executeCommand("OpenMapFromArchive", pakPath.string(), archiveRelativePath); diff --git a/test/VFS.cpp b/test/VFS.cpp index 00d7fbb679..45a1d4bbf4 100644 --- a/test/VFS.cpp +++ b/test/VFS.cpp @@ -59,15 +59,15 @@ TEST_F(VfsTest, GetArchiveFileInfo) EXPECT_EQ(foundFiles.count(fileInPak), 1); // file in pk4 // Get the file size of example.mtr - fs::path physicalFilePath = _context.getTestResourcePath(); + fs::path physicalFilePath = _context.getTestProjectPath(); physicalFilePath /= physicalFile; - fs::path pk4Path = _context.getTestResourcePath(); + fs::path pk4Path = _context.getTestProjectPath(); pk4Path /= "tdm_example_mtrs.pk4"; EXPECT_EQ(foundFiles.find(physicalFile)->second.getSize(), os::getFileSize(physicalFilePath.string())); EXPECT_EQ(foundFiles.find(physicalFile)->second.getIsPhysicalFile(), true); - EXPECT_EQ(foundFiles.find(physicalFile)->second.getArchivePath(), _context.getTestResourcePath()); + EXPECT_EQ(foundFiles.find(physicalFile)->second.getArchivePath(), _context.getTestProjectPath()); EXPECT_EQ(foundFiles.find(fileInPak)->second.getSize(), 1096); // that file should have 1096 bytes EXPECT_EQ(foundFiles.find(fileInPak)->second.getIsPhysicalFile(), false); @@ -158,7 +158,7 @@ TEST_F(VfsTest, assetsLstFileHandling) TEST_F(VfsTest, openArchiveInAbsolutePath) { - fs::path pk4Path = _context.getTestResourcePath(); + fs::path pk4Path = _context.getTestProjectPath(); pk4Path /= "tdm_example_mtrs.pk4"; auto archive = GlobalFileSystem().openArchiveInAbsolutePath(pk4Path.string()); @@ -178,7 +178,7 @@ TEST_F(VfsTest, openArchiveInAbsolutePath) TEST_F(VfsTest, VisitEachFileInArchive) { - fs::path pk4Path = _context.getTestResourcePath(); + fs::path pk4Path = _context.getTestProjectPath(); pk4Path /= "tdm_example_mtrs.pk4"; // Use a visitor to walk the tree @@ -199,7 +199,7 @@ TEST_F(VfsTest, VisitEachFileInAbsolutePath) // Use a visitor to walk the tree std::set foundFiles; GlobalFileSystem().forEachFileInAbsolutePath( - _context.getTestResourcePath(), "*", + _context.getTestProjectPath(), "*", [&](const vfs::FileInfo& fi) { foundFiles.insert(fi.name); }, 0 );