diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5ab3b8a85a..9855443cde 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,6 +72,7 @@ Ubuntu_GCC_preprocess: - cmake --install . - if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw_test_suite --gtest_output="xml:openmw_tests.xml"; fi - if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw-cs-tests --gtest_output="xml:openmw_cs_tests.xml"; fi + - if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw-iniimporter-tests --gtest_output="xml:openmw_iniimporter_tests.xml"; fi - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_detournavigator_navmeshtilescache_benchmark; fi - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_esm_refid_benchmark; fi - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_settings_access_benchmark; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index ff96dd8a6a..4adce72811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -684,6 +684,7 @@ endif(BUILD_NIFTEST) # UnitTests if (BUILD_UNITTESTS) add_subdirectory( apps/openmw_test_suite ) + add_subdirectory( apps/mwiniimporter_tests ) endif() if (BUILD_BENCHMARKS) diff --git a/apps/mwiniimporter_tests/CMakeLists.txt b/apps/mwiniimporter_tests/CMakeLists.txt new file mode 100644 index 0000000000..6692c6021d --- /dev/null +++ b/apps/mwiniimporter_tests/CMakeLists.txt @@ -0,0 +1,26 @@ +file(GLOB INIIMPORTER_TESTS_SRC_FILES + main.cpp +) + +source_group(apps\\openmw-iniimporter-tests FILES ${INIIMPORTER_TESTS_SRC_FILES}) + +openmw_add_executable(openmw-iniimporter-tests ${INIIMPORTER_TESTS_SRC_FILES}) + +target_include_directories(openmw-iniimporter-tests SYSTEM PRIVATE ${GTEST_INCLUDE_DIRS}) +target_include_directories(openmw-iniimporter-tests SYSTEM PRIVATE ${GMOCK_INCLUDE_DIRS}) + +target_link_libraries(openmw-iniimporter-tests PRIVATE + GTest::GTest + GMock::GMock +) + +if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(openmw-iniimporter-tests PRIVATE --coverage) + target_link_libraries(openmw-iniimporter-tests PRIVATE gcov) +endif() + +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) + target_precompile_headers(openmw-iniimporter-tests PRIVATE + + ) +endif() diff --git a/apps/mwiniimporter_tests/main.cpp b/apps/mwiniimporter_tests/main.cpp new file mode 100644 index 0000000000..1005a698e6 --- /dev/null +++ b/apps/mwiniimporter_tests/main.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include + + +struct TestParam +{ + std::string name; + std::string fileName; +}; + +const std::vector testParams = { + { "ascii", "ascii" }, + { "unicode", "(╯°□°)╯︵ ┻━┻"}, + { "emoji", "💩"} +}; + +class IniImporterTest : public ::testing::TestWithParam +{ +}; + + +TEST_P(IniImporterTest, TestIniImport) +{ + auto param = IniImporterTest::GetParam(); + + // Create temporary file + std::string iniData = R"([Archives] +Archive 0=game1.bsa +Archive 1=game2.bsa +)"; + std::filesystem::path tempIniFile = std::filesystem::temp_directory_path() / param.fileName += "morrowind.ini"; + std::ofstream tempFile(tempIniFile); + tempFile << iniData; + tempFile.close(); + std::filesystem::path tempCfgFile = std::filesystem::temp_directory_path() / param.fileName += "openmw.cfg"; + + std::stringstream cmd; + cmd << "./openmw-iniimporter -i " << tempIniFile << " -c " << tempCfgFile; + + int ret = std::system(cmd.str().c_str()); + ASSERT_EQ(ret, 0); + + // Verify the cfg file was created and has the expected contents + std::ifstream ifs(tempCfgFile); + ASSERT_TRUE(ifs.good()); + + std::string cfgData = R"(fallback-archive=Morrowind.bsa +fallback-archive=game1.bsa +fallback-archive=game2.bsa +)"; + + std::stringstream actual; + actual << ifs.rdbuf(); + + ASSERT_EQ(cfgData, actual.str()); + + // Clean up temporary file + std::filesystem::remove(tempCfgFile); + std::filesystem::remove(tempIniFile); +} + +INSTANTIATE_TEST_SUITE_P(IniImporterTests, IniImporterTest, ::testing::ValuesIn(testParams)); + + +int main(int argc, char* argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file