forked from calref/cboe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_read.cpp
136 lines (131 loc) · 5.04 KB
/
item_read.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// item_read.cpp
// BoE
//
// Created by Celtic Minstrel on 15-07-29.
//
//
#include <fstream>
#include "ticpp.h"
#include "catch.hpp"
#include "dialog.hpp"
#include "scenario.hpp"
using namespace std;
using namespace ticpp;
extern Document xmlDocFromStream(istream& stream, string name);
extern void readItemsFromXml(Document&& data, cScenario& scenario);
TEST_CASE("Loading an item type definition") {
ifstream fin;
cScenario scen;
Document doc;
fin.exceptions(ios::badbit);
SECTION("When the root tag is wrong") {
fin.open("files/bad_root.xml");
doc = xmlDocFromStream(fin, "bad_root.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xBadNode);
}
SECTION("When the version attribute is missing") {
fin.open("files/items/no_version.xml");
doc = xmlDocFromStream(fin, "no_version.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xMissingAttr);
}
SECTION("When the root tag has a bad attribute") {
fin.open("files/items/bad_root_attr.xml");
doc = xmlDocFromStream(fin, "bad_root_attr.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xBadAttr);
}
SECTION("When an unknown toplevel tag appears") {
fin.open("files/items/bad_toplevel.xml");
doc = xmlDocFromStream(fin, "bad_toplevel.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xBadNode);
}
SECTION("When the ID attribute is missing") {
fin.open("files/items/missing_id.xml");
doc = xmlDocFromStream(fin, "missing_id.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), Exception);
}
SECTION("When a required subtag is missing") {
fin.open("files/items/missing_req.xml");
doc = xmlDocFromStream(fin, "missing_req.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xMissingElem);
}
SECTION("When a bad subtag is found") {
fin.open("files/items/bad_tag.xml");
doc = xmlDocFromStream(fin, "bad_tag.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xBadNode);
}
SECTION("When an unknown property is found") {
fin.open("files/items/bad_prop.xml");
doc = xmlDocFromStream(fin, "bad_prop.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xBadNode);
}
SECTION("When the variety is invalid") {
fin.open("files/items/bad_type.xml");
doc = xmlDocFromStream(fin, "bad_type.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), Exception);
}
SECTION("When the weapon key skill is invalid") {
fin.open("files/items/bad_weapon.xml");
doc = xmlDocFromStream(fin, "bad_weapon.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), Exception);
}
SECTION("When the special ability is missing a required subtag") {
fin.open("files/items/missing_abil.xml");
doc = xmlDocFromStream(fin, "missing_abil.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xMissingElem);
}
SECTION("When the special ability is invalid") {
fin.open("files/items/bad_abil.xml");
doc = xmlDocFromStream(fin, "bad_abil.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), Exception);
}
SECTION("When the special ability has an invalid subtag") {
fin.open("files/items/bad_abil_tag.xml");
doc = xmlDocFromStream(fin, "bad_abil_tag.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), xBadNode);
}
SECTION("When the special ability has an invalid use flag") {
fin.open("files/items/bad_use.xml");
doc = xmlDocFromStream(fin, "bad_use.xml");
REQUIRE_THROWS_AS(readItemsFromXml(move(doc), scen), Exception);
}
SECTION("With the minimal required data") {
fin.open("files/items/minimal.xml");
doc = xmlDocFromStream(fin, "minimal.xml");
REQUIRE_NOTHROW(readItemsFromXml(move(doc), scen));
REQUIRE(scen.scen_items.size() >= 1);
CHECK(scen.scen_items[0].full_name == "Test Sword");
CHECK(scen.scen_items[0].name == "Sword");
CHECK(scen.scen_items[0].variety == eItemType::ONE_HANDED);
CHECK(scen.scen_items[0].item_level == 3);
CHECK(scen.scen_items[0].graphic_num == 0);
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.");
}
}