summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2016-02-02 08:49:32 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2016-02-02 08:49:32 -0800
commitd2e72ee05a14bcefe0023816919e660ee8d523c7 (patch)
tree6ee1d50e5dec30c6247cf3ba49712af36d6b0f20 /tests
parentf441c63ea491f30fbbaa3e557badc5752ebca7d3 (diff)
tests: Add tests for long setters
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dom_modify.cpp63
-rw-r--r--tests/test_dom_text.cpp64
2 files changed, 127 insertions, 0 deletions
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index 67d550b..4c944e9 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -5,6 +5,7 @@
#include <math.h>
#include <string.h>
+#include <limits.h>
TEST_XML(dom_attr_assign, "<node/>")
{
@@ -70,6 +71,68 @@ TEST_XML(dom_attr_set_value, "<node/>")
CHECK_NODE(node, STR("<node attr1=\"v1\" attr2=\"-2147483647\" attr3=\"-2147483648\" attr4=\"4294967295\" attr5=\"4294967294\" attr6=\"0.5\" attr7=\"0.25\" attr8=\"true\" />"));
}
+#if LONG_MAX > 2147483647
+TEST_XML(dom_attr_assign_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.append_attribute(STR("attr1")) = -9223372036854775807l;
+ node.append_attribute(STR("attr2")) = -9223372036854775807l - 1;
+ xml_attribute() = -9223372036854775807l - 1;
+
+ node.append_attribute(STR("attr3")) = 18446744073709551615ul;
+ node.append_attribute(STR("attr4")) = 18446744073709551614ul;
+ xml_attribute() = 18446744073709551615ul;
+
+ CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\" />"));
+}
+
+TEST_XML(dom_attr_set_value_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_attribute(STR("attr1")).set_value(-9223372036854775807l));
+ CHECK(node.append_attribute(STR("attr2")).set_value(-9223372036854775807l - 1));
+ CHECK(!xml_attribute().set_value(-9223372036854775807l - 1));
+
+ CHECK(node.append_attribute(STR("attr3")).set_value(18446744073709551615ul));
+ CHECK(node.append_attribute(STR("attr4")).set_value(18446744073709551614ul));
+ CHECK(!xml_attribute().set_value(18446744073709551615ul));
+
+ CHECK_NODE(node, STR("<node attr1=\"-9223372036854775807\" attr2=\"-9223372036854775808\" attr3=\"18446744073709551615\" attr4=\"18446744073709551614\" />"));
+}
+#else
+TEST_XML(dom_attr_assign_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.append_attribute(STR("attr1")) = -2147483647l;
+ node.append_attribute(STR("attr2")) = -2147483647l - 1;
+ xml_attribute() = -2147483647l - 1;
+
+ node.append_attribute(STR("attr3")) = 4294967295ul;
+ node.append_attribute(STR("attr4")) = 4294967294ul;
+ xml_attribute() = 4294967295ul;
+
+ CHECK_NODE(node, STR("<node attr1=\"-2147483647\" attr2=\"-2147483648\" attr3=\"4294967295\" attr4=\"4294967294\" />"));
+}
+
+TEST_XML(dom_attr_set_value_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_attribute(STR("attr1")).set_value(-2147483647l));
+ CHECK(node.append_attribute(STR("attr2")).set_value(-2147483647l - 1));
+ CHECK(!xml_attribute().set_value(-2147483647l - 1));
+
+ CHECK(node.append_attribute(STR("attr3")).set_value(4294967295ul));
+ CHECK(node.append_attribute(STR("attr4")).set_value(4294967294ul));
+ CHECK(!xml_attribute().set_value(4294967295ul));
+
+ CHECK_NODE(node, STR("<node attr1=\"-2147483647\" attr2=\"-2147483648\" attr3=\"4294967295\" attr4=\"4294967294\" />"));
+}
+#endif
+
#ifdef PUGIXML_HAS_LONG_LONG
TEST_XML(dom_attr_assign_llong, "<node/>")
{
diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp
index 4d91452..7582460 100644
--- a/tests/test_dom_text.cpp
+++ b/tests/test_dom_text.cpp
@@ -2,6 +2,8 @@
#include "helpers.hpp"
+#include <limits.h>
+
TEST_XML_FLAGS(dom_text_empty, "<node><a>foo</a><b><![CDATA[bar]]></b><c><?pi value?></c><d/></node>", parse_default | parse_pi)
{
xml_node node = doc.child(STR("node"));
@@ -299,6 +301,68 @@ TEST_XML(dom_text_set_value, "<node/>")
CHECK_NODE(node, STR("<node><text1>v1</text1><text2>-2147483647</text2><text3>-2147483648</text3><text4>4294967295</text4><text5>4294967294</text5><text6>0.5</text6><text7>0.25</text7><text8>true</text8></node>"));
}
+#if LONG_MAX > 2147483647
+TEST_XML(dom_text_assign_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.append_child(STR("text1")).text() = -9223372036854775807l;
+ node.append_child(STR("text2")).text() = -9223372036854775807l - 1;
+ xml_text() = -9223372036854775807l - 1;
+
+ node.append_child(STR("text3")).text() = 18446744073709551615ul;
+ node.append_child(STR("text4")).text() = 18446744073709551614ul;
+ xml_text() = 18446744073709551615ul;
+
+ CHECK_NODE(node, STR("<node><text1>-9223372036854775807</text1><text2>-9223372036854775808</text2><text3>18446744073709551615</text3><text4>18446744073709551614</text4></node>"));
+}
+
+TEST_XML(dom_text_set_value_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_child(STR("text1")).text().set(-9223372036854775807l));
+ CHECK(node.append_child(STR("text2")).text().set(-9223372036854775807l - 1));
+ CHECK(!xml_text().set(-9223372036854775807l - 1));
+
+ CHECK(node.append_child(STR("text3")).text().set(18446744073709551615ul));
+ CHECK(node.append_child(STR("text4")).text().set(18446744073709551614ul));
+ CHECK(!xml_text().set(18446744073709551615ul));
+
+ CHECK_NODE(node, STR("<node><text1>-9223372036854775807</text1><text2>-9223372036854775808</text2><text3>18446744073709551615</text3><text4>18446744073709551614</text4></node>"));
+}
+#else
+TEST_XML(dom_text_assign_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.append_child(STR("text1")).text() = -2147483647l;
+ node.append_child(STR("text2")).text() = -2147483647l - 1;
+ xml_text() = -2147483647l - 1;
+
+ node.append_child(STR("text3")).text() = 4294967295ul;
+ node.append_child(STR("text4")).text() = 4294967294ul;
+ xml_text() = 4294967295ul;
+
+ CHECK_NODE(node, STR("<node><text1>-2147483647</text1><text2>-2147483648</text2><text3>4294967295</text3><text4>4294967294</text4></node>"));
+}
+
+TEST_XML(dom_text_set_value_long, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_child(STR("text1")).text().set(-2147483647l));
+ CHECK(node.append_child(STR("text2")).text().set(-2147483647l - 1));
+ CHECK(!xml_text().set(-2147483647l - 1));
+
+ CHECK(node.append_child(STR("text3")).text().set(4294967295ul));
+ CHECK(node.append_child(STR("text4")).text().set(4294967294ul));
+ CHECK(!xml_text().set(4294967295ul));
+
+ CHECK_NODE(node, STR("<node><text1>-2147483647</text1><text2>-2147483648</text2><text3>4294967295</text3><text4>4294967294</text4></node>"));
+}
+#endif
+
#ifdef PUGIXML_HAS_LONG_LONG
TEST_XML(dom_text_assign_llong, "<node/>")
{