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
|
#include "common.hpp"
#include <fstream>
TEST(document_create)
{
pugi::xml_document doc;
doc.append_child().set_name("node");
CHECK_NODE(doc, "<node />");
}
TEST(document_load_stream)
{
pugi::xml_document doc;
std::istringstream iss("<node/>");
CHECK(doc.load(iss));
CHECK_NODE(doc, "<node />");
}
TEST(document_load_stream_error)
{
pugi::xml_document doc;
std::ifstream fs1("");
CHECK(doc.load(fs1).status == status_io_error);
std::ifstream fs2("con");
CHECK(doc.load(fs2).status == status_io_error);
}
TEST(document_load_string)
{
pugi::xml_document doc;
CHECK(doc.load("<node/>"));
CHECK_NODE(doc, "<node />");
}
TEST(document_load_file)
{
pugi::xml_document doc;
CHECK(doc.load_file("tests/data/small.xml"));
CHECK_NODE(doc, "<node />");
}
TEST(document_load_file_large)
{
pugi::xml_document doc;
CHECK(doc.load_file("tests/data/large.xml"));
std::ostringstream oss;
oss << "<node>";
for (int i = 0; i < 10000; ++i) oss << "<node />";
oss << "</node>";
CHECK_NODE(doc, oss.str().c_str());
}
TEST(document_load_file_error)
{
pugi::xml_document doc;
CHECK(doc.load_file("").status == status_file_not_found);
CHECK(doc.load_file("con").status == status_io_error);
}
TEST_XML(document_save, "<node/>")
{
std::ostringstream oss;
xml_writer_stream writer(oss);
doc.save(writer, "", pugi::format_no_declaration | pugi::format_raw);
CHECK(oss.str() == "<node />");
}
TEST_XML(document_save_bom, "<node/>")
{
std::ostringstream oss;
xml_writer_stream writer(oss);
doc.save(writer, "", pugi::format_no_declaration | pugi::format_raw | pugi::format_write_bom_utf8);
CHECK(oss.str() == "\xef\xbb\xbf<node />");
}
TEST_XML(document_save_declaration, "<node/>")
{
std::ostringstream oss;
xml_writer_stream writer(oss);
doc.save(writer);
CHECK(oss.str() == "<?xml version=\"1.0\"?>\n<node />\n");
}
TEST_XML(document_save_file, "<node/>")
{
CHECK(doc.save_file("tests/data/output.xml"));
CHECK(doc.load_file("tests/data/output.xml", pugi::parse_default | pugi::parse_declaration));
CHECK_NODE(doc, "<?xml version=\"1.0\"?><node />");
unlink("tests/data/output.xml");
}
TEST(document_parse)
{
char text[] = "<node/>";
pugi::xml_document doc;
CHECK(doc.parse(text));
CHECK_NODE(doc, "<node />");
}
TEST(document_parse_transfer_ownership)
{
char* text = static_cast<char*>(malloc(strlen("<node/>") + 1));
CHECK(text);
strcpy(text, "<node/>");
pugi::xml_document doc;
CHECK(doc.parse(transfer_ownership_tag(), text));
CHECK_NODE(doc, "<node />");
}
|