diff --git a/src/backend/plugin/plugin.cpp b/src/backend/plugin/plugin.cpp index 63788182..4ee16193 100644 --- a/src/backend/plugin/plugin.cpp +++ b/src/backend/plugin/plugin.cpp @@ -94,12 +94,12 @@ namespace loot { // Get whether the plugin loads an archive (BSA/BA2) or not. const string archiveExtension = game.getArchiveFileExtension(); - if (game.Id() == Game::tes5 || game.Id() == Game::fo4) { - // Skyrim and Fallout 4 plugins only load archives that exactly match their basename. + if (game.Id() == Game::tes5) { + // Skyrim plugins only load BSAs that exactly match their basename. _loadsArchive = boost::filesystem::exists(game.DataPath() / (Name().substr(0, Name().length() - 4) + archiveExtension)); } else if (game.Id() != Game::tes4 || boost::iends_with(Name(), ".esp")) { - //Oblivion .esp files and FO3, FNV plugins can load BSAs which begin with the plugin basename. + //Oblivion .esp files and FO3, FNV, FO4 plugins can load archives which begin with the plugin basename. string basename = Name().substr(0, Name().length() - 4); for (boost::filesystem::directory_iterator it(game.DataPath()); it != boost::filesystem::directory_iterator(); ++it) { if (boost::iequals(it->path().extension().string(), archiveExtension) && boost::istarts_with(it->path().filename().string(), basename)) { diff --git a/src/tests/backend/plugin/plugin_test.h b/src/tests/backend/plugin/plugin_test.h index f29def82..bf3a2826 100644 --- a/src/tests/backend/plugin/plugin_test.h +++ b/src/tests/backend/plugin/plugin_test.h @@ -34,7 +34,9 @@ namespace loot { protected: PluginTest() : emptyFile("EmptyFile.esm"), - nonPluginFile("NotAPlugin.esm") {} + nonPluginFile("NotAPlugin.esm"), + blankArchive("Blank" + Game(GetParam()).getArchiveFileExtension()), + blankSuffixArchive("Blank - Different - suffix" + Game(GetParam()).getArchiveFileExtension()) {} inline void SetUp() { BaseGameTest::SetUp(); @@ -54,11 +56,11 @@ namespace loot { out.close(); ASSERT_TRUE(boost::filesystem::exists(dataPath / nonPluginFile)); - if (GetParam() == GameSettings::tes4 || GetParam() == GameSettings::fo4) { - // Create a dummy BSA file. - out.open(dataPath / getArchiveName()); - out.close(); - } + // Create dummy archive files. + out.open(dataPath / blankArchive); + out.close(); + out.open(dataPath / blankSuffixArchive); + out.close(); } inline void TearDown() { @@ -66,23 +68,16 @@ namespace loot { boost::filesystem::remove(dataPath / emptyFile); boost::filesystem::remove(dataPath / nonPluginFile); - - if (GetParam() == GameSettings::tes4 || GetParam() == GameSettings::fo4) - boost::filesystem::remove(dataPath / getArchiveName()); + boost::filesystem::remove(dataPath / blankArchive); + boost::filesystem::remove(dataPath / blankSuffixArchive); } Game game; const std::string emptyFile; const std::string nonPluginFile; - - private: - inline std::string getArchiveName() { - if (GetParam() == GameSettings::fo4) - return "Blank.ba2"; - else - return "Blank.bsa"; - } + const std::string blankArchive; + const std::string blankSuffixArchive; }; // Pass an empty first argument, as it's a prefix for the test instantation, @@ -149,12 +144,39 @@ namespace loot { }), plugin.getMasters()); } - TEST_P(PluginTest, loadsArchiveShouldReturnTrueForAPluginThatLoadsAnArchive) { + TEST_P(PluginTest, loadsArchiveForAnArchiveThatExactlyMatchesAnEsmFileBasenameShouldReturnTrueForAllGamesExceptOblivion) { + bool loadsArchive = Plugin(game, blankEsm, true).LoadsArchive(); + + if (GetParam() == Game::tes4) + EXPECT_FALSE(loadsArchive); + else + EXPECT_TRUE(loadsArchive); + } + + TEST_P(PluginTest, loadsArchiveForAnArchiveThatExactlyMatchesAnEspFileBasenameShouldReturnTrue) { EXPECT_TRUE(Plugin(game, blankEsp, true).LoadsArchive()); } + TEST_P(PluginTest, loadsArchiveForAnArchiveWithAFilenameWhichStartsWithTheEsmFileBasenameShouldReturnTrueForAllGamesExceptOblivionAndSkyrim) { + bool loadsArchive = Plugin(game, blankDifferentEsm, true).LoadsArchive(); + + if (GetParam() == Game::tes4 || GetParam() == Game::tes5) + EXPECT_FALSE(loadsArchive); + else + EXPECT_TRUE(loadsArchive); + } + + TEST_P(PluginTest, loadsArchiveForAnArchiveWithAFilenameWhichStartsWithTheEspFileBasenameShouldReturnTrueForAllGamesExceptSkyrim) { + bool loadsArchive = Plugin(game, blankDifferentEsp, true).LoadsArchive(); + + if (GetParam() == Game::tes5) + EXPECT_FALSE(loadsArchive); + else + EXPECT_TRUE(loadsArchive); + } + TEST_P(PluginTest, loadsArchiveShouldReturnFalseForAPluginThatDoesNotLoadAnArchive) { - EXPECT_FALSE(Plugin(game, blankDifferentEsm, true).LoadsArchive()); + EXPECT_FALSE(Plugin(game, blankMasterDependentEsp, true).LoadsArchive()); } TEST_P(PluginTest, loadsArchiveShouldReturnFalseForAPluginWithARegexFilename) {