Skip to content

Commit

Permalink
Another items read/write test
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Sep 15, 2015
1 parent a778d25 commit 2a609ad
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/files/items/full.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<items boes="2.0.0">
<item id='0'>
<variety>weapon-1hand</variety>
<level>3</level>
<pic>0</pic>
<value>100</value>
<weight>10</weight>
<full-name>Test Sword</full-name>
<name>Sword</name>
<awkward>1</awkward>
<bonus>5</bonus>
<protection>4</protection>
<charges>20</charges>
<weapon-type>defense</weapon-type>
<missile-type>3</missile-type>
<flag>9</flag>
<class>400</class>
<treasure>2</treasure>
<ability>
<type>poison-aug</type>
<strength>6</strength>
<data>42</data>
<use-flag>harm-one</use-flag>
</ability>
<properties>
<identified>true</identified>
<magic>true</magic>
<cursed>true</cursed>
<concealed>true</concealed>
<enchanted>true</enchanted>
<unsellable>true</unsellable>
</properties>
<description>This is a silly, silly description.</description>
</item>
</items>
26 changes: 26 additions & 0 deletions test/item_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,30 @@ TEST_CASE("Loading an item type definition") {
CHECK(scen.scen_items[0].value == 100);
CHECK(scen.scen_items[0].weight == 10);
}
SECTION("With all possible data") {
fin.open("files/items/full.xml");
doc = xmlDocFromStream(fin, "full.xml");
REQUIRE_NOTHROW(readItemsFromXml(move(doc), scen));
REQUIRE(scen.scen_items.size() >= 1);
CHECK(scen.scen_items[0].awkward == 1);
CHECK(scen.scen_items[0].bonus == 5);
CHECK(scen.scen_items[0].protection == 4);
CHECK(scen.scen_items[0].charges == 20);
CHECK(scen.scen_items[0].weap_type == eSkill::DEFENSE);
CHECK(scen.scen_items[0].missile == 3);
CHECK(scen.scen_items[0].type_flag == 9);
CHECK(scen.scen_items[0].special_class == 400);
CHECK(scen.scen_items[0].treas_class == 2);
CHECK(scen.scen_items[0].ability == eItemAbil::POISON_AUGMENT);
CHECK(scen.scen_items[0].abil_data[0] == 6);
CHECK(scen.scen_items[0].abil_data[1] == 42);
CHECK(scen.scen_items[0].magic_use_type == eItemUse::HARM_ONE);
CHECK(scen.scen_items[0].ident);
CHECK(scen.scen_items[0].magic);
CHECK(scen.scen_items[0].cursed);
CHECK(scen.scen_items[0].concealed);
CHECK(scen.scen_items[0].enchanted);
CHECK(scen.scen_items[0].unsellable);
CHECK(scen.scen_items[0].desc == "This is a silly, silly description.");
}
}
46 changes: 46 additions & 0 deletions test/item_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,50 @@ TEST_CASE("Saving item types") {
CHECK(scen.scen_items[0].name == "Potion");
CHECK(scen.scen_items[0].full_name == "Test Potion");
}
SECTION("With all information") {
scen.scen_items[0].awkward = 1;
scen.scen_items[0].bonus = 5;
scen.scen_items[0].protection = 4;
scen.scen_items[0].charges = 20;
// So that both weap_type and missile are saved \/
scen.scen_items[0].variety = eItemType::MISSILE_NO_AMMO;
scen.scen_items[0].weap_type = eSkill::DEFENSE;
scen.scen_items[0].missile = 3;
scen.scen_items[0].type_flag = 9;
scen.scen_items[0].special_class = 400;
scen.scen_items[0].treas_class = 2;
scen.scen_items[0].ability = eItemAbil::POISON_AUGMENT;
scen.scen_items[0].abil_data[0] = 6;
scen.scen_items[0].abil_data[1] = 42;
scen.scen_items[0].magic_use_type = eItemUse::HARM_ONE;
scen.scen_items[0].ident = true;
scen.scen_items[0].magic = true;
scen.scen_items[0].cursed = true;
scen.scen_items[0].concealed = true;
scen.scen_items[0].enchanted = true;
scen.scen_items[0].unsellable = true;
scen.scen_items[0].desc = " This is a silly, silly description. ";
in_and_out("full", scen);
REQUIRE(scen.scen_items.size() == 1);
CHECK(scen.scen_items[0].awkward == 1);
CHECK(scen.scen_items[0].bonus == 5);
CHECK(scen.scen_items[0].protection == 4);
CHECK(scen.scen_items[0].charges == 20);
CHECK(scen.scen_items[0].weap_type == eSkill::DEFENSE);
CHECK(scen.scen_items[0].missile == 3);
CHECK(scen.scen_items[0].type_flag == 9);
CHECK(scen.scen_items[0].special_class == 400);
CHECK(scen.scen_items[0].treas_class == 2);
CHECK(scen.scen_items[0].ability == eItemAbil::POISON_AUGMENT);
CHECK(scen.scen_items[0].abil_data[0] == 6);
CHECK(scen.scen_items[0].abil_data[1] == 42);
CHECK(scen.scen_items[0].magic_use_type == eItemUse::HARM_ONE);
CHECK(scen.scen_items[0].ident);
CHECK(scen.scen_items[0].magic);
CHECK(scen.scen_items[0].cursed);
CHECK(scen.scen_items[0].concealed);
CHECK(scen.scen_items[0].enchanted);
CHECK(scen.scen_items[0].unsellable);
CHECK(scen.scen_items[0].desc == " This is a silly, silly description. ");
}
}

0 comments on commit 2a609ad

Please sign in to comment.