Skip to content

Commit 7be3078

Browse files
authored
A few tests (#230)
* Added simple Imp Character tests * Fix typo in ProvinceTests * Update tests' CMakeLists * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * Update test.yml * Update tests' cmakelists * Update test.yml * Update test.yml * Update test.yml * Update test.yml * organize test files * add temp line to workflow * Update test.yml
1 parent 4dcb4db commit 7be3078

File tree

8 files changed

+79
-44
lines changed

8 files changed

+79
-44
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ jobs:
6565
cmake -H. -Bbuild && cmake --build build -- -j3
6666
- name: "Run Tests"
6767
run: |
68+
cp -r ImperatorToCK3Tests/TestFiles/. ImperatorToCK3Tests/build/TestFiles/
69+
ls -R ImperatorToCK3Tests/build/TestFiles
70+
cat ImperatorToCK3Tests/build/TestFiles/title_history/TitlesHistory.txt
71+
cp -r ImperatorToCK3/Data_Files/configurables/. ImperatorToCK3Tests/build/configurables/
6872
cd ImperatorToCK3Tests/build
6973
./ImperatorToCK3Tests
7074
- name: "Build gcov"
@@ -74,7 +78,6 @@ jobs:
7478
export CXX=/usr/bin/g++-11
7579
make init
7680
make gcov
77-
make lcov
7881
- name: "Check test coverage"
7982
run: |
8083
cd ImperatorToCK3Tests/build

ImperatorToCK3Tests/CMakeLists.txt

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,18 @@ include_directories(
3333
add_subdirectory(../commonItems/ZipLib [binary_dir])
3434

3535
# Set the sources
36-
set(test_sources
37-
test_main.cpp
38-
#the tests
39-
ImperatorWorldTests/Characters/CharacterTests.cpp
40-
ImperatorWorldTests/Characters/CharactersTests.cpp
41-
ImperatorWorldTests/Families/FamilyTests.cpp
42-
ImperatorWorldTests/Families/FamiliesTests.cpp
43-
ImperatorWorldTests/Provinces/ProvinceTests.cpp
44-
ImperatorWorldTests/Provinces/ProvincesTests.cpp
45-
ImperatorWorldTests/Provinces/PopTests.cpp
46-
ImperatorWorldTests/Provinces/PopsTests.cpp
47-
CommonTests/CommonFunctionsTests.cpp
48-
)
49-
50-
file(GLOB CONFIGURATION_SOURCES "../ImperatorToCK3/Source/Configuration/*.cpp")
51-
file(GLOB COMMON_UTILITIES_SOURCES "../ImperatorToCK3/Source/CommonUtilities/*.cpp")
52-
file(GLOB IMPWORLD_SOURCES "../ImperatorToCK3/Source/Imperator/*.cpp")
53-
file(GLOB IMPWORLD_SUBDIRS_SOURCES "../ImperatorToCK3/Source/Imperator/*/*.cpp")
54-
file(GLOB MAPPERS_SOURCES "../ImperatorToCK3/Source/Mappers/*/*.cpp")
55-
file(GLOB CK3WORLD_SOURCES "../ImperatorToCK3/Source/CK3/*.cpp")
56-
file(GLOB CK3WORLD_SUBDIRS_SOURCES "../ImperatorToCK3/Source/CK3/*/*.cpp")
36+
file(GLOB_RECURSE CK3WorldTests_SOURCES "CK3WorldTests/*.cpp")
37+
file(GLOB_RECURSE ImperatorWorldTests_SOURCES "ImperatorWorldTests/*.cpp")
38+
file(GLOB_RECURSE MapperTests_SOURCES "MapperTests/*.cpp")
39+
file(GLOB_RECURSE CommonTests_SOURCES "CommonTests/*.cpp")
40+
file(GLOB_RECURSE CommonUtilitiesTests_SOURCES "CommonUtilitiesTests/*.cpp")
41+
set(test_sources test_main.cpp)
42+
43+
file(GLOB_RECURSE CONFIGURATION_SOURCES "../ImperatorToCK3/Source/Configuration/*.cpp")
44+
file(GLOB_RECURSE COMMON_UTILITIES_SOURCES "../ImperatorToCK3/Source/CommonUtilities/*.cpp")
45+
file(GLOB_RECURSE IMPWORLD_SOURCES "../ImperatorToCK3/Source/Imperator/*.cpp")
46+
file(GLOB_RECURSE MAPPERS_SOURCES "../ImperatorToCK3/Source/Mappers/*.cpp")
47+
file(GLOB_RECURSE CK3WORLD_SOURCES "../ImperatorToCK3/Source/CK3/*.cpp")
5748
set(BASE64_SOURCES "../cpp-base64/base64.cpp")
5849
set(COMMON_SOURCES "../commonItems/CommonFunctions.cpp")
5950
set(COMMON_SOURCES ${COMMON_SOURCES} "../commonItems/Color.cpp")
@@ -73,21 +64,25 @@ set(COMMON_SOURCES ${COMMON_SOURCES} "../commonItems/StringUtils.cpp")
7364
# Create the executable
7465
add_executable(ImperatorToCK3Tests
7566
${test_sources}
67+
${CK3WorldTests_SOURCES}
68+
${ImperatorWorldTests_SOURCES}
69+
${MapperTests_SOURCES}
70+
${CommonTests_SOURCES}
71+
${CommonUtilitiesTests_SOURCES}
72+
7673
${CONFIGURATION_SOURCES}
7774
${COMMON_UTILITIES_SOURCES}
7875
${IMPWORLD_SOURCES}
79-
${IMPWORLD_SUBDIRS_SOURCES}
8076
${MAPPERS_SOURCES}
8177
${CK3WORLD_SOURCES}
82-
${CK3WORLD_SUBDIRS_SOURCES}
8378
${COMMON_SOURCES}
8479
${BASE64_SOURCES}
8580
)
8681

8782
# Create the gcov target. Run coverage tests with 'make gcov'
8883
add_custom_target(gcov
8984
COMMAND mkdir -p gcoverage
90-
COMMAND ${CMAKE_MAKE_PROGRAM} test
85+
COMMAND ${CMAKE_MAKE_PROGRAM} test VERBOSE=1
9186
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
9287
)
9388
add_custom_command(TARGET gcov
@@ -118,6 +113,7 @@ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES gcoverage)
118113
# Create the gcov-clean target. This cleans the build as well as generated
119114
# .gcda and .gcno files.
120115
add_custom_target(init
116+
COMMAND echo "=================== INIT ===================="
121117
COMMAND ${CMAKE_MAKE_PROGRAM} clean
122118
COMMAND rm -f ${OBJECT_DIR}/*.gcno
123119
COMMAND rm -f ${OBJECT_DIR}/*.gcda

ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@
240240
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles</DestinationFolders>
241241
</CopyFileToFolders>
242242
</ItemGroup>
243-
<ItemGroup>
244-
<CopyFileToFolders Include="CoatsOfArms.txt">
245-
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles</DestinationFolders>
246-
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles</DestinationFolders>
247-
</CopyFileToFolders>
248-
</ItemGroup>
249243
<ItemGroup>
250244
<CopyFileToFolders Include="TestFiles\title_map.txt">
251245
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)configurables</DestinationFolders>
@@ -264,12 +258,6 @@
264258
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)configurables</DestinationFolders>
265259
</CopyFileToFolders>
266260
</ItemGroup>
267-
<ItemGroup>
268-
<CopyFileToFolders Include="TestFiles\TitlesHistory.txt">
269-
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
270-
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
271-
</CopyFileToFolders>
272-
</ItemGroup>
273261
<ItemGroup>
274262
<CopyFileToFolders Include="TestFiles\mod\brokenmod.mod">
275263
<FileType>Document</FileType>
@@ -304,6 +292,16 @@
304292
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/TestFiles/mod/themod</DestinationFolders>
305293
</CopyFileToFolders>
306294
</ItemGroup>
295+
<ItemGroup>
296+
<CopyFileToFolders Include="TestFiles\CoatsOfArms.txt">
297+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles</DestinationFolders>
298+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles</DestinationFolders>
299+
</CopyFileToFolders>
300+
<CopyFileToFolders Include="TestFiles\title_history\TitlesHistory.txt">
301+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
302+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
303+
</CopyFileToFolders>
304+
</ItemGroup>
307305
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
308306
<ImportGroup Label="ExtensionTargets">
309307
</ImportGroup>

ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj.filters

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@
136136
<Filter Include="TestFiles\mod\themod">
137137
<UniqueIdentifier>{2a75fe57-eb1b-4796-8b22-192f62b450a7}</UniqueIdentifier>
138138
</Filter>
139+
<Filter Include="TestFiles\title_history">
140+
<UniqueIdentifier>{3616713c-5f94-44e0-b646-5781ed8b4592}</UniqueIdentifier>
141+
</Filter>
139142
</ItemGroup>
140143
<ItemGroup>
141144
<ClCompile Include="ImperatorWorldTests\Families\FamilyTests.cpp">
@@ -568,9 +571,6 @@
568571
<CopyFileToFolders Include="TestFiles\CK3ProvincesHistoryFile.txt">
569572
<Filter>TestFiles</Filter>
570573
</CopyFileToFolders>
571-
<CopyFileToFolders Include="CoatsOfArms.txt">
572-
<Filter>TestFiles</Filter>
573-
</CopyFileToFolders>
574574
<CopyFileToFolders Include="TestFiles\title_map.txt">
575575
<Filter>TestFiles</Filter>
576576
</CopyFileToFolders>
@@ -580,9 +580,6 @@
580580
<CopyFileToFolders Include="..\ImperatorToCK3\Data_Files\configurables\religion_map.txt">
581581
<Filter>TestFiles</Filter>
582582
</CopyFileToFolders>
583-
<CopyFileToFolders Include="TestFiles\TitlesHistory.txt">
584-
<Filter>TestFiles</Filter>
585-
</CopyFileToFolders>
586583
<CopyFileToFolders Include="TestFiles\mod\themod.mod">
587584
<Filter>TestFiles\mod</Filter>
588585
</CopyFileToFolders>
@@ -601,5 +598,11 @@
601598
<CopyFileToFolders Include="TestFiles\mod\themod\README.md">
602599
<Filter>TestFiles\mod\themod</Filter>
603600
</CopyFileToFolders>
601+
<CopyFileToFolders Include="TestFiles\title_history\TitlesHistory.txt">
602+
<Filter>TestFiles\title_history</Filter>
603+
</CopyFileToFolders>
604+
<CopyFileToFolders Include="TestFiles\CoatsOfArms.txt">
605+
<Filter>TestFiles</Filter>
606+
</CopyFileToFolders>
604607
</ItemGroup>
605608
</Project>

ImperatorToCK3Tests/ImperatorWorldTests/Characters/CharacterTests.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ TEST(ImperatorWorld_CharacterTests, deathDateDefaultsToNullopt) {
174174
ASSERT_FALSE(theCharacter.getDeathDate());
175175
}
176176

177+
TEST(ImperatorWorld_CharacterTests, deathReasonDefaultsToNullopt) {
178+
const auto genesDB = std::make_shared<Imperator::GenesDB>();
179+
std::stringstream input;
180+
const auto character = *Imperator::Character::Factory().getCharacter(input, "42", genesDB);
181+
182+
ASSERT_EQ(std::nullopt, character.getDeathReason());
183+
}
184+
185+
TEST(ImperatorWorld_CharacterTests, deathReasonCanBeSet) {
186+
const auto genesDB = std::make_shared<Imperator::GenesDB>();
187+
std::stringstream input;
188+
input << R"( = { death = killed_in_battle })";
189+
const auto character = *Imperator::Character::Factory().getCharacter(input, "42", genesDB);
190+
191+
ASSERT_EQ("killed_in_battle", character.getDeathReason());
192+
}
193+
177194
TEST(ImperatorWorld_CharacterTests, spousesCanBeSet) {
178195
const auto genesDB = std::make_shared<Imperator::GenesDB>();
179196
std::stringstream input;
@@ -371,6 +388,24 @@ TEST(ImperatorWorld_CharacterTests, nameDefaultsToBlank) {
371388
ASSERT_TRUE(theCharacter.getName().empty());
372389
}
373390

391+
TEST(ImperatorWorld_CharacterTests, nicknameCanBeSet) {
392+
const auto genesDB = std::make_shared<Imperator::GenesDB>();
393+
std::stringstream input;
394+
input << R"(= { nickname = "the Great" })";
395+
396+
const auto theCharacter = *Imperator::Character::Factory().getCharacter(input, "42", genesDB);
397+
398+
ASSERT_EQ("the Great", theCharacter.getNickname());
399+
}
400+
401+
TEST(ImperatorWorld_CharacterTests, nicknameDefaultsToEmpty) {
402+
const auto genesDB = std::make_shared<Imperator::GenesDB>();
403+
std::stringstream input;
404+
const auto theCharacter = *Imperator::Character::Factory().getCharacter(input, "42", genesDB);
405+
406+
ASSERT_TRUE(theCharacter.getNickname().empty());
407+
}
408+
374409
TEST(ImperatorWorld_CharacterTests, attributesDefaultToZero) {
375410
const auto genesDB = std::make_shared<Imperator::GenesDB>();
376411
std::stringstream input;

ImperatorToCK3Tests/ImperatorWorldTests/Provinces/ProvinceTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ TEST(ImperatorWorld_ProvinceTests, province_rankDefaultsToSettlement) {
147147
}
148148

149149
TEST(ImperatorWorld_ProvinceTests, province_rankCanBeSet) {
150-
std::stringstream input{ "= { province_rank=settelement }" };
150+
std::stringstream input{ "= { province_rank=settlement }" };
151151
std::stringstream input2{ "= { province_rank=city }" };
152152
std::stringstream input3{ "= { province_rank=city_metropolis }" };
153153

0 commit comments

Comments
 (0)