Split API tests into a separate executable

So that there's no coupling between the backend code and the API tests,
allowing them to be used against different DLL builds.
This commit is contained in:
Oliver Hamlet
2016-07-13 20:47:22 +01:00
parent 4a343a1450
commit b236c83801
9 changed files with 159 additions and 77 deletions
+1
View File
@@ -48,6 +48,7 @@ before_script:
script:
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then npm test; fi
- make tests && ./tests
- make api-tests && ./api-tests
before_deploy:
# Build the metadata validator
+42 -19
View File
@@ -234,26 +234,15 @@ set (LOOT_VALIDATOR_HEADERS ${LOOT_HEADERS})
set (LOOT_TESTS_SRC ${LOOT_SRC}
"${CMAKE_SOURCE_DIR}/src/api/loot_db.cpp"
"${CMAKE_SOURCE_DIR}/src/tests/main.cpp")
"${CMAKE_SOURCE_DIR}/src/tests/backend/main.cpp")
set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.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"
# Testing this here rather than as part of the API tests
# because it tests internal code and requires internal
# linking.
"${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/backend/app/loot_paths_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/app/loot_settings_test.h"
@@ -281,15 +270,36 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/masterlist_test.h"
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata_list_test.h")
set(LOOT_API_TESTS_SRC "${CMAKE_SOURCE_DIR}/src/tests/api/main.cpp")
set(LOOT_API_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.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_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")
source_group("Header Files\\backend" FILES ${LOOT_HEADERS})
source_group("Header Files\\gui" FILES ${LOOT_GUI_HEADERS})
source_group("Header Files\\api" FILES ${LOOT_API_HEADERS})
source_group("Header Files\\tests" FILES ${LOOT_TESTS_HEADERS})
source_group("Header Files\\tests" FILES ${LOOT_API_TESTS_HEADERS})
source_group("Source Files\\backend" FILES ${LOOT_SRC})
source_group("Source Files\\gui" FILES ${LOOT_GUI_SRC})
source_group("Source Files\\api" FILES ${LOOT_API_SRC})
source_group("Source Files\\tests" FILES ${LOOT_TESTS_SRC})
source_group("Source Files\\tests" FILES ${LOOT_API_TESTS_SRC})
source_group("Source Files\\validator" FILES ${LOOT_VALIDATOR_SRC})
# Include source and library directories.
@@ -387,15 +397,20 @@ ENDIF ()
# Define Targets
##############################
# Build tests.
add_executable(tests ${LOOT_TESTS_SRC} ${LOOT_TESTS_HEADERS})
add_dependencies(tests GTest libespm libgit2 libloadorder pseudosem testing-metadata testing-plugins yaml-cpp)
target_link_libraries(tests ${Boost_LIBRARIES} ${LIBGIT2_LIBRARIES} ${LIBLOADORDER_LIBRARIES} ${GTEST_LIBRARIES} ${LOOT_LIBS} ${YAML_CPP_LIBRARIES})
# Build API.
add_library (loot_api ${LOOT_API_SRC} ${LOOT_API_HEADERS})
add_dependencies (loot_api libespm libgit2 libloadorder pseudosem yaml-cpp)
target_link_libraries (loot_api ${Boost_LIBRARIES} ${LIBGIT2_LIBRARIES} ${LIBLOADORDER_LIBRARIES} ${LOOT_LIBS} ${YAML_CPP_LIBRARIES})
# Build tests.
add_executable(tests ${LOOT_TESTS_SRC} ${LOOT_TESTS_HEADERS})
add_dependencies(tests loot_api GTest testing-metadata testing-plugins)
target_link_libraries(tests loot_api ${Boost_LIBRARIES} ${GTEST_LIBRARIES} ${LOOT_LIBS} ${YAML_CPP_LIBRARIES})
# Build API tests.
add_executable(api-tests ${LOOT_API_TESTS_SRC} ${LOOT_API_TESTS_HEADERS})
add_dependencies(api-tests loot_api GTest testing-metadata testing-plugins)
target_link_libraries(api-tests loot_api ${Boost_LIBRARIES} ${GTEST_LIBRARIES} ${LOOT_LIBS} ${YAML_CPP_LIBRARIES})
# Build application.
add_executable (LOOT ${LOOT_GUI_SRC} ${LOOT_GUI_HEADERS})
@@ -485,6 +500,10 @@ add_custom_command(TARGET tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${SOURCE_DIR}
"$<TARGET_FILE_DIR:tests>/testing-metadata")
add_custom_command(TARGET api-tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${SOURCE_DIR}
"$<TARGET_FILE_DIR:api-tests>/testing-metadata")
# Copy testing plugins
ExternalProject_Get_Property(testing-plugins SOURCE_DIR)
@@ -492,6 +511,10 @@ add_custom_command(TARGET tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${SOURCE_DIR}
$<TARGET_FILE_DIR:tests>)
add_custom_command(TARGET api-tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${SOURCE_DIR}
$<TARGET_FILE_DIR:api-tests>)
find_package(Doxygen)
find_package(LATEX)
+5 -5
View File
@@ -56,11 +56,11 @@ namespace loot {
INSTANTIATE_TEST_CASE_P(,
loot_db_test,
::testing::Values(
loot_game_tes4,
loot_game_tes5,
loot_game_fo3,
loot_game_fonv,
loot_game_fo4));
GameSettings::tes4,
GameSettings::tes5,
GameSettings::fo3,
GameSettings::fonv,
GameSettings::fo4));
TEST_P(loot_db_test, settingRevisionIdStringShouldCopyIt) {
db->setRevisionIdString("id");
+59
View File
@@ -0,0 +1,59 @@
/* 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/>.
*/
#ifdef TRAVIS
#pragma message("This is a Travis build, so defining BOOST_NO_CXX11_SCOPED_ENUMS to avoid boost::filesystem::copy_file() linking errors.")
#define BOOST_NO_CXX11_SCOPED_ENUMS
#endif
#include <gtest/gtest.h>
#include "loot_apply_load_order_test.h"
#include "loot_create_db_test.h"
#include "loot_eval_lists_test.h"
#include "loot_get_dirty_info_test.h"
#include "loot_get_masterlist_revision_test.h"
#include "loot_get_plugin_messages_test.h"
#include "loot_get_plugin_tags_test.h"
#include "loot_get_tag_map_test.h"
#include "loot_load_lists_test.h"
#include "loot_sort_plugins_test.h"
#include "loot_update_masterlist_test.h"
#include "loot_write_minimal_list_test.h"
#include "test_api.h"
#include <boost/log/core.hpp>
#include <boost/locale.hpp>
int main(int argc, char **argv) {
//Set the locale to get encoding conversions working correctly.
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
//Disable logging or else stdout will get overrun.
boost::log::core::get()->set_logging_enabled(false);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
+2
View File
@@ -27,6 +27,8 @@ along with LOOT. If not, see
#include "../include/loot/api.h"
#include <gtest/gtest.h>
namespace loot {
namespace test {
TEST(loot_get_version, shouldReturnAnInvalidArgsErrorIfPassedNullPointers) {
+2
View File
@@ -27,6 +27,8 @@ along with LOOT. If not, see
#include "backend/app/loot_paths.h"
#include <gtest/gtest.h>
namespace loot {
namespace test {
TEST(LootPaths, getReadmePathShouldUseLootAppPath) {
@@ -28,6 +28,8 @@ along with LOOT. If not, see
#include "backend/app/loot_settings.h"
#include "backend/app/loot_version.h"
#include <gtest/gtest.h>
namespace loot {
namespace test {
class LootSettingsTest : public ::testing::Test {
@@ -27,45 +27,33 @@
#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 "backend/app/loot_paths_test.h"
#include "backend/app/loot_settings_test.h"
#include "backend/app/loot_state_test.h"
#include "backend/game/game_test.h"
#include "backend/game/game_cache_test.h"
#include "backend/game/game_settings_test.h"
#include "backend/game/load_order_handler_test.h"
#include "backend/helpers/git_helper_test.h"
#include "backend/helpers/helpers_test.h"
#include "backend/helpers/language_test.h"
#include "backend/helpers/version_test.h"
#include "backend/helpers/yaml_set_helpers_test.h"
#include "backend/metadata/condition_grammar_test.h"
#include "backend/metadata/conditional_metadata_test.h"
#include "backend/metadata/file_test.h"
#include "backend/metadata/location_test.h"
#include "backend/metadata/message_test.h"
#include "backend/metadata/message_content_test.h"
#include "backend/metadata/plugin_dirty_info_test.h"
#include "backend/metadata/plugin_metadata_test.h"
#include "backend/metadata/tag_test.h"
#include "backend/plugin/plugin_test.h"
#include "backend/plugin/plugin_sorter_test.h"
#include "backend/masterlist_test.h"
#include "backend/metadata_list_test.h"
#include "tests/api/loot_db_test.h"
#include "app/loot_paths_test.h"
#include "app/loot_settings_test.h"
#include "app/loot_state_test.h"
#include "game/game_test.h"
#include "game/game_cache_test.h"
#include "game/game_settings_test.h"
#include "game/load_order_handler_test.h"
#include "helpers/git_helper_test.h"
#include "helpers/helpers_test.h"
#include "helpers/language_test.h"
#include "helpers/version_test.h"
#include "helpers/yaml_set_helpers_test.h"
#include "metadata/condition_grammar_test.h"
#include "metadata/conditional_metadata_test.h"
#include "metadata/file_test.h"
#include "metadata/location_test.h"
#include "metadata/message_test.h"
#include "metadata/message_content_test.h"
#include "metadata/plugin_dirty_info_test.h"
#include "metadata/plugin_metadata_test.h"
#include "metadata/tag_test.h"
#include "plugin/plugin_test.h"
#include "plugin/plugin_sorter_test.h"
#include "masterlist_test.h"
#include "metadata_list_test.h"
#include <boost/log/core.hpp>
+19 -14
View File
@@ -25,13 +25,12 @@ along with LOOT. If not, see
#ifndef LOOT_TEST_BASE_GAME_TEST
#define LOOT_TEST_BASE_GAME_TEST
#include "backend/game/game_settings.h"
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>
#include <map>
#include <unordered_set>
namespace loot {
@@ -115,7 +114,7 @@ namespace loot {
for (const auto& plugin : loadOrder)
actual.push_back(plugin.second);
}
else if (GetParam() == GameSettings::tes5) {
else if (GetParam() == tes5) {
boost::filesystem::ifstream in(localPath / "loadorder.txt");
while (in) {
std::string line;
@@ -179,35 +178,41 @@ namespace loot {
const uint32_t blankEsmCrc;
private:
static const unsigned int tes4 = 1;
static const unsigned int tes5 = 2;
static const unsigned int fo3 = 3;
static const unsigned int fonv = 4;
static const unsigned int fo4 = 5;
inline boost::filesystem::path getLocalPath() const {
if (GetParam() == GameSettings::tes4)
if (GetParam() == tes4)
return "./local/Oblivion";
else
return "./local/Skyrim";
}
inline boost::filesystem::path getPluginsPath() const {
if (GetParam() == GameSettings::tes4)
if (GetParam() == tes4)
return "./Oblivion/Data";
else
return "./Skyrim/Data";
}
inline std::string getMasterFile() const {
if (GetParam() == GameSettings::tes4)
if (GetParam() == tes4)
return "Oblivion.esm";
else if (GetParam() == GameSettings::tes5)
else if (GetParam() == tes5)
return "Skyrim.esm";
else if (GetParam() == GameSettings::fo3)
else if (GetParam() == fo3)
return "Fallout3.esm";
else if (GetParam() == GameSettings::fonv)
else if (GetParam() == fonv)
return "FalloutNV.esm";
else
return "Fallout4.esm";
}
inline uint32_t getBlankEsmCrc() const {
if (GetParam() == GameSettings::tes4)
if (GetParam() == tes4)
return 0x374E2A6F;
else
return 0x187BE342;
@@ -216,9 +221,9 @@ namespace loot {
inline void setLoadOrder(const std::vector<std::pair<std::string, bool>>& loadOrder) const {
boost::filesystem::ofstream out(localPath / "plugins.txt");
for (const auto &plugin : loadOrder) {
if (GetParam() == GameSettings::fo4 && plugin.second)
if (GetParam() == fo4 && plugin.second)
out << '*';
else if (GetParam() != GameSettings::fo4 && !plugin.second)
else if (GetParam() != fo4 && !plugin.second)
continue;
out << plugin.first << std::endl;
@@ -236,7 +241,7 @@ namespace loot {
modificationTime += 60;
}
}
else if (GetParam() == GameSettings::tes5) {
else if (GetParam() == tes5) {
boost::filesystem::ofstream out(localPath / "loadorder.txt");
for (const auto &plugin : loadOrder)
out << plugin.first << std::endl;
@@ -244,7 +249,7 @@ namespace loot {
}
inline static bool isLoadOrderTimestampBased(unsigned int gameId) {
return gameId == GameSettings::tes4 || gameId == GameSettings::fo3 || gameId == GameSettings::fonv;
return gameId == tes4 || gameId == fo3 || gameId == fonv;
}
};
}