Newer
Older
#include "common.hpp"
#include <limits>
#ifdef __BORLANDC__
using std::ldexpf;
#endif
TEST_XML(dom_attr_assign, "<node/>")
{
xml_node node = doc.child(STR("node"));
node.append_attribute(STR("attr1")) = STR("v1");
xml_attribute() = STR("v1");
node.append_attribute(STR("attr2")) = -2147483647;
node.append_attribute(STR("attr3")) = -2147483647 - 1;
xml_attribute() = -2147483647 - 1;
node.append_attribute(STR("attr4")) = 4294967295u;
node.append_attribute(STR("attr5")) = 4294967294u;
Arseny Kapoulkine
committed
xml_attribute() = 4294967295u;
node.append_attribute(STR("attr6")) = 0.5;
xml_attribute() = 0.5;
node.append_attribute(STR("attr7")) = 0.25f;
xml_attribute() = 0.25f;
node.append_attribute(STR("attr8")) = true;
xml_attribute() = true;
CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />"));
TEST_XML(dom_attr_set_name, "<node attr='value' />")
{
xml_attribute attr = doc.child(STR("node")).attribute(STR("attr"));
CHECK(attr.set_name(STR("n")));
CHECK(!xml_attribute().set_name(STR("n")));
CHECK_NODE(doc, STR("<node n=\"value\" />"));
}
TEST_XML(dom_attr_set_value, "<node/>")
{
xml_node node = doc.child(STR("node"));
CHECK(node.append_attribute(STR("attr1")).set_value(STR("v1")));
CHECK(!xml_attribute().set_value(STR("v1")));
CHECK(node.append_attribute(STR("attr2")).set_value(-2147483647));
CHECK(node.append_attribute(STR("attr3")).set_value(-2147483647 - 1));
CHECK(!xml_attribute().set_value(-2147483647));
CHECK(node.append_attribute(STR("attr4")).set_value(4294967295u));
CHECK(node.append_attribute(STR("attr5")).set_value(4294967294u));
CHECK(!xml_attribute().set_value(4294967295u));
CHECK(node.append_attribute(STR("attr6")).set_value(0.5));
CHECK(!xml_attribute().set_value(0.5));
CHECK(node.append_attribute(STR("attr7")).set_value(0.25f));
CHECK(!xml_attribute().set_value(0.25f));
CHECK(node.append_attribute(STR("attr8")).set_value(true));
CHECK(!xml_attribute().set_value(true));
CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />"));
Arseny Kapoulkine
committed
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
#ifdef PUGIXML_HAS_LONG_LONG
TEST_XML(dom_attr_assign_llong, "<node/>")
{
xml_node node = doc.child(STR("node"));
node.append_attribute(STR("attr1")) = -9223372036854775807ll;
node.append_attribute(STR("attr2")) = -9223372036854775807ll - 1;
xml_attribute() = -9223372036854775807ll - 1;
node.append_attribute(STR("attr3")) = 18446744073709551615ull;
node.append_attribute(STR("attr4")) = 18446744073709551614ull;
xml_attribute() = 18446744073709551615ull;
CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\" />"));
}
TEST_XML(dom_attr_set_value_llong, "<node/>")
{
xml_node node = doc.child(STR("node"));
CHECK(node.append_attribute(STR("attr1")).set_value(-9223372036854775807ll));
CHECK(node.append_attribute(STR("attr2")).set_value(-9223372036854775807ll - 1));
CHECK(!xml_attribute().set_value(-9223372036854775807ll - 1));
CHECK(node.append_attribute(STR("attr3")).set_value(18446744073709551615ull));
CHECK(node.append_attribute(STR("attr4")).set_value(18446744073709551614ull));
CHECK(!xml_attribute().set_value(18446744073709551615ull));
CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\" />"));
}
#endif
TEST_XML(dom_attr_assign_large_number_float, "<node attr='' />")
{
xml_node node = doc.child(STR("node"));
node.attribute(STR("attr")) = std::numeric_limits<float>::max();
CHECK(test_node(node, STR("<node attr=\"3.40282347e+038\" />"), STR(""), pugi::format_raw) ||
test_node(node, STR("<node attr=\"3.40282347e+38\" />"), STR(""), pugi::format_raw));
}
TEST_XML(dom_attr_assign_large_number_double, "<node attr='' />")
{
xml_node node = doc.child(STR("node"));
node.attribute(STR("attr")) = std::numeric_limits<double>::max();
// Borland C does not print double values with enough precision
#ifdef __BORLANDC__
CHECK_NODE(node, STR("<node attr=\"1.7976931348623156e+308\" />"));
#else
CHECK_NODE(node, STR("<node attr=\"1.7976931348623157e+308\" />"));
#endif
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
TEST_XML(dom_node_set_name, "<node>text</node>")
{
CHECK(doc.child(STR("node")).set_name(STR("n")));
CHECK(!doc.child(STR("node")).first_child().set_name(STR("n")));
CHECK(!xml_node().set_name(STR("n")));
CHECK_NODE(doc, STR("<n>text</n>"));
}
TEST_XML(dom_node_set_value, "<node>text</node>")
{
CHECK(doc.child(STR("node")).first_child().set_value(STR("no text")));
CHECK(!doc.child(STR("node")).set_value(STR("no text")));
CHECK(!xml_node().set_value(STR("no text")));
CHECK_NODE(doc, STR("<node>no text</node>"));
}
TEST_XML(dom_node_set_value_allocated, "<node>text</node>")
{
CHECK(doc.child(STR("node")).first_child().set_value(STR("no text")));
CHECK(!doc.child(STR("node")).set_value(STR("no text")));
CHECK(!xml_node().set_value(STR("no text")));
CHECK(doc.child(STR("node")).first_child().set_value(STR("no text at all")));
CHECK_NODE(doc, STR("<node>no text at all</node>"));
}
arseny.kapoulkine@gmail.com
committed
TEST_XML(dom_node_prepend_attribute, "<node><child/></node>")
{
CHECK(xml_node().prepend_attribute(STR("a")) == xml_attribute());
CHECK(doc.prepend_attribute(STR("a")) == xml_attribute());
xml_attribute a1 = doc.child(STR("node")).prepend_attribute(STR("a1"));
CHECK(a1);
a1 = STR("v1");
xml_attribute a2 = doc.child(STR("node")).prepend_attribute(STR("a2"));
CHECK(a2 && a1 != a2);
a2 = STR("v2");
xml_attribute a3 = doc.child(STR("node")).child(STR("child")).prepend_attribute(STR("a3"));
CHECK(a3 && a1 != a3 && a2 != a3);
a3 = STR("v3");
CHECK_NODE(doc, STR("<node a2=\"v2\" a1=\"v1\"><child a3=\"v3\" /></node>"));
}
TEST_XML(dom_node_append_attribute, "<node><child/></node>")
{
CHECK(xml_node().append_attribute(STR("a")) == xml_attribute());
CHECK(doc.append_attribute(STR("a")) == xml_attribute());
xml_attribute a1 = doc.child(STR("node")).append_attribute(STR("a1"));
CHECK(a1);
a1 = STR("v1");
xml_attribute a2 = doc.child(STR("node")).append_attribute(STR("a2"));
CHECK(a2 && a1 != a2);
a2 = STR("v2");
xml_attribute a3 = doc.child(STR("node")).child(STR("child")).append_attribute(STR("a3"));
CHECK(a3 && a1 != a3 && a2 != a3);
a3 = STR("v3");
CHECK_NODE(doc, STR("<node a1=\"v1\" a2=\"v2\"><child a3=\"v3\" /></node>"));
}
Loading
Loading full blame...