diff --git a/src/tools/fileio_scen.cpp b/src/tools/fileio_scen.cpp index 0ad2eadf..4c79805f 100644 --- a/src/tools/fileio_scen.cpp +++ b/src/tools/fileio_scen.cpp @@ -757,7 +757,6 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) { game->GetText(&scenario.init_spec); } else if(type == "start-town") { game->GetText(&scenario.which_town_start); - // TODO: Make sure town is valid } else if(type == "town-start") { scenario.where_start = readLocFromXml(*game); } else if(type == "outdoor-start") { @@ -776,7 +775,6 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) { auto town_p = &scenario.town_mods[town_mods].spec; location& loc = scenario.town_mods[town_mods]; loc = readLocFromXml(*game, "add-", "town", town_p); - // TODO: Make sure town is valid town_mods++; } else if(type == "special-item") { scenario.special_items.emplace_back(); diff --git a/test/files/scenario/bad_format.xml b/test/files/scenario/bad_format.xml new file mode 100644 index 00000000..71c7f0c2 --- /dev/null +++ b/test/files/scenario/bad_format.xml @@ -0,0 +1,31 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + unknown + 2.0.0 + + + diff --git a/test/files/scenario/bad_graphics1.xml b/test/files/scenario/bad_graphics1.xml new file mode 100644 index 00000000..e25ab94c --- /dev/null +++ b/test/files/scenario/bad_graphics1.xml @@ -0,0 +1,47 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + 2 + + 0 + 1 + + + diff --git a/test/files/scenario/bad_graphics2.xml b/test/files/scenario/bad_graphics2.xml new file mode 100644 index 00000000..7655e185 --- /dev/null +++ b/test/files/scenario/bad_graphics2.xml @@ -0,0 +1,46 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + 2 + + 0 + + + diff --git a/test/files/scenario/bad_graphics3.xml b/test/files/scenario/bad_graphics3.xml new file mode 100644 index 00000000..ea1c4a00 --- /dev/null +++ b/test/files/scenario/bad_graphics3.xml @@ -0,0 +1,46 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + 2 + + 0 + 1 + + diff --git a/test/files/scenario/bad_graphics4.xml b/test/files/scenario/bad_graphics4.xml new file mode 100644 index 00000000..d8ceb48a --- /dev/null +++ b/test/files/scenario/bad_graphics4.xml @@ -0,0 +1,46 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + 2 + + 0 + 1 + + diff --git a/test/files/scenario/bad_graphics5.xml b/test/files/scenario/bad_graphics5.xml new file mode 100644 index 00000000..12d19218 --- /dev/null +++ b/test/files/scenario/bad_graphics5.xml @@ -0,0 +1,46 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + 2 + + 0 + 20 + + diff --git a/test/files/scenario/bad_version.xml b/test/files/scenario/bad_version.xml new file mode 100644 index 00000000..9771914d --- /dev/null +++ b/test/files/scenario/bad_version.xml @@ -0,0 +1,7 @@ + + + Test Scenario + 0 + campaign + 2.6.7b2 + diff --git a/test/files/scenario/extra_teaser.xml b/test/files/scenario/extra_teaser.xml new file mode 100644 index 00000000..3fc3a650 --- /dev/null +++ b/test/files/scenario/extra_teaser.xml @@ -0,0 +1,46 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Teaser 3 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + 2 + + 0 + + diff --git a/test/files/scenario/missing_editor.xml b/test/files/scenario/missing_editor.xml new file mode 100644 index 00000000..fa902762 --- /dev/null +++ b/test/files/scenario/missing_editor.xml @@ -0,0 +1,41 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + 0 + 0 + 0 + 7 + + + + + + diff --git a/test/files/scenario/missing_email.xml b/test/files/scenario/missing_email.xml new file mode 100644 index 00000000..42dcf83f --- /dev/null +++ b/test/files/scenario/missing_email.xml @@ -0,0 +1,11 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + + diff --git a/test/files/scenario/missing_flags.xml b/test/files/scenario/missing_flags.xml new file mode 100644 index 00000000..3c4f5cca --- /dev/null +++ b/test/files/scenario/missing_flags.xml @@ -0,0 +1,22 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + diff --git a/test/files/scenario/missing_game.xml b/test/files/scenario/missing_game.xml new file mode 100644 index 00000000..3a7634fb --- /dev/null +++ b/test/files/scenario/missing_game.xml @@ -0,0 +1,32 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + r + 3 + + + true + false + false + + + oboe + 2.0.0 + + + + diff --git a/test/files/scenario/missing_pic.xml b/test/files/scenario/missing_pic.xml new file mode 100644 index 00000000..3d30c45a --- /dev/null +++ b/test/files/scenario/missing_pic.xml @@ -0,0 +1,5 @@ + + + Test Scenario + + diff --git a/test/files/scenario/missing_rating.xml b/test/files/scenario/missing_rating.xml new file mode 100644 index 00000000..57397445 --- /dev/null +++ b/test/files/scenario/missing_rating.xml @@ -0,0 +1,20 @@ + + + Test Scenario + 0 + campaign + 2.6.7 + en-US + + BoE Test Suite + nowhere@example.com + + + Teaser 1 + Teaser 2 + Welcome to the test scenario! + + + 3 + + diff --git a/test/scen_read.cpp b/test/scen_read.cpp index 031d0ded..9a72e389 100644 --- a/test/scen_read.cpp +++ b/test/scen_read.cpp @@ -21,26 +21,98 @@ TEST_CASE("Loading a new-format scenario record") { SECTION("When the version attribute is missing") { fin.open("files/scenario/bad_root.xml"); doc = xmlDocFromStream(fin, "bad_root.xml"); - REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xBadNode); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); } SECTION("When the version attribute is missing") { fin.open("files/scenario/no_version.xml"); doc = xmlDocFromStream(fin, "no_version.xml"); - REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xMissingAttr); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingAttr); } SECTION("When the root tag has a bad attribute") { fin.open("files/scenario/bad_root_attr.xml"); doc = xmlDocFromStream(fin, "bad_root_attr.xml"); - REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xBadAttr); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr); } SECTION("When an essential toplevel element is missing") { fin.open("files/scenario/missing_toplevel.xml"); doc = xmlDocFromStream(fin, "missing_toplevel.xml"); - REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xMissingElem); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem); } SECTION("When there are too many intro strings") { fin.open("files/scenario/intro_overflow.xml"); doc = xmlDocFromStream(fin, "intro_overflow.xml"); - REQUIRE_THROWS_AS(readScenarioFromXml(std::move(doc), scen), xBadNode); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); + } + SECTION("When the scenario pic element is empty") { + fin.open("files/scenario/missing_pic.xml"); + doc = xmlDocFromStream(fin, "missing_pic.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), Exception); + } + SECTION("When the scenario version is invalid") { + fin.open("files/scenario/bad_version.xml"); + doc = xmlDocFromStream(fin, "bad_version.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), string); + } + SECTION("When the author email is missing") { + fin.open("files/scenario/missing_email.xml"); + doc = xmlDocFromStream(fin, "missing_email.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), Exception); + } + SECTION("When a scenario rating is missing") { + fin.open("files/scenario/missing_rating.xml"); + doc = xmlDocFromStream(fin, "missing_rating.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), Exception); + } + SECTION("When there are too many teaser strings") { + fin.open("files/scenario/extra_teaser.xml"); + doc = xmlDocFromStream(fin, "extra_teaser.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); + } + SECTION("When some flags are missing") { + fin.open("files/scenario/missing_flags.xml"); + doc = xmlDocFromStream(fin, "missing_flags.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem); + } + SECTION("When it's not OBoE format") { + fin.open("files/scenario/bad_format.xml"); + doc = xmlDocFromStream(fin, "bad_format.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadVal); + } + SECTION("When an essential child element is missing") { + fin.open("files/scenario/missing_game.xml"); + doc = xmlDocFromStream(fin, "missing_game.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem); + } + SECTION("When an essential child element is missing") { + fin.open("files/scenario/missing_editor.xml"); + doc = xmlDocFromStream(fin, "missing_editor.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem); + } + SECTION("With an erroneous section") { + SECTION("Two of them") { + fin.open("files/scenario/bad_graphics1.xml"); + doc = xmlDocFromStream(fin, "bad_graphics1.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); + } + SECTION("Invalid child element") { + fin.open("files/scenario/bad_graphics2.xml"); + doc = xmlDocFromStream(fin, "bad_graphics2.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); + } + SECTION("Invalid attribute") { + fin.open("files/scenario/bad_graphics4.xml"); + doc = xmlDocFromStream(fin, "bad_graphics4.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr); + } + SECTION("Missing index attribute") { + fin.open("files/scenario/bad_graphics3.xml"); + doc = xmlDocFromStream(fin, "bad_graphics3.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingAttr); + } + SECTION("Bad graphic type") { + fin.open("files/scenario/bad_graphics5.xml"); + doc = xmlDocFromStream(fin, "bad_graphics5.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadVal); + } } }