Skip to content

Commit

Permalink
A few tests (#230)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
IhateTrains authored Aug 12, 2021
1 parent 4dcb4db commit 7be3078
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
44 changes: 20 additions & 24 deletions ImperatorToCK3Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -73,21 +64,25 @@ 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}
)

# 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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="CoatsOfArms.txt">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="TestFiles\title_map.txt">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)configurables</DestinationFolders>
Expand All @@ -264,12 +258,6 @@
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)configurables</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="TestFiles\TitlesHistory.txt">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="TestFiles\mod\brokenmod.mod">
<FileType>Document</FileType>
Expand Down Expand Up @@ -304,6 +292,16 @@
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/TestFiles/mod/themod</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="TestFiles\CoatsOfArms.txt">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="TestFiles\title_history\TitlesHistory.txt">
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)TestFiles/title_history</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
15 changes: 9 additions & 6 deletions ImperatorToCK3Tests/ImperatorToCK3Tests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
<Filter Include="TestFiles\mod\themod">
<UniqueIdentifier>{2a75fe57-eb1b-4796-8b22-192f62b450a7}</UniqueIdentifier>
</Filter>
<Filter Include="TestFiles\title_history">
<UniqueIdentifier>{3616713c-5f94-44e0-b646-5781ed8b4592}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ImperatorWorldTests\Families\FamilyTests.cpp">
Expand Down Expand Up @@ -568,9 +571,6 @@
<CopyFileToFolders Include="TestFiles\CK3ProvincesHistoryFile.txt">
<Filter>TestFiles</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="CoatsOfArms.txt">
<Filter>TestFiles</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestFiles\title_map.txt">
<Filter>TestFiles</Filter>
</CopyFileToFolders>
Expand All @@ -580,9 +580,6 @@
<CopyFileToFolders Include="..\ImperatorToCK3\Data_Files\configurables\religion_map.txt">
<Filter>TestFiles</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestFiles\TitlesHistory.txt">
<Filter>TestFiles</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestFiles\mod\themod.mod">
<Filter>TestFiles\mod</Filter>
</CopyFileToFolders>
Expand All @@ -601,5 +598,11 @@
<CopyFileToFolders Include="TestFiles\mod\themod\README.md">
<Filter>TestFiles\mod\themod</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestFiles\title_history\TitlesHistory.txt">
<Filter>TestFiles\title_history</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestFiles\CoatsOfArms.txt">
<Filter>TestFiles</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ TEST(ImperatorWorld_CharacterTests, deathDateDefaultsToNullopt) {
ASSERT_FALSE(theCharacter.getDeathDate());
}

TEST(ImperatorWorld_CharacterTests, deathReasonDefaultsToNullopt) {
const auto genesDB = std::make_shared<Imperator::GenesDB>();
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<Imperator::GenesDB>();
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<Imperator::GenesDB>();
std::stringstream input;
Expand Down Expand Up @@ -371,6 +388,24 @@ TEST(ImperatorWorld_CharacterTests, nameDefaultsToBlank) {
ASSERT_TRUE(theCharacter.getName().empty());
}

TEST(ImperatorWorld_CharacterTests, nicknameCanBeSet) {
const auto genesDB = std::make_shared<Imperator::GenesDB>();
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<Imperator::GenesDB>();
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<Imperator::GenesDB>();
std::stringstream input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }" };

Expand Down
File renamed without changes.

0 comments on commit 7be3078

Please sign in to comment.