From d2e72ee05a14bcefe0023816919e660ee8d523c7 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 2 Feb 2016 08:49:32 -0800 Subject: tests: Add tests for long setters --- tests/test_dom_modify.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test_dom_text.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) (limited to 'tests') 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 #include +#include TEST_XML(dom_attr_assign, "") { @@ -70,6 +71,68 @@ TEST_XML(dom_attr_set_value, "") CHECK_NODE(node, STR("")); } +#if LONG_MAX > 2147483647 +TEST_XML(dom_attr_assign_long, "") +{ + 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("")); +} + +TEST_XML(dom_attr_set_value_long, "") +{ + 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("")); +} +#else +TEST_XML(dom_attr_assign_long, "") +{ + 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("")); +} + +TEST_XML(dom_attr_set_value_long, "") +{ + 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("")); +} +#endif + #ifdef PUGIXML_HAS_LONG_LONG TEST_XML(dom_attr_assign_llong, "") { 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 + TEST_XML_FLAGS(dom_text_empty, "foo", parse_default | parse_pi) { xml_node node = doc.child(STR("node")); @@ -299,6 +301,68 @@ TEST_XML(dom_text_set_value, "") CHECK_NODE(node, STR("v1-2147483647-2147483648429496729542949672940.50.25true")); } +#if LONG_MAX > 2147483647 +TEST_XML(dom_text_assign_long, "") +{ + 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("-9223372036854775807-92233720368547758081844674407370955161518446744073709551614")); +} + +TEST_XML(dom_text_set_value_long, "") +{ + 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("-9223372036854775807-92233720368547758081844674407370955161518446744073709551614")); +} +#else +TEST_XML(dom_text_assign_long, "") +{ + 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("-2147483647-214748364842949672954294967294")); +} + +TEST_XML(dom_text_set_value_long, "") +{ + 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("-2147483647-214748364842949672954294967294")); +} +#endif + #ifdef PUGIXML_HAS_LONG_LONG TEST_XML(dom_text_assign_llong, "") { -- cgit v1.2.3