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.
This commit is contained in:
Oliver Hamlet
2025-07-22 19:56:21 +01:00
parent bdc1f827f6
commit b6d9cb0d9e
4 changed files with 70 additions and 155 deletions
+1 -52
View File
@@ -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"
"$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:RelWithDebInfo>>:/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}
-4
View File
@@ -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 ^
+69
View File
@@ -24,6 +24,8 @@
#include <gtest/gtest.h>
#include <filesystem>
#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) {
-99
View File
@@ -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
<https://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <filesystem>
#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();
}