Skip to content

Commit

Permalink
Add medium plugin methods to PluginInterface
Browse files Browse the repository at this point in the history
Lots of test changes to use the Starfield test plugins.
  • Loading branch information
Ortham committed Jun 24, 2024
1 parent 2cae218 commit c5b3ef0
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 123 deletions.
4 changes: 2 additions & 2 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ FetchContent_Declare(

FetchContent_Declare(
testing-plugins
URL "https://github.com/Ortham/testing-plugins/archive/1.5.0.tar.gz"
URL_HASH "SHA256=98c9094fb0f0152b1af7a6206950207f7ddc6602cd44ed67ebf70603ef490791")
URL "https://github.com/Ortham/testing-plugins/archive/1.6.1.tar.gz"
URL_HASH "")

FetchContent_MakeAvailable(GTest testing-plugins)

Expand Down
13 changes: 13 additions & 0 deletions include/loot/plugin_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class PluginInterface {
*/
virtual bool IsLightPlugin() const = 0;

/**
* Check if the plugin is a medium plugin.
* @return True if plugin is a medium plugin, false otherwise.
*/
virtual bool IsMediumPlugin() const = 0;

/**
* Check if the plugin is an override plugin.
* @return True if plugin is an override plugin, false otherwise.
Expand All @@ -112,6 +118,13 @@ class PluginInterface {
*/
virtual bool IsValidAsLightPlugin() const = 0;

/**
* Check if the plugin is or would be valid as a medium plugin.
* @return True if the plugin is a valid medium plugin or would be a valid
* medium plugin, false otherwise.
*/
virtual bool IsValidAsMediumPlugin() const = 0;

/**
* Check if the plugin is or would be valid as an override plugin.
* @return True if the plugin is a valid override plugin or would be a valid
Expand Down
2 changes: 1 addition & 1 deletion src/api/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void Game::LoadPlugins(const std::vector<std::filesystem::path>& pluginPaths,
}
});

if (GetType() == GameType::starfield) {
if (!loadHeadersOnly && GetType() == GameType::starfield) {
auto plugins = cache_.GetPlugins();
const auto pluginsMetadata = Plugin::GetPluginsMetadata(plugins);
for (auto& plugin : plugins) {
Expand Down
18 changes: 18 additions & 0 deletions src/api/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ bool Plugin::IsLightPlugin() const {
return isLightPlugin;
}

bool Plugin::IsMediumPlugin() const {
bool isMediumPlugin = false;
const auto ret = esp_plugin_is_medium_plugin(esPlugin.get(), &isMediumPlugin);
HandleEspluginError("check if \"" + name_ + "\" is a medium plugin", ret);

return isMediumPlugin;
}

bool Plugin::IsOverridePlugin() const {
bool isOverridePlugin = false;
const auto ret =
Expand All @@ -326,6 +334,16 @@ bool Plugin::IsValidAsLightPlugin() const {
return isValid;
}

bool Plugin::IsValidAsMediumPlugin() const {
bool isValid = false;
const auto ret =
esp_plugin_is_valid_as_medium_plugin(esPlugin.get(), &isValid);
HandleEspluginError("check if \"" + name_ + "\" is valid as a medium plugin",
ret);

return isValid;
}

bool Plugin::IsValidAsOverridePlugin() const {
bool isValid = false;
const auto ret =
Expand Down
2 changes: 2 additions & 0 deletions src/api/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ class Plugin final : public PluginSortingInterface {
bool IsMaster() const override;

bool IsLightPlugin() const override;
bool IsMediumPlugin() const override;
bool IsOverridePlugin() const override;

bool IsValidAsLightPlugin() const override;
bool IsValidAsMediumPlugin() const override;
bool IsValidAsOverridePlugin() const override;
bool IsEmpty() const override;
bool LoadsArchive() const override;
Expand Down
130 changes: 87 additions & 43 deletions src/tests/api/interface/game_interface_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ namespace test {
class GameInterfaceTest : public ApiGameOperationsTest {
protected:
GameInterfaceTest() :
emptyFile("EmptyFile.esm"),
nonAsciiEsm(u8"non\u00C1scii.esm"),
pluginsToLoad({
// These are all ASCII filenames.
emptyFile("EmptyFile.esm"), nonAsciiEsm(u8"non\u00C1scii.esm") {
// Make sure the plugin with a non-ASCII filename exists.
std::filesystem::copy_file(dataPath / blankEsm,
dataPath / std::filesystem::u8path(nonAsciiEsm));

if (GetParam() == GameType::starfield) {
pluginsToLoad = {
masterFile,
blankEsm,
blankFullEsm,
blankMasterDependentEsm,
blankEsp,
blankMasterDependentEsp,
};
} else {
pluginsToLoad = {
masterFile,
blankEsm,
blankDifferentEsm,
Expand All @@ -48,15 +60,13 @@ class GameInterfaceTest : public ApiGameOperationsTest {
blankDifferentMasterDependentEsp,
blankPluginDependentEsp,
blankDifferentPluginDependentEsp,
}) {
// Make sure the plugin with a non-ASCII filename exists.
std::filesystem::copy_file(dataPath / blankEsm,
dataPath / std::filesystem::u8path(nonAsciiEsm));
};
}
}

const std::string emptyFile;
const std::string nonAsciiEsm;
const std::vector<std::filesystem::path> pluginsToLoad;
std::vector<std::filesystem::path> pluginsToLoad;
};

// Pass an empty first argument, as it's a prefix for the test instantation,
Expand Down Expand Up @@ -108,7 +118,11 @@ TEST_P(
GameInterfaceTest,
loadPluginsWithHeadersOnlyTrueShouldLoadTheHeadersOfAllInstalledPlugins) {
handle_->LoadPlugins(pluginsToLoad, true);
EXPECT_EQ(11, handle_->GetLoadedPlugins().size());
if (GetParam() == GameType::starfield) {
EXPECT_EQ(6, handle_->GetLoadedPlugins().size());
} else {
EXPECT_EQ(11, handle_->GetLoadedPlugins().size());
}

// Check that one plugin's header has been read.
ASSERT_NO_THROW(handle_->GetPlugin(masterFile));
Expand All @@ -132,7 +146,11 @@ TEST_P(GameInterfaceTest, loadPluginsShouldTrimDotGhostFileExtensions) {
TEST_P(GameInterfaceTest,
loadPluginsWithHeadersOnlyFalseShouldFullyLoadAllInstalledPlugins) {
handle_->LoadPlugins(pluginsToLoad, false);
EXPECT_EQ(11, handle_->GetLoadedPlugins().size());
if (GetParam() == GameType::starfield) {
EXPECT_EQ(6, handle_->GetLoadedPlugins().size());
} else {
EXPECT_EQ(11, handle_->GetLoadedPlugins().size());
}

// Check that one plugin's header has been read.
ASSERT_NO_THROW(handle_->GetPlugin(masterFile));
Expand Down Expand Up @@ -165,19 +183,31 @@ TEST_P(GameInterfaceTest,
}

TEST_P(GameInterfaceTest, sortPluginsShouldSucceedIfPassedValidArguments) {
std::vector<std::string> expectedOrder = {
masterFile,
blankEsm,
blankMasterDependentEsm,
blankDifferentEsm,
blankDifferentMasterDependentEsm,
blankMasterDependentEsp,
blankDifferentMasterDependentEsp,
blankEsp,
blankPluginDependentEsp,
blankDifferentEsp,
blankDifferentPluginDependentEsp,
};
std::vector<std::string> expectedOrder;
if (GetParam() == GameType::starfield) {
expectedOrder = {
masterFile,
blankEsm,
blankFullEsm,
blankMasterDependentEsm,
blankEsp,
blankMasterDependentEsp,
};
} else {
expectedOrder = {
masterFile,
blankEsm,
blankMasterDependentEsm,
blankDifferentEsm,
blankDifferentMasterDependentEsm,
blankMasterDependentEsp,
blankDifferentMasterDependentEsp,
blankEsp,
blankPluginDependentEsp,
blankDifferentEsp,
blankDifferentPluginDependentEsp,
};
}

if (GetParam() == GameType::fo4 || GetParam() == GameType::tes5se) {
expectedOrder.insert(expectedOrder.begin() + 5, blankEsl);
Expand All @@ -186,7 +216,7 @@ TEST_P(GameInterfaceTest, sortPluginsShouldSucceedIfPassedValidArguments) {
ASSERT_NO_THROW(GenerateMasterlist());
ASSERT_NO_THROW(handle_->GetDatabase().LoadLists(masterlistPath, ""));

std::vector<std::filesystem::path> pluginsToSort({
/*std::vector<std::filesystem::path> pluginsToSort({
// These are all ASCII filenames.
blankEsp,
blankPluginDependentEsp,
Expand All @@ -199,14 +229,14 @@ TEST_P(GameInterfaceTest, sortPluginsShouldSucceedIfPassedValidArguments) {
blankEsm,
blankMasterDependentEsm,
blankDifferentEsm,
});
});*/

if (GetParam() == GameType::fo4 || GetParam() == GameType::tes5se) {
pluginsToSort.push_back(blankEsl);
pluginsToLoad.push_back(blankEsl);
}

handle_->LoadCurrentLoadOrderState();
std::vector<std::string> actualOrder = handle_->SortPlugins(pluginsToSort);
std::vector<std::string> actualOrder = handle_->SortPlugins(pluginsToLoad);

EXPECT_EQ(expectedOrder, actualOrder);
}
Expand Down Expand Up @@ -245,27 +275,41 @@ TEST_P(GameInterfaceTest, setLoadOrderShouldSetTheLoadOrder) {
handle_->SetAdditionalDataPaths({});

handle_->LoadCurrentLoadOrderState();
std::vector<std::string> loadOrder({
masterFile,
blankEsm,
blankMasterDependentEsm,
blankDifferentEsm,
blankDifferentMasterDependentEsm,
blankDifferentEsp,
blankDifferentPluginDependentEsp,
blankEsp,
blankMasterDependentEsp,
blankDifferentMasterDependentEsp,
blankPluginDependentEsp,
});

const auto gameSupportsEsl =
GetParam() == GameType::fo4 || GetParam() == GameType::fo4vr ||
GetParam() == GameType::tes5se || GetParam() == GameType::tes5vr ||
GetParam() == GameType::starfield;

if (gameSupportsEsl) {
loadOrder.insert(loadOrder.begin() + 5, blankEsl);
std::vector<std::string> loadOrder;
if (GetParam() == GameType::starfield) {
loadOrder = {
masterFile,
blankEsm,
blankMasterDependentEsm,
blankDifferentEsm,
blankDifferentEsp,
blankEsp,
blankMasterDependentEsp,
};
} else {
loadOrder = {
masterFile,
blankEsm,
blankMasterDependentEsm,
blankDifferentEsm,
blankDifferentMasterDependentEsm,
blankDifferentEsp,
blankDifferentPluginDependentEsp,
blankEsp,
blankMasterDependentEsp,
blankDifferentMasterDependentEsp,
blankPluginDependentEsp,
};

if (gameSupportsEsl) {
loadOrder.insert(loadOrder.begin() + 5, blankEsl);
}
}

EXPECT_NO_THROW(handle_->SetLoadOrder(loadOrder));
Expand Down
55 changes: 38 additions & 17 deletions src/tests/api/internals/game/game_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,34 @@ class GameTest : public CommonGameTestFixture {
}

void loadInstalledPlugins(Game& game, bool headersOnly) {
const std::vector<std::filesystem::path> plugins({
// These are all ASCII filenames.
masterFile,
blankEsm,
blankDifferentEsm,
blankMasterDependentEsm,
blankDifferentMasterDependentEsm,
blankEsp,
blankDifferentEsp,
blankMasterDependentEsp,
blankDifferentMasterDependentEsp,
blankPluginDependentEsp,
blankDifferentPluginDependentEsp,
});
game.LoadPlugins(plugins, headersOnly);
if (GetParam() == GameType::starfield) {
const std::vector<std::filesystem::path> plugins({
// These are all ASCII filenames.
masterFile,
blankEsm,
blankFullEsm,
blankMasterDependentEsm,
blankEsp,
blankMasterDependentEsp,
});
game.LoadPlugins(plugins, headersOnly);
} else {
const std::vector<std::filesystem::path> plugins({
// These are all ASCII filenames.
masterFile,
blankEsm,
blankDifferentEsm,
blankMasterDependentEsm,
blankDifferentMasterDependentEsm,
blankEsp,
blankDifferentEsp,
blankMasterDependentEsp,
blankDifferentMasterDependentEsp,
blankPluginDependentEsp,
blankDifferentPluginDependentEsp,
});
game.LoadPlugins(plugins, headersOnly);
}
}

const std::string blankArchive;
Expand Down Expand Up @@ -215,7 +228,11 @@ TEST_P(
Game game = Game(GetParam(), dataPath.parent_path(), localPath);

EXPECT_NO_THROW(loadInstalledPlugins(game, true));
EXPECT_EQ(11, game.GetCache().GetPlugins().size());
if (GetParam() == GameType::starfield) {
EXPECT_EQ(6, game.GetCache().GetPlugins().size());
} else {
EXPECT_EQ(11, game.GetCache().GetPlugins().size());
}

// Check that one plugin's header has been read.
ASSERT_NO_THROW(game.GetPlugin(masterFile));
Expand Down Expand Up @@ -259,7 +276,11 @@ TEST_P(GameTest,
Game game = Game(GetParam(), dataPath.parent_path(), localPath);

EXPECT_NO_THROW(loadInstalledPlugins(game, false));
EXPECT_EQ(11, game.GetCache().GetPlugins().size());
if (GetParam() == GameType::starfield) {
EXPECT_EQ(6, game.GetCache().GetPlugins().size());
} else {
EXPECT_EQ(11, game.GetCache().GetPlugins().size());
}

// Check that one plugin's header has been read.
ASSERT_NO_THROW(game.GetPlugin(blankEsm));
Expand Down
Loading

0 comments on commit c5b3ef0

Please sign in to comment.