Skip to content

Commit

Permalink
#5108: Fix unit tests after TestContext API change
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 30, 2020
1 parent e10a696 commit c9c505a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions radiantcore/settings/GameManager.cpp
Expand Up @@ -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;
Expand Down
25 changes: 13 additions & 12 deletions test/MapSavingLoading.cpp
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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));

Expand All @@ -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));
Expand All @@ -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));

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test/VFS.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -199,7 +199,7 @@ TEST_F(VfsTest, VisitEachFileInAbsolutePath)
// Use a visitor to walk the tree
std::set<std::string> foundFiles;
GlobalFileSystem().forEachFileInAbsolutePath(
_context.getTestResourcePath(), "*",
_context.getTestProjectPath(), "*",
[&](const vfs::FileInfo& fi) { foundFiles.insert(fi.name); },
0
);
Expand Down

0 comments on commit c9c505a

Please sign in to comment.