summaryrefslogtreecommitdiff
path: root/tests/test_dom_modify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_dom_modify.cpp')
-rw-r--r--tests/test_dom_modify.cpp115
1 files changed, 98 insertions, 17 deletions
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index 45cf3ea..5167358 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -3,6 +3,8 @@
#include <limits>
#include <string>
+#include <math.h>
+
TEST_XML(dom_attr_assign, "<node/>")
{
xml_node node = doc.child(STR("node"));
@@ -21,10 +23,13 @@ TEST_XML(dom_attr_assign, "<node/>")
node.append_attribute(STR("attr6")) = 0.5;
xml_attribute() = 0.5;
- node.append_attribute(STR("attr7")) = true;
+ 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=\"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' />")
@@ -55,10 +60,13 @@ TEST_XML(dom_attr_set_value, "<node/>")
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(true));
+ 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=\"true\" />"));
+ CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />"));
}
#ifdef PUGIXML_HAS_LONG_LONG
@@ -93,6 +101,17 @@ TEST_XML(dom_attr_set_value_llong, "<node/>")
}
#endif
+TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.attribute(STR("attr1")) = std::numeric_limits<float>::max();
+ node.attribute(STR("attr2")) = std::numeric_limits<double>::max();
+
+ CHECK(test_node(node, STR("<node attr1=\"3.40282347e+038\" attr2=\"1.7976931348623157e+308\" />"), STR(""), pugi::format_raw) ||
+ test_node(node, STR("<node attr1=\"3.40282347e+38\" attr2=\"1.7976931348623157e+308\" />"), STR(""), pugi::format_raw));
+}
+
TEST_XML(dom_node_set_name, "<node>text</node>")
{
CHECK(doc.child(STR("node")).set_name(STR("n")));
@@ -746,17 +765,6 @@ TEST_XML_FLAGS(dom_node_copy_types, "<?xml version='1.0'?><!DOCTYPE id><root><?p
CHECK_NODE(doc, STR("<?xml version=\"1.0\"?><!DOCTYPE id><?xml version=\"1.0\"?><!DOCTYPE id><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root><root><?pi value?><!--comment--><node id=\"1\">pcdata<![CDATA[cdata]]></node></root>"));
}
-TEST_XML(dom_attr_assign_large_number, "<node attr1='' attr2='' />")
-{
- xml_node node = doc.child(STR("node"));
-
- node.attribute(STR("attr1")) = std::numeric_limits<float>::max();
- node.attribute(STR("attr2")) = std::numeric_limits<double>::max();
-
- CHECK(test_node(node, STR("<node attr1=\"3.40282e+038\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw) ||
- test_node(node, STR("<node attr1=\"3.40282e+38\" attr2=\"1.79769e+308\" />"), STR(""), pugi::format_raw));
-}
-
TEST(dom_node_declaration_name)
{
xml_document doc;
@@ -1289,7 +1297,7 @@ TEST(dom_node_copy_stackless)
data += STR("</a>");
xml_document doc;
- CHECK(doc.load(data.c_str()));
+ CHECK(doc.load_string(data.c_str()));
xml_document copy;
CHECK(copy.append_copy(doc.first_child()));
@@ -1324,7 +1332,7 @@ TEST(dom_node_copy_copyless)
TEST(dom_node_copy_copyless_mix)
{
xml_document doc;
- CHECK(doc.load(STR("<node>pcdata<?name value?><child attr1=\"\" attr2=\"value2\" /></node>"), parse_full));
+ CHECK(doc.load_string(STR("<node>pcdata<?name value?><child attr1=\"\" attr2=\"value2\" /></node>"), parse_full));
xml_node child = doc.child(STR("node")).child(STR("child"));
@@ -1426,3 +1434,76 @@ TEST_XML(dom_node_set_deallocate, "<node attr='value'>text</node>")
CHECK_NODE(doc, STR("<:anonymous :anonymous=\"\"></:anonymous>"));
}
+
+TEST(dom_node_copy_declaration_empty_name)
+{
+ xml_document doc1;
+ xml_node decl1 = doc1.append_child(node_declaration);
+ decl1.set_name(STR(""));
+
+ xml_document doc2;
+ xml_node decl2 = doc2.append_copy(decl1);
+
+ CHECK_STRING(decl2.name(), STR(""));
+}
+
+TEST(dom_fp_roundtrip_min_max)
+{
+ xml_document doc;
+ xml_node node = doc.append_child(STR("node"));
+ xml_attribute attr = node.append_attribute(STR("attr"));
+
+ node.text().set(std::numeric_limits<float>::min());
+ CHECK(node.text().as_float() == std::numeric_limits<float>::min());
+
+ attr.set_value(std::numeric_limits<float>::max());
+ CHECK(attr.as_float() == std::numeric_limits<float>::max());
+
+ attr.set_value(std::numeric_limits<double>::min());
+ CHECK(attr.as_double() == std::numeric_limits<double>::min());
+
+ node.text().set(std::numeric_limits<double>::max());
+ CHECK(node.text().as_double() == std::numeric_limits<double>::max());
+}
+
+const double fp_roundtrip_base[] =
+{
+ 0.31830988618379067154,
+ 0.43429448190325182765,
+ 0.57721566490153286061,
+ 0.69314718055994530942,
+ 0.70710678118654752440,
+ 0.78539816339744830962,
+};
+
+TEST(dom_fp_roundtrip_float)
+{
+ xml_document doc;
+
+ for (int e = -125; e <= 128; ++e)
+ {
+ for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i)
+ {
+ float value = ldexpf(static_cast<float>(fp_roundtrip_base[i]), e);
+
+ doc.text().set(value);
+ CHECK(doc.text().as_float() == value);
+ }
+ }
+}
+
+TEST(dom_fp_roundtrip_double)
+{
+ xml_document doc;
+
+ for (int e = -1021; e <= 1024; ++e)
+ {
+ for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i)
+ {
+ double value = ldexp(fp_roundtrip_base[i], e);
+
+ doc.text().set(value);
+ CHECK(doc.text().as_double() == value);
+ }
+ }
+}