Improve API tests

* Use a named fixture for each API function
* Make filenames match fixture class names
* Parameterise the fixture tests
* Split tests up so they only test one thing
* Rename tests to be more descriptive

Part of #515.
This commit is contained in:
Oliver Hamlet
2016-03-24 11:33:18 +00:00
parent 61827fc914
commit 4516fe7bc0
18 changed files with 1544 additions and 581 deletions
+18 -2
View File
@@ -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"
+118
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+97
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#ifndef LOOT_TEST_LOOT_CREATE_DB
#define LOOT_TEST_LOOT_CREATE_DB
#include "../include/loot/api.h"
#include "tests/base_game_test.h"
#include <climits>
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
@@ -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>({
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>({
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(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(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(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",
+87
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+81
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+140
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+80
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+82
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+91
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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<std::string> 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
+108
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
@@ -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
<http://www.gnu.org/licenses/>.
*/
#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
+17 -554
View File
File diff suppressed because it is too large Load Diff
+125
View File
@@ -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
<http://www.gnu.org/licenses/>.
*/
#ifndef LOOT_TEST_BASE_GAME_TEST
#define LOOT_TEST_BASE_GAME_TEST
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
namespace loot {
namespace test {
class BaseGameTest : public ::testing::TestWithParam<unsigned int> {
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
+13 -1
View File
@@ -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"