More scenario record read tests

This commit is contained in:
2015-09-02 19:59:54 -04:00
parent 8f4d5453cd
commit d3b0b26deb
17 changed files with 790 additions and 5 deletions

View File

@@ -81,7 +81,7 @@ public:
std::vector<cTerrain> ter_types;
std::array<cTimer,20> scenario_timers;
std::vector<cSpecial> scen_specials;
cItemStorage storage_shortcuts[10];
std::array<cItemStorage,10> storage_shortcuts;
// These two \/ are populated at load time and then never used again
location last_out_edited;
short last_town_edited;

View File

@@ -526,7 +526,7 @@ static void readShopFromXml(ticpp::Element& data, cShop& shop) {
throw xBadNode(type, entry->Row(), entry->Column(), fname);
entries_found++;
if(type == "item") {
int amount, num, chance = 100;
int amount = -1, num, chance = 100;
std::string title, descr;
Iterator<Attribute> attr;
for(attr = attr.begin(entry.Get()); attr != attr.end(); attr++) {
@@ -538,8 +538,12 @@ static void readShopFromXml(ticpp::Element& data, cShop& shop) {
else amount = boost::lexical_cast<int>(val);
} else if(name == "chance") {
attr->GetValue(&chance);
if(amount == -1)
amount = 1;
} else throw xBadAttr(type, name, attr->Row(), attr->Column(), fname);
}
if(amount == -1)
amount = 0;
entry->GetText(&num);
shop.addItem(num, dummy_item, amount, chance);
} else if(type == "special") {
@@ -896,7 +900,7 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
if(!found_chance)
throw xMissingAttr(type, "chance", store->Row(), store->Column(), fname);
num_items++;
}
} else throw xBadNode(type, store->Row(), store->Column(), fname);
}
if(!reqs.empty())
throw xMissingElem("storage", *reqs.begin(), edit->Row(), edit->Column(), fname);

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
<town-flag town="1" add-y="21"/>
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
<town-flag town="1" add-x="16"/>
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
<town-flag add-x="16" add-y="21"/>
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
<town-flag town="1" x="16" y="21"/>
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<icon>12</icon>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
<on-init>5</on-init>
<store-items town="0" top="12" left="13" bottom="20" right="36"/>
<town-flag town="1" add-x="16" add-y="21"/>
<timer freq="100">15</timer>
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -74,6 +74,7 @@
<name>Special Shop Item the Third</name>
<description><![CDATA[Yay for the magic purchase!]]></description>
</special>
<item>89</item>
</entries>
</shop>
</game>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item odds="25">46</item>
</storage>
</editor>
</scenario>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<on-terrain>64</on-terrain>
<property>true</property>
<item chance="25">46</item>
</storage>
</editor>
</scenario>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item>46</item>
</storage>
</editor>
</scenario>

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
</editor>
</scenario>

View File

@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
</editor>
</scenario>

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
<item chance="25">46</item>
</storage>
</editor>
</scenario>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.1.5">
<title>Test Scenario</title>
<icon>7</icon>
<id>campaign</id>
<version>2.6.7</version>
<language>en-US</language>
<author>
<name>BoE Test Suite</name>
<email>nowhere@example.com</email>
</author>
<text>
<teaser>Teaser 1</teaser>
<teaser>Teaser 2</teaser>
<intro-msg><![CDATA[Welcome!!! To the test scenario!]]></intro-msg>
</text>
<ratings>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>
<adjust-difficulty>true</adjust-difficulty>
<legacy>false</legacy>
<custom-graphics>false</custom-graphics>
</flags>
<creator>
<type>oboe</type>
<version>2.5.3</version>
<os></os>
</creator>
<game>
<num-towns>3</num-towns>
<out-width>2</out-width>
<out-height>1</out-height>
<start-town>7</start-town>
<town-start x="24" y="28" />
<outdoor-start x="1" y="3" />
<sector-start x="12" y="21" />
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
<storage>
<on-terrain>64</on-terrain>
<is-property>true</is-property>
<item chance="25">46</item>
</storage>
</editor>
</scenario>

View File

@@ -156,6 +156,53 @@ TEST_CASE("Loading a new-format scenario record") {
CHECK(scen.default_ground == 2);
CHECK(scen.last_out_edited == loc(0,0));
CHECK(scen.last_town_edited == 0);
CHECK(scen.init_spec == -1);
}
SECTION("With a different icon in the intro dialog") {
fin.open("files/scenario/intro.xml");
doc = xmlDocFromStream(fin, "intro.xml");
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
CHECK(scen.intro_pic == 7);
CHECK(scen.intro_mess_pic == 12);
}
SECTION("With some optional game data") {
fin.open("files/scenario/optional.xml");
doc = xmlDocFromStream(fin, "optional.xml");
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
CHECK(scen.init_spec == 5);;
REQUIRE(scen.store_item_rects.size() >= 1);
REQUIRE(scen.store_item_rects.size() >= 1);
CHECK(scen.store_item_rects[0] == rectangle(12,13,20,36));
CHECK(scen.store_item_towns[0] == 0);
REQUIRE(scen.town_mods.size() >= 1);
CHECK(scen.town_mods[0] == loc(16,21));
CHECK(scen.town_mods[0].spec == 1);
REQUIRE(scen.scenario_timers.size() >= 1);
CHECK(scen.scenario_timers[0].time == 100);
CHECK(scen.scenario_timers[0].node == 15);
CHECK(scen.scenario_timers[0].node_type == 0);
}
SECTION("With an invalid town mod flag") {
SECTION("Missing X") {
fin.open("files/scenario/bad_townmod1.xml");
doc = xmlDocFromStream(fin, "bad_townmod1.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingAttr);
}
SECTION("Missing Y") {
fin.open("files/scenario/bad_townmod2.xml");
doc = xmlDocFromStream(fin, "bad_townmod2.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingAttr);
}
SECTION("Missing town") {
fin.open("files/scenario/bad_townmod3.xml");
doc = xmlDocFromStream(fin, "bad_townmod3.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingAttr);
}
SECTION("Invalid attribtue") {
fin.open("files/scenario/bad_townmod4.xml");
doc = xmlDocFromStream(fin, "bad_townmod4.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr);
}
}
SECTION("With a special item") {
SECTION("Valid") {
@@ -252,7 +299,7 @@ TEST_CASE("Loading a new-format scenario record") {
doc = xmlDocFromStream(fin, "shop.xml");
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
REQUIRE(scen.shops.size() == 1);
REQUIRE(scen.shops[0].size() == 13);
REQUIRE(scen.shops[0].size() == 14);
CHECK(scen.shops[0].getFace() == 0);
CHECK(scen.shops[0].getName() == "The Shop of Everything");
CHECK(scen.shops[0].getType() == eShopType::NORMAL);
@@ -264,7 +311,7 @@ TEST_CASE("Loading a new-format scenario record") {
CHECK(scen.shops[0].getItem(1).quantity == 0);
CHECK(scen.shops[0].getItem(1).index == 11);
CHECK(scen.shops[0].getItem(2).type == eShopItemType::OPT_ITEM);
CHECK(scen.shops[0].getItem(2).quantity == 42000);
CHECK(scen.shops[0].getItem(2).quantity == 42001);
CHECK(scen.shops[0].getItem(2).index == 12);
CHECK(scen.shops[0].getItem(3).type == eShopItemType::MAGE_SPELL);
CHECK(scen.shops[0].getItem(3).item.item_level == 30);
@@ -300,6 +347,9 @@ TEST_CASE("Loading a new-format scenario record") {
CHECK(scen.shops[0].getItem(12).item.value == 12000);
CHECK(scen.shops[0].getItem(12).item.full_name == "Special Shop Item the Third");
CHECK(scen.shops[0].getItem(12).item.desc == "Yay for the magic purchase!");
CHECK(scen.shops[0].getItem(13).type == eShopItemType::ITEM);
CHECK(scen.shops[0].getItem(13).quantity == 0);
CHECK(scen.shops[0].getItem(13).index == 89);
}
SECTION("Too many items") {
fin.open("files/scenario/shop-overflow.xml");
@@ -328,4 +378,46 @@ TEST_CASE("Loading a new-format scenario record") {
}
ResMgr::popPath<StringRsrc>();
}
SECTION("With item storage shortcuts") {
SECTION("Valid") {
fin.open("files/scenario/storage.xml");
doc = xmlDocFromStream(fin, "storage.xml");
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
REQUIRE(scen.storage_shortcuts.size() >= 1);
CHECK(scen.storage_shortcuts[0].ter_type == 64);
CHECK(scen.storage_shortcuts[0].property);
CHECK(scen.storage_shortcuts[0].item_num[0] == 46);
CHECK(scen.storage_shortcuts[0].item_odds[0] == 25);
}
SECTION("Missing terrain") {
fin.open("files/scenario/storage-missing_ter.xml");
doc = xmlDocFromStream(fin, "storage-missing_ter.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingElem);
}
SECTION("Missing chance") {
fin.open("files/scenario/storage-missing_chance.xml");
doc = xmlDocFromStream(fin, "storage-missing_chance.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xMissingAttr);
}
SECTION("Invalid attribute") {
fin.open("files/scenario/storage-bad_attr.xml");
doc = xmlDocFromStream(fin, "storage-bad_attr.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadAttr);
}
SECTION("Invalid subtag") {
fin.open("files/scenario/storage-bad_node.xml");
doc = xmlDocFromStream(fin, "storage-bad_node.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode);
}
SECTION("Too many items") {
fin.open("files/scenario/storage-too_many_items.xml");
doc = xmlDocFromStream(fin, "storage-too_many_items.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode);
}
SECTION("Too many shortcuts") {
fin.open("files/scenario/storage-too_many.xml");
doc = xmlDocFromStream(fin, "storage-too_many.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode);
}
}
}