diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-02-08 20:36:09 +0000 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-02-08 20:36:09 +0000 |
commit | f9bbc39bd9a14124c1cba696c99d051a39e34b60 (patch) | |
tree | a870b80a24fc0a49a51d6a6df47e38f375c4cdb0 /tests | |
parent | c3550de72b83bf70aa82f63b7395f1a0b41a4b0d (diff) |
Implement long long support if PUGIXML_HAS_LONG_LONG is defined (autodetection is not implemented yet)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@962 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_dom_modify.cpp | 34 | ||||
-rw-r--r-- | tests/test_dom_text.cpp | 91 | ||||
-rw-r--r-- | tests/test_dom_traverse.cpp | 55 |
3 files changed, 177 insertions, 3 deletions
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 620504a..c7a3989 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -15,7 +15,7 @@ TEST_XML(dom_attr_assign, "<node/>") node.append_attribute(STR("attr4")) = 4294967295u; node.append_attribute(STR("attr5")) = 4294967294u; - xml_attribute() = 2147483647; + xml_attribute() = 4294967295u; node.append_attribute(STR("attr6")) = 0.5; xml_attribute() = 0.5; @@ -50,6 +50,38 @@ 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=\"true\" />")); } +#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_node_set_name, "<node>text</node>") { CHECK(doc.child(STR("node")).set_name(STR("n"))); diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp index 2e38f29..fb65b03 100644 --- a/tests/test_dom_text.cpp +++ b/tests/test_dom_text.cpp @@ -155,6 +155,56 @@ TEST_XML(dom_text_as_bool, "<node><text1>0</text1><text2>1</text2><text3>true</t CHECK(!node.child(STR("text7")).text().as_bool());
}
+#ifdef PUGIXML_HAS_LONG_LONG
+TEST_XML(dom_text_as_llong, "<node><text1>1</text1><text2>-1</text2><text3>-9223372036854775808</text3><text4>9223372036854775807</text4><text5>0</text5></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(xml_text().as_llong() == 0);
+ CHECK(node.child(STR("text1")).text().as_llong() == 1);
+ CHECK(node.child(STR("text2")).text().as_llong() == -1);
+ CHECK(node.child(STR("text3")).text().as_llong() == -9223372036854775807ll - 1);
+ CHECK(node.child(STR("text4")).text().as_llong() == 9223372036854775807ll);
+ CHECK(node.child(STR("text5")).text().as_llong() == 0);
+}
+
+TEST_XML(dom_text_as_llong_hex, "<node><text1>0777</text1><text2>0x5ab</text2><text3>0XFf</text3><text4>-0x20</text4><text5>-0x8000000000000000</text5><text6>0x</text6></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.child(STR("text1")).text().as_llong() == 777); // no octal support! intentional
+ CHECK(node.child(STR("text2")).text().as_llong() == 1451);
+ CHECK(node.child(STR("text3")).text().as_llong() == 255);
+ CHECK(node.child(STR("text4")).text().as_llong() == -32);
+ CHECK(node.child(STR("text5")).text().as_llong() == -9223372036854775807ll - 1);
+ CHECK(node.child(STR("text6")).text().as_llong() == 0);
+}
+
+TEST_XML(dom_text_as_ullong, "<node><text1>0</text1><text2>1</text2><text3>9223372036854775807</text3><text4>18446744073709551615</text4><text5>0</text5></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(xml_text().as_ullong() == 0);
+ CHECK(node.child(STR("text1")).text().as_ullong() == 0);
+ CHECK(node.child(STR("text2")).text().as_ullong() == 1);
+ CHECK(node.child(STR("text3")).text().as_ullong() == 9223372036854775807ll);
+ CHECK(node.child(STR("text4")).text().as_ullong() == 18446744073709551615ull);
+ CHECK(node.child(STR("text5")).text().as_ullong() == 0);
+}
+
+TEST_XML(dom_text_as_ullong_hex, "<node><text1>0777</text1><text2>0x5ab</text2><text3>0XFf</text3><text4>0x20</text4><text5>0xFFFFFFFFFFFFFFFF</text5><text6>0x</text6></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.child(STR("text1")).text().as_ullong() == 777); // no octal support! intentional
+ CHECK(node.child(STR("text2")).text().as_ullong() == 1451);
+ CHECK(node.child(STR("text3")).text().as_ullong() == 255);
+ CHECK(node.child(STR("text4")).text().as_ullong() == 32);
+ CHECK(node.child(STR("text5")).text().as_ullong() == 18446744073709551615ull);
+ CHECK(node.child(STR("text6")).text().as_ullong() == 0);
+}
+#endif
+
TEST_XML(dom_text_get_no_state, "<node/>")
{
xml_node node = doc.child(STR("node"));
@@ -208,7 +258,7 @@ TEST_XML(dom_text_assign, "<node/>") node.append_child(STR("text4")).text() = 4294967295u;
node.append_child(STR("text5")).text() = 4294967294u;
- xml_text() = 2147483647;
+ xml_text() = 4294967295u;
node.append_child(STR("text6")).text() = 0.5;
xml_text() = 0.5;
@@ -232,7 +282,7 @@ TEST_XML(dom_text_set_value, "<node/>") CHECK(node.append_child(STR("text4")).text().set(4294967295u));
CHECK(node.append_child(STR("text5")).text().set(4294967294u));
- CHECK(!xml_text().set(2147483647));
+ CHECK(!xml_text().set(4294967295u));
CHECK(node.append_child(STR("text6")).text().set(0.5));
CHECK(!xml_text().set(0.5));
@@ -243,6 +293,38 @@ 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>true</text7></node>"));
}
+#ifdef PUGIXML_HAS_LONG_LONG
+TEST_XML(dom_text_assign_llong, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.append_child(STR("text1")).text() = -9223372036854775807ll;
+ node.append_child(STR("text2")).text() = -9223372036854775807ll - 1;
+ xml_text() = -9223372036854775807ll - 1;
+
+ node.append_child(STR("text3")).text() = 18446744073709551615ull;
+ node.append_child(STR("text4")).text() = 18446744073709551614ull;
+ xml_text() = 18446744073709551615ull;
+
+ CHECK_NODE(node, STR("<node><text1>-9223372036854775807</text1><text2>-9223372036854775808</text2><text3>18446744073709551615</text3><text4>18446744073709551614</text4></node>"));
+}
+
+TEST_XML(dom_text_set_value_llong, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_child(STR("text1")).text().set(-9223372036854775807ll));
+ CHECK(node.append_child(STR("text2")).text().set(-9223372036854775807ll - 1));
+ CHECK(!xml_text().set(-9223372036854775807ll - 1));
+
+ CHECK(node.append_child(STR("text3")).text().set(18446744073709551615ull));
+ CHECK(node.append_child(STR("text4")).text().set(18446744073709551614ull));
+ CHECK(!xml_text().set(18446744073709551615ull));
+
+ CHECK_NODE(node, STR("<node><text1>-9223372036854775807</text1><text2>-9223372036854775808</text2><text3>18446744073709551615</text3><text4>18446744073709551614</text4></node>"));
+}
+#endif
+
TEST_XML(dom_text_middle, "<node><c1>notthisone</c1>text<c2/></node>")
{
xml_node node = doc.child(STR("node"));
@@ -285,4 +367,9 @@ TEST(dom_text_defaults) CHECK(text.as_double(42) == 42);
CHECK(text.as_float(42) == 42);
CHECK(text.as_bool(true) == true);
+
+#ifdef PUGIXML_HAS_LONG_LONG
+ CHECK(text.as_llong(42) == 42);
+ CHECK(text.as_ullong(42) == 42);
+#endif
}
diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 9c7c9ec..43fec80 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -179,6 +179,56 @@ TEST_XML(dom_attr_as_bool, "<node attr1='0' attr2='1' attr3='true' attr4='True' CHECK(!node.attribute(STR("attr7")).as_bool()); } +#ifdef PUGIXML_HAS_LONG_LONG +TEST_XML(dom_attr_as_llong, "<node attr1='1' attr2='-1' attr3='-9223372036854775808' attr4='9223372036854775807' attr5='0'/>") +{ + xml_node node = doc.child(STR("node")); + + CHECK(xml_attribute().as_llong() == 0); + CHECK(node.attribute(STR("attr1")).as_llong() == 1); + CHECK(node.attribute(STR("attr2")).as_llong() == -1); + CHECK(node.attribute(STR("attr3")).as_llong() == -9223372036854775807ll - 1); + CHECK(node.attribute(STR("attr4")).as_llong() == 9223372036854775807ll); + CHECK(node.attribute(STR("attr5")).as_llong() == 0); +} + +TEST_XML(dom_attr_as_llong_hex, "<node attr1='0777' attr2='0x5ab' attr3='0XFf' attr4='-0x20' attr5='-0x8000000000000000' attr6='0x'/>") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.attribute(STR("attr1")).as_llong() == 777); // no octal support! intentional + CHECK(node.attribute(STR("attr2")).as_llong() == 1451); + CHECK(node.attribute(STR("attr3")).as_llong() == 255); + CHECK(node.attribute(STR("attr4")).as_llong() == -32); + CHECK(node.attribute(STR("attr5")).as_llong() == -9223372036854775807ll - 1); + CHECK(node.attribute(STR("attr6")).as_llong() == 0); +} + +TEST_XML(dom_attr_as_ullong, "<node attr1='0' attr2='1' attr3='9223372036854775807' attr4='18446744073709551615' attr5='0'/>") +{ + xml_node node = doc.child(STR("node")); + + CHECK(xml_attribute().as_ullong() == 0); + CHECK(node.attribute(STR("attr1")).as_ullong() == 0); + CHECK(node.attribute(STR("attr2")).as_ullong() == 1); + CHECK(node.attribute(STR("attr3")).as_ullong() == 9223372036854775807ull); + CHECK(node.attribute(STR("attr4")).as_ullong() == 18446744073709551615ull); + CHECK(node.attribute(STR("attr5")).as_ullong() == 0); +} + +TEST_XML(dom_attr_as_ullong_hex, "<node attr1='0777' attr2='0x5ab' attr3='0XFf' attr4='0x20' attr5='0xFFFFFFFFFFFFFFFF' attr6='0x'/>") +{ + xml_node node = doc.child(STR("node")); + + CHECK(node.attribute(STR("attr1")).as_ullong() == 777); // no octal support! intentional + CHECK(node.attribute(STR("attr2")).as_ullong() == 1451); + CHECK(node.attribute(STR("attr3")).as_ullong() == 255); + CHECK(node.attribute(STR("attr4")).as_ullong() == 32); + CHECK(node.attribute(STR("attr5")).as_ullong() == 18446744073709551615ull); + CHECK(node.attribute(STR("attr6")).as_ullong() == 0); +} +#endif + TEST(dom_attr_defaults) { xml_attribute attr; @@ -189,6 +239,11 @@ TEST(dom_attr_defaults) CHECK(attr.as_double(42) == 42); CHECK(attr.as_float(42) == 42); CHECK(attr.as_bool(true) == true); + +#ifdef PUGIXML_HAS_LONG_LONG + CHECK(attr.as_llong(42) == 42); + CHECK(attr.as_ullong(42) == 42); +#endif } TEST_XML(dom_attr_iterator, "<node><node1 attr1='0'/><node2 attr1='0' attr2='1'/><node3/></node>") |