diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ee41e3f9..57f5c54d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,6 +65,10 @@ jobs: cmake -H. -Bbuild && cmake --build build -- -j3 - name: "Run Tests" run: | + cp -r ImperatorToCK3Tests/TestFiles/. ImperatorToCK3Tests/build/TestFiles/ + ls -R ImperatorToCK3Tests/build/TestFiles + cat ImperatorToCK3Tests/build/TestFiles/title_history/TitlesHistory.txt + cp -r ImperatorToCK3/Data_Files/configurables/. ImperatorToCK3Tests/build/configurables/ cd ImperatorToCK3Tests/build ./ImperatorToCK3Tests - name: "Build gcov" @@ -74,7 +78,6 @@ jobs: export CXX=/usr/bin/g++-11 make init make gcov - make lcov - name: "Check test coverage" run: | cd ImperatorToCK3Tests/build diff --git a/ImperatorToCK3Tests/CMakeLists.txt b/ImperatorToCK3Tests/CMakeLists.txt index 4489ec608..394bcabe7 100644 --- a/ImperatorToCK3Tests/CMakeLists.txt +++ b/ImperatorToCK3Tests/CMakeLists.txt @@ -33,27 +33,18 @@ include_directories( add_subdirectory(../commonItems/ZipLib [binary_dir]) # Set the sources -set(test_sources - test_main.cpp - #the tests - ImperatorWorldTests/Characters/CharacterTests.cpp - ImperatorWorldTests/Characters/CharactersTests.cpp - ImperatorWorldTests/Families/FamilyTests.cpp - ImperatorWorldTests/Families/FamiliesTests.cpp - ImperatorWorldTests/Provinces/ProvinceTests.cpp - ImperatorWorldTests/Provinces/ProvincesTests.cpp - ImperatorWorldTests/Provinces/PopTests.cpp - ImperatorWorldTests/Provinces/PopsTests.cpp - CommonTests/CommonFunctionsTests.cpp -) - -file(GLOB CONFIGURATION_SOURCES "../ImperatorToCK3/Source/Configuration/*.cpp") -file(GLOB COMMON_UTILITIES_SOURCES "../ImperatorToCK3/Source/CommonUtilities/*.cpp") -file(GLOB IMPWORLD_SOURCES "../ImperatorToCK3/Source/Imperator/*.cpp") -file(GLOB IMPWORLD_SUBDIRS_SOURCES "../ImperatorToCK3/Source/Imperator/*/*.cpp") -file(GLOB MAPPERS_SOURCES "../ImperatorToCK3/Source/Mappers/*/*.cpp") -file(GLOB CK3WORLD_SOURCES "../ImperatorToCK3/Source/CK3/*.cpp") -file(GLOB CK3WORLD_SUBDIRS_SOURCES "../ImperatorToCK3/Source/CK3/*/*.cpp") +file(GLOB_RECURSE CK3WorldTests_SOURCES "CK3WorldTests/*.cpp") +file(GLOB_RECURSE ImperatorWorldTests_SOURCES "ImperatorWorldTests/*.cpp") +file(GLOB_RECURSE MapperTests_SOURCES "MapperTests/*.cpp") +file(GLOB_RECURSE CommonTests_SOURCES "CommonTests/*.cpp") +file(GLOB_RECURSE CommonUtilitiesTests_SOURCES "CommonUtilitiesTests/*.cpp") +set(test_sources test_main.cpp) + +file(GLOB_RECURSE CONFIGURATION_SOURCES "../ImperatorToCK3/Source/Configuration/*.cpp") +file(GLOB_RECURSE COMMON_UTILITIES_SOURCES "../ImperatorToCK3/Source/CommonUtilities/*.cpp") +file(GLOB_RECURSE IMPWORLD_SOURCES "../ImperatorToCK3/Source/Imperator/*.cpp") +file(GLOB_RECURSE MAPPERS_SOURCES "../ImperatorToCK3/Source/Mappers/*.cpp") +file(GLOB_RECURSE CK3WORLD_SOURCES "../ImperatorToCK3/Source/CK3/*.cpp") set(BASE64_SOURCES "../cpp-base64/base64.cpp") set(COMMON_SOURCES "../commonItems/CommonFunctions.cpp") set(COMMON_SOURCES ${COMMON_SOURCES} "../commonItems/Color.cpp") @@ -73,13 +64,17 @@ set(COMMON_SOURCES ${COMMON_SOURCES} "../commonItems/StringUtils.cpp") # Create the executable add_executable(ImperatorToCK3Tests ${test_sources} + ${CK3WorldTests_SOURCES} + ${ImperatorWorldTests_SOURCES} + ${MapperTests_SOURCES} + ${CommonTests_SOURCES} + ${CommonUtilitiesTests_SOURCES} + ${CONFIGURATION_SOURCES} ${COMMON_UTILITIES_SOURCES} ${IMPWORLD_SOURCES} - ${IMPWORLD_SUBDIRS_SOURCES} ${MAPPERS_SOURCES} ${CK3WORLD_SOURCES} - ${CK3WORLD_SUBDIRS_SOURCES} ${COMMON_SOURCES} ${BASE64_SOURCES} ) @@ -87,7 +82,7 @@ add_executable(ImperatorToCK3Tests # Create the gcov target. Run coverage tests with 'make gcov' add_custom_target(gcov COMMAND mkdir -p gcoverage - COMMAND ${CMAKE_MAKE_PROGRAM} test + COMMAND ${CMAKE_MAKE_PROGRAM} test VERBOSE=1 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_command(TARGET gcov @@ -118,6 +113,7 @@ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES gcoverage) # Create the gcov-clean target. This cleans the build as well as generated # .gcda and .gcno files. add_custom_target(init + COMMAND echo "=================== INIT ====================" COMMAND ${CMAKE_MAKE_PROGRAM} clean COMMAND rm -f ${OBJECT_DIR}/*.gcno COMMAND rm -f ${OBJECT_DIR}/*.gcda diff --git a/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj b/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj index 4809db096..a99de8473 100644 --- a/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj +++ b/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj @@ -240,12 +240,6 @@ $(OutDir)TestFiles - - - $(OutDir)TestFiles - $(OutDir)TestFiles - - $(OutDir)configurables @@ -264,12 +258,6 @@ $(OutDir)configurables - - - $(OutDir)TestFiles/title_history - $(OutDir)TestFiles/title_history - - Document @@ -304,6 +292,16 @@ $(OutDir)/TestFiles/mod/themod + + + $(OutDir)TestFiles + $(OutDir)TestFiles + + + $(OutDir)TestFiles/title_history + $(OutDir)TestFiles/title_history + + diff --git a/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj.filters b/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj.filters index a58dbad14..6ef76e16d 100644 --- a/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj.filters +++ b/ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj.filters @@ -136,6 +136,9 @@ {2a75fe57-eb1b-4796-8b22-192f62b450a7} + + {3616713c-5f94-44e0-b646-5781ed8b4592} + @@ -568,9 +571,6 @@ TestFiles - - TestFiles - TestFiles @@ -580,9 +580,6 @@ TestFiles - - TestFiles - TestFiles\mod @@ -601,5 +598,11 @@ TestFiles\mod\themod + + TestFiles\title_history + + + TestFiles + \ No newline at end of file diff --git a/ImperatorToCK3Tests/ImperatorWorldTests/Characters/CharacterTests.cpp b/ImperatorToCK3Tests/ImperatorWorldTests/Characters/CharacterTests.cpp index bfbc23e12..e186c1de5 100644 --- a/ImperatorToCK3Tests/ImperatorWorldTests/Characters/CharacterTests.cpp +++ b/ImperatorToCK3Tests/ImperatorWorldTests/Characters/CharacterTests.cpp @@ -174,6 +174,23 @@ TEST(ImperatorWorld_CharacterTests, deathDateDefaultsToNullopt) { ASSERT_FALSE(theCharacter.getDeathDate()); } +TEST(ImperatorWorld_CharacterTests, deathReasonDefaultsToNullopt) { + const auto genesDB = std::make_shared(); + std::stringstream input; + const auto character = *Imperator::Character::Factory().getCharacter(input, "42", genesDB); + + ASSERT_EQ(std::nullopt, character.getDeathReason()); +} + +TEST(ImperatorWorld_CharacterTests, deathReasonCanBeSet) { + const auto genesDB = std::make_shared(); + std::stringstream input; + input << R"( = { death = killed_in_battle })"; + const auto character = *Imperator::Character::Factory().getCharacter(input, "42", genesDB); + + ASSERT_EQ("killed_in_battle", character.getDeathReason()); +} + TEST(ImperatorWorld_CharacterTests, spousesCanBeSet) { const auto genesDB = std::make_shared(); std::stringstream input; @@ -371,6 +388,24 @@ TEST(ImperatorWorld_CharacterTests, nameDefaultsToBlank) { ASSERT_TRUE(theCharacter.getName().empty()); } +TEST(ImperatorWorld_CharacterTests, nicknameCanBeSet) { + const auto genesDB = std::make_shared(); + std::stringstream input; + input << R"(= { nickname = "the Great" })"; + + const auto theCharacter = *Imperator::Character::Factory().getCharacter(input, "42", genesDB); + + ASSERT_EQ("the Great", theCharacter.getNickname()); +} + +TEST(ImperatorWorld_CharacterTests, nicknameDefaultsToEmpty) { + const auto genesDB = std::make_shared(); + std::stringstream input; + const auto theCharacter = *Imperator::Character::Factory().getCharacter(input, "42", genesDB); + + ASSERT_TRUE(theCharacter.getNickname().empty()); +} + TEST(ImperatorWorld_CharacterTests, attributesDefaultToZero) { const auto genesDB = std::make_shared(); std::stringstream input; diff --git a/ImperatorToCK3Tests/ImperatorWorldTests/Provinces/ProvinceTests.cpp b/ImperatorToCK3Tests/ImperatorWorldTests/Provinces/ProvinceTests.cpp index b20c08284..1389b9b0d 100644 --- a/ImperatorToCK3Tests/ImperatorWorldTests/Provinces/ProvinceTests.cpp +++ b/ImperatorToCK3Tests/ImperatorWorldTests/Provinces/ProvinceTests.cpp @@ -147,7 +147,7 @@ TEST(ImperatorWorld_ProvinceTests, province_rankDefaultsToSettlement) { } TEST(ImperatorWorld_ProvinceTests, province_rankCanBeSet) { - std::stringstream input{ "= { province_rank=settelement }" }; + std::stringstream input{ "= { province_rank=settlement }" }; std::stringstream input2{ "= { province_rank=city }" }; std::stringstream input3{ "= { province_rank=city_metropolis }" }; diff --git a/ImperatorToCK3Tests/CoatsOfArms.txt b/ImperatorToCK3Tests/TestFiles/CoatsOfArms.txt similarity index 100% rename from ImperatorToCK3Tests/CoatsOfArms.txt rename to ImperatorToCK3Tests/TestFiles/CoatsOfArms.txt diff --git a/ImperatorToCK3Tests/TestFiles/TitlesHistory.txt b/ImperatorToCK3Tests/TestFiles/title_history/TitlesHistory.txt similarity index 100% rename from ImperatorToCK3Tests/TestFiles/TitlesHistory.txt rename to ImperatorToCK3Tests/TestFiles/title_history/TitlesHistory.txt