forked from calref/cboe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathter_write.cpp
108 lines (103 loc) · 3.58 KB
/
ter_write.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
//
// ter_write.cpp
// BoE
//
// Created by Celtic Minstrel on 15-07-29.
//
//
#include <fstream>
#include "catch.hpp"
#include "tinyprint.h"
#include "scenario.hpp"
using namespace std;
using namespace ticpp;
extern Document xmlDocFromStream(istream& stream, string name);
extern void readTerrainFromXml(Document&& data, cScenario& scenario);
extern void writeTerrainToXml(Printer&& data, cScenario& scenario);
static void in_and_out(string name, cScenario& scen) {
string fpath = "junk/ter_";
fpath += name;
fpath += ".xml";
ofstream fout;
fout.exceptions(ios::badbit);
fout.open(fpath);
writeTerrainToXml(Printer(name, fout), scen);
fout.close();
// Reconstruct the scenario, to ensure that it doesn't just pass due to old data still being around
scen.~cScenario();
new(&scen) cScenario();
ifstream fin;
fin.exceptions(ios::badbit);
fin.open(fpath);
readTerrainFromXml(xmlDocFromStream(fin, name), scen);
}
TEST_CASE("Saving terrain types") {
cScenario scen;
scen.ter_types.resize(1);
scen.ter_types[0].name = "Test Terrain";
scen.ter_types[0].picture = 0;
scen.ter_types[0].map_pic = 1;
scen.ter_types[0].blockage = eTerObstruct::BLOCK_SIGHT;
scen.ter_types[0].trim_type = eTrimType::CITY;
scen.ter_types[0].combat_arena = 2;
scen.ter_types[0].special = eTerSpec::WILDERNESS_SURFACE;
SECTION("With basic information") {
in_and_out("basic", scen);
REQUIRE(scen.ter_types.size() == 1);
CHECK(scen.ter_types[0].name == "Test Terrain");
CHECK(scen.ter_types[0].picture == 0);
CHECK(scen.ter_types[0].map_pic == 1);
CHECK(scen.ter_types[0].blockage == eTerObstruct::BLOCK_SIGHT);
CHECK(scen.ter_types[0].trim_type == eTrimType::CITY);
CHECK(scen.ter_types[0].combat_arena == 2);
CHECK(scen.ter_types[0].special == eTerSpec::WILDERNESS_SURFACE);
CHECK(scen.ter_types[0].flag1 == -1);
CHECK(scen.ter_types[0].step_sound == eStepSnd::STEP);
}
SECTION("With all information") {
scen.ter_types[0].flag1 = 1;
scen.ter_types[0].flag2 = 2;
scen.ter_types[0].flag3 = 3;
scen.ter_types[0].trans_to_what = 100;
scen.ter_types[0].fly_over = true;
scen.ter_types[0].boat_over = true;
scen.ter_types[0].block_horse = true;
scen.ter_types[0].is_archetype = true;
scen.ter_types[0].light_radius = 3;
scen.ter_types[0].step_sound = eStepSnd::SPLASH;
scen.ter_types[0].ground_type = 2;
scen.ter_types[0].trim_ter = 1;
scen.ter_types[0].shortcut_key = 'u';
scen.ter_types[0].frill_for = 5;
scen.ter_types[0].frill_chance = 15;
scen.ter_types[0].obj_num = 1;
scen.ter_types[0].obj_pos = loc(0,0);
scen.ter_types[0].obj_size = loc(2,1);
in_and_out("full", scen);
REQUIRE(scen.ter_types.size() == 1);
CHECK(scen.ter_types[0].flag1 == 1);
CHECK(scen.ter_types[0].flag2 == 2);
CHECK(scen.ter_types[0].flag3 == 3);
CHECK(scen.ter_types[0].trans_to_what == 100);
CHECK(scen.ter_types[0].fly_over);
CHECK(scen.ter_types[0].boat_over);
CHECK(scen.ter_types[0].block_horse);
CHECK(scen.ter_types[0].is_archetype);
CHECK(scen.ter_types[0].light_radius == 3);
CHECK(scen.ter_types[0].step_sound == eStepSnd::SPLASH);
CHECK(scen.ter_types[0].ground_type == 2);
CHECK(scen.ter_types[0].trim_ter == 1);
CHECK(scen.ter_types[0].shortcut_key == 'u');
CHECK(scen.ter_types[0].frill_for == 5);
CHECK(scen.ter_types[0].frill_chance == 15);
CHECK(scen.ter_types[0].obj_num == 1);
CHECK(scen.ter_types[0].obj_pos == loc(0,0));
CHECK(scen.ter_types[0].obj_size == loc(2,1));
}
SECTION("With default frill chance") {
scen.ter_types[0].frill_for = 5;
scen.ter_types[0].frill_chance = 10;
in_and_out("default_frill", scen);
CHECK(scen.ter_types[0].frill_chance == 10);
}
}