Skip to content

Commit

Permalink
Fix some tests on linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
Idhrendur committed Jan 13, 2025
1 parent 950385c commit 065a7aa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 23)
set (UNICODE_DEFAULT OFF)

if (PLATFORM STREQUAL "Windows")
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE -DWINDOWS)
elseif (PLATFORM STREQUAL "Linux")
#set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*)
if (COVERAGE STREQUAL true)
Expand Down
2 changes: 1 addition & 1 deletion tests/CommonItemsTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX20_U8PATH_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WINDOWS;NDEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX20_U8PATH_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp20</LanguageStandard>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);../external/googletest/googletest;../external/googletest/googletest/include;../external/googletest/googlemock;../external/googletest/googlemock/include</AdditionalIncludeDirectories>
Expand Down
32 changes: 32 additions & 0 deletions tests/ModLoaderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ TEST(ModLoaderTests, ModsByPathCanBeLocatedUnpackedAndUpdated)

ASSERT_EQ(mods.size(), 1);
EXPECT_EQ(mods[0].name, "The Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod\\themodsfolder/");
#else
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod/themodsfolder/");
#endif
EXPECT_THAT(mods[0].dependencies, UnorderedElementsAre("Packed Mod", "Missing Mod"));
#pragma warning(pop)
}
Expand All @@ -68,7 +72,11 @@ TEST(ModLoaderTests, ModsByNameCanBeLocatedUnpackedAndUpdated)

ASSERT_EQ(mods.size(), 1);
EXPECT_EQ(mods[0].name, "The Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod\\themodsfolder/");
#else
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod/themodsfolder/");
#endif
EXPECT_THAT(mods[0].dependencies, UnorderedElementsAre("Packed Mod", "Missing Mod"));
#pragma warning(pop)
}
Expand All @@ -88,7 +96,11 @@ TEST(ModLoaderTests, ModsByNameCanBeLocatedByMetadataUnpackedAndUpdated)

ASSERT_EQ(mods.size(), 1);
EXPECT_EQ(mods[0].name, "The Metadata Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod\\the_metadata_mod/");
#else
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod/the_metadata_mod/");
#endif
EXPECT_THAT(mods[0].replacedFolders, testing::UnorderedElementsAre("replaced/path", "replaced/path/two"));
#pragma warning(pop)
}
Expand All @@ -111,7 +123,11 @@ TEST(ModLoaderTests, BrokenMissingAndNonexistentModsAreDiscarded)

ASSERT_EQ(mods.size(), 1);
EXPECT_EQ(mods[0].name, "The Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod\\themodsfolder/");
#else
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod/themodsfolder/");
#endif
#pragma warning(pop)
}

Expand All @@ -130,7 +146,11 @@ TEST(ModLoaderTests, CompressedModsCanBeUnpacked)

ASSERT_EQ(mods.size(), 1);
EXPECT_EQ(mods[0].name, "Packed Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[0].path.string(), "mods\\packedmod/");
#else
EXPECT_EQ(mods[0].path.string(), "mods/packedmod/");
#endif
EXPECT_TRUE(commonItems::DoesFolderExist(mods[0].path));
#pragma warning(pop)
}
Expand Down Expand Up @@ -167,13 +187,25 @@ TEST(ModLoaderTests, MultipleModDirectoriesCanBeLoaded)

ASSERT_EQ(mods.size(), 3);
EXPECT_EQ(mods[0].name, "The Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder\\mod\\themodsfolder");
#else
EXPECT_EQ(mods[0].path.string(), "GameDocumentsFolder/mod/themodsfolder");
#endif
EXPECT_THAT(mods[0].dependencies, UnorderedElementsAre("Packed Mod", "Missing Mod"));
EXPECT_EQ(mods[1].name, "The Metadata Mod Two");
#ifdef WINDOWS
EXPECT_EQ(mods[1].path.string(), "SteamModsFolder\\529340\\the_metadata_mod_two");
#else
EXPECT_EQ(mods[1].path.string(), "SteamModsFolder/529340/the_metadata_mod_two");
#endif
EXPECT_THAT(mods[1].replacedFolders, testing::UnorderedElementsAre("replaced/path", "replaced/path/two"));
EXPECT_EQ(mods[2].name, "The Metadata Mod");
#ifdef WINDOWS
EXPECT_EQ(mods[2].path.string(), "GameDocumentsFolder\\mod\\the_metadata_mod");
#else
EXPECT_EQ(mods[2].path.string(), "GameDocumentsFolder/mod/the_metadata_mod");
#endif
EXPECT_THAT(mods[2].replacedFolders, testing::UnorderedElementsAre("replaced/path", "replaced/path/two"));
}

Expand Down
29 changes: 25 additions & 4 deletions tests/ModParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ TEST(ModParserTests, modPrimitivesCanBeSet)
EXPECT_EQ("modPath", theMod.getPath());
EXPECT_EQ(path("modPath"), theMod.getFilesystemPath());
EXPECT_THAT(theMod.getDependencies(), UnorderedElementsAre("dep1", "dep2"));
#ifdef WINDOWS
EXPECT_THAT(theMod.getReplacedPaths(), UnorderedElementsAre("replaced\\path", "replaced\\path\\two"));
#else
EXPECT_THAT(theMod.getReplacedPaths(), UnorderedElementsAre("replaced/path", "replaced/path/two"));
#endif
EXPECT_THAT(theMod.getFilesystemReplacedPaths(), UnorderedElementsAre(path("replaced/path"), path("replaced/path/two")));

commonItems::ModParser the_mod_file;
Expand All @@ -64,7 +68,11 @@ TEST(ModParserTests, modPrimitivesCanBeSet)
EXPECT_EQ(the_mod_file.getPath(), "modPath");
EXPECT_EQ(the_mod_file.getFilesystemPath(), path("modPath"));
EXPECT_THAT(the_mod_file.getDependencies(), UnorderedElementsAre("dep1", "dep2"));
#ifdef WINDOWS
EXPECT_THAT(the_mod_file.getReplacedPaths(), UnorderedElementsAre("replaced\\path", "replaced\\path\\two"));
#else
EXPECT_THAT(the_mod_file.getReplacedPaths(), UnorderedElementsAre("replaced/path", "replaced/path/two"));
#endif
EXPECT_THAT(the_mod_file.getFilesystemReplacedPaths(), UnorderedElementsAre(path("replaced/path"), path("replaced/path/two")));
#pragma warning(pop)
}
Expand All @@ -91,10 +99,15 @@ TEST(ModParserTests, metadataPrimitivesDefaultToBlank)
the_mod_file.parseMetadata(std::string("some_nonexistent_path/empty_mod/metadata/.metadata.json")); // doesn't exist

EXPECT_TRUE(the_mod_file.getName().empty());
EXPECT_EQ(the_mod_file.getPath(),
"some_nonexistent_path\\empty_mod"); // path is derived from the path itself, so the path is filled out even with an empty/missing file
EXPECT_EQ(the_mod_file.getFilesystemPath(),
path("some_nonexistent_path/empty_mod")); // path is derived from the path itself, so the path is filled out even with an empty/missing file
#ifdef WINDOWS
// path is derived from the path itself, so the path is filled out even with an empty/missing file
EXPECT_EQ(the_mod_file.getPath(), "some_nonexistent_path\\empty_mod");
#else
// path is derived from the path itself, so the path is filled out even with an empty/missing file
EXPECT_EQ(the_mod_file.getPath(), "some_nonexistent_path/empty_mod");
#endif
// path is derived from the path itself, so the path is filled out even with an empty/missing file
EXPECT_EQ(the_mod_file.getFilesystemPath(), path("some_nonexistent_path/empty_mod"));
EXPECT_TRUE(the_mod_file.getDependencies().empty());
EXPECT_TRUE(the_mod_file.getReplacedPaths().empty());
EXPECT_TRUE(the_mod_file.getFilesystemReplacedPaths().empty());
Expand Down Expand Up @@ -123,7 +136,11 @@ TEST(ModParserTests, metadataPrimitivesCanBeSet)
EXPECT_TRUE(theMod.getPath().empty()); // path is derived from the path itself, so a stream leaves no path
EXPECT_TRUE(theMod.getFilesystemPath().empty()); // path is derived from the path itself, so a stream leaves no path
EXPECT_TRUE(theMod.getDependencies().empty()); // dependencies are unknown for now
#ifdef WINDOWS
EXPECT_THAT(theMod.getReplacedPaths(), UnorderedElementsAre("replaced\\path", "replaced\\path\\two"));
#else
EXPECT_THAT(theMod.getReplacedPaths(), UnorderedElementsAre("replaced/path", "replaced/path/two"));
#endif
EXPECT_THAT(theMod.getFilesystemReplacedPaths(), UnorderedElementsAre(path("replaced/path"), path("replaced/path/two")));

commonItems::ModParser the_mod_file;
Expand All @@ -134,7 +151,11 @@ TEST(ModParserTests, metadataPrimitivesCanBeSet)
EXPECT_EQ(the_mod_file.getPath(), "mod\\parseable_metadata");
EXPECT_EQ(the_mod_file.getFilesystemPath(), path("mod/parseable_metadata"));
EXPECT_TRUE(the_mod_file.getDependencies().empty()); // dependencies are unknown for now
#ifdef WINDOWS
EXPECT_THAT(the_mod_file.getReplacedPaths(), UnorderedElementsAre("replaced\\path", "replaced\\path\\two"));
#else
EXPECT_THAT(the_mod_file.getReplacedPaths(), UnorderedElementsAre("replaced/path", "replaced/path/two"));
#endif
EXPECT_THAT(the_mod_file.getFilesystemReplacedPaths(), UnorderedElementsAre(path("replaced/path"), path("replaced/path/two")));
#pragma warning(pop)
}
Expand Down

0 comments on commit 065a7aa

Please sign in to comment.