From 3c7569a0684a52e18bf753eb309f6ed04d96a514 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Tue, 7 Jul 2015 21:00:55 -0400 Subject: [PATCH] Test cases for reading quests --- test/files/scenario/quest-bad_attr.xml | 49 ++++++++++++++++++ test/files/scenario/quest-bad_deadline.xml | 50 ++++++++++++++++++ test/files/scenario/quest-bad_elem.xml | 49 ++++++++++++++++++ test/files/scenario/quest-bad_reward.xml | 50 ++++++++++++++++++ test/files/scenario/quest-extra_bank.xml | 52 +++++++++++++++++++ test/files/scenario/quest-missing_elem.xml | 48 ++++++++++++++++++ test/files/scenario/quest.xml | 49 ++++++++++++++++++ test/files/scenario/quest2.xml | 52 +++++++++++++++++++ test/scen_read.cpp | 59 ++++++++++++++++++++++ 9 files changed, 458 insertions(+) create mode 100644 test/files/scenario/quest-bad_attr.xml create mode 100644 test/files/scenario/quest-bad_deadline.xml create mode 100644 test/files/scenario/quest-bad_elem.xml create mode 100644 test/files/scenario/quest-bad_reward.xml create mode 100644 test/files/scenario/quest-extra_bank.xml create mode 100644 test/files/scenario/quest-missing_elem.xml create mode 100644 test/files/scenario/quest.xml create mode 100644 test/files/scenario/quest2.xml diff --git a/test/files/scenario/quest-bad_attr.xml b/test/files/scenario/quest-bad_attr.xml new file mode 100644 index 00000000..4366b6d5 --- /dev/null +++ b/test/files/scenario/quest-bad_attr.xml @@ -0,0 +1,49 @@ + + + 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 + + + + + My Silly Quest + + + + + 2 + + 0 + + diff --git a/test/files/scenario/quest-bad_deadline.xml b/test/files/scenario/quest-bad_deadline.xml new file mode 100644 index 00000000..c5c1fd14 --- /dev/null +++ b/test/files/scenario/quest-bad_deadline.xml @@ -0,0 +1,50 @@ + + + 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 + + + + + My Silly Quest + + 50 + + + + 2 + + 0 + + diff --git a/test/files/scenario/quest-bad_elem.xml b/test/files/scenario/quest-bad_elem.xml new file mode 100644 index 00000000..215527e0 --- /dev/null +++ b/test/files/scenario/quest-bad_elem.xml @@ -0,0 +1,49 @@ + + + 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 + + + + + My Silly Quest + + + + + 2 + + 0 + + diff --git a/test/files/scenario/quest-bad_reward.xml b/test/files/scenario/quest-bad_reward.xml new file mode 100644 index 00000000..93cfbf51 --- /dev/null +++ b/test/files/scenario/quest-bad_reward.xml @@ -0,0 +1,50 @@ + + + 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 + + + + + My Silly Quest + + + + + + 2 + + 0 + + diff --git a/test/files/scenario/quest-extra_bank.xml b/test/files/scenario/quest-extra_bank.xml new file mode 100644 index 00000000..3dd1867e --- /dev/null +++ b/test/files/scenario/quest-extra_bank.xml @@ -0,0 +1,52 @@ + + + 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 + + + + + My Silly Quest + + 1 + 2 + 3 + + + + 2 + + 0 + + diff --git a/test/files/scenario/quest-missing_elem.xml b/test/files/scenario/quest-missing_elem.xml new file mode 100644 index 00000000..37c41152 --- /dev/null +++ b/test/files/scenario/quest-missing_elem.xml @@ -0,0 +1,48 @@ + + + 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/quest.xml b/test/files/scenario/quest.xml new file mode 100644 index 00000000..f4ff4571 --- /dev/null +++ b/test/files/scenario/quest.xml @@ -0,0 +1,49 @@ + + + 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 + + + + + My Silly Quest + + + + + 2 + + 0 + + diff --git a/test/files/scenario/quest2.xml b/test/files/scenario/quest2.xml new file mode 100644 index 00000000..a67f44fe --- /dev/null +++ b/test/files/scenario/quest2.xml @@ -0,0 +1,52 @@ + + + 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 + + + + + My Silly Quest + + 50 + + 1 + + + + 2 + + 0 + + diff --git a/test/scen_read.cpp b/test/scen_read.cpp index eaca9cde..260ddded 100644 --- a/test/scen_read.cpp +++ b/test/scen_read.cpp @@ -183,4 +183,63 @@ TEST_CASE("Loading a new-format scenario record") { REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem); } } + SECTION("With a quest") { + SECTION("Valid minimal quest") { + fin.open("files/scenario/quest.xml"); + doc = xmlDocFromStream(fin, "quest.xml"); + REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen)); + REQUIRE(scen.quests.size() == 1); + CHECK(scen.quests[0].name == "My Silly Quest"); + CHECK(scen.quests[0].descr == " It is! The best quest! "); + CHECK(scen.quests[0].flags == 0); + CHECK(scen.quests[0].gold == 0); + CHECK(scen.quests[0].xp == 0); + CHECK(scen.quests[0].bank1 == -1); + CHECK(scen.quests[0].bank2 == -1); + CHECK(scen.quests[0].deadline == -1); + CHECK(scen.quests[0].event == -1); + } + SECTION("Valid quest, more complex") { + fin.open("files/scenario/quest2.xml"); + doc = xmlDocFromStream(fin, "quest2.xml"); + REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen)); + REQUIRE(scen.quests.size() == 1); + CHECK(scen.quests[0].gold == 150); + CHECK(scen.quests[0].xp == 1500); + CHECK(scen.quests[0].deadline == 50); + CHECK(scen.quests[0].event == 5); + CHECK(scen.quests[0].bank1 == 1); + CHECK(scen.quests[0].bank2 == -1); + } + SECTION("Invalid attribute") { + fin.open("files/scenario/quest-bad_attr.xml"); + doc = xmlDocFromStream(fin, "quest-bad_attr.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr); + } + SECTION("Invalid element") { + fin.open("files/scenario/quest-bad_elem.xml"); + doc = xmlDocFromStream(fin, "quest-bad_elem.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); + } + SECTION("Missing name") { + fin.open("files/scenario/quest-missing_elem.xml"); + doc = xmlDocFromStream(fin, "quest-missing_elem.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem); + } + SECTION("Invalid deadline") { + fin.open("files/scenario/quest-bad_deadline.xml"); + doc = xmlDocFromStream(fin, "quest-bad_deadline.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr); + } + SECTION("Invalid reward") { + fin.open("files/scenario/quest-bad_reward.xml"); + doc = xmlDocFromStream(fin, "quest-bad_reward.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr); + } + SECTION("Too many banks") { + fin.open("files/scenario/quest-extra_bank.xml"); + doc = xmlDocFromStream(fin, "quest-extra_bank.xml"); + REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode); + } + } }