Another terrain read/write test

This commit is contained in:
2015-09-04 13:52:18 -04:00
parent 8bc8e10075
commit 44b75b732b
6 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<terrains boes="2.0.0">
<terrain id='0'>
<editor>
<obj/>
</editor>
</terrain>
</terrains>

View File

@@ -0,0 +1,33 @@
<terrains boes="2.0.0">
<terrain id='0'>
<name>Test Terrain</name>
<pic>0</pic>
<map>0</map>
<blockage>move</blockage>
<transform>10</transform>
<fly>true</fly>
<boat>true</boat>
<ride>false</ride>
<archetype>true</archetype>
<light>3</light>
<step-sound>splash</step-sound>
<ground>2</ground>
<trim>none</trim>
<trim-for>1</trim-for>
<arena>0</arena>
<special>
<type>dmg</type>
<flag>4</flag>
<flag>6</flag>
<flag>3</flag>
</special>
<editor>
<shortcut>u</shortcut>
<object>
<num>1</num>
<pos x='0' y='0'/>
<size x='2' y='1'/>
</object>
</editor>
</terrain>
</terrains>

View File

@@ -0,0 +1,9 @@
<terrains boes="2.0.0">
<terrain id='0'>
<editor>
<object>
<number>1</number>
</object>
</editor>
</terrain>
</terrains>

View File

@@ -0,0 +1,9 @@
<terrains boes="2.0.0">
<terrain id='0'>
<editor>
<object>
<num>1</num>
</object>
</editor>
</terrain>
</terrains>

View File

@@ -89,6 +89,21 @@ TEST_CASE("Loading a terrain type definition") {
doc = xmlDocFromStream(fin, "bad_abil_tag.xml");
REQUIRE_THROWS_AS(readTerrainFromXml(move(doc), scen), xBadNode);
}
SECTION("With an incomplete object definition") {
fin.open("files/terrain/object_missing.xml");
doc = xmlDocFromStream(fin, "object_missing.xml");
REQUIRE_THROWS_AS(readTerrainFromXml(move(doc), scen), xMissingElem);
}
SECTION("With an invalid object definition") {
fin.open("files/terrain/object_bad.xml");
doc = xmlDocFromStream(fin, "object_bad.xml");
REQUIRE_THROWS_AS(readTerrainFromXml(move(doc), scen), xBadNode);
}
SECTION("With an invalid editor subtag") {
fin.open("files/terrain/bad_editor.xml");
doc = xmlDocFromStream(fin, "bad_editor.xml");
REQUIRE_THROWS_AS(readTerrainFromXml(move(doc), scen), xBadNode);
}
SECTION("With the minimal required data") {
fin.open("files/terrain/minimal.xml");
doc = xmlDocFromStream(fin, "minimal.xml");
@@ -99,7 +114,35 @@ TEST_CASE("Loading a terrain type definition") {
CHECK(scen.ter_types[0].map_pic == 0);
CHECK(scen.ter_types[0].combat_arena == 0);
CHECK(scen.ter_types[0].blockage == eTerObstruct::BLOCK_MOVE);
CHECK(scen.ter_types[0].ground_type == 0);
CHECK(scen.ter_types[0].trim_type == eTrimType::NONE);
CHECK(scen.ter_types[0].special == eTerSpec::NONE);
CHECK(scen.ter_types[0].step_sound == eStepSnd::STEP);
CHECK_FALSE(scen.ter_types[0].fly_over);
CHECK_FALSE(scen.ter_types[0].boat_over);
CHECK_FALSE(scen.ter_types[0].block_horse);
CHECK_FALSE(scen.ter_types[0].is_archetype);
}
SECTION("With all possible data") {
fin.open("files/terrain/full.xml");
doc = xmlDocFromStream(fin, "full.xml");
REQUIRE_NOTHROW(readTerrainFromXml(move(doc), scen));
CHECK(scen.ter_types[0].special == eTerSpec::DAMAGING);
CHECK(scen.ter_types[0].flag1 == 4);
CHECK(scen.ter_types[0].flag2 == 6);
CHECK(scen.ter_types[0].flag3 == 3);
CHECK(scen.ter_types[0].trans_to_what == 10);
CHECK(scen.ter_types[0].fly_over);
CHECK(scen.ter_types[0].boat_over);
CHECK(scen.ter_types[0].block_horse);
CHECK(scen.ter_types[0].is_archetype);
CHECK(scen.ter_types[0].light_radius == 3);
CHECK(scen.ter_types[0].step_sound == eStepSnd::SPLASH);
CHECK(scen.ter_types[0].ground_type == 2);
CHECK(scen.ter_types[0].trim_ter == 1);
CHECK(scen.ter_types[0].shortcut_key == 'u');
CHECK(scen.ter_types[0].obj_num == 1);
CHECK(scen.ter_types[0].obj_pos == loc(0,0));
CHECK(scen.ter_types[0].obj_size == loc(2,1));
}
}

View File

@@ -59,4 +59,40 @@ TEST_CASE("Saving terrain types") {
CHECK(scen.ter_types[0].flag1 == -1);
CHECK(scen.ter_types[0].step_sound == eStepSnd::STEP);
}
SECTION("With all information") {
scen.ter_types[0].flag1 = 1;
scen.ter_types[0].flag2 = 2;
scen.ter_types[0].flag3 = 3;
scen.ter_types[0].trans_to_what = 100;
scen.ter_types[0].fly_over = true;
scen.ter_types[0].boat_over = true;
scen.ter_types[0].block_horse = true;
scen.ter_types[0].is_archetype = true;
scen.ter_types[0].light_radius = 3;
scen.ter_types[0].step_sound = eStepSnd::SPLASH;
scen.ter_types[0].ground_type = 2;
scen.ter_types[0].trim_ter = 1;
scen.ter_types[0].shortcut_key = 'u';
scen.ter_types[0].obj_num = 1;
scen.ter_types[0].obj_pos = loc(0,0);
scen.ter_types[0].obj_size = loc(2,1);
in_and_out("basic", scen);
REQUIRE(scen.ter_types.size() == 1);
CHECK(scen.ter_types[0].flag1 == 1);
CHECK(scen.ter_types[0].flag2 == 2);
CHECK(scen.ter_types[0].flag3 == 3);
CHECK(scen.ter_types[0].trans_to_what == 100);
CHECK(scen.ter_types[0].fly_over);
CHECK(scen.ter_types[0].boat_over);
CHECK(scen.ter_types[0].block_horse);
CHECK(scen.ter_types[0].is_archetype);
CHECK(scen.ter_types[0].light_radius == 3);
CHECK(scen.ter_types[0].step_sound == eStepSnd::SPLASH);
CHECK(scen.ter_types[0].ground_type == 2);
CHECK(scen.ter_types[0].trim_ter == 1);
CHECK(scen.ter_types[0].shortcut_key == 'u');
CHECK(scen.ter_types[0].obj_num == 1);
CHECK(scen.ter_types[0].obj_pos == loc(0,0));
CHECK(scen.ter_types[0].obj_size == loc(2,1));
}
}