A few more scenario read tests

- Introduce enum for scenario content rating
This commit is contained in:
2015-07-07 18:58:35 -04:00
parent 2218513aa5
commit 137a3aa5d4
25 changed files with 208 additions and 34 deletions

View File

@@ -57,10 +57,10 @@
<xs:element name="content">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="g"/>
<xs:enumeration value="pg"/>
<xs:enumeration value="r"/>
<xs:enumeration value="nc17"/>
<xs:enumeration value="G"/>
<xs:enumeration value="PG"/>
<xs:enumeration value="R"/>
<xs:enumeration value="NC-17"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

View File

@@ -1398,7 +1398,6 @@ void tip_of_day() {
static void put_scen_info(cDialog& me) {
unsigned int i;
std::ostringstream sout;
const char *ratings[] = {"G","PG","R","NC-17"};
const char *difficulty[] = {"Low","Medium","High","Very High"};
for(i = 0; i < 3; i++) {
@@ -1415,7 +1414,7 @@ static void put_scen_info(cDialog& me) {
sout << '.' << int(scen_headers[store_scen_page_on * 3 + i].ver[1]);
sout << '.' << int(scen_headers[store_scen_page_on * 3 + i].ver[2]);
sout << " - | Difficulty: " << difficulty[scen_headers[store_scen_page_on * 3 + i].difficulty];
sout << ", Rating: " << ratings[scen_headers[store_scen_page_on * 3 + i].rating];
sout << ", Rating: " << scen_headers[store_scen_page_on * 3 + i].rating;
sout << " |" << scen_headers[store_scen_page_on * 3 + i].who1;
sout << " |" << scen_headers[store_scen_page_on * 3 + i].who2;
me["desc" + n].setText(sout.str());

View File

@@ -631,3 +631,18 @@ std::istream& operator>> (std::istream& in, eAttitude& att) {
in.setstate(std::ios::failbit);
return in;
}
// MARK: eContentRating
cEnumLookup rating_strs = {"G", "PG", "R", "NC-17"};
std::ostream& operator<< (std::ostream& out, eContentRating rating) {
writeEnum(out, rating, rating_strs, "docile");
return out;
}
std::istream& operator>> (std::istream& in, eContentRating& rating) {
if(!readEnum(in, rating, rating_strs, eContentRating::G))
in.setstate(std::ios::failbit);
return in;
}

View File

@@ -69,7 +69,7 @@ cScenario::cScenario() {
where_start.x = 24;
where_start.y = 24;
out_start = where_start;
rating = 0;
rating = eContentRating::G;
difficulty = 0;
intro_pic = intro_mess_pic = 0;
adjust_diff = true;
@@ -133,7 +133,7 @@ void cScenario::append(legacy::scenario_data_type& old){
special_items[i].flags = old.special_items[i];
special_items[i].special = old.special_item_special[i];
}
rating = old.rating;
rating = eContentRating(old.rating);
// TODO: Is this used anywhere?
uses_custom_graphics = old.uses_custom_graphics;
for(i = 0; i < 30; i++) {

View File

@@ -72,7 +72,8 @@ public:
std::vector<cSpecItem> special_items;
std::vector<cQuest> quests;
std::vector<cShop> shops;
short rating,uses_custom_graphics;
short uses_custom_graphics;
eContentRating rating;
std::vector<ePicType> custom_graphics;
std::vector<cMonster> scen_monsters;
std::array<cVehicle,30> boats;
@@ -122,4 +123,7 @@ public:
~cScenario();
};
std::istream& operator>> (std::istream& in, eContentRating& rating);
std::ostream& operator<< (std::ostream& out, eContentRating rating);
#endif

View File

@@ -38,6 +38,8 @@ inline eDirection& operator++ (eDirection& me, int) {
else return me = (eDirection)(1 + (int)me);
}
enum eContentRating {G, PG, R, NC17};
enum class eQuestStatus {AVAILABLE, STARTED, COMPLETED, FAILED};
enum class eMainStatus {

View File

@@ -138,12 +138,7 @@ void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
}
data.CloseElement("text");
data.OpenElement("ratings");
switch(scenario.rating) {
case 0: data.PushElement("content", "g"); break;
case 1: data.PushElement("content", "pg"); break;
case 2: data.PushElement("content", "r"); break;
case 3: data.PushElement("content", "nc17"); break;
}
data.PushElement("content", scenario.rating);
data.PushElement("difficulty", scenario.difficulty + 1);
data.CloseElement("ratings");
data.OpenElement("flags");

View File

@@ -653,6 +653,7 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
} else if(type == "icon") {
// TODO: This element can have some attributes on it.
elem->GetText(&scenario.intro_pic);
scenario.intro_mess_pic = scenario.intro_pic;
} else if(type == "id") {
elem->GetText(&scenario.campaign_id, false);
} else if(type == "version") {
@@ -689,12 +690,7 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
} else if(type == "ratings") {
Element* content = elem->FirstChildElement("content");
Element* difficulty = elem->FirstChildElement("difficulty");
content->GetText(&val);
if(val == "g") scenario.rating = 0;
else if(val == "pg") scenario.rating = 1;
else if(val == "r") scenario.rating = 2;
else if(val == "nc17") scenario.rating = 3;
else throw xBadVal("content", xBadVal::CONTENT, val, content->Row(), content->Column(), fname);
content->GetText(&scenario.rating);
difficulty->GetText(&scenario.difficulty);
if(scenario.difficulty < 1 || scenario.difficulty > 4)
throw xBadVal("difficulty", xBadVal::CONTENT, std::to_string(scenario.difficulty), difficulty->Row(),difficulty->Column(), fname);

View File

@@ -59,4 +59,5 @@ TEST_CASE("Enum text conversions") {
test_enum(LIGHT_NORMAL, "lit", LIGHT_NONE, "none");
test_enum(eTalkNode::REGULAR, "reg", eTalkNode::JOB_BANK, "jobs", eTalkNode::SELL_WEAPONS, "sell-weap", eTalkNode::CALL_SCEN_SPEC, "call-global");
test_enum(eAttitude::DOCILE, "docile", eAttitude::HOSTILE_B, "hostile-b");
test_enum(eContentRating::G, "G", eContentRating::NC17, "NC-17");
}

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.0.0">
<title>Test Scenario</title>
<icon>0</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>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>Q</content>
<difficulty>3</difficulty>
</ratings>
</scenario>

View File

@@ -16,7 +16,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -21,7 +21,7 @@
<intro-msg></intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -0,0 +1,45 @@
<?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>
</editor>
</scenario>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags/>

View File

@@ -15,7 +15,7 @@
<intro-msg>Welcome to the test scenario!</intro-msg>
</text>
<ratings>
<content>r</content>
<content>R</content>
<difficulty>3</difficulty>
</ratings>
<flags>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<scenario boes="2.0.0">
<title>Test Scenario</title>
<icon>0</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/>
<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.0.0</version>
<os></os>
</creator>
<game>
<num-towns>0</num-towns>
<out-width>0</out-width>
<out-height>0</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" />
<special-item>
<name>My Special Item</name>
<description><![CDATA[Special Item -- Description!]]></description>
</special-item>
</game>
<editor>
<default-ground>2</default-ground>
<last-out-section x="0" y="0" />
<last-town>0</last-town>
</editor>
</scenario>

View File

@@ -63,6 +63,11 @@ TEST_CASE("Loading a new-format scenario record") {
doc = xmlDocFromStream(fin, "missing_rating.xml");
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), Exception);
}
SECTION("When the scenario content rating is invalid") {
fin.open("files/scenario/bad_rating.xml");
doc = xmlDocFromStream(fin, "bad_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");
@@ -115,4 +120,50 @@ TEST_CASE("Loading a new-format scenario record") {
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadVal);
}
}
SECTION("With the minimal required data") {
fin.open("files/scenario/minimal.xml");
doc = xmlDocFromStream(fin, "minimal.xml");
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
CHECK(scen.scen_name == "Test Scenario");
CHECK(scen.intro_pic == 7);
CHECK(scen.campaign_id == "campaign");
CHECK(scen.format.prog_make_ver[0] == 2);
CHECK(scen.format.prog_make_ver[1] == 5);
CHECK(scen.format.prog_make_ver[2] == 3);
CHECK(scen.format.ver[0] == 2);
CHECK(scen.format.ver[1] == 6);
CHECK(scen.format.ver[2] == 7);
// TODO: Check language
CHECK(scen.contact_info[0] == "BoE Test Suite");
CHECK(scen.contact_info[1] == "nowhere@example.com");
CHECK(scen.who_wrote[0] == "Teaser 1");
CHECK(scen.who_wrote[1] == "Teaser 2");
CHECK(scen.intro_mess_pic == 7);
CHECK(scen.intro_strs[0] == "Welcome!!! To the test scenario!");
CHECK(scen.rating == eContentRating::R);
CHECK(scen.difficulty == 2); // Difficulty is 3, but it's stored as 2 (0-3 instead of 1-4)
CHECK(scen.adjust_diff == true);
CHECK(scen.is_legacy == false);
CHECK(scen.uses_custom_graphics == false);
CHECK(scen.towns.size() == 3);
CHECK(scen.outdoors.width() == 2);
CHECK(scen.outdoors.height() == 1);
CHECK(scen.which_town_start == 7);
CHECK(scen.where_start == loc(24,28));
CHECK(scen.out_sec_start == loc(1,3));
CHECK(scen.out_start == loc(12,21));
CHECK(scen.default_ground == 2);
CHECK(scen.last_out_edited == loc(0,0));
CHECK(scen.last_town_edited == 0);
}
SECTION("With a special item") {
fin.open("files/scenario/special_item.xml");
doc = xmlDocFromStream(fin, "special_item.xml");
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
CHECK(scen.special_items.size() == 1);
CHECK(scen.special_items[0].name == "My Special Item");
CHECK(scen.special_items[0].descr == "Special Item -- Description!");
CHECK(scen.special_items[0].flags == 0);
CHECK(scen.special_items[0].special == -1);
}
}

View File

@@ -50,7 +50,7 @@ TEST_CASE("Saving a scenario record") {
scen.contact_info[0] = "BoE Test Suite";
scen.contact_info[1] = "nowhere@example.com";
scen.intro_strs[0] = "Welcome to the test scenario!";
scen.rating = 2;
scen.rating = eContentRating::R;
scen.difficulty = 2;
scen.which_town_start = 7;
scen.where_start = {24,28};
@@ -72,7 +72,7 @@ TEST_CASE("Saving a scenario record") {
CHECK(scen.contact_info[0] == "BoE Test Suite");
CHECK(scen.contact_info[1] == "nowhere@example.com");
CHECK(scen.intro_strs[0] == "Welcome to the test scenario!");
CHECK(scen.rating == 2);
CHECK(scen.rating == eContentRating::R);
CHECK(scen.difficulty == 2);
CHECK(scen.which_town_start == 7);
CHECK(scen.where_start == loc(24,28));