-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_list.cpp
92 lines (78 loc) · 1.9 KB
/
test_list.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
#include <fstream>
#include <sstream>
#undef NDEBUG
#include <cassert>
#include "nbt.hpp"
int main() {
std::vector<nbt::TagList> test_list {
std::vector<nbt::TagEnd> {{}},
std::vector<nbt::TagByte> {
1,
2,
3,
},
std::vector<nbt::TagShort> {
1 << 8,
2 << 8,
3 << 8,
},
std::vector<nbt::TagInt> {
1 << 16,
2 << 16,
3 << 16,
},
std::vector<nbt::TagLong> {
1LL << 32,
2LL << 32,
3LL << 32,
},
std::vector<nbt::TagFloat> {
0.1f,
0.2f,
0.3f,
},
std::vector<nbt::TagDouble> {
0.1f,
0.2f,
0.3f,
},
std::vector<nbt::TagByteArray> {
{1},
{2},
{3},
},
std::vector<nbt::TagIntArray> {
{1 << 16},
{2 << 16},
{3 << 16},
},
std::vector<nbt::TagLongArray> {
{1LL << 32},
{2LL << 32},
{3LL << 32},
},
std::vector<nbt::TagString> {
"String #1",
"String #2",
"String #3",
},
std::vector<nbt::TagCompound> {
{{"name", "Compound #1"}},
{{"name", "Compound #2"}},
{{"name", "Compound #3"}},
},
};
nbt::NBT nbt {"List Test", {{"list", test_list}}};
std::stringstream good_buffer;
good_buffer << std::ifstream {"list.nbt"}.rdbuf();
std::stringstream test_buffer;
nbt.encode(test_buffer);
assert(("binary_list", good_buffer.str() == test_buffer.str()));
nbt::NBT file {good_buffer};
assert(nbt.data->tags.at("list") == file.data->tags.at("list"));
std::stringstream print_buffer;
print_buffer << nbt;
std::stringstream good_print;
good_print << std::ifstream {"printed_list.txt"}.rdbuf();
assert(("printed_list", print_buffer.str() == good_print.str()));
}