From b6d9cb0d9e54bda9da99812f40fcfcdf0d22490f Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 22 Jul 2025 19:32:39 +0100 Subject: [PATCH] Remove the libloot_internals_tests target Move its tests to libloot_tests, as there's nothing in the internals that can't be just as easily tested through the public API. --- cpp/cmake/tests.cmake | 53 +-------------- cpp/scripts/OpenCppCoverage.bat | 4 -- cpp/src/tests/api/interface/main.cpp | 69 +++++++++++++++++++ cpp/src/tests/api/internals/main.cpp | 99 ---------------------------- 4 files changed, 70 insertions(+), 155 deletions(-) delete mode 100644 cpp/src/tests/api/internals/main.cpp diff --git a/cpp/cmake/tests.cmake b/cpp/cmake/tests.cmake index f5d1ddc7..10d1abb2 100644 --- a/cpp/cmake/tests.cmake +++ b/cpp/cmake/tests.cmake @@ -33,11 +33,6 @@ set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_INITIAL}) # General Settings ############################## -set(LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES - "${CMAKE_SOURCE_DIR}/src/tests/api/internals/main.cpp") - -# set(LIBLOOT_SRC_TESTS_INTERNALS_H_FILES) - set(LIBLOOT_SRC_TESTS_INTERFACE_CPP_FILES "${CMAKE_SOURCE_DIR}/src/tests/api/interface/main.cpp") @@ -56,14 +51,6 @@ set(LIBLOOT_SRC_TESTS_INTERFACE_H_FILES "${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/plugin_metadata_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/tag_test.h") -source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/internals" - PREFIX "Source Files" - FILES ${LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES}) - -# source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/internals" -# PREFIX "Header Files" -# FILES ${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES}) - source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/interface" PREFIX "Source Files" FILES ${LIBLOOT_SRC_TESTS_INTERFACE_CPP_FILES}) @@ -72,15 +59,6 @@ source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/interface" PREFIX "Header Files" FILES ${LIBLOOT_SRC_TESTS_INTERFACE_H_FILES}) - -set(LIBLOOT_INTERNALS_TESTS_ALL_SOURCES - ${LIBLOOT_ALL_SOURCES} - ${LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES} - # ${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES} - "${CMAKE_SOURCE_DIR}/src/tests/common_game_test_fixture.h" - "${CMAKE_SOURCE_DIR}/src/tests/test_helpers.h" - "${CMAKE_SOURCE_DIR}/src/tests/printers.h") - set(LIBLOOT_INTERFACE_TESTS_ALL_SOURCES ${LIBLOOT_SRC_TESTS_INTERFACE_CPP_FILES} ${LIBLOOT_SRC_TESTS_INTERFACE_H_FILES} @@ -93,63 +71,39 @@ set(LIBLOOT_INTERFACE_TESTS_ALL_SOURCES # Define Targets ############################## -# Build tests. -add_executable(libloot_internals_tests ${LIBLOOT_INTERNALS_TESTS_ALL_SOURCES}) -target_link_libraries(libloot_internals_tests PRIVATE - libloot-cpp - GTest::gtest_main) - # Build API tests. add_executable(libloot_tests ${LIBLOOT_INTERFACE_TESTS_ALL_SOURCES}) add_dependencies(libloot_tests loot) target_link_libraries(libloot_tests PRIVATE loot GTest::gtest_main) enable_testing() -gtest_discover_tests(libloot_internals_tests DISCOVERY_TIMEOUT 10) gtest_discover_tests(libloot_tests DISCOVERY_TIMEOUT 10) ############################## # Set Target-Specific Flags ############################## -target_include_directories(libloot_internals_tests PRIVATE - ${LIBLOOT_INCLUDE_DIRS}) - -target_include_directories(libloot_internals_tests SYSTEM PRIVATE - ${LIBLOOT_COMMON_SYSTEM_INCLUDE_DIRS}) - target_include_directories(libloot_tests PRIVATE ${LIBLOOT_INCLUDE_DIRS}) target_include_directories(libloot_tests SYSTEM PRIVATE ${LIBLOOT_COMMON_SYSTEM_INCLUDE_DIRS}) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - target_compile_definitions(libloot_internals_tests PRIVATE - UNICODE _UNICODE LOOT_STATIC) target_compile_definitions(libloot_tests PRIVATE UNICODE _UNICODE) if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") target_compile_definitions(libloot_tests PRIVATE LOOT_STATIC) endif() - target_link_libraries(libloot_internals_tests PRIVATE ${LOOT_LIBS}) target_link_libraries(libloot_tests PRIVATE ${LOOT_LIBS}) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(libloot_internals_tests PRIVATE "-Wall" "-Wextra") target_compile_options(libloot_tests PRIVATE "-Wall" "-Wextra") endif() if(MSVC) # Turn off permissive mode to be more standards-compliant and avoid compiler errors. target_compile_options(libloot_tests PRIVATE "/Zc:__cplusplus" "/permissive-" "/W4") - - # Set /bigobj to allow building Debug and RelWithDebInfo tests - target_compile_options(libloot_internals_tests PRIVATE - "/Zc:__cplusplus" - "/permissive-" - "/W4" - "$<$,$>:/bigobj>") endif() @@ -188,7 +142,7 @@ if(RUN_CLANG_TIDY) set(CLANG_TIDY_TEST clang-tidy "-header-filter=.*" "-checks=${CLANG_TIDY_TEST_CHECKS_JOINED}") - set_target_properties(libloot_internals_tests libloot_tests + set_target_properties(libloot_tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_TEST}") endif() @@ -199,11 +153,6 @@ endif() ############################## # Copy testing plugins -add_custom_command(TARGET libloot_internals_tests POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${testing-plugins_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/testing-plugins) - add_custom_command(TARGET libloot_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${testing-plugins_SOURCE_DIR} diff --git a/cpp/scripts/OpenCppCoverage.bat b/cpp/scripts/OpenCppCoverage.bat index 889b57c0..8872a8fd 100644 --- a/cpp/scripts/OpenCppCoverage.bat +++ b/cpp/scripts/OpenCppCoverage.bat @@ -1,9 +1,5 @@ rmdir /q /s build\coverage -OpenCppCoverage.exe --sources %cd%\src --sources %cd%\include ^ - --export_type binary:build\coverage\unit.cov --working_dir build ^ - -- build\Debug\libloot_internals_tests.exe - OpenCppCoverage.exe --sources %cd%\src --sources %cd%\include ^ --input_coverage build\coverage\unit.cov ^ --export_type cobertura:build\coverage\cobertura.xml ^ diff --git a/cpp/src/tests/api/interface/main.cpp b/cpp/src/tests/api/interface/main.cpp index f278e612..9444f1eb 100644 --- a/cpp/src/tests/api/interface/main.cpp +++ b/cpp/src/tests/api/interface/main.cpp @@ -24,6 +24,8 @@ #include +#include + #include "loot/api.h" #include "tests/api/interface/metadata/file_test.h" #include "tests/api/interface/metadata/group_test.h" @@ -44,6 +46,73 @@ int main(int argc, char **argv) { return RUN_ALL_TESTS(); } +#ifdef _WIN32 +TEST(Filesystem, + pathStringConstructorDoesNotConvertCharacterEncodingFromUtf8ToNative) { + std::string utf8 = u8"Andr\u00E9_settings.toml"; + std::u16string utf16 = u"Andr\u00E9_settings.toml"; + + ASSERT_EQ('\xc3', utf8[4]); + ASSERT_EQ('\xa9', utf8[5]); + + std::filesystem::path path(utf8); + + EXPECT_EQ(utf8, path.string()); + EXPECT_NE(utf8, path.u8string()); + EXPECT_NE(utf16, path.u16string()); +} + +TEST( + Filesystem, + pathStringAndLocaleConstructorDoesNotConvertCharacterEncodingFromUtf8WithClassicLocale) { + std::string utf8 = u8"Andr\u00E9_settings.toml"; + std::u16string utf16 = u"Andr\u00E9_settings.toml"; + + ASSERT_EQ('\xc3', utf8[4]); + ASSERT_EQ('\xa9', utf8[5]); + + std::filesystem::path path(utf8, std::locale::classic()); + + EXPECT_EQ(utf8, path.string()); + + EXPECT_NE(utf8, path.u8string()); + EXPECT_NE(utf16, path.u16string()); +} +#else +TEST(Filesystem, pathStringConstructorUsesNativeEncodingOfUtf8) { + std::string utf8 = u8"Andr\u00E9_settings.toml"; + std::u16string utf16 = u"Andr\u00E9_settings.toml"; + + ASSERT_EQ('\xc3', utf8[4]); + ASSERT_EQ('\xa9', utf8[5]); + + std::filesystem::path path(utf8); + + EXPECT_EQ(utf8, path.string()); + EXPECT_EQ(utf8, path.u8string()); + EXPECT_EQ(utf16, path.u16string()); +} +#endif + +TEST(Filesystem, u8pathConvertsCharacterEncodingFromUtf8ToNative) { + std::string utf8 = u8"Andr\u00E9_settings.toml"; + std::u16string utf16 = u"Andr\u00E9_settings.toml"; + + ASSERT_EQ('\xc3', utf8[4]); + ASSERT_EQ('\xa9', utf8[5]); + + std::filesystem::path path = std::filesystem::u8path(utf8); + +#ifdef _WIN32 + EXPECT_NE(utf8, path.string()); +#else + EXPECT_EQ(utf8, path.string()); +#endif + + EXPECT_EQ(utf8, path.u8string()); + EXPECT_EQ(utf16, path.u16string()); +} + namespace loot { namespace test { void testLoggingCallback(LogLevel, std::string_view) { diff --git a/cpp/src/tests/api/internals/main.cpp b/cpp/src/tests/api/internals/main.cpp deleted file mode 100644 index ed295dc9..00000000 --- a/cpp/src/tests/api/internals/main.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* 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 - . - */ - -#include - -#include - -#ifdef _WIN32 -TEST(Filesystem, - pathStringConstructorDoesNotConvertCharacterEncodingFromUtf8ToNative) { - std::string utf8 = u8"Andr\u00E9_settings.toml"; - std::u16string utf16 = u"Andr\u00E9_settings.toml"; - - ASSERT_EQ('\xc3', utf8[4]); - ASSERT_EQ('\xa9', utf8[5]); - - std::filesystem::path path(utf8); - - EXPECT_EQ(utf8, path.string()); - EXPECT_NE(utf8, path.u8string()); - EXPECT_NE(utf16, path.u16string()); -} - -TEST( - Filesystem, - pathStringAndLocaleConstructorDoesNotConvertCharacterEncodingFromUtf8WithClassicLocale) { - std::string utf8 = u8"Andr\u00E9_settings.toml"; - std::u16string utf16 = u"Andr\u00E9_settings.toml"; - - ASSERT_EQ('\xc3', utf8[4]); - ASSERT_EQ('\xa9', utf8[5]); - - std::filesystem::path path(utf8, std::locale::classic()); - - EXPECT_EQ(utf8, path.string()); - - EXPECT_NE(utf8, path.u8string()); - EXPECT_NE(utf16, path.u16string()); -} -#else -TEST(Filesystem, pathStringConstructorUsesNativeEncodingOfUtf8) { - std::string utf8 = u8"Andr\u00E9_settings.toml"; - std::u16string utf16 = u"Andr\u00E9_settings.toml"; - - ASSERT_EQ('\xc3', utf8[4]); - ASSERT_EQ('\xa9', utf8[5]); - - std::filesystem::path path(utf8); - - EXPECT_EQ(utf8, path.string()); - EXPECT_EQ(utf8, path.u8string()); - EXPECT_EQ(utf16, path.u16string()); -} -#endif - -TEST(Filesystem, u8pathConvertsCharacterEncodingFromUtf8ToNative) { - std::string utf8 = u8"Andr\u00E9_settings.toml"; - std::u16string utf16 = u"Andr\u00E9_settings.toml"; - - ASSERT_EQ('\xc3', utf8[4]); - ASSERT_EQ('\xa9', utf8[5]); - - std::filesystem::path path = std::filesystem::u8path(utf8); - -#ifdef _WIN32 - EXPECT_NE(utf8, path.string()); -#else - EXPECT_EQ(utf8, path.string()); -#endif - - EXPECT_EQ(utf8, path.u8string()); - EXPECT_EQ(utf16, path.u16string()); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -}