diff --git a/CMakeLists.txt b/CMakeLists.txt
index d94e2d44..f69f74cc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -215,10 +215,26 @@ set (LOOT_TESTS_SRC ${LOOT_SRC}
"${CMAKE_SOURCE_DIR}/src/gui/loot_state.cpp"
"${CMAKE_SOURCE_DIR}/src/tests/main.cpp")
-set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/fixtures.h"
+set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/fixtures.h"
"${CMAKE_SOURCE_DIR}/src/tests/printers.h"
+
+ "${CMAKE_SOURCE_DIR}/src/tests/api/api_game_operations_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_apply_load_order_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_create_db_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_db_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_eval_lists_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_get_dirty_info_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_get_masterlist_revision_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_get_plugin_messages_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_get_plugin_tags_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_get_tag_map_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_load_lists_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_sort_plugins_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_update_masterlist_test.h"
+ "${CMAKE_SOURCE_DIR}/src/tests/api/loot_write_minimal_list_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/api/test_api.h"
- "${CMAKE_SOURCE_DIR}/src/tests/api/test_loot_db.h"
+
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game_cache.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/game/test_game_settings.h"
diff --git a/src/tests/api/api_game_operations_test.h b/src/tests/api/api_game_operations_test.h
new file mode 100644
index 00000000..3216f91f
--- /dev/null
+++ b/src/tests/api/api_game_operations_test.h
@@ -0,0 +1,118 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2013-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_API_GAME_OPERATIONS_TEST
+#define LOOT_TEST_API_GAME_OPERATIONS_TEST
+
+#include "../base_game_test.h"
+
+namespace loot {
+ namespace test {
+ class ApiGameOperationsTest : public BaseGameTest {
+ protected:
+ ApiGameOperationsTest() :
+ db(nullptr),
+ masterlistPath(localPath / "masterlist.yaml"),
+ noteMessage("Do not clean ITM records, they are intentional and required for the mod to function."),
+ warningMessage("Check you are using v2+. If not, Update. v1 has a severe bug with the Mystic Emporium disappearing."),
+ errorMessage("Obsolete. Remove this and install Enhanced Weather.") {}
+
+ inline virtual void SetUp() {
+ BaseGameTest::SetUp();
+
+ ASSERT_FALSE(boost::filesystem::exists(masterlistPath));
+
+ ASSERT_EQ(loot_ok, loot_create_db(&db, GetParam(), dataPath.parent_path().string().c_str(), localPath.string().c_str()));
+ }
+
+ inline virtual void TearDown() {
+ BaseGameTest::TearDown();
+
+ ASSERT_NO_THROW(loot_destroy_db(db));
+
+ // The masterlist may have been created during the test, so delete it.
+ ASSERT_NO_THROW(boost::filesystem::remove(masterlistPath));
+ }
+
+ inline void generateMasterlist() {
+ using std::endl;
+
+ boost::filesystem::ofstream masterlist(masterlistPath);
+ masterlist
+ << "plugins:" << endl
+ << " - name: " << blankEsm << endl
+ << " after:" << endl
+ << " - " << masterFile << endl
+ << " msg:" << endl
+ << " - type: say" << endl
+ << " content: '" << noteMessage << "'" << endl
+ << " tag:" << endl
+ << " - Actors.ACBS" << endl
+ << " - Actors.AIData" << endl
+ << " - '-C.Water'" << endl
+ << " - name: " << blankDifferentEsm << endl
+ << " after:" << endl
+ << " - " << blankMasterDependentEsm << endl
+ << " msg:" << endl
+ << " - type: warn" << endl
+ << " content: '" << warningMessage << "'" << endl
+ << " dirty:" << endl
+ << " - crc: 0x7d22f9df" << endl
+ << " util: TES4Edit" << endl
+ << " udr: 4" << endl
+ << " - name: " << blankDifferentEsp << endl
+ << " after:" << endl
+ << " - " << blankPluginDependentEsp << endl
+ << " msg:" << endl
+ << " - type: error" << endl
+ << " content: '" << errorMessage << "'" << endl
+ << " - name: " << blankEsp << endl
+ << " after:" << endl
+ << " - " << blankDifferentMasterDependentEsp << endl
+ << " - name: " << blankDifferentMasterDependentEsp << endl
+ << " after:" << endl
+ << " - " << blankMasterDependentEsp << endl
+ << " msg:" << endl
+ << " - type: say" << endl
+ << " content: '" << noteMessage << "'" << endl
+ << " - type: warn" << endl
+ << " content: '" << warningMessage << "'" << endl
+ << " - type: error" << endl
+ << " content: '" << errorMessage << "'" << endl;
+
+ masterlist.close();
+ }
+
+ loot_db * db;
+
+ const boost::filesystem::path masterlistPath;
+
+ const std::string noteMessage;
+ const std::string warningMessage;
+ const std::string errorMessage;
+ };
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_apply_load_order_test.h b/src/tests/api/loot_apply_load_order_test.h
new file mode 100644
index 00000000..e798890f
--- /dev/null
+++ b/src/tests/api/loot_apply_load_order_test.h
@@ -0,0 +1,77 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_APPLY_LOAD_ORDER
+#define LOOT_TEST_LOOT_APPLY_LOAD_ORDER
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_apply_load_order_test : public ApiGameOperationsTest {};
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_apply_load_order_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_apply_load_order_test, shouldReturnAnInvalidArgsIfTheDbOrLoadOrderPointersAreNull) {
+ const char * loadOrder[1] = {
+ masterFile.c_str(),
+ };
+ size_t numPlugins = 0;
+
+ EXPECT_EQ(loot_error_invalid_args, loot_apply_load_order(NULL, loadOrder, numPlugins));
+ EXPECT_EQ(loot_error_invalid_args, loot_apply_load_order(db, NULL, numPlugins));
+ }
+
+ TEST_P(loot_apply_load_order_test, shouldReturnOkIfLoadOrderGivenIsNotEmpty) {
+ const char * loadOrder[11] = {
+ masterFile.c_str(),
+ blankEsm.c_str(),
+ blankMasterDependentEsm.c_str(),
+ blankDifferentEsm.c_str(),
+ blankDifferentMasterDependentEsm.c_str(),
+ blankMasterDependentEsp.c_str(),
+ blankDifferentMasterDependentEsp.c_str(),
+ blankEsp.c_str(),
+ blankPluginDependentEsp.c_str(),
+ blankDifferentEsp.c_str(),
+ blankDifferentPluginDependentEsp.c_str(),
+ };
+ size_t numPlugins = 11;
+
+ EXPECT_EQ(loot_ok, loot_apply_load_order(db, loadOrder, numPlugins));
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_create_db_test.h b/src/tests/api/loot_create_db_test.h
new file mode 100644
index 00000000..09434741
--- /dev/null
+++ b/src/tests/api/loot_create_db_test.h
@@ -0,0 +1,97 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_CREATE_DB
+#define LOOT_TEST_LOOT_CREATE_DB
+
+#include "../include/loot/api.h"
+#include "tests/base_game_test.h"
+
+#include
+
+namespace loot {
+ namespace test {
+ class loot_create_db_test : public BaseGameTest {
+ protected:
+ loot_create_db_test() :
+ db(nullptr) {}
+
+ inline virtual void TearDown() {
+ BaseGameTest::TearDown();
+
+ ASSERT_NO_THROW(loot_destroy_db(db));
+ }
+
+ loot_db * db;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_create_db_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_create_db_test, shouldSucceedIfPassedValidParametersWithRelativePaths) {
+ EXPECT_EQ(loot_ok, loot_create_db(&db, GetParam(), dataPath.parent_path().string().c_str(), localPath.string().c_str()));
+ EXPECT_NE(nullptr, db);
+ }
+
+ TEST_P(loot_create_db_test, shouldSucceedIfPassedValidParametersWithAbsolutePaths) {
+ boost::filesystem::path game = boost::filesystem::current_path() / dataPath.parent_path();
+ boost::filesystem::path local = boost::filesystem::current_path() / localPath;
+
+ EXPECT_EQ(loot_ok, loot_create_db(&db, GetParam(), game.string().c_str(), local.string().c_str()));
+ EXPECT_NE(nullptr, db);
+ }
+
+ TEST_P(loot_create_db_test, shouldReturnAnInvalidArgsErrorIfPassedANullPointer) {
+ EXPECT_EQ(loot_error_invalid_args, loot_create_db(NULL, GetParam(), dataPath.parent_path().string().c_str(), localPath.string().c_str()));
+ }
+
+ TEST_P(loot_create_db_test, shouldReturnAnInvalidArgsErrorIfPassedAnInvalidGameType) {
+ EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, UINT_MAX, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
+ }
+
+ TEST_P(loot_create_db_test, shouldReturnAnInvalidArgsErrorIfPassedAGamePathThatDoesNotExist) {
+ EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, GetParam(), missingPath.string().c_str(), localPath.string().c_str()));
+ }
+
+ TEST_P(loot_create_db_test, shouldReturnAnInvalidArgsErrorIfPassedALocalPathThatDoesNotExist) {
+ EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, GetParam(), dataPath.parent_path().string().c_str(), missingPath.string().c_str()));
+ }
+
+#ifdef _WIN32
+ TEST_P(loot_create_db_test, shouldReturnOkIfPassedANullLocalPathPointer) {
+ EXPECT_EQ(loot_ok, loot_create_db(&db, GetParam(), dataPath.parent_path().string().c_str(), NULL));
+ }
+#endif
+ }
+}
+
+#endif
diff --git a/src/tests/api/test_loot_db.h b/src/tests/api/loot_db_test.h
similarity index 77%
rename from src/tests/api/test_loot_db.h
rename to src/tests/api/loot_db_test.h
index 01f3bd8b..e5d5ed6c 100644
--- a/src/tests/api/test_loot_db.h
+++ b/src/tests/api/loot_db_test.h
@@ -27,30 +27,52 @@ along with LOOT. If not, see
#include "api/loot_db.h"
#include "backend/game/game_settings.h"
-#include "tests/fixtures.h"
+#include "tests/base_game_test.h"
namespace loot {
namespace test {
- class loot_db_test : public SkyrimTest {
+ class loot_db_test : public BaseGameTest {
protected:
- virtual void SetUp() {
- SkyrimTest::SetUp();
+ loot_db_test() :
+ db(nullptr) {}
- db = new loot_db(Game::tes5, dataPath.parent_path().string().c_str(), localPath.string().c_str());
+ virtual void SetUp() {
+ BaseGameTest::SetUp();
+
+ db = new loot_db(GetParam(), dataPath.parent_path().string().c_str(), localPath.string().c_str());
}
+
+ inline virtual void TearDown() {
+ BaseGameTest::TearDown();
+
+ delete db;
+ }
+
+ loot_db * db;
};
- TEST_F(loot_db_test, settingRevisionIdStringShouldCopyIt) {
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_db_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_db_test, settingRevisionIdStringShouldCopyIt) {
db->setRevisionIdString("id");
EXPECT_STREQ("id", db->getRevisionIdString());
}
- TEST_F(loot_db_test, settingRevisionDateStringShouldCopyIt) {
+ TEST_P(loot_db_test, settingRevisionDateStringShouldCopyIt) {
db->setRevisionDateString("date");
EXPECT_STREQ("date", db->getRevisionDateString());
}
- TEST_F(loot_db_test, settingPluginNamesShouldCopyThem) {
+ TEST_P(loot_db_test, settingPluginNamesShouldCopyThem) {
db->setPluginNames(std::vector({
PluginMetadata("Blank.esm"),
PluginMetadata("Blank.esp"),
@@ -61,7 +83,7 @@ namespace loot {
EXPECT_STREQ("Blank.esp", db->getPluginNames()[1]);
}
- TEST_F(loot_db_test, settingPluginNamesTwiceShouldOverwriteTheFirstDataSet) {
+ TEST_P(loot_db_test, settingPluginNamesTwiceShouldOverwriteTheFirstDataSet) {
db->setPluginNames(std::vector({
PluginMetadata("Blank.esm"),
PluginMetadata("Blank.esp"),
@@ -76,7 +98,7 @@ namespace loot {
EXPECT_STREQ("Blank - Different.esp", db->getPluginNames()[1]);
}
- TEST_F(loot_db_test, addingNewBashTagsToTheMapShouldAppendThem) {
+ TEST_P(loot_db_test, addingNewBashTagsToTheMapShouldAppendThem) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -87,7 +109,7 @@ namespace loot {
EXPECT_STREQ("Relev", db->getBashTagMap()[1]);
}
- TEST_F(loot_db_test, addingAnExistingBashTagToTheMapShouldNotDuplicateIt) {
+ TEST_P(loot_db_test, addingAnExistingBashTagToTheMapShouldNotDuplicateIt) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -99,11 +121,11 @@ namespace loot {
EXPECT_STREQ("Relev", db->getBashTagMap()[1]);
}
- TEST_F(loot_db_test, gettingABashTagsUidForATagThatIsNotInTheMapShouldThrow) {
+ TEST_P(loot_db_test, gettingABashTagsUidForATagThatIsNotInTheMapShouldThrow) {
EXPECT_ANY_THROW(db->getBashTagUid("Relev"));
}
- TEST_F(loot_db_test, gettingABashTagsUidShouldReturnItsTagMapIndex) {
+ TEST_P(loot_db_test, gettingABashTagsUidShouldReturnItsTagMapIndex) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -112,11 +134,11 @@ namespace loot {
EXPECT_EQ(1, db->getBashTagUid("Relev"));
}
- TEST_F(loot_db_test, clearingAnEmptyBashTagMapShouldDoNothing) {
+ TEST_P(loot_db_test, clearingAnEmptyBashTagMapShouldDoNothing) {
EXPECT_NO_THROW(db->clearBashTagMap());
}
- TEST_F(loot_db_test, clearingABashTagMapShouldEmptyIt) {
+ TEST_P(loot_db_test, clearingABashTagMapShouldEmptyIt) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -126,7 +148,7 @@ namespace loot {
EXPECT_TRUE(db->getBashTagMap().empty());
}
- TEST_F(loot_db_test, clearingABashTagMapShouldAffectExistingReferences) {
+ TEST_P(loot_db_test, clearingABashTagMapShouldAffectExistingReferences) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -137,13 +159,13 @@ namespace loot {
EXPECT_TRUE(bashTagMap.empty());
}
- TEST_F(loot_db_test, settingAddedTagsWithNoTagMapShouldThrow) {
+ TEST_P(loot_db_test, settingAddedTagsWithNoTagMapShouldThrow) {
EXPECT_ANY_THROW(db->setAddedTags({
"Relev",
}));
}
- TEST_F(loot_db_test, gettingSetAddedTagsShouldReturnTheirUids) {
+ TEST_P(loot_db_test, gettingSetAddedTagsShouldReturnTheirUids) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -158,13 +180,13 @@ namespace loot {
}), db->getAddedTagIds());
}
- TEST_F(loot_db_test, settingRemovedTagsWithNoTagMapShouldThrow) {
+ TEST_P(loot_db_test, settingRemovedTagsWithNoTagMapShouldThrow) {
EXPECT_ANY_THROW(db->setRemovedTags({
"Relev",
}));
}
- TEST_F(loot_db_test, gettingSetRemovedTagsShouldReturnTheirUids) {
+ TEST_P(loot_db_test, gettingSetRemovedTagsShouldReturnTheirUids) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
@@ -179,7 +201,7 @@ namespace loot {
}), db->getRemovedTagIds());
}
- TEST_F(loot_db_test, settingPluginMessagesShouldCopyThem) {
+ TEST_P(loot_db_test, settingPluginMessagesShouldCopyThem) {
db->setPluginMessages(std::list({
Message(Message::warn, "Test 1"),
Message(Message::error, "Test 2"),
@@ -192,7 +214,7 @@ namespace loot {
EXPECT_STREQ("Test 2", db->getPluginMessages()[1].message);
}
- TEST_F(loot_db_test, settingPluginMessagesTwiceShouldOverwriteTheFirstDataSet) {
+ TEST_P(loot_db_test, settingPluginMessagesTwiceShouldOverwriteTheFirstDataSet) {
db->setPluginMessages(std::list({
Message(Message::warn, "Test 1"),
Message(Message::error, "Test 2"),
@@ -212,7 +234,7 @@ namespace loot {
EXPECT_STREQ("Test 5", db->getPluginMessages()[2].message);
}
- TEST_F(loot_db_test, clearingArraysShouldEmptyPluginNamesTagIdsAndMessages) {
+ TEST_P(loot_db_test, clearingArraysShouldEmptyPluginNamesTagIdsAndMessages) {
db->setPluginMessages(std::list({
Message(Message::warn, "Test 1"),
Message(Message::error, "Test 2"),
@@ -247,7 +269,7 @@ namespace loot {
EXPECT_TRUE(db->getRemovedTagIds().empty());
}
- TEST_F(loot_db_test, clearingArraysShouldNotEmptyBashTagMap) {
+ TEST_P(loot_db_test, clearingArraysShouldNotEmptyBashTagMap) {
db->addBashTagsToMap({
"C.Climate",
"Relev",
diff --git a/src/tests/api/loot_eval_lists_test.h b/src/tests/api/loot_eval_lists_test.h
new file mode 100644
index 00000000..bb4f2e01
--- /dev/null
+++ b/src/tests/api/loot_eval_lists_test.h
@@ -0,0 +1,87 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_EVAL_LISTS
+#define LOOT_TEST_LOOT_EVAL_LISTS
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_eval_lists_test : public ApiGameOperationsTest {};
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_eval_lists_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_eval_lists_test, shouldReturnAnInvalidArgsErrorIfPassedANullPointer) {
+ EXPECT_EQ(loot_error_invalid_args, loot_eval_lists(NULL, loot_lang_any));
+ }
+
+ TEST_P(loot_eval_lists_test, shouldReturnAnInvalidArgsErrorIfPassedAnInvalidLanguageCode) {
+ EXPECT_EQ(loot_error_invalid_args, loot_eval_lists(db, UINT_MAX));
+ }
+
+ TEST_P(loot_eval_lists_test, shouldReturnOkForAllLanguagesWithNoListsLoaded) {
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_any));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_english));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_spanish));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_russian));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_french));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_chinese));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_polish));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_brazilian_portuguese));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_finnish));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_german));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_danish));
+ }
+
+ TEST_P(loot_eval_lists_test, shouldReturnOKForAllLanguagesWithAMasterlistLoaded) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_any));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_english));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_spanish));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_russian));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_french));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_chinese));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_polish));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_brazilian_portuguese));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_finnish));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_german));
+ EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_danish));
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_get_dirty_info_test.h b/src/tests/api/loot_get_dirty_info_test.h
new file mode 100644
index 00000000..286512b4
--- /dev/null
+++ b/src/tests/api/loot_get_dirty_info_test.h
@@ -0,0 +1,81 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_GET_DIRTY_INFO
+#define LOOT_TEST_LOOT_GET_DIRTY_INFO
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_get_dirty_info_test : public ApiGameOperationsTest {
+ protected:
+ loot_get_dirty_info_test() :
+ needsCleaning(0) {}
+
+ unsigned int needsCleaning;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_get_dirty_info_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_get_dirty_info_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_get_dirty_info(NULL, blankEsp.c_str(), &needsCleaning));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_dirty_info(db, NULL, &needsCleaning));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_dirty_info(db, blankEsp.c_str(), NULL));
+ }
+
+ TEST_P(loot_get_dirty_info_test, shouldReturnOkAndOutputUnknownForAPluginWithNoDirtyInfo) {
+ EXPECT_EQ(loot_ok, loot_get_dirty_info(db, blankEsp.c_str(), &needsCleaning));
+ EXPECT_EQ(loot_needs_cleaning_unknown, needsCleaning);
+ }
+
+ TEST_P(loot_get_dirty_info_test, shouldReturnOkAndOutputYesForAPluginWithDirtyInfo) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_dirty_info(db, blankDifferentEsm.c_str(), &needsCleaning));
+ EXPECT_EQ(loot_needs_cleaning_yes, needsCleaning);
+ }
+
+ TEST_P(loot_get_dirty_info_test, shouldReturnOkAndOutputNoForAPluginWithADoNotCleanMessage) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_dirty_info(db, blankEsm.c_str(), &needsCleaning));
+ EXPECT_EQ(loot_needs_cleaning_no, needsCleaning);
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_get_masterlist_revision_test.h b/src/tests/api/loot_get_masterlist_revision_test.h
new file mode 100644
index 00000000..5894c540
--- /dev/null
+++ b/src/tests/api/loot_get_masterlist_revision_test.h
@@ -0,0 +1,119 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_GET_MASTERLIST_REVISION
+#define LOOT_TEST_LOOT_GET_MASTERLIST_REVISION
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_get_masterlist_revision_test : public ApiGameOperationsTest {
+ protected:
+ loot_get_masterlist_revision_test() :
+ revisionId("foo"),
+ revisionDate("bar"),
+ isModified(true),
+ updated(false) {}
+
+ const char * revisionId;
+ const char * revisionDate;
+ bool isModified;
+ bool updated;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_get_masterlist_revision_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_get_masterlist_revision_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(NULL, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, &isModified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, NULL, false, &revisionId, &revisionDate, &isModified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, NULL, &revisionDate, &isModified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, NULL, &isModified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, NULL));
+ }
+
+ TEST_P(loot_get_masterlist_revision_test, shouldSucceedIfNoMasterlistIsPresent) {
+ EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, &isModified));
+ EXPECT_EQ(NULL, revisionId);
+ EXPECT_EQ(NULL, revisionDate);
+ EXPECT_FALSE(isModified);
+ }
+
+ TEST_P(loot_get_masterlist_revision_test, shouldSucceedIfANonVersionControlledMasterlistIsPresent) {
+ ASSERT_NO_THROW(generateMasterlist());
+ EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, &isModified));
+ EXPECT_EQ(NULL, revisionId);
+ EXPECT_EQ(NULL, revisionDate);
+ EXPECT_FALSE(isModified);
+ }
+
+ TEST_P(loot_get_masterlist_revision_test, shouldOutputLongStringsAndBooleanFalseIfAVersionControlledMasterlistIsPresentAndGetShortIdParameterIsFalse) {
+ ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+
+ EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, &isModified));
+ EXPECT_STRNE(NULL, revisionId);
+ EXPECT_EQ(40, strlen(revisionId));
+ EXPECT_STRNE(NULL, revisionDate);
+ EXPECT_EQ(10, strlen(revisionDate));
+ EXPECT_FALSE(isModified);
+ }
+
+ TEST_P(loot_get_masterlist_revision_test, shouldOutputShortStringsAndBooleanFalseIfAVersionControlledMasterlistIsPresentAndGetShortIdParameterIsTrue) {
+ ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+
+ EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, &isModified));
+ EXPECT_STRNE(NULL, revisionId);
+ EXPECT_GE(size_t(40), strlen(revisionId));
+ EXPECT_LE(size_t(7), strlen(revisionId));
+ EXPECT_STRNE(NULL, revisionDate);
+ EXPECT_EQ(10, strlen(revisionDate));
+ EXPECT_FALSE(isModified);
+ }
+
+ TEST_P(loot_get_masterlist_revision_test, shouldSucceedIfAnEditedVersionControlledMasterlistIsPresent) {
+ ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+
+ ASSERT_NO_THROW(generateMasterlist());
+ EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionId, &revisionDate, &isModified));
+
+ EXPECT_STRNE(NULL, revisionId);
+ EXPECT_EQ(40, strlen(revisionId));
+ EXPECT_STRNE(NULL, revisionDate);
+ EXPECT_EQ(10, strlen(revisionDate));
+ EXPECT_TRUE(isModified);
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_get_plugin_messages_test.h b/src/tests/api/loot_get_plugin_messages_test.h
new file mode 100644
index 00000000..9ddd0283
--- /dev/null
+++ b/src/tests/api/loot_get_plugin_messages_test.h
@@ -0,0 +1,113 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_GET_PLUGIN_MESSAGES
+#define LOOT_TEST_LOOT_GET_PLUGIN_MESSAGES
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_get_plugin_messages_test : public ApiGameOperationsTest {
+ protected:
+ loot_get_plugin_messages_test() :
+ messages(nullptr),
+ numMessages(0) {}
+
+ const loot_message * messages;
+ size_t numMessages;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_get_plugin_messages_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_get_plugin_messages_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(NULL, blankEsp.c_str(), &messages, &numMessages));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(db, NULL, &messages, &numMessages));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(db, blankEsp.c_str(), NULL, &numMessages));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(db, blankEsp.c_str(), &messages, NULL));
+ }
+
+ TEST_P(loot_get_plugin_messages_test, shouldReturnOkAndOutputANullArrayIfAPluginWithNoMessagesIsQueried) {
+ EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, blankEsp.c_str(), &messages, &numMessages));
+ EXPECT_EQ(0, numMessages);
+ EXPECT_EQ(NULL, messages);
+ }
+
+ TEST_P(loot_get_plugin_messages_test, shouldReturnOkAndOutputANoteIfAPluginWithANoteMessageIsQueried) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, blankEsm.c_str(), &messages, &numMessages));
+ ASSERT_EQ(1, numMessages);
+ EXPECT_EQ(loot_message_say, messages[0].type);
+ EXPECT_STREQ(noteMessage.c_str(), messages[0].message);
+ }
+
+ TEST_P(loot_get_plugin_messages_test, shouldReturnOkAndOutputAWarningIfAPluginWithAWarningMessageIsQueried) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, blankDifferentEsm.c_str(), &messages, &numMessages));
+ ASSERT_EQ(1, numMessages);
+ EXPECT_EQ(loot_message_warn, messages[0].type);
+ EXPECT_STREQ(warningMessage.c_str(), messages[0].message);
+ }
+
+ TEST_P(loot_get_plugin_messages_test, shouldReturnOkAndOutputAnErrorIfAPluginWithAnErrorMessageIsQueried) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, blankDifferentEsp.c_str(), &messages, &numMessages));
+ ASSERT_EQ(1, numMessages);
+ EXPECT_EQ(loot_message_error, messages[0].type);
+ EXPECT_STREQ(errorMessage.c_str(), messages[0].message);
+ }
+
+ TEST_P(loot_get_plugin_messages_test, shouldReturnOkAndOutputMultipleMessagesIfAPluginWithMultipleMessagesIsQueried) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, blankDifferentMasterDependentEsp.c_str(), &messages, &numMessages));
+ ASSERT_EQ(3, numMessages);
+ EXPECT_EQ(loot_message_say, messages[0].type);
+ EXPECT_STREQ(noteMessage.c_str(), messages[0].message);
+ EXPECT_EQ(loot_message_warn, messages[1].type);
+ EXPECT_STREQ(warningMessage.c_str(), messages[1].message);
+ EXPECT_EQ(loot_message_error, messages[2].type);
+ EXPECT_STREQ(errorMessage.c_str(), messages[2].message);
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_get_plugin_tags_test.h b/src/tests/api/loot_get_plugin_tags_test.h
new file mode 100644
index 00000000..49026914
--- /dev/null
+++ b/src/tests/api/loot_get_plugin_tags_test.h
@@ -0,0 +1,140 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_GET_PLUGIN_TAGS
+#define LOOT_TEST_LOOT_GET_PLUGIN_TAGS
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_get_plugin_tags_test : public ApiGameOperationsTest {
+ protected:
+ loot_get_plugin_tags_test() :
+ tagMap(nullptr),
+ numTags(0),
+ added(nullptr),
+ removed(nullptr),
+ numAdded(0),
+ numRemoved(0),
+ modified(false) {}
+
+ const char * const * tagMap;
+ size_t numTags;
+
+ const unsigned int * added;
+ const unsigned int * removed;
+ size_t numAdded;
+ size_t numRemoved;
+ bool modified;
+
+ void getTagMap() {
+ ASSERT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
+
+ ASSERT_EQ(3, numTags);
+ ASSERT_STREQ("Actors.ACBS", tagMap[0]);
+ ASSERT_STREQ("Actors.AIData", tagMap[1]);
+ ASSERT_STREQ("C.Water", tagMap[2]);
+ }
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_get_plugin_tags_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_get_plugin_tags_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(NULL, blankEsm.c_str(), &added, &numAdded, &removed, &numRemoved, &modified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, NULL, &added, &numAdded, &removed, &numRemoved, &modified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, blankEsm.c_str(), NULL, &numAdded, &removed, &numRemoved, &modified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, blankEsm.c_str(), &added, NULL, &removed, &numRemoved, &modified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, blankEsm.c_str(), &added, &numAdded, NULL, &numRemoved, &modified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, blankEsm.c_str(), &added, &numAdded, &removed, NULL, &modified));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, blankEsm.c_str(), &added, &numAdded, &removed, &numRemoved, NULL));
+ }
+
+ TEST_P(loot_get_plugin_tags_test, shouldReturnANoTagMapIfCalledBeforeATagMapHasBeenGotten) {
+ EXPECT_EQ(loot_error_no_tag_map, loot_get_plugin_tags(db, blankEsm.c_str(), &added, &numAdded, &removed, &numRemoved, &modified));
+ }
+
+ TEST_P(loot_get_plugin_tags_test, shouldReturnOkAndOutputEmptyNonModifiedArraysIfAPluginWithoutTagsIsQueried) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+ getTagMap();
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_tags(db, blankEsp.c_str(), &added, &numAdded, &removed, &numRemoved, &modified));
+
+ EXPECT_EQ(0, numAdded);
+ EXPECT_EQ(NULL, added);
+ EXPECT_EQ(0, numRemoved);
+ EXPECT_EQ(NULL, removed);
+ EXPECT_FALSE(modified);
+ }
+
+ TEST_P(loot_get_plugin_tags_test, shouldReturnOkAndNonEmptyNonModifiedArraysIfAPluginWithTagsIsQueried) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+ getTagMap();
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_tags(db, blankEsm.c_str(), &added, &numAdded, &removed, &numRemoved, &modified));
+
+ // The values are tag map indices, check they match up as expected.
+ ASSERT_EQ(2, numAdded);
+ EXPECT_EQ(0, added[0]);
+ EXPECT_EQ(1, added[1]);
+
+ ASSERT_EQ(1, numRemoved);
+ EXPECT_EQ(2, removed[0]);
+
+ EXPECT_FALSE(modified);
+ }
+
+ TEST_P(loot_get_plugin_tags_test, shouldReturnOkAndNonEmptyModifiedArraysIfAPluginWithTagsIsQueriedAndMetadataWasAlsoLoadedFromAUserlist) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), masterlistPath.string().c_str()));
+ getTagMap();
+
+ EXPECT_EQ(loot_ok, loot_get_plugin_tags(db, blankEsm.c_str(), &added, &numAdded, &removed, &numRemoved, &modified));
+
+ // The values are tag map indices, check they match up as expected.
+ ASSERT_EQ(2, numAdded);
+ EXPECT_EQ(0, added[0]);
+ EXPECT_EQ(1, added[1]);
+
+ ASSERT_EQ(1, numRemoved);
+ EXPECT_EQ(2, removed[0]);
+
+ EXPECT_TRUE(modified);
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_get_tag_map_test.h b/src/tests/api/loot_get_tag_map_test.h
new file mode 100644
index 00000000..3bf76771
--- /dev/null
+++ b/src/tests/api/loot_get_tag_map_test.h
@@ -0,0 +1,80 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_GET_TAG_MAP
+#define LOOT_TEST_LOOT_GET_TAG_MAP
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_get_tag_map_test : public ApiGameOperationsTest {
+ protected:
+ loot_get_tag_map_test() :
+ tagMap(nullptr),
+ numTags(0) {}
+
+ const char * const * tagMap;
+ size_t numTags;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_get_tag_map_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_get_tag_map_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_get_tag_map(NULL, &tagMap, &numTags));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_tag_map(db, NULL, &numTags));
+ EXPECT_EQ(loot_error_invalid_args, loot_get_tag_map(db, &tagMap, NULL));
+ }
+
+ TEST_P(loot_get_tag_map_test, shouldReturnOkAndOutputAnEmptyTagMapIfNoMetadataHasBeenLoaded) {
+ EXPECT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
+ EXPECT_EQ(0, numTags);
+ EXPECT_EQ(NULL, tagMap);
+ }
+
+ TEST_P(loot_get_tag_map_test, shouldReturnOKAndOutputANonEmptyTagMapIfMetadataHasBeenLoaded) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
+
+ ASSERT_EQ(3, numTags);
+ EXPECT_STREQ("Actors.ACBS", tagMap[0]);
+ EXPECT_STREQ("Actors.AIData", tagMap[1]);
+ EXPECT_STREQ("C.Water", tagMap[2]);
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_load_lists_test.h b/src/tests/api/loot_load_lists_test.h
new file mode 100644
index 00000000..6c29bced
--- /dev/null
+++ b/src/tests/api/loot_load_lists_test.h
@@ -0,0 +1,82 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_LOAD_LISTS
+#define LOOT_TEST_LOOT_LOAD_LISTS
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_load_lists_test : public ApiGameOperationsTest {
+ protected:
+ loot_load_lists_test() :
+ userlistPath(localPath / "userlist.yaml") {}
+
+ inline virtual void TearDown() {
+ ApiGameOperationsTest::TearDown();
+
+ // The userlist may have been created during the test, so delete it.
+ ASSERT_NO_THROW(boost::filesystem::remove(userlistPath));
+ }
+
+ boost::filesystem::path userlistPath;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_load_lists_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_load_lists_test, shouldReturnAnInvalidArgsErrorIfTheDbOrMasterlistPathArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_load_lists(NULL, masterlistPath.string().c_str(), NULL));
+ EXPECT_EQ(loot_error_invalid_args, loot_load_lists(db, NULL, NULL));
+ }
+
+ TEST_P(loot_load_lists_test, shouldReturnAPathNotFoundErrorIfNoMasterlistIsPresent) {
+ EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+ }
+
+ TEST_P(loot_load_lists_test, shouldReturnAPathNotFoundErrorIfAMasterlistIsPresentButAUserlistDoesNotExistAtTheGivenPath) {
+ ASSERT_NO_THROW(generateMasterlist());
+ EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
+ }
+
+ TEST_P(loot_load_lists_test, shouldReturnOkIfTheMasterlistAndUserlistAreBothPresent) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_NO_THROW(boost::filesystem::copy(masterlistPath, userlistPath));
+
+ EXPECT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_sort_plugins_test.h b/src/tests/api/loot_sort_plugins_test.h
new file mode 100644
index 00000000..0cb9a831
--- /dev/null
+++ b/src/tests/api/loot_sort_plugins_test.h
@@ -0,0 +1,91 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_SORT_PLUGINS
+#define LOOT_TEST_LOOT_SORT_PLUGINS
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_sort_plugins_test : public ApiGameOperationsTest {
+ protected:
+ loot_sort_plugins_test() :
+ sortedPlugins(nullptr),
+ numPlugins(0) {}
+
+ const char * const * sortedPlugins;
+ size_t numPlugins;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_sort_plugins_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_sort_plugins_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(NULL, &sortedPlugins, &numPlugins));
+ EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(db, NULL, &numPlugins));
+ EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(db, &sortedPlugins, NULL));
+ }
+
+ TEST_P(loot_sort_plugins_test, shouldSucceedIfPassedValidArguments) {
+ std::list expectedOrder = {
+ masterFile,
+ blankEsm,
+ blankMasterDependentEsm,
+ blankDifferentEsm,
+ blankDifferentMasterDependentEsm,
+ blankMasterDependentEsp,
+ blankDifferentMasterDependentEsp,
+ blankEsp,
+ blankPluginDependentEsp,
+ blankDifferentEsp,
+ blankDifferentPluginDependentEsp,
+ };
+
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_sort_plugins(db, &sortedPlugins, &numPlugins));
+
+ ASSERT_EQ(expectedOrder.size(), numPlugins);
+
+ size_t i = 0;
+ for (const auto& plugin : expectedOrder) {
+ EXPECT_EQ(plugin, sortedPlugins[i]);
+ ++i;
+ }
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_update_masterlist_test.h b/src/tests/api/loot_update_masterlist_test.h
new file mode 100644
index 00000000..dc69f43e
--- /dev/null
+++ b/src/tests/api/loot_update_masterlist_test.h
@@ -0,0 +1,108 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_UPDATE_MASTERLIST
+#define LOOT_TEST_LOOT_UPDATE_MASTERLIST
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_update_masterlist_test : public ApiGameOperationsTest {
+ protected:
+ loot_update_masterlist_test() :
+ updated(false) {}
+
+ inline virtual void TearDown() {
+ ApiGameOperationsTest::TearDown();
+
+ // Also remove the ".git" folder if it has been created.
+ ASSERT_NO_THROW(boost::filesystem::remove_all(masterlistPath.parent_path() / ".git"));
+ }
+
+ bool updated;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_update_masterlist_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAnInvalidArgsErrorIfAnyOfTheArgumentsAreNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(NULL, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, NULL, "https://github.com/loot/testing-metadata.git", "master", &updated));
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), NULL, "master", &updated));
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", NULL, &updated));
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", NULL));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAnInvalidArgsErrorIfTheMasterlistPathGivenIsInvalid) {
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, ";//\?", "https://github.com/loot/testing-metadata.git", "master", &updated));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAnInvalidArgsErrorIfTheMasterlistPathGivenIsEmpty) {
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, "", "https://github.com/loot/testing-metadata.git", "master", &updated));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAGitErrorIfTheRepositoryUrlGivenCannotBeFound) {
+ EXPECT_EQ(loot_error_git_error, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/oblivion-does-not-exist.git", "master", &updated));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAnInvalidArgsErrorIfTheRepositoryUrlGivenIsEmpty) {
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "", "master", &updated));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAGitErrorIfTheRepositoryBranchGivenCannotBeFound) {
+ EXPECT_EQ(loot_error_git_error, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "missing-branch", &updated));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldReturnAnInvalidArgsErrorIfTheRepositoryBranchGivenIsEmpty) {
+ EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "", &updated));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldSucceedIfPassedValidParametersAndOutputTrueIfTheMasterlistWasUpdated) {
+ EXPECT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+ EXPECT_TRUE(updated);
+ EXPECT_TRUE(boost::filesystem::exists(masterlistPath));
+ }
+
+ TEST_P(loot_update_masterlist_test, shouldSucceedIfCalledRepeatedlyButOnlyOutputTrueForTheFirstCall) {
+ EXPECT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+ EXPECT_TRUE(updated);
+
+ EXPECT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
+ EXPECT_FALSE(updated);
+ EXPECT_TRUE(boost::filesystem::exists(masterlistPath));
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/loot_write_minimal_list_test.h b/src/tests/api/loot_write_minimal_list_test.h
new file mode 100644
index 00000000..9c7061d3
--- /dev/null
+++ b/src/tests/api/loot_write_minimal_list_test.h
@@ -0,0 +1,132 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2014-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_LOOT_WRITE_MINIMAL_LIST
+#define LOOT_TEST_LOOT_WRITE_MINIMAL_LIST
+
+#include "../include/loot/api.h"
+#include "api_game_operations_test.h"
+
+namespace loot {
+ namespace test {
+ class loot_write_minimal_list_test : public ApiGameOperationsTest {
+ protected:
+ loot_write_minimal_list_test() :
+ outputPath(localPath / "minimal.yml") {}
+
+ void SetUp() {
+ ApiGameOperationsTest::SetUp();
+
+ ASSERT_FALSE(boost::filesystem::exists(outputPath));
+ }
+
+ void TearDown() {
+ ApiGameOperationsTest::TearDown();
+
+ ASSERT_NO_THROW(boost::filesystem::remove(outputPath));
+ }
+
+ std::string getExpectedContent() const {
+ using std::endl;
+
+ std::stringstream expectedContent;
+ expectedContent
+ << "plugins:" << endl
+ << " - name: '" << blankEsm << "'" << endl
+ << " tag:" << endl
+ << " - Actors.ACBS" << endl
+ << " - Actors.AIData" << endl
+ << " - -C.Water" << endl
+ << " - name: '" << blankDifferentEsm << "'" << endl
+ << " dirty:" << endl
+ << " - crc: 0x7d22f9df" << endl
+ << " util: 'TES4Edit'" << endl
+ << " udr: 4";
+
+ return expectedContent.str();
+ }
+
+ const boost::filesystem::path outputPath;
+ };
+
+ // Pass an empty first argument, as it's a prefix for the test instantation,
+ // but we only have the one so no prefix is necessary.
+ INSTANTIATE_TEST_CASE_P(,
+ loot_write_minimal_list_test,
+ ::testing::Values(
+ loot_game_tes4,
+ loot_game_tes5,
+ loot_game_fo3,
+ loot_game_fonv,
+ loot_game_fo4));
+
+ TEST_P(loot_write_minimal_list_test, shouldReturnAnInvalidArgsErrorIfAPointerArgumentIsNull) {
+ EXPECT_EQ(loot_error_invalid_args, loot_write_minimal_list(NULL, outputPath.string().c_str(), false));
+ EXPECT_EQ(loot_error_invalid_args, loot_write_minimal_list(db, NULL, false));
+ }
+
+ TEST_P(loot_write_minimal_list_test, shouldReturnAFileWriteErrorIfThePathGivenIsInvalid) {
+ EXPECT_EQ(loot_error_file_write_fail, loot_write_minimal_list(db, "/:?*", false));
+ }
+
+ TEST_P(loot_write_minimal_list_test, shouldReturnOkAndWriteToFileIfArgumentsGivenAreValid) {
+ EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputPath.string().c_str(), false));
+ EXPECT_TRUE(boost::filesystem::exists(outputPath));
+ }
+
+ TEST_P(loot_write_minimal_list_test, shouldReturnAFileWriteErrorIfTheFileAlreadyExistsAndTheOverwriteArgumentIsFalse) {
+ ASSERT_EQ(loot_ok, loot_write_minimal_list(db, outputPath.string().c_str(), false));
+ ASSERT_TRUE(boost::filesystem::exists(outputPath));
+
+ EXPECT_EQ(loot_error_file_write_fail, loot_write_minimal_list(db, outputPath.string().c_str(), false));
+ }
+
+ TEST_P(loot_write_minimal_list_test, shouldReturnOkAndWriteToFileIfTheArgumentsAreValidAndTheOverwriteArgumentIsTrue) {
+ EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputPath.string().c_str(), true));
+ EXPECT_TRUE(boost::filesystem::exists(outputPath));
+ }
+
+ TEST_P(loot_write_minimal_list_test, shouldReturnOkIfTheFileAlreadyExistsAndTheOverwriteArgumentIsTrue) {
+ ASSERT_EQ(loot_ok, loot_write_minimal_list(db, outputPath.string().c_str(), false));
+ ASSERT_TRUE(boost::filesystem::exists(outputPath));
+
+ EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputPath.string().c_str(), true));
+ }
+
+ TEST_P(loot_write_minimal_list_test, shouldWriteOnlyBashTagsAndDirtyInfo) {
+ ASSERT_NO_THROW(generateMasterlist());
+ ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
+
+ EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputPath.string().c_str(), true));
+
+ boost::filesystem::ifstream in(outputPath);
+ std::stringstream content;
+ content << in.rdbuf();
+
+ EXPECT_EQ(getExpectedContent(), content.str());
+ }
+ }
+}
+
+#endif
diff --git a/src/tests/api/test_api.h b/src/tests/api/test_api.h
index 2c464f76..94f6a4b0 100644
--- a/src/tests/api/test_api.h
+++ b/src/tests/api/test_api.h
@@ -26,13 +26,10 @@ along with LOOT. If not, see
#define LOOT_TEST_API
#include "../include/loot/api.h"
-#include "tests/fixtures.h"
-
-#include
namespace loot {
namespace test {
- TEST(GetVersion, HandlesNullInput) {
+ TEST(loot_get_version, shouldReturnAnInvalidArgsErrorIfPassedNullPointers) {
unsigned int vMajor, vMinor, vPatch;
EXPECT_EQ(loot_error_invalid_args, loot_get_version(&vMajor, NULL, NULL));
EXPECT_EQ(loot_error_invalid_args, loot_get_version(NULL, &vMinor, NULL));
@@ -40,37 +37,37 @@ namespace loot {
EXPECT_EQ(loot_error_invalid_args, loot_get_version(NULL, NULL, NULL));
}
- TEST(GetVersion, HandlesValidInput) {
+ TEST(loot_get_version, shouldReturnOkIfPassedNonNullPointers) {
unsigned int vMajor, vMinor, vPatch;
EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch));
}
- TEST(GetBuildID, HandlesNullInput) {
+ TEST(loot_get_build_id, shouldReturnAnInvalidArgsErrorIfPassedANullPointer) {
EXPECT_EQ(loot_error_invalid_args, loot_get_build_id(NULL));
}
- TEST(GetBuildID, HandlesValidInput) {
+ TEST(loot_get_build_id, shouldReturnOkAndOutputANonNullNonPlaceholderRevisionString) {
const char * revision;
EXPECT_EQ(loot_ok, loot_get_build_id(&revision));
EXPECT_STRNE(NULL, revision);
EXPECT_STRNE("@GIT_COMMIT_STRING@", revision); // The CMake placeholder.
}
- TEST(IsCompatible, shouldReturnTrueWithEqualMajorAndMinorVersionsAndUnequalPatchVersion) {
+ TEST(loot_is_compatible, shouldReturnTrueWithEqualMajorAndMinorVersionsAndUnequalPatchVersion) {
unsigned int vMajor, vMinor, vPatch;
EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch));
EXPECT_TRUE(loot_is_compatible(vMajor, vMinor, vPatch + 1));
}
- TEST(IsCompatible, shouldReturnFalseWithEqualMajorVersionAndUnequalMinorAndPatchVersions) {
+ TEST(loot_is_compatible, shouldReturnFalseWithEqualMajorVersionAndUnequalMinorAndPatchVersions) {
unsigned int vMajor, vMinor, vPatch;
EXPECT_EQ(loot_ok, loot_get_version(&vMajor, &vMinor, &vPatch));
EXPECT_FALSE(loot_is_compatible(vMajor, vMinor + 1, vPatch + 1));
}
- TEST(GetErrorMessage, HandlesInputCorrectly) {
+ TEST(loot_get_error_message, shouldReturnAnInvalidArgsErrorIfPassedANullPointer) {
EXPECT_EQ(loot_error_invalid_args, loot_get_error_message(NULL));
const char * error;
@@ -78,556 +75,22 @@ namespace loot {
ASSERT_STREQ("Null message pointer passed.", error);
}
- TEST_F(OblivionTest, CreateDbHandlesValidInputs) {
- EXPECT_EQ(loot_ok, loot_create_db(&db, loot_game_tes4, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
- ASSERT_NO_THROW(loot_destroy_db(db));
- db = nullptr;
-
- // Also test absolute paths.
- boost::filesystem::path game = boost::filesystem::current_path() / dataPath.parent_path();
- boost::filesystem::path local = boost::filesystem::current_path() / localPath;
- EXPECT_EQ(loot_ok, loot_create_db(&db, loot_game_tes4, game.string().c_str(), local.string().c_str()));
+ TEST(loot_get_error_message, shouldReturnOkIfPassedANonNullPointer) {
+ const char * error;
+ EXPECT_EQ(loot_ok, loot_get_error_message(&error));
}
- TEST_F(OblivionTest, CreateDbHandlesInvalidHandleInput) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(NULL, loot_game_tes4, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
+ TEST(loot_get_error_message, shouldOutputAnErrorMessageDetailingTheLastErrorIfAnErrorHasOccurred) {
+ EXPECT_EQ(loot_error_invalid_args, loot_get_error_message(NULL));
+
+ const char * error;
+ EXPECT_EQ(loot_ok, loot_get_error_message(&error));
+ ASSERT_STREQ("Null message pointer passed.", error);
}
- TEST_F(OblivionTest, CreateDbHandlesInvalidGameType) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, UINT_MAX, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
- }
-
- TEST_F(OblivionTest, CreateDbHandlesInvalidGamePathInput) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, loot_game_tes4, missingPath.string().c_str(), localPath.string().c_str()));
- }
-
- TEST_F(OblivionTest, CreateDbHandlesInvalidLocalPathInput) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, loot_game_tes4, dataPath.parent_path().string().c_str(), missingPath.string().c_str()));
- }
-
-#ifdef _WIN32
- TEST_F(OblivionTest, CreateDbHandlesNullLocalPath) {
- EXPECT_EQ(loot_ok, loot_create_db(&db, loot_game_tes4, dataPath.parent_path().string().c_str(), NULL));
- }
-#endif
-
- TEST_F(SkyrimTest, CreateDbHandlesValidInputs) {
- EXPECT_EQ(loot_ok, loot_create_db(&db, loot_game_tes5, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
- ASSERT_NO_THROW(loot_destroy_db(db));
- db = nullptr;
-
- // Also test absolute paths.
- boost::filesystem::path game = boost::filesystem::current_path() / dataPath.parent_path();
- boost::filesystem::path local = boost::filesystem::current_path() / localPath;
- EXPECT_EQ(loot_ok, loot_create_db(&db, loot_game_tes5, game.string().c_str(), local.string().c_str()));
- }
-
- TEST_F(SkyrimTest, CreateDbHandlesInvalidHandleInput) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(NULL, loot_game_tes5, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
- }
-
- TEST_F(SkyrimTest, CreateDbHandlesInvalidGameType) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, UINT_MAX, dataPath.parent_path().string().c_str(), localPath.string().c_str()));
- }
-
- TEST_F(SkyrimTest, CreateDbHandlesInvalidGamePathInput) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, loot_game_tes5, missingPath.string().c_str(), localPath.string().c_str()));
- }
-
- TEST_F(SkyrimTest, CreateDbHandlesInvalidLocalPathInput) {
- EXPECT_EQ(loot_error_invalid_args, loot_create_db(&db, loot_game_tes5, dataPath.parent_path().string().c_str(), missingPath.string().c_str()));
- }
-
-#ifdef _WIN32
- TEST_F(SkyrimTest, CreateDbHandlesNullLocalPath) {
- EXPECT_EQ(loot_ok, loot_create_db(&db, loot_game_tes5, dataPath.parent_path().string().c_str(), NULL));
- }
-#endif
-
- TEST(GameHandleDestroyTest, HandledNullInput) {
+ TEST(loot_destroy_db, shouldNotThrowIfPassedANullPointer) {
ASSERT_NO_THROW(loot_destroy_db(NULL));
}
-
- TEST_F(OblivionAPIOperationsTest, UpdateMasterlist) {
- bool updated;
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(NULL, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, NULL, "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), NULL, "master", &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", NULL, &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", NULL));
-
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, ";//\?", "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, "", "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_error_git_error, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/oblivion-does-not-exist.git", "master", &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "", "master", &updated));
- EXPECT_EQ(loot_error_git_error, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "missing-branch", &updated));
- EXPECT_EQ(loot_error_invalid_args, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "", &updated));
-
- // Test actual masterlist update.
- EXPECT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_TRUE(updated);
-
- // Test with an up-to-date masterlist.
- EXPECT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_FALSE(updated);
- }
-
- TEST_F(OblivionAPIOperationsTest, GetMasterlistRevision) {
- const char * revisionID;
- const char * revisionDate;
- bool isModified;
- EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(NULL, masterlistPath.string().c_str(), false, &revisionID, &revisionDate, &isModified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, NULL, false, &revisionID, &revisionDate, &isModified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, NULL, &revisionDate, &isModified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionID, NULL, &isModified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionID, &revisionDate, NULL));
-
- // Test with no masterlist.
- EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionID, &revisionDate, &isModified));
- EXPECT_EQ(NULL, revisionID);
- EXPECT_EQ(NULL, revisionDate);
- EXPECT_FALSE(isModified);
-
- // Test with a generated (non-revision-control) masterlist.
- ASSERT_NO_THROW(GenerateMasterlist());
- EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionID, &revisionDate, &isModified));
- EXPECT_EQ(NULL, revisionID);
- EXPECT_EQ(NULL, revisionDate);
- EXPECT_FALSE(isModified);
-
- // Update the masterlist and test.
- bool updated;
- ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- ASSERT_TRUE(updated);
- EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionID, &revisionDate, &isModified));
- EXPECT_STRNE(NULL, revisionID);
- EXPECT_EQ(40, strlen(revisionID));
- EXPECT_STRNE(NULL, revisionDate);
- EXPECT_EQ(10, strlen(revisionDate));
- EXPECT_FALSE(isModified);
-
- // Test with a short revision string.
- EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), true, &revisionID, &revisionDate, &isModified));
- EXPECT_STRNE(NULL, revisionID);
- EXPECT_GE(size_t(40), strlen(revisionID));
- EXPECT_LE(size_t(7), strlen(revisionID));
- EXPECT_STRNE(NULL, revisionDate);
- EXPECT_EQ(10, strlen(revisionDate));
- EXPECT_FALSE(isModified);
-
- // Overwrite the masterlist with a generated one.
- ASSERT_NO_THROW(GenerateMasterlist());
- EXPECT_EQ(loot_ok, loot_get_masterlist_revision(db, masterlistPath.string().c_str(), false, &revisionID, &revisionDate, &isModified));
- EXPECT_STRNE(NULL, revisionID);
- EXPECT_EQ(40, strlen(revisionID));
- EXPECT_STRNE(NULL, revisionDate);
- EXPECT_EQ(10, strlen(revisionDate));
- EXPECT_TRUE(isModified);
- }
-
- TEST_F(OblivionAPIOperationsTest, LoadLists) {
- EXPECT_EQ(loot_error_invalid_args, loot_load_lists(NULL, masterlistPath.string().c_str(), NULL));
- EXPECT_EQ(loot_error_invalid_args, loot_load_lists(db, NULL, NULL));
-
- EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- bool updated;
- ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
-
- ASSERT_NO_THROW(boost::filesystem::copy(masterlistPath, userlistPath));
- EXPECT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
- }
-
- TEST_F(SkyrimAPIOperationsTest, LoadLists) {
- EXPECT_EQ(loot_error_invalid_args, loot_load_lists(NULL, masterlistPath.string().c_str(), NULL));
- EXPECT_EQ(loot_error_invalid_args, loot_load_lists(db, NULL, NULL));
-
- EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- bool updated;
- ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
-
- ASSERT_NO_THROW(boost::filesystem::copy(masterlistPath, userlistPath));
- EXPECT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
- }
-
- TEST_F(OblivionAPIOperationsTest, EvalLists) {
- // No lists loaded.
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_any));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_english));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_spanish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_russian));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_french));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_chinese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_polish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_brazilian_portuguese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_finnish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_german));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_danish));
-
- // Invalid args.
- EXPECT_EQ(loot_error_invalid_args, loot_eval_lists(NULL, loot_lang_any));
- EXPECT_EQ(loot_error_invalid_args, loot_eval_lists(db, UINT_MAX));
-
- // Now test different languages with a list loaded.
- bool updated;
- ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_any));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_english));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_spanish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_russian));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_french));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_chinese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_polish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_brazilian_portuguese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_finnish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_german));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_danish));
- }
-
- TEST_F(SkyrimAPIOperationsTest, EvalLists) {
- // No lists loaded.
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_any));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_english));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_spanish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_russian));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_french));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_chinese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_polish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_brazilian_portuguese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_finnish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_german));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_danish));
-
- // Invalid args.
- EXPECT_EQ(loot_error_invalid_args, loot_eval_lists(NULL, loot_lang_any));
- EXPECT_EQ(loot_error_invalid_args, loot_eval_lists(db, UINT_MAX));
-
- // Now test different languages with a list loaded.
- bool updated;
- ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_any));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_english));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_spanish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_russian));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_french));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_chinese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_polish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_brazilian_portuguese));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_finnish));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_german));
- EXPECT_EQ(loot_ok, loot_eval_lists(db, loot_lang_danish));
- }
-
- TEST_F(OblivionAPIOperationsTest, SortPlugins) {
- const char * const * sortedPlugins;
- size_t numPlugins;
- EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(NULL, &sortedPlugins, &numPlugins));
- EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(db, NULL, &numPlugins));
- EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(db, &sortedPlugins, NULL));
-
- EXPECT_EQ(loot_ok, loot_sort_plugins(db, &sortedPlugins, &numPlugins));
-
- // Expected order was obtained from running the API function once.
- std::list expectedOrder = {
- "Oblivion.esm",
- "Blank.esm",
- "Blank - Different.esm",
- "Blank - Master Dependent.esm",
- "Blank - Different Master Dependent.esm",
- "Blank.esp",
- "Blank - Different.esp",
- "Blank - Master Dependent.esp",
- "Blank - Different Master Dependent.esp",
- "Blank - Plugin Dependent.esp",
- "Blank - Different Plugin Dependent.esp",
- };
- std::list actualOrder;
- for (size_t i = 0; i < numPlugins; ++i) {
- actualOrder.push_back(sortedPlugins[i]);
- }
- EXPECT_EQ(11, numPlugins);
- EXPECT_EQ(expectedOrder, actualOrder);
- }
-
- TEST_F(SkyrimAPIOperationsTest, SortPlugins) {
- const char * const * sortedPlugins;
- size_t numPlugins;
- EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(NULL, &sortedPlugins, &numPlugins));
- EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(db, NULL, &numPlugins));
- EXPECT_EQ(loot_error_invalid_args, loot_sort_plugins(db, &sortedPlugins, NULL));
-
- EXPECT_EQ(loot_ok, loot_sort_plugins(db, &sortedPlugins, &numPlugins));
-
- // Expected order was obtained from running the API function once.
- std::list expectedOrder = {
- "Skyrim.esm",
- "Blank.esm",
- "Blank - Different.esm",
- "Blank - Master Dependent.esm",
- "Blank - Different Master Dependent.esm",
- "Blank.esp",
- "Blank - Different.esp",
- "Blank - Master Dependent.esp",
- "Blank - Different Master Dependent.esp",
- "Blank - Plugin Dependent.esp",
- "Blank - Different Plugin Dependent.esp",
- };
- std::list actualOrder;
- for (size_t i = 0; i < numPlugins; ++i) {
- actualOrder.push_back(sortedPlugins[i]);
- }
- EXPECT_EQ(11, numPlugins);
- EXPECT_EQ(expectedOrder, actualOrder);
- }
-
- TEST_F(OblivionAPIOperationsTest, ApplyLoadOrder) {
- const char * loadOrder[11] = {
- "Oblivion.esm",
- "Blank.esm",
- "Blank - Different.esm",
- "Blank - Different Master Dependent.esm",
- "Blank - Master Dependent.esm",
- "Blank.esp",
- "Blank - Different.esp",
- "Blank - Different Master Dependent.esp",
- "Blank - Different Plugin Dependent.esp",
- "Blank - Master Dependent.esp",
- "Blank - Plugin Dependent.esp",
- };
- size_t numPlugins = 11;
- EXPECT_EQ(loot_error_invalid_args, loot_apply_load_order(NULL, loadOrder, numPlugins));
- EXPECT_EQ(loot_error_invalid_args, loot_apply_load_order(db, NULL, numPlugins));
-
- EXPECT_EQ(loot_ok, loot_apply_load_order(db, loadOrder, numPlugins));
- }
-
- TEST_F(SkyrimAPIOperationsTest, ApplyLoadOrder) {
- const char * loadOrder[11] = {
- "Skyrim.esm",
- "Blank.esm",
- "Blank - Different.esm",
- "Blank - Different Master Dependent.esm",
- "Blank - Master Dependent.esm",
- "Blank.esp",
- "Blank - Different.esp",
- "Blank - Different Master Dependent.esp",
- "Blank - Different Plugin Dependent.esp",
- "Blank - Master Dependent.esp",
- "Blank - Plugin Dependent.esp",
- };
- size_t numPlugins = 11;
- EXPECT_EQ(loot_error_invalid_args, loot_apply_load_order(NULL, loadOrder, numPlugins));
- EXPECT_EQ(loot_error_invalid_args, loot_apply_load_order(db, NULL, numPlugins));
-
- EXPECT_EQ(loot_ok, loot_apply_load_order(db, loadOrder, numPlugins));
- }
-
- TEST_F(OblivionAPIOperationsTest, GetTagMap) {
- const char * const * tagMap;
- size_t numTags;
- EXPECT_EQ(loot_error_invalid_args, loot_get_tag_map(NULL, &tagMap, &numTags));
- EXPECT_EQ(loot_error_invalid_args, loot_get_tag_map(db, NULL, &numTags));
- EXPECT_EQ(loot_error_invalid_args, loot_get_tag_map(db, &tagMap, NULL));
-
- // Get tag map with no masterlist loaded: should have no tags.
- EXPECT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
- EXPECT_EQ(0, numTags);
- EXPECT_EQ(NULL, tagMap);
-
- // Get a masterlist, then get tags from it.
- ASSERT_NO_THROW(GenerateMasterlist());
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- EXPECT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
- ASSERT_EQ(22, numTags);
- EXPECT_STREQ("Actors.ACBS", tagMap[0]);
- EXPECT_STREQ("Actors.AIData", tagMap[1]);
- EXPECT_STREQ("Actors.AIPackages", tagMap[2]);
- EXPECT_STREQ("Actors.CombatStyle", tagMap[3]);
- EXPECT_STREQ("Actors.DeathItem", tagMap[4]);
- EXPECT_STREQ("Actors.Stats", tagMap[5]);
- EXPECT_STREQ("C.Climate", tagMap[6]);
- EXPECT_STREQ("C.Light", tagMap[7]);
- EXPECT_STREQ("C.Music", tagMap[8]);
- EXPECT_STREQ("C.Name", tagMap[9]);
- EXPECT_STREQ("C.Owner", tagMap[10]);
- EXPECT_STREQ("C.Water", tagMap[11]);
- EXPECT_STREQ("Creatures.Blood", tagMap[12]);
- EXPECT_STREQ("Delev", tagMap[13]);
- EXPECT_STREQ("Factions", tagMap[14]);
- EXPECT_STREQ("Invent", tagMap[15]);
- EXPECT_STREQ("NPC.Class", tagMap[16]);
- EXPECT_STREQ("Names", tagMap[17]);
- EXPECT_STREQ("Relations", tagMap[18]);
- EXPECT_STREQ("Relev", tagMap[19]);
- EXPECT_STREQ("Scripts", tagMap[20]);
- EXPECT_STREQ("Stats", tagMap[21]);
- }
-
- TEST_F(OblivionAPIOperationsTest, GetPluginTags) {
- const unsigned int * added;
- const unsigned int * removed;
- size_t numAdded, numRemoved;
- bool modified;
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(NULL, "Unofficial Oblivion Patch.esp", &added, &numAdded, &removed, &numRemoved, &modified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, NULL, &added, &numAdded, &removed, &numRemoved, &modified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", NULL, &numAdded, &removed, &numRemoved, &modified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, NULL, &removed, &numRemoved, &modified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, &numAdded, NULL, &numRemoved, &modified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, &numAdded, &removed, NULL, &modified));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, &numAdded, &removed, &numRemoved, NULL));
-
- // Get tags before getting a tag map.
- EXPECT_EQ(loot_error_no_tag_map, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, &numAdded, &removed, &numRemoved, &modified));
-
- // Load tag map.
- const char * const * tagMap;
- size_t numTags;
- ASSERT_NO_THROW(GenerateMasterlist());
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- ASSERT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
-
- // Get tags for a plugin without any.
- EXPECT_EQ(loot_ok, loot_get_plugin_tags(db, "Blank.esp", &added, &numAdded, &removed, &numRemoved, &modified));
- EXPECT_EQ(0, numAdded);
- EXPECT_EQ(NULL, added);
- EXPECT_EQ(0, numRemoved);
- EXPECT_EQ(NULL, removed);
- EXPECT_FALSE(modified);
-
- // Get tags for a plugin with some.
- EXPECT_EQ(loot_ok, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, &numAdded, &removed, &numRemoved, &modified));
- ASSERT_EQ(21, numAdded);
- for (size_t i = 0; i < 11; ++i) {
- EXPECT_EQ(i, added[i]);
- }
- for (size_t i = 11; i < 21; ++i) {
- EXPECT_EQ(i + 1, added[i]);
- }
-
- ASSERT_EQ(1, numRemoved);
- EXPECT_EQ(11, removed[0]);
- EXPECT_FALSE(modified);
-
- // Now load the masterlist as the userlist too, and check the modified flag.
- ASSERT_NO_THROW(boost::filesystem::copy_file(masterlistPath, userlistPath));
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str()));
- ASSERT_EQ(loot_ok, loot_get_tag_map(db, &tagMap, &numTags));
-
- EXPECT_EQ(loot_ok, loot_get_plugin_tags(db, "Unofficial Oblivion Patch.esp", &added, &numAdded, &removed, &numRemoved, &modified));
- ASSERT_EQ(21, numAdded);
- for (size_t i = 0; i < 11; ++i) {
- EXPECT_EQ(i, added[i]);
- }
- for (size_t i = 11; i < 21; ++i) {
- EXPECT_EQ(i + 1, added[i]);
- }
- EXPECT_EQ(0, added[0]);
- ASSERT_EQ(1, numRemoved);
- EXPECT_EQ(11, removed[0]);
- EXPECT_TRUE(modified);
- }
-
- TEST_F(OblivionAPIOperationsTest, GetPluginMessages) {
- const loot_message * messages;
- size_t numMessages;
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(NULL, "EnhancedWeatherSIOnly.esm", &messages, &numMessages));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(db, NULL, &messages, &numMessages));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(db, "EnhancedWeatherSIOnly.esm", NULL, &numMessages));
- EXPECT_EQ(loot_error_invalid_args, loot_get_plugin_messages(db, "EnhancedWeatherSIOnly.esm", &messages, NULL));
-
- // Fetch and load the metadata.
- ASSERT_NO_THROW(GenerateMasterlist());
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
-
- // Test for plugin with no messages.
- EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, "Silgrad_Tower.esm", &messages, &numMessages));
- EXPECT_EQ(0, numMessages);
- EXPECT_EQ(NULL, messages);
-
- // Test for plugin with one note.
- EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, "No Lights Flicker.esm", &messages, &numMessages));
- EXPECT_EQ(1, numMessages);
- EXPECT_EQ(loot_message_say, messages[0].type);
- EXPECT_STREQ("Use Wrye Bash Bashed Patch tweak instead.", messages[0].message);
-
- // Test for plugin with one warning.
- EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, "bookplacing.esm", &messages, &numMessages));
- EXPECT_EQ(1, numMessages);
- EXPECT_EQ(loot_message_warn, messages[0].type);
- EXPECT_STREQ("Check you are using v2+. If not, Update. v1 has a severe bug with the Mystic Emporium disappearing.", messages[0].message);
-
- // Test for plugin with one error.
- EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, "EnhancedWeatherSIOnly.esm", &messages, &numMessages));
- EXPECT_EQ(1, numMessages);
- EXPECT_EQ(loot_message_error, messages[0].type);
- EXPECT_STREQ("Obsolete. Remove this and install Enhanced Weather.", messages[0].message);
-
- // Test for plugin with more than one message.
- EXPECT_EQ(loot_ok, loot_get_plugin_messages(db, "nVidia Black Screen Fix.esp", &messages, &numMessages));
- EXPECT_EQ(2, numMessages);
- EXPECT_EQ(loot_message_say, messages[0].type);
- EXPECT_STREQ("Use Wrye Bash Bashed Patch tweak instead.", messages[0].message);
- EXPECT_EQ(loot_message_say, messages[1].type);
- EXPECT_STREQ("Alternatively, remove this and use UOP v3.0.1+ instead.", messages[1].message);
- }
-
- TEST_F(OblivionAPIOperationsTest, GetDirtyInfo) {
- unsigned int needsCleaning;
- EXPECT_EQ(loot_error_invalid_args, loot_get_dirty_info(NULL, "Oblivion.esm", &needsCleaning));
- EXPECT_EQ(loot_error_invalid_args, loot_get_dirty_info(db, NULL, &needsCleaning));
- EXPECT_EQ(loot_error_invalid_args, loot_get_dirty_info(db, "Oblivion.esm", NULL));
-
- // Fetch and load the metadata.
- ASSERT_NO_THROW(GenerateMasterlist());
- ASSERT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
-
- // A plugin with no metadata.
- EXPECT_EQ(loot_ok, loot_get_dirty_info(db, "Oblivion.esm", &needsCleaning));
- EXPECT_EQ(loot_needs_cleaning_unknown, needsCleaning);
-
- // A plugin with dirty metadata.
- EXPECT_EQ(loot_ok, loot_get_dirty_info(db, "Hammerfell.esm", &needsCleaning));
- EXPECT_EQ(loot_needs_cleaning_yes, needsCleaning);
-
- // A plugin with a standard "Do not clean" message.
- EXPECT_EQ(loot_ok, loot_get_dirty_info(db, "Unofficial Oblivion Patch.esp", &needsCleaning));
- EXPECT_EQ(loot_needs_cleaning_no, needsCleaning);
- }
-
- TEST_F(OblivionAPIOperationsTest, WriteMinimalList) {
- std::string outputFile = (localPath / "minimal.yml").string();
- EXPECT_EQ(loot_error_invalid_args, loot_write_minimal_list(NULL, outputFile.c_str(), false));
- EXPECT_EQ(loot_error_invalid_args, loot_write_minimal_list(db, NULL, false));
- EXPECT_EQ(loot_error_file_write_fail, loot_write_minimal_list(db, "/:?*", false));
-
- ASSERT_FALSE(boost::filesystem::exists(outputFile));
- EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputFile.c_str(), false));
- EXPECT_TRUE(boost::filesystem::exists(outputFile));
- EXPECT_EQ(loot_error_file_write_fail, loot_write_minimal_list(db, outputFile.c_str(), false));
-
- EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputFile.c_str(), true));
- ASSERT_NO_THROW(boost::filesystem::remove(outputFile));
- EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputFile.c_str(), true));
- EXPECT_TRUE(boost::filesystem::exists(outputFile));
- ASSERT_NO_THROW(boost::filesystem::remove(outputFile));
-
- // Check that Bash Tag removals get outputted correctly.
- bool updated;
- ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/testing-metadata.git", "master", &updated));
- EXPECT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), NULL));
- EXPECT_EQ(loot_ok, loot_write_minimal_list(db, outputFile.c_str(), false));
-
- boost::filesystem::ifstream in(outputFile);
- std::string line;
- while (std::getline(in, line)) {
- EXPECT_FALSE(boost::contains(line, "- \"-\""));
- }
- in.close();
- ASSERT_NO_THROW(boost::filesystem::remove(outputFile));
- }
}
}
diff --git a/src/tests/base_game_test.h b/src/tests/base_game_test.h
new file mode 100644
index 00000000..105db2c4
--- /dev/null
+++ b/src/tests/base_game_test.h
@@ -0,0 +1,125 @@
+/* LOOT
+
+A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
+Fallout: New Vegas.
+
+Copyright (C) 2013-2016 WrinklyNinja
+
+This file is part of LOOT.
+
+LOOT is free software: you can redistribute
+it and/or modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation, either version 3 of
+the License, or (at your option) any later version.
+
+LOOT is distributed in the hope that it will
+be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LOOT. If not, see
+.
+*/
+
+#ifndef LOOT_TEST_BASE_GAME_TEST
+#define LOOT_TEST_BASE_GAME_TEST
+
+#include
+#include
+
+namespace loot {
+ namespace test {
+ class BaseGameTest : public ::testing::TestWithParam {
+ protected:
+ BaseGameTest() :
+ missingPath("./missing"),
+ dataPath(getPluginsPath()),
+ localPath(getLocalPath()),
+ masterFile(getMasterFile()),
+ blankEsm("Blank.esm"),
+ blankDifferentEsm("Blank - Different.esm"),
+ blankMasterDependentEsm("Blank - Master Dependent.esm"),
+ blankDifferentMasterDependentEsm("Blank - Different Master Dependent.esm"),
+ blankEsp("Blank.esp"),
+ blankDifferentEsp("Blank - Different.esp"),
+ blankMasterDependentEsp("Blank - Master Dependent.esp"),
+ blankDifferentMasterDependentEsp("Blank - Different Master Dependent.esp"),
+ blankPluginDependentEsp("Blank - Plugin Dependent.esp"),
+ blankDifferentPluginDependentEsp("Blank - Different Plugin Dependent.esp") {}
+
+ inline virtual void SetUp() {
+ ASSERT_NO_THROW(boost::filesystem::create_directories(localPath));
+ ASSERT_TRUE(boost::filesystem::exists(localPath));
+
+ ASSERT_FALSE(boost::filesystem::exists(missingPath));
+
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankEsm));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankDifferentEsm));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankMasterDependentEsm));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankDifferentMasterDependentEsm));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankEsp));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankDifferentEsp));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankMasterDependentEsp));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankDifferentMasterDependentEsp));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankPluginDependentEsp));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / blankDifferentPluginDependentEsp));
+
+ // Make sure the game master file exists.
+ ASSERT_FALSE(boost::filesystem::exists(dataPath / masterFile));
+ ASSERT_NO_THROW(boost::filesystem::copy_file(dataPath / blankEsm, dataPath / masterFile));
+ ASSERT_TRUE(boost::filesystem::exists(dataPath / masterFile));
+ }
+
+ inline virtual void TearDown() {
+ ASSERT_NO_THROW(boost::filesystem::remove(dataPath / masterFile));
+ }
+
+ const boost::filesystem::path missingPath;
+ const boost::filesystem::path dataPath;
+ const boost::filesystem::path localPath;
+
+ const std::string masterFile;
+ const std::string blankEsm;
+ const std::string blankDifferentEsm;
+ const std::string blankMasterDependentEsm;
+ const std::string blankDifferentMasterDependentEsm;
+ const std::string blankEsp;
+ const std::string blankDifferentEsp;
+ const std::string blankMasterDependentEsp;
+ const std::string blankDifferentMasterDependentEsp;
+ const std::string blankPluginDependentEsp;
+ const std::string blankDifferentPluginDependentEsp;
+
+ private:
+ inline boost::filesystem::path getLocalPath() const {
+ if (GetParam() == loot_game_tes4)
+ return "./local/Oblivion";
+ else
+ return "./local/Skyrim";
+ }
+
+ inline boost::filesystem::path getPluginsPath() const {
+ if (GetParam() == loot_game_tes4)
+ return "./Oblivion/Data";
+ else
+ return "./Skyrim/Data";
+ }
+
+ inline std::string getMasterFile() const {
+ if (GetParam() == loot_game_tes4)
+ return "Oblivion.esm";
+ else if (GetParam() == loot_game_tes5)
+ return "Skyrim.esm";
+ else if (GetParam() == loot_game_fo3)
+ return "Fallout3.esm";
+ else if (GetParam() == loot_game_fonv)
+ return "FalloutNV.esm";
+ else
+ return "Fallout4.esm";
+ }
+ };
+ }
+}
+
+#endif
diff --git a/src/tests/main.cpp b/src/tests/main.cpp
index 0eaabece..53358127 100644
--- a/src/tests/main.cpp
+++ b/src/tests/main.cpp
@@ -27,8 +27,20 @@
#define BOOST_NO_CXX11_SCOPED_ENUMS
#endif
+#include "api/loot_apply_load_order_test.h"
+#include "api/loot_create_db_test.h"
+#include "api/loot_db_test.h"
+#include "api/loot_eval_lists_test.h"
+#include "api/loot_get_dirty_info_test.h"
+#include "api/loot_get_masterlist_revision_test.h"
+#include "api/loot_get_plugin_messages_test.h"
+#include "api/loot_get_plugin_tags_test.h"
+#include "api/loot_get_tag_map_test.h"
+#include "api/loot_load_lists_test.h"
+#include "api/loot_sort_plugins_test.h"
+#include "api/loot_update_masterlist_test.h"
+#include "api/loot_write_minimal_list_test.h"
#include "api/test_api.h"
-#include "api/test_loot_db.h"
#include "backend/game/test_game.h"
#include "backend/game/test_game_cache.h"
#include "backend/game/test_game_settings.h"