Skip to content

Commit

Permalink
Move all tests out of empty namespace (ParadoxGameConverters#620)
Browse files Browse the repository at this point in the history
* Move all tests out of empty namespace

* Formatting
  • Loading branch information
Idhrendur authored May 11, 2024
1 parent 91e83a6 commit 91f0546
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 208 deletions.
59 changes: 34 additions & 25 deletions src/hoi4_world/countries/hoi4_country_converter_tests_tech.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Contains tech and research tests for hoi4::Country
// Contains tech and research tests for Country
#include "external/commonItems/external/googletest/googlemock/include/gmock/gmock-matchers.h"
#include "external/commonItems/external/googletest/googletest/include/gtest/gtest.h"
#include "hoi4_country_converter.h"
Expand All @@ -7,23 +7,27 @@
#include "src/mappers/country/country_mapper.h"
#include "src/vic3_world/world/vic3_world.h"

TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_Decentralized)


namespace hoi4
{

TEST(Hoi4worldCountriesCountryConverter, DecentralizedCountriesHaveTwoResearchSlots)
{
vic3::World source_world(
const vic3::World source_world(
{.country_rankings = vic3::CountryRankings(std::set{4}, std::set{3, 2}, {{2, 10}, {3, 10}, {4, 10}})});
vic3::Country c1({.number = 1, .country_type = "decentralized"});
const vic3::Country c1({.number = 1, .country_type = "decentralized"});

const mappers::CountryMapper country_mapper({{1, "TAG"}});
std::map<int, hoi4::Character> dummy_characters;
std::map<int, Character> dummy_characters;
std::map<std::string, mappers::CultureQueue> dummy_culture_queues;
mappers::TemplateMap templates;
hoi4::States states{{}, {}};

const auto country_one = ConvertCountry(source_world,
c1,
commonItems::LocalizationDatabase{{}, {}},
country_mapper,
states,
{},
mappers::IdeologyMapper({}, {}),
mappers::UnitMapper(templates),
{},
Expand All @@ -42,23 +46,24 @@ TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_Decentralized)

EXPECT_EQ(country_one.value().GetStartingResearchSlots(), 2);
}
TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_default)


TEST(Hoi4worldCountriesCountryConverter, CountriesHaveThreeResearchSlotsByDefault)
{
vic3::World source_world(
const vic3::World source_world(
{.country_rankings = vic3::CountryRankings(std::set{4}, std::set{3, 2}, {{2, 10}, {3, 10}, {4, 10}})});
vic3::Country c2({.number = 2, .country_type = "colonial"});
const vic3::Country c2({.number = 2, .country_type = "colonial"});

const mappers::CountryMapper country_mapper({{2, "Z02"}});
std::map<int, hoi4::Character> dummy_characters;
std::map<int, Character> dummy_characters;
std::map<std::string, mappers::CultureQueue> dummy_culture_queues;
mappers::TemplateMap templates;
hoi4::States states{{}, {}};

const auto country_two = ConvertCountry(source_world,
c2,
commonItems::LocalizationDatabase{{}, {}},
country_mapper,
states,
{},
mappers::IdeologyMapper({}, {}),
mappers::UnitMapper(templates),
{},
Expand All @@ -77,23 +82,24 @@ TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_default)

EXPECT_EQ(country_two.value().GetStartingResearchSlots(), 3);
}
TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_Unrecognized)


TEST(Hoi4worldCountriesCountryConverter, UnrecognizedCountriesHaveTwoResearchSlots)
{
vic3::World source_world(
const vic3::World source_world(
{.country_rankings = vic3::CountryRankings(std::set{4}, std::set{3, 2}, {{2, 10}, {3, 10}, {4, 10}})});
vic3::Country c3({.number = 3, .country_type = "unrecognized"});
const vic3::Country c3({.number = 3, .country_type = "unrecognized"});

const mappers::CountryMapper country_mapper({{3, "Z03"}});
std::map<int, hoi4::Character> dummy_characters;
std::map<int, Character> dummy_characters;
std::map<std::string, mappers::CultureQueue> dummy_culture_queues;
mappers::TemplateMap templates;
hoi4::States states{{}, {}};

const auto country_three = ConvertCountry(source_world,
c3,
commonItems::LocalizationDatabase{{}, {}},
country_mapper,
states,
{},
mappers::IdeologyMapper({}, {}),
mappers::UnitMapper(templates),
{},
Expand All @@ -112,23 +118,24 @@ TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_Unrecognized)

EXPECT_EQ(country_three.value().GetStartingResearchSlots(), 2);
}
TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_GreatPower)


TEST(Hoi4worldCountriesCountryConverter, GreatPowersHaveFourResearchSlots)
{
vic3::World source_world(
const vic3::World source_world(
{.country_rankings = vic3::CountryRankings(std::set{4}, std::set{3, 2}, {{2, 10}, {3, 10}, {4, 10}})});
vic3::Country c4({.number = 4, .country_type = "recognized"});
const vic3::Country c4({.number = 4, .country_type = "recognized"});

const mappers::CountryMapper country_mapper({{4, "Z04"}});
std::map<int, hoi4::Character> dummy_characters;
std::map<int, Character> dummy_characters;
std::map<std::string, mappers::CultureQueue> dummy_culture_queues;
mappers::TemplateMap templates;
hoi4::States states{{}, {}};

const auto country_four = ConvertCountry(source_world,
c4,
commonItems::LocalizationDatabase{{}, {}},
country_mapper,
states,
{},
mappers::IdeologyMapper({}, {}),
mappers::UnitMapper(templates),
{},
Expand All @@ -147,3 +154,5 @@ TEST(Hoi4worldCountriesCountryConverter, StartingResearchSlots_GreatPower)

EXPECT_EQ(country_four.value().GetStartingResearchSlots(), 4);
}

} // namespace hoi4
9 changes: 7 additions & 2 deletions src/hoi4_world/countries/hoi4_country_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@



namespace hoi4
{

TEST(Hoi4worldCountriesCountry, PuppetsCanBeRemoved)
{
hoi4::Country country({.puppets = {"ONE", "TWO", "THR", "FOR"}});
Country country({.puppets = {"ONE", "TWO", "THR", "FOR"}});

country.RemovePuppets({"TWO", "FOR"});

EXPECT_THAT(country.GetPuppets(), testing::UnorderedElementsAre("ONE", "THR"));
}
}

} // namespace hoi4
17 changes: 11 additions & 6 deletions src/hoi4_world/map/coastal_provinces_creator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@



namespace hoi4
{

TEST(Hoi4worldMapCoastalProvincesCreatorTests, CoastalProvincesDefaultToEmpty)
{
const maps::ProvinceDefinitions province_definitions;
const maps::MapData map_data({.province_definitions = province_definitions});
const hoi4::CoastalProvinces coastal_provinces = hoi4::CoastalProvinces{hoi4::CreateCoastalProvinces(map_data,
const CoastalProvinces coastal_provinces = CoastalProvinces{CreateCoastalProvinces(map_data,
province_definitions.GetLandProvinces(),
province_definitions.GetSeaProvinces())};

Expand All @@ -22,7 +25,7 @@ TEST(Hoi4worldMapCoastalProvincesCreatorTests, CoastalProvincesAreDetected)
{
const maps::ProvinceDefinitions province_definitions({.land_provinces = {"1"}, .sea_provinces = {"2"}});
const maps::MapData map_data({.province_neighbors = {{"1", {"2"}}}, .province_definitions = province_definitions});
const hoi4::CoastalProvinces coastal_provinces = hoi4::CoastalProvinces{hoi4::CreateCoastalProvinces(map_data,
const CoastalProvinces coastal_provinces = CoastalProvinces{CreateCoastalProvinces(map_data,
province_definitions.GetLandProvinces(),
province_definitions.GetSeaProvinces())};

Expand All @@ -36,7 +39,7 @@ TEST(Hoi4worldMapCoastalProvincesCreatorTests, MultipleConnectingSeaProvincesAre
const maps::ProvinceDefinitions province_definitions({.land_provinces = {"1"}, .sea_provinces = {"2", "3"}});
const maps::MapData map_data(
{.province_neighbors = {{"1", {"2", "3"}}}, .province_definitions = province_definitions});
const hoi4::CoastalProvinces coastal_provinces = hoi4::CoastalProvinces{hoi4::CreateCoastalProvinces(map_data,
const CoastalProvinces coastal_provinces = CoastalProvinces{CreateCoastalProvinces(map_data,
province_definitions.GetLandProvinces(),
province_definitions.GetSeaProvinces())};

Expand All @@ -49,7 +52,7 @@ TEST(Hoi4worldMapCoastalProvincesCreatorTests, NeighboringLandProvincesDoNotMake
{
const maps::ProvinceDefinitions province_definitions({.land_provinces = {"1", "2"}});
const maps::MapData map_data({.province_neighbors = {{"1", {"2"}}}, .province_definitions = province_definitions});
const hoi4::CoastalProvinces coastal_provinces = hoi4::CoastalProvinces{hoi4::CreateCoastalProvinces(map_data,
const CoastalProvinces coastal_provinces = CoastalProvinces{CreateCoastalProvinces(map_data,
province_definitions.GetLandProvinces(),
province_definitions.GetSeaProvinces())};

Expand All @@ -62,10 +65,12 @@ TEST(Hoi4worldMapCoastalProvincesCreatorTests, BadProvinceNamesAreSkipped)
const maps::ProvinceDefinitions province_definitions({.land_provinces = {"1", "a"}, .sea_provinces = {"2", "b"}});
const maps::MapData map_data(
{.province_neighbors = {{"1", {"2", "b"}}, {"a", {"2", "b"}}}, .province_definitions = province_definitions});
const hoi4::CoastalProvinces coastal_provinces = hoi4::CoastalProvinces{hoi4::CreateCoastalProvinces(map_data,
const CoastalProvinces coastal_provinces = CoastalProvinces{CreateCoastalProvinces(map_data,
province_definitions.GetLandProvinces(),
province_definitions.GetSeaProvinces())};

EXPECT_THAT(coastal_provinces.GetCoastalProvinces(),
testing::UnorderedElementsAre(testing::Pair(1, std::vector{2})));
}
}

} // namespace hoi4
20 changes: 13 additions & 7 deletions src/hoi4_world/map/hoi4_province_definition_importer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@



namespace hoi4
{

TEST(Hoi4worldMapHoi4provincedefinitionimporter, ExceptionThrownForNoDefinitions)
{
commonItems::ModFilesystem mod_filesystem("", {});
const commonItems::ModFilesystem mod_filesystem("", {});

EXPECT_THROW(const maps::ProvinceDefinitions province_definitions = hoi4::ImportProvinceDefinitions(mod_filesystem),
EXPECT_THROW([[maybe_unused]] const maps::ProvinceDefinitions province_definitions =
ImportProvinceDefinitions(mod_filesystem),
std::runtime_error);
}


TEST(Hoi4worldMapHoi4provincedefinitionimporter, DefinitionsCanBeImported)
{
commonItems::ModFilesystem mod_filesystem("test_files/hoi4_world", {});
const commonItems::ModFilesystem mod_filesystem("test_files/hoi4_world", {});

const maps::ProvinceDefinitions province_definitions = hoi4::ImportProvinceDefinitions(mod_filesystem);
const maps::ProvinceDefinitions province_definitions = ImportProvinceDefinitions(mod_filesystem);

EXPECT_THAT(province_definitions.GetLandProvinces(),
testing::UnorderedElementsAre("10", "20", "30", "40", "50", "60"));
Expand All @@ -26,9 +30,11 @@ TEST(Hoi4worldMapHoi4provincedefinitionimporter, DefinitionsCanBeImported)

TEST(Hoi4worldMapHoi4provincedefinitionimporter, SeaProvincesAreDetected)
{
commonItems::ModFilesystem mod_filesystem("test_files/hoi4_world", {});
const commonItems::ModFilesystem mod_filesystem("test_files/hoi4_world", {});

const maps::ProvinceDefinitions province_definitions = hoi4::ImportProvinceDefinitions(mod_filesystem);
const maps::ProvinceDefinitions province_definitions = ImportProvinceDefinitions(mod_filesystem);

EXPECT_TRUE(province_definitions.IsSeaProvince("2"));
}
}

} // namespace hoi4
15 changes: 10 additions & 5 deletions src/hoi4_world/roles/role_importer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@



namespace hoi4
{

TEST(Hoi4worldRolesRoleimporterTests, DefaultsAreDefaulted)
{
std::stringstream input;

hoi4::RoleImporter importer;
const hoi4::Role role = importer.ImportRole("", input);
RoleImporter importer;
const Role role = importer.ImportRole("", input);

EXPECT_TRUE(role.GetName().empty());
EXPECT_TRUE(role.GetCategory().empty());
Expand Down Expand Up @@ -104,8 +107,8 @@ TEST(Hoi4worldRolesRoleimporterTests, ItemsCanBeImported)
input << "\t\n";
input << "}\n";

hoi4::RoleImporter importer;
const hoi4::Role role = importer.ImportRole("unification_italy", input);
RoleImporter importer;
const Role role = importer.ImportRole("unification_italy", input);

EXPECT_EQ(role.GetName(), "unification_italy");
EXPECT_EQ(role.GetCategory(), "unification");
Expand Down Expand Up @@ -177,4 +180,6 @@ TEST(Hoi4worldRolesRoleimporterTests, ItemsCanBeImported)
"= {\n"
"\t\tid = $TAG$_another_event\n"
"\t}"));
}
}

} // namespace hoi4
14 changes: 9 additions & 5 deletions src/hoi4_world/roles/roles_importer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@



namespace hoi4
{
TEST(Hoi4worldRolesRolesimporterTests, RolesCanBeImported)
{
const std::map<std::string, hoi4::Role> roles = hoi4::ImportRoles();
const std::map<std::string, Role> roles = ImportRoles();

EXPECT_THAT(roles,
testing::ElementsAre(testing::Pair("role_1", hoi4::Role{{.name = "role_1"}}),
testing::Pair("role_2", hoi4::Role{{.name = "role_2"}}),
testing::Pair("role_3", hoi4::Role{{.name = "role_3"}})));
}
testing::ElementsAre(testing::Pair("role_1", Role{{.name = "role_1"}}),
testing::Pair("role_2", Role{{.name = "role_2"}}),
testing::Pair("role_3", Role{{.name = "role_3"}})));
}

} // namespace hoi4
19 changes: 12 additions & 7 deletions src/hoi4_world/states/default_states_importer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@



namespace hoi4
{

TEST(Hoi4worldStatesDefaultstatesimporterTests, NoStateFilesMeansNoStates)
{
commonItems::ModFilesystem filesystem("test_files/hoi4_world/NoStateFilesMeansNoStates", {});
const auto default_states = hoi4::ImportDefaultStates(filesystem);
const commonItems::ModFilesystem filesystem("test_files/hoi4_world/NoStateFilesMeansNoStates", {});
const auto default_states = ImportDefaultStates(filesystem);

EXPECT_TRUE(default_states.empty());
}


TEST(Hoi4worldStatesDefaultstatesimporterTests, DefaultStatesCanBeImported)
{
commonItems::ModFilesystem filesystem("test_files/hoi4_world/DefaultStatesCanBeImported", {});
const auto default_states = hoi4::ImportDefaultStates(filesystem);
const commonItems::ModFilesystem filesystem("test_files/hoi4_world/DefaultStatesCanBeImported", {});
const auto default_states = ImportDefaultStates(filesystem);

EXPECT_THAT(default_states,
testing::UnorderedElementsAre(testing::Pair(1,
hoi4::DefaultState({.impassable = true,
DefaultState({.impassable = true,
.owner_tag = "FRA",
.provinces = {3838, 9851, 11804},
.manpower = 322900,
Expand All @@ -32,12 +35,14 @@ TEST(Hoi4worldStatesDefaultstatesimporterTests, DefaultStatesCanBeImported)
.dockyards = 2,
.resources = {{"steel", 5}, {"test_resource", 42}}})),
testing::Pair(2,
hoi4::DefaultState({.impassable = false,
DefaultState({.impassable = false,
.owner_tag = "ITA",
.provinces = {923, 6862, 9794, 9904, 11751, 11846, 11882},
.manpower = 2781971,
.civilian_factories = 4,
.military_factories = 1,
.dockyards = 0,
.resources = {}}))));
}
}

} // namespace hoi4
Loading

0 comments on commit 91f0546

Please sign in to comment.