summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-09-19 00:14:18 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-09-19 00:14:18 -0700
commit234c2f3657ec50671299a359877b058d55aa1d1d (patch)
treeb16a2938c945b345f01e9113334c6ac33c5a7f87
parentd62b2541d7f120c692837c130abb22fe5b777a6c (diff)
tests: Convert several files to Unix line endings
They were still using Windows EOL by mistake
-rw-r--r--tests/test_dom_text.cpp762
-rw-r--r--tests/test_header_string_iostream.cpp10
-rw-r--r--tests/test_version.cpp10
-rw-r--r--tests/test_xpath_variables.cpp1164
4 files changed, 973 insertions, 973 deletions
diff --git a/tests/test_dom_text.cpp b/tests/test_dom_text.cpp
index 007334a..01c815c 100644
--- a/tests/test_dom_text.cpp
+++ b/tests/test_dom_text.cpp
@@ -1,381 +1,381 @@
-#include "common.hpp"
-
-#include "helpers.hpp"
-
-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"));
-
- CHECK(node.child(STR("a")).text());
- CHECK(node.child(STR("b")).text());
- CHECK(!node.child(STR("c")).text());
- CHECK(!node.child(STR("d")).text());
- CHECK(!xml_node().text());
- CHECK(!xml_text());
-
- generic_empty_test(node.child(STR("a")).text());
-}
-
-TEST_XML(dom_text_bool_ops, "<node>foo</node>")
-{
- generic_bool_ops_test(doc.child(STR("node")).text());
-}
-
-TEST_XML_FLAGS(dom_text_get, "<node><a>foo</a><b><node/><![CDATA[bar]]></b><c><?pi value?></c><d/></node>", parse_default | parse_pi)
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK_STRING(node.child(STR("a")).text().get(), STR("foo"));
- CHECK_STRING(node.child(STR("a")).first_child().text().get(), STR("foo"));
-
- CHECK_STRING(node.child(STR("b")).text().get(), STR("bar"));
- CHECK_STRING(node.child(STR("b")).last_child().text().get(), STR("bar"));
-
- CHECK_STRING(node.child(STR("c")).text().get(), STR(""));
- CHECK_STRING(node.child(STR("c")).first_child().text().get(), STR(""));
-
- CHECK_STRING(node.child(STR("d")).text().get(), STR(""));
-
- CHECK_STRING(xml_node().text().get(), STR(""));
-}
-
-TEST_XML_FLAGS(dom_text_as_string, "<node><a>foo</a><b><node/><![CDATA[bar]]></b><c><?pi value?></c><d/></node>", parse_default | parse_pi)
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK_STRING(node.child(STR("a")).text().as_string(), STR("foo"));
- CHECK_STRING(node.child(STR("a")).first_child().text().as_string(), STR("foo"));
-
- CHECK_STRING(node.child(STR("b")).text().as_string(), STR("bar"));
- CHECK_STRING(node.child(STR("b")).last_child().text().as_string(), STR("bar"));
-
- CHECK_STRING(node.child(STR("c")).text().as_string(), STR(""));
- CHECK_STRING(node.child(STR("c")).first_child().text().as_string(), STR(""));
-
- CHECK_STRING(node.child(STR("d")).text().as_string(), STR(""));
-
- CHECK_STRING(xml_node().text().as_string(), STR(""));
-}
-
-TEST_XML(dom_text_as_int, "<node><text1>1</text1><text2>-1</text2><text3>-2147483648</text3><text4>2147483647</text4><text5>0</text5></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(xml_text().as_int() == 0);
- CHECK(node.child(STR("text1")).text().as_int() == 1);
- CHECK(node.child(STR("text2")).text().as_int() == -1);
- CHECK(node.child(STR("text3")).text().as_int() == -2147483647 - 1);
- CHECK(node.child(STR("text4")).text().as_int() == 2147483647);
- CHECK(node.child(STR("text5")).text().as_int() == 0);
-}
-
-TEST_XML(dom_text_as_int_hex, "<node><text1>0777</text1><text2>0x5ab</text2><text3>0XFf</text3><text4>-0x20</text4><text5>-0x80000000</text5><text6>0x</text6></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.child(STR("text1")).text().as_int() == 777); // no octal support! intentional
- CHECK(node.child(STR("text2")).text().as_int() == 1451);
- CHECK(node.child(STR("text3")).text().as_int() == 255);
- CHECK(node.child(STR("text4")).text().as_int() == -32);
- CHECK(node.child(STR("text5")).text().as_int() == -2147483647 - 1);
- CHECK(node.child(STR("text6")).text().as_int() == 0);
-}
-
-TEST_XML(dom_text_as_uint, "<node><text1>0</text1><text2>1</text2><text3>2147483647</text3><text4>4294967295</text4><text5>0</text5></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(xml_text().as_uint() == 0);
- CHECK(node.child(STR("text1")).text().as_uint() == 0);
- CHECK(node.child(STR("text2")).text().as_uint() == 1);
- CHECK(node.child(STR("text3")).text().as_uint() == 2147483647);
- CHECK(node.child(STR("text4")).text().as_uint() == 4294967295u);
- CHECK(node.child(STR("text5")).text().as_uint() == 0);
-}
-
-TEST_XML(dom_text_as_uint_hex, "<node><text1>0777</text1><text2>0x5ab</text2><text3>0XFf</text3><text4>0x20</text4><text5>0xFFFFFFFF</text5><text6>0x</text6></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.child(STR("text1")).text().as_uint() == 777); // no octal support! intentional
- CHECK(node.child(STR("text2")).text().as_uint() == 1451);
- CHECK(node.child(STR("text3")).text().as_uint() == 255);
- CHECK(node.child(STR("text4")).text().as_uint() == 32);
- CHECK(node.child(STR("text5")).text().as_uint() == 4294967295u);
- CHECK(node.child(STR("text6")).text().as_uint() == 0);
-}
-
-TEST_XML(dom_text_as_integer_space, "<node><text1> \t\n1234</text1><text2>\n\t 0x123</text2><text3>- 16</text3><text4>- 0x10</text4></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.child(STR("text1")).text().as_int() == 1234);
- CHECK(node.child(STR("text2")).text().as_int() == 291);
- CHECK(node.child(STR("text3")).text().as_int() == 0);
- CHECK(node.child(STR("text4")).text().as_int() == 0);
-}
-
-TEST_XML(dom_text_as_float, "<node><text1>0</text1><text2>1</text2><text3>0.12</text3><text4>-5.1</text4><text5>3e-4</text5><text6>3.14159265358979323846</text6></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(xml_text().as_float() == 0);
- CHECK_DOUBLE(node.child(STR("text1")).text().as_float(), 0);
- CHECK_DOUBLE(node.child(STR("text2")).text().as_float(), 1);
- CHECK_DOUBLE(node.child(STR("text3")).text().as_float(), 0.12);
- CHECK_DOUBLE(node.child(STR("text4")).text().as_float(), -5.1);
- CHECK_DOUBLE(node.child(STR("text5")).text().as_float(), 3e-4);
- CHECK_DOUBLE(node.child(STR("text6")).text().as_float(), 3.14159265358979323846);
-}
-
-TEST_XML(dom_text_as_double, "<node><text1>0</text1><text2>1</text2><text3>0.12</text3><text4>-5.1</text4><text5>3e-4</text5><text6>3.14159265358979323846</text6></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(xml_text().as_double() == 0);
- CHECK_DOUBLE(node.child(STR("text1")).text().as_double(), 0);
- CHECK_DOUBLE(node.child(STR("text2")).text().as_double(), 1);
- CHECK_DOUBLE(node.child(STR("text3")).text().as_double(), 0.12);
- CHECK_DOUBLE(node.child(STR("text4")).text().as_double(), -5.1);
- CHECK_DOUBLE(node.child(STR("text5")).text().as_double(), 3e-4);
- CHECK_DOUBLE(node.child(STR("text6")).text().as_double(), 3.14159265358979323846);
-}
-
-TEST_XML(dom_text_as_bool, "<node><text1>0</text1><text2>1</text2><text3>true</text3><text4>True</text4><text5>Yes</text5><text6>yes</text6><text7>false</text7></node>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(!xml_text().as_bool());
- CHECK(!node.child(STR("text1")).text().as_bool());
- CHECK(node.child(STR("text2")).text().as_bool());
- CHECK(node.child(STR("text3")).text().as_bool());
- CHECK(node.child(STR("text4")).text().as_bool());
- CHECK(node.child(STR("text5")).text().as_bool());
- CHECK(node.child(STR("text6")).text().as_bool());
- 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"));
- xml_text t = node.text();
-
- CHECK(!t);
- CHECK(t.get() && *t.get() == 0);
- CHECK(!node.first_child());
-
- node.append_child(node_pcdata);
-
- CHECK(t);
- CHECK_STRING(t.get(), STR(""));
-
- node.first_child().set_value(STR("test"));
-
- CHECK(t);
- CHECK_STRING(t.get(), STR("test"));
-}
-
-TEST_XML(dom_text_set, "<node/>")
-{
- xml_node node = doc.child(STR("node"));
- xml_text t = node.text();
-
- t.set(STR(""));
- CHECK(node.first_child().type() == node_pcdata);
- CHECK_NODE(node, STR("<node></node>"));
-
- t.set(STR("boo"));
- CHECK(node.first_child().type() == node_pcdata);
- CHECK(node.first_child() == node.last_child());
- CHECK_NODE(node, STR("<node>boo</node>"));
-
- t.set(STR("foobarfoobar"));
- CHECK(node.first_child().type() == node_pcdata);
- CHECK(node.first_child() == node.last_child());
- CHECK_NODE(node, STR("<node>foobarfoobar</node>"));
-}
-
-TEST_XML(dom_text_assign, "<node/>")
-{
- xml_node node = doc.child(STR("node"));
-
- node.append_child(STR("text1")).text() = STR("v1");
- xml_text() = STR("v1");
-
- node.append_child(STR("text2")).text() = -2147483647;
- node.append_child(STR("text3")).text() = -2147483647 - 1;
- xml_text() = -2147483647 - 1;
-
- node.append_child(STR("text4")).text() = 4294967295u;
- node.append_child(STR("text5")).text() = 4294967294u;
- xml_text() = 4294967295u;
-
- node.append_child(STR("text6")).text() = 0.5;
- xml_text() = 0.5;
-
- node.append_child(STR("text7")).text() = 0.25f;
- xml_text() = 0.25f;
-
- node.append_child(STR("text8")).text() = true;
- xml_text() = true;
-
- 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>"));
-}
-
-TEST_XML(dom_text_set_value, "<node/>")
-{
- xml_node node = doc.child(STR("node"));
-
- CHECK(node.append_child(STR("text1")).text().set(STR("v1")));
- CHECK(!xml_text().set(STR("v1")));
-
- CHECK(node.append_child(STR("text2")).text().set(-2147483647));
- CHECK(node.append_child(STR("text3")).text().set(-2147483647 - 1));
- CHECK(!xml_text().set(-2147483647 - 1));
-
- CHECK(node.append_child(STR("text4")).text().set(4294967295u));
- CHECK(node.append_child(STR("text5")).text().set(4294967294u));
- CHECK(!xml_text().set(4294967295u));
-
- CHECK(node.append_child(STR("text6")).text().set(0.5));
- CHECK(!xml_text().set(0.5));
-
- CHECK(node.append_child(STR("text7")).text().set(0.25f));
- CHECK(!xml_text().set(0.25f));
-
- CHECK(node.append_child(STR("text8")).text().set(true));
- CHECK(!xml_text().set(true));
-
- 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>"));
-}
-
-#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"));
- xml_text t = node.text();
-
- CHECK_STRING(t.get(), STR("text"));
- t.set(STR("notext"));
-
- CHECK_NODE(node, STR("<node><c1>notthisone</c1>notext<c2 /></node>"));
- CHECK(node.remove_child(t.data()));
-
- CHECK(!t);
- CHECK_NODE(node, STR("<node><c1>notthisone</c1><c2 /></node>"));
-
- t.set(STR("yestext"));
-
- CHECK(t);
- CHECK_NODE(node, STR("<node><c1>notthisone</c1><c2 />yestext</node>"));
- CHECK(t.data() == node.last_child());
-}
-
-TEST_XML_FLAGS(dom_text_data, "<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"));
-
- CHECK(node.child(STR("a")).text().data() == node.child(STR("a")).first_child());
- CHECK(node.child(STR("b")).text().data() == node.child(STR("b")).first_child());
- CHECK(!node.child(STR("c")).text().data());
- CHECK(!node.child(STR("d")).text().data());
- CHECK(!xml_text().data());
-}
-
-TEST(dom_text_defaults)
-{
- xml_text text;
-
- CHECK_STRING(text.as_string(STR("foo")), STR("foo"));
- CHECK(text.as_int(42) == 42);
- CHECK(text.as_uint(42) == 42);
- 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
-}
+#include "common.hpp"
+
+#include "helpers.hpp"
+
+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"));
+
+ CHECK(node.child(STR("a")).text());
+ CHECK(node.child(STR("b")).text());
+ CHECK(!node.child(STR("c")).text());
+ CHECK(!node.child(STR("d")).text());
+ CHECK(!xml_node().text());
+ CHECK(!xml_text());
+
+ generic_empty_test(node.child(STR("a")).text());
+}
+
+TEST_XML(dom_text_bool_ops, "<node>foo</node>")
+{
+ generic_bool_ops_test(doc.child(STR("node")).text());
+}
+
+TEST_XML_FLAGS(dom_text_get, "<node><a>foo</a><b><node/><![CDATA[bar]]></b><c><?pi value?></c><d/></node>", parse_default | parse_pi)
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK_STRING(node.child(STR("a")).text().get(), STR("foo"));
+ CHECK_STRING(node.child(STR("a")).first_child().text().get(), STR("foo"));
+
+ CHECK_STRING(node.child(STR("b")).text().get(), STR("bar"));
+ CHECK_STRING(node.child(STR("b")).last_child().text().get(), STR("bar"));
+
+ CHECK_STRING(node.child(STR("c")).text().get(), STR(""));
+ CHECK_STRING(node.child(STR("c")).first_child().text().get(), STR(""));
+
+ CHECK_STRING(node.child(STR("d")).text().get(), STR(""));
+
+ CHECK_STRING(xml_node().text().get(), STR(""));
+}
+
+TEST_XML_FLAGS(dom_text_as_string, "<node><a>foo</a><b><node/><![CDATA[bar]]></b><c><?pi value?></c><d/></node>", parse_default | parse_pi)
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK_STRING(node.child(STR("a")).text().as_string(), STR("foo"));
+ CHECK_STRING(node.child(STR("a")).first_child().text().as_string(), STR("foo"));
+
+ CHECK_STRING(node.child(STR("b")).text().as_string(), STR("bar"));
+ CHECK_STRING(node.child(STR("b")).last_child().text().as_string(), STR("bar"));
+
+ CHECK_STRING(node.child(STR("c")).text().as_string(), STR(""));
+ CHECK_STRING(node.child(STR("c")).first_child().text().as_string(), STR(""));
+
+ CHECK_STRING(node.child(STR("d")).text().as_string(), STR(""));
+
+ CHECK_STRING(xml_node().text().as_string(), STR(""));
+}
+
+TEST_XML(dom_text_as_int, "<node><text1>1</text1><text2>-1</text2><text3>-2147483648</text3><text4>2147483647</text4><text5>0</text5></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(xml_text().as_int() == 0);
+ CHECK(node.child(STR("text1")).text().as_int() == 1);
+ CHECK(node.child(STR("text2")).text().as_int() == -1);
+ CHECK(node.child(STR("text3")).text().as_int() == -2147483647 - 1);
+ CHECK(node.child(STR("text4")).text().as_int() == 2147483647);
+ CHECK(node.child(STR("text5")).text().as_int() == 0);
+}
+
+TEST_XML(dom_text_as_int_hex, "<node><text1>0777</text1><text2>0x5ab</text2><text3>0XFf</text3><text4>-0x20</text4><text5>-0x80000000</text5><text6>0x</text6></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.child(STR("text1")).text().as_int() == 777); // no octal support! intentional
+ CHECK(node.child(STR("text2")).text().as_int() == 1451);
+ CHECK(node.child(STR("text3")).text().as_int() == 255);
+ CHECK(node.child(STR("text4")).text().as_int() == -32);
+ CHECK(node.child(STR("text5")).text().as_int() == -2147483647 - 1);
+ CHECK(node.child(STR("text6")).text().as_int() == 0);
+}
+
+TEST_XML(dom_text_as_uint, "<node><text1>0</text1><text2>1</text2><text3>2147483647</text3><text4>4294967295</text4><text5>0</text5></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(xml_text().as_uint() == 0);
+ CHECK(node.child(STR("text1")).text().as_uint() == 0);
+ CHECK(node.child(STR("text2")).text().as_uint() == 1);
+ CHECK(node.child(STR("text3")).text().as_uint() == 2147483647);
+ CHECK(node.child(STR("text4")).text().as_uint() == 4294967295u);
+ CHECK(node.child(STR("text5")).text().as_uint() == 0);
+}
+
+TEST_XML(dom_text_as_uint_hex, "<node><text1>0777</text1><text2>0x5ab</text2><text3>0XFf</text3><text4>0x20</text4><text5>0xFFFFFFFF</text5><text6>0x</text6></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.child(STR("text1")).text().as_uint() == 777); // no octal support! intentional
+ CHECK(node.child(STR("text2")).text().as_uint() == 1451);
+ CHECK(node.child(STR("text3")).text().as_uint() == 255);
+ CHECK(node.child(STR("text4")).text().as_uint() == 32);
+ CHECK(node.child(STR("text5")).text().as_uint() == 4294967295u);
+ CHECK(node.child(STR("text6")).text().as_uint() == 0);
+}
+
+TEST_XML(dom_text_as_integer_space, "<node><text1> \t\n1234</text1><text2>\n\t 0x123</text2><text3>- 16</text3><text4>- 0x10</text4></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.child(STR("text1")).text().as_int() == 1234);
+ CHECK(node.child(STR("text2")).text().as_int() == 291);
+ CHECK(node.child(STR("text3")).text().as_int() == 0);
+ CHECK(node.child(STR("text4")).text().as_int() == 0);
+}
+
+TEST_XML(dom_text_as_float, "<node><text1>0</text1><text2>1</text2><text3>0.12</text3><text4>-5.1</text4><text5>3e-4</text5><text6>3.14159265358979323846</text6></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(xml_text().as_float() == 0);
+ CHECK_DOUBLE(node.child(STR("text1")).text().as_float(), 0);
+ CHECK_DOUBLE(node.child(STR("text2")).text().as_float(), 1);
+ CHECK_DOUBLE(node.child(STR("text3")).text().as_float(), 0.12);
+ CHECK_DOUBLE(node.child(STR("text4")).text().as_float(), -5.1);
+ CHECK_DOUBLE(node.child(STR("text5")).text().as_float(), 3e-4);
+ CHECK_DOUBLE(node.child(STR("text6")).text().as_float(), 3.14159265358979323846);
+}
+
+TEST_XML(dom_text_as_double, "<node><text1>0</text1><text2>1</text2><text3>0.12</text3><text4>-5.1</text4><text5>3e-4</text5><text6>3.14159265358979323846</text6></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(xml_text().as_double() == 0);
+ CHECK_DOUBLE(node.child(STR("text1")).text().as_double(), 0);
+ CHECK_DOUBLE(node.child(STR("text2")).text().as_double(), 1);
+ CHECK_DOUBLE(node.child(STR("text3")).text().as_double(), 0.12);
+ CHECK_DOUBLE(node.child(STR("text4")).text().as_double(), -5.1);
+ CHECK_DOUBLE(node.child(STR("text5")).text().as_double(), 3e-4);
+ CHECK_DOUBLE(node.child(STR("text6")).text().as_double(), 3.14159265358979323846);
+}
+
+TEST_XML(dom_text_as_bool, "<node><text1>0</text1><text2>1</text2><text3>true</text3><text4>True</text4><text5>Yes</text5><text6>yes</text6><text7>false</text7></node>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(!xml_text().as_bool());
+ CHECK(!node.child(STR("text1")).text().as_bool());
+ CHECK(node.child(STR("text2")).text().as_bool());
+ CHECK(node.child(STR("text3")).text().as_bool());
+ CHECK(node.child(STR("text4")).text().as_bool());
+ CHECK(node.child(STR("text5")).text().as_bool());
+ CHECK(node.child(STR("text6")).text().as_bool());
+ 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"));
+ xml_text t = node.text();
+
+ CHECK(!t);
+ CHECK(t.get() && *t.get() == 0);
+ CHECK(!node.first_child());
+
+ node.append_child(node_pcdata);
+
+ CHECK(t);
+ CHECK_STRING(t.get(), STR(""));
+
+ node.first_child().set_value(STR("test"));
+
+ CHECK(t);
+ CHECK_STRING(t.get(), STR("test"));
+}
+
+TEST_XML(dom_text_set, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+ xml_text t = node.text();
+
+ t.set(STR(""));
+ CHECK(node.first_child().type() == node_pcdata);
+ CHECK_NODE(node, STR("<node></node>"));
+
+ t.set(STR("boo"));
+ CHECK(node.first_child().type() == node_pcdata);
+ CHECK(node.first_child() == node.last_child());
+ CHECK_NODE(node, STR("<node>boo</node>"));
+
+ t.set(STR("foobarfoobar"));
+ CHECK(node.first_child().type() == node_pcdata);
+ CHECK(node.first_child() == node.last_child());
+ CHECK_NODE(node, STR("<node>foobarfoobar</node>"));
+}
+
+TEST_XML(dom_text_assign, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ node.append_child(STR("text1")).text() = STR("v1");
+ xml_text() = STR("v1");
+
+ node.append_child(STR("text2")).text() = -2147483647;
+ node.append_child(STR("text3")).text() = -2147483647 - 1;
+ xml_text() = -2147483647 - 1;
+
+ node.append_child(STR("text4")).text() = 4294967295u;
+ node.append_child(STR("text5")).text() = 4294967294u;
+ xml_text() = 4294967295u;
+
+ node.append_child(STR("text6")).text() = 0.5;
+ xml_text() = 0.5;
+
+ node.append_child(STR("text7")).text() = 0.25f;
+ xml_text() = 0.25f;
+
+ node.append_child(STR("text8")).text() = true;
+ xml_text() = true;
+
+ 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>"));
+}
+
+TEST_XML(dom_text_set_value, "<node/>")
+{
+ xml_node node = doc.child(STR("node"));
+
+ CHECK(node.append_child(STR("text1")).text().set(STR("v1")));
+ CHECK(!xml_text().set(STR("v1")));
+
+ CHECK(node.append_child(STR("text2")).text().set(-2147483647));
+ CHECK(node.append_child(STR("text3")).text().set(-2147483647 - 1));
+ CHECK(!xml_text().set(-2147483647 - 1));
+
+ CHECK(node.append_child(STR("text4")).text().set(4294967295u));
+ CHECK(node.append_child(STR("text5")).text().set(4294967294u));
+ CHECK(!xml_text().set(4294967295u));
+
+ CHECK(node.append_child(STR("text6")).text().set(0.5));
+ CHECK(!xml_text().set(0.5));
+
+ CHECK(node.append_child(STR("text7")).text().set(0.25f));
+ CHECK(!xml_text().set(0.25f));
+
+ CHECK(node.append_child(STR("text8")).text().set(true));
+ CHECK(!xml_text().set(true));
+
+ 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>"));
+}
+
+#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"));
+ xml_text t = node.text();
+
+ CHECK_STRING(t.get(), STR("text"));
+ t.set(STR("notext"));
+
+ CHECK_NODE(node, STR("<node><c1>notthisone</c1>notext<c2 /></node>"));
+ CHECK(node.remove_child(t.data()));
+
+ CHECK(!t);
+ CHECK_NODE(node, STR("<node><c1>notthisone</c1><c2 /></node>"));
+
+ t.set(STR("yestext"));
+
+ CHECK(t);
+ CHECK_NODE(node, STR("<node><c1>notthisone</c1><c2 />yestext</node>"));
+ CHECK(t.data() == node.last_child());
+}
+
+TEST_XML_FLAGS(dom_text_data, "<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"));
+
+ CHECK(node.child(STR("a")).text().data() == node.child(STR("a")).first_child());
+ CHECK(node.child(STR("b")).text().data() == node.child(STR("b")).first_child());
+ CHECK(!node.child(STR("c")).text().data());
+ CHECK(!node.child(STR("d")).text().data());
+ CHECK(!xml_text().data());
+}
+
+TEST(dom_text_defaults)
+{
+ xml_text text;
+
+ CHECK_STRING(text.as_string(STR("foo")), STR("foo"));
+ CHECK(text.as_int(42) == 42);
+ CHECK(text.as_uint(42) == 42);
+ 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_header_string_iostream.cpp b/tests/test_header_string_iostream.cpp
index 1105626..3210080 100644
--- a/tests/test_header_string_iostream.cpp
+++ b/tests/test_header_string_iostream.cpp
@@ -1,5 +1,5 @@
-// Tests compatibility with string/iostream
-#include <string>
-#include "../src/pugixml.hpp"
-#include <istream>
-#include <ostream>
+// Tests compatibility with string/iostream
+#include <string>
+#include "../src/pugixml.hpp"
+#include <istream>
+#include <ostream>
diff --git a/tests/test_version.cpp b/tests/test_version.cpp
index cf64efc..38ec7bc 100644
--- a/tests/test_version.cpp
+++ b/tests/test_version.cpp
@@ -1,5 +1,5 @@
-#include "../src/pugixml.hpp"
-
-#if PUGIXML_VERSION != 160
-#error Unexpected pugixml version
-#endif
+#include "../src/pugixml.hpp"
+
+#if PUGIXML_VERSION != 160
+#error Unexpected pugixml version
+#endif
diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp
index ab436cd..fec1386 100644
--- a/tests/test_xpath_variables.cpp
+++ b/tests/test_xpath_variables.cpp
@@ -1,582 +1,582 @@
-#ifndef PUGIXML_NO_XPATH
-
-#include "common.hpp"
-
-#include <string>
-
-TEST(xpath_variables_type_none)
-{
- xpath_variable_set set;
-
- xpath_variable* var = set.add(STR("target"), xpath_type_none);
- CHECK(!var);
-}
-
-TEST(xpath_variables_type_boolean)
-{
- xpath_variable_set set;
-
- xpath_variable* var = set.add(STR("target"), xpath_type_boolean);
- CHECK(var);
-
- CHECK(var->type() == xpath_type_boolean);
- CHECK_STRING(var->name(), STR("target"));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE_NAN(var->get_number());
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().empty());
-
- CHECK(var->set(true));
- CHECK(!var->set(1.0));
- CHECK(!var->set(STR("abc")));
- CHECK(!var->set(xpath_node_set()));
-
- CHECK(var->get_boolean() == true);
- CHECK_DOUBLE_NAN(var->get_number());
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().empty());
-}
-
-TEST(xpath_variables_type_number)
-{
- xpath_variable_set set;
-
- xpath_variable* var = set.add(STR("target"), xpath_type_number);
- CHECK(var);
-
- CHECK(var->type() == xpath_type_number);
- CHECK_STRING(var->name(), STR("target"));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE(var->get_number(), 0);
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().empty());
-
- CHECK(!var->set(true));
- CHECK(var->set(1.0));
- CHECK(!var->set(STR("abc")));
- CHECK(!var->set(xpath_node_set()));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE(var->get_number(), 1);
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().empty());
-}
-
-TEST(xpath_variables_type_string)
-{
- xpath_variable_set set;
-
- xpath_variable* var = set.add(STR("target"), xpath_type_string);
- CHECK(var);
-
- CHECK(var->type() == xpath_type_string);
- CHECK_STRING(var->name(), STR("target"));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE_NAN(var->get_number());
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().empty());
-
- CHECK(!var->set(true));
- CHECK(!var->set(1.0));
- CHECK(var->set(STR("abc")));
- CHECK(!var->set(xpath_node_set()));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE_NAN(var->get_number());
- CHECK_STRING(var->get_string(), STR("abc"));
- CHECK(var->get_node_set().empty());
-
- CHECK(var->set(STR("abcdef")));
- CHECK_STRING(var->get_string(), STR("abcdef"));
-}
-
-TEST_XML(xpath_variables_type_node_set, "<node/>")
-{
- xpath_variable_set set;
-
- xpath_variable* var = set.add(STR("target"), xpath_type_node_set);
- CHECK(var);
-
- CHECK(var->type() == xpath_type_node_set);
- CHECK_STRING(var->name(), STR("target"));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE_NAN(var->get_number());
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().empty());
-
- CHECK(!var->set(true));
- CHECK(!var->set(1.0));
- CHECK(!var->set(STR("abc")));
- CHECK(var->set(doc.select_nodes(STR("*"))));
-
- CHECK(var->get_boolean() == false);
- CHECK_DOUBLE_NAN(var->get_number());
- CHECK_STRING(var->get_string(), STR(""));
- CHECK(var->get_node_set().size() == 1 && var->get_node_set()[0] == doc.first_child());
-}
-
-TEST(xpath_variables_set_operations)
-{
- xpath_variable_set set;
-
- xpath_variable* v1 = set.add(STR("var1"), xpath_type_number);
- CHECK(v1);
-
- xpath_variable* v2 = set.add(STR("var2"), xpath_type_string);
- CHECK(v2);
-
- CHECK(v1 != v2);
-
- CHECK(set.add(STR("var1"), xpath_type_number) == v1);
- CHECK(set.add(STR("var2"), xpath_type_string) == v2);
- CHECK(set.add(STR("var2"), xpath_type_node_set) == 0);
-
- CHECK(set.get(STR("var1")) == v1);
- CHECK(set.get(STR("var2")) == v2);
- CHECK(set.get(STR("var")) == 0);
- CHECK(set.get(STR("var11")) == 0);
-
- CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var1")) == v1);
- CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var3")) == 0);
-}
-
-TEST_XML(xpath_variables_set_operations_set, "<node/>")
-{
- xpath_variable_set set;
-
- xpath_variable* v1 = set.add(STR("var1"), xpath_type_number);
- CHECK(v1);
-
- xpath_variable* v2 = set.add(STR("var2"), xpath_type_string);
- CHECK(v2);
-
- CHECK(set.set(STR("var1"), 1.0));
- CHECK_DOUBLE(v1->get_number(), 1.0);
-
- CHECK(set.set(STR("var2"), STR("value")));
- CHECK_STRING(v2->get_string(), STR("value"));
-
- CHECK(!set.set(STR("var1"), true));
-
- CHECK(set.set(STR("var3"), doc.select_nodes(STR("*"))));
-
- xpath_variable* v3 = set.get(STR("var3"));
-
- CHECK(v3);
- CHECK(v3->type() == xpath_type_node_set);
- CHECK(v3->get_node_set().size() == 1);
-}
-
-TEST(xpath_variables_set_out_of_memory)
-{
- test_runner::_memory_fail_threshold = 1;
-
- xpath_variable_set set;
-
- xpath_variable* var = 0;
- CHECK_ALLOC_FAIL(var = set.add(STR("target"), xpath_type_number));
- CHECK(!var);
-}
-
-TEST(xpath_variables_out_of_memory)
-{
- test_runner::_memory_fail_threshold = 64;
-
- xpath_variable_set set;
-
- xpath_variable* var = set.add(STR("target"), xpath_type_string);
- CHECK(var);
-
- CHECK_ALLOC_FAIL(CHECK(!var->set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))));
-}
-
-TEST_XML(xpath_variables_evaluate, "<node/>")
-{
- xpath_variable_set set;
- set.set(STR("var1"), true);
- set.set(STR("var2"), 0.5);
- set.set(STR("var3"), STR("value"));
- set.set(STR("var4"), doc.select_nodes(STR("*")));
-
- CHECK_XPATH_BOOLEAN_VAR(doc, STR("$var1"), &set, true);
- CHECK_XPATH_NUMBER_VAR(doc, STR("$var2"), &set, 0.5);
- CHECK_XPATH_STRING_VAR(doc, STR("$var3"), &set, STR("value"));
- CHECK_XPATH_NODESET_VAR(doc, STR("$var4"), &set) % 2;
-}
-
-TEST_XML(xpath_variables_evaluate_conversion, "<node>3</node>")
-{
- xpath_variable_set set;
- set.set(STR("var"), doc.select_nodes(STR("*")));
-
- CHECK_XPATH_BOOLEAN_VAR(doc, STR("$var"), &set, true);
- CHECK_XPATH_NUMBER_VAR(doc, STR("$var"), &set, 3);
- CHECK_XPATH_STRING_VAR(doc, STR("$var"), &set, STR("3"));
- CHECK_XPATH_NODESET_VAR(doc, STR("$var"), &set) % 2;
-}
-
-TEST(xpath_variables_evaluate_node_set_fail)
-{
- xpath_variable_set set;
- set.set(STR("var"), false);
-
- xpath_query q(STR("$var"), &set);
-
-#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK(q.evaluate_node_set(xml_node()).empty());
-#else
- try
- {
- q.evaluate_node_set(xml_node());
-
- CHECK_FORCE_FAIL("Expected exception");
- }
- catch (const xpath_exception&)
- {
- }
-#endif
-}
-
-TEST(xpath_variables_multiple_documents)
-{
- xml_document doc;
- doc.append_child().set_name(STR("node"));
-
- xml_document doc1;
- doc1.append_child().set_name(STR("node"));
-
- xml_document doc2;
- doc2.append_child().set_name(STR("node"));
-
- xpath_variable_set set;
- set.set(STR("var1"), doc1.select_nodes(STR("*")));
- set.set(STR("var2"), doc2.select_nodes(STR("*")));
-
- xpath_node_set ns = doc.select_nodes(STR("$var1 | $var2 | node"), &set);
- ns.sort();
-
- CHECK(ns.size() == 3);
- CHECK(ns[0] != ns[1] && ns[0] != ns[2]);
-
- xml_node n0 = doc.child(STR("node")), n1 = doc1.child(STR("node")), n2 = doc2.child(STR("node"));
-
- CHECK(n0 == ns[0].node() || n0 == ns[1].node() || n0 == ns[2].node());
- CHECK(n1 == ns[0].node() || n1 == ns[1].node() || n1 == ns[2].node());
- CHECK(n2 == ns[0].node() || n2 == ns[1].node() || n2 == ns[2].node());
-}
-
-TEST(xpath_variables_long_name)
-{
- xpath_variable_set set;
- set.set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), true);
-
- CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set, true);
-}
-
-TEST(xpath_variables_long_name_out_of_memory)
-{
- xpath_variable_set set;
- set.set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), true);
-
- test_runner::_memory_fail_threshold = 4096 + 64 + 52 * sizeof(char_t);
-
- CHECK_ALLOC_FAIL(CHECK(!xpath_query(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set)));
-}
-
-TEST_XML(xpath_variables_select, "<node attr='1'/><node attr='2'/>")
-{
- xpath_variable_set set;
- set.set(STR("one"), 1.0);
-
- xpath_node_set ns = doc.select_nodes(STR("node[@attr=$one+1]"), &set);
- CHECK(ns.size() == 1 && ns[0].node() == doc.last_child());
-
- xpath_node n = doc.select_node(STR("node[@attr=$one+1]"), &set);
- CHECK(n == ns[0]);
-}
-
-TEST(xpath_variables_empty_name)
-{
- xpath_variable_set set;
- CHECK(!set.add(STR(""), xpath_type_number));
-}
-
-TEST_XML(xpath_variables_inside_filter, "<node key='1' value='2'/><node key='2' value='1'/><node key='1' value='1'/>")
-{
- xpath_variable_set set;
- set.set(STR("one"), 1.0);
-
- xpath_node_set ns = doc.select_nodes(STR("(node[@key = $one])[@value = $one]"), &set);
- CHECK(ns.size() == 1 && ns[0].node() == doc.last_child());
-}
-
-TEST_XML(xpath_variables_step, "<node><child/><child/><child><child/></child></node>")
-{
- xpath_variable_set set;
- set.set(STR("root"), doc.select_nodes(STR("node")));
-
- CHECK_XPATH_NODESET_VAR(xml_node(), STR("$root/child"), &set) % 3 % 4 % 5;
- CHECK_XPATH_NODESET_VAR(xml_node(), STR("$root//child"), &set) % 3 % 4 % 5 % 6;
-}
-
-TEST_XML(xpath_variables_index, "<node><child/><child/><child><child/></child></node>")
-{
- xpath_variable_set set;
- set.set(STR("index"), 2.0);
-
- CHECK_XPATH_NODESET_VAR(doc, STR("node/child[$index]"), &set) % 4;
- CHECK_XPATH_NODESET_VAR(doc, STR("node/child[position()=$index]"), &set) % 4;
-}
-
-TEST(xpath_variables_qname)
-{
- xpath_variable_set set;
- set.set(STR("foo:bar"), true);
-
- CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$foo:bar"), &set, true);
-}
-
-TEST(xpath_variables_name_error)
-{
- xpath_variable_set set;
- set.set(STR("foo:"), true);
- set.set(STR(":bar"), true);
- set.set(STR("foo:*"), true);
- set.set(STR("foo"), true);
- set.set(STR("3"), true);
-
- CHECK_XPATH_FAIL_VAR(STR("$foo:"), &set);
- CHECK_XPATH_FAIL_VAR(STR("$:bar"), &set);
- CHECK_XPATH_FAIL_VAR(STR("$foo:*"), &set);
- CHECK_XPATH_FAIL_VAR(STR("$foo:bar:baz"), &set);
- CHECK_XPATH_FAIL_VAR(STR("$ foo"), &set);
-
- CHECK_XPATH_FAIL_VAR(STR("$3"), &set);
-}
-
-TEST(xpath_variables_empty_string)
-{
- xpath_variable_set set;
- set.add(STR("empty"), xpath_type_string);
-
- CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$empty = substring-before('a', 'z')"), &set, true);
-}
-
-TEST(xpath_variables_name_underscore)
-{
- xpath_variable_set set;
- set.set(STR("_foo_bar"), true);
-
- CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$_foo_bar"), &set, true);
-}
-
-TEST(xpath_variables_name_case)
-{
- xpath_variable_set set;
- set.set(STR("i"), 5.0);
- set.set(STR("I"), 2.0);
-
- CHECK_XPATH_NUMBER_VAR(xml_node(), STR("$i div $I"), &set, 2.5);
-}
-
-TEST(xpath_variables_name_unicode)
-{
-#ifdef PUGIXML_WCHAR_MODE
- #ifdef U_LITERALS
- const char_t* name = L"\u0400\u203D";
- #else
- const char_t* name = L"\x0400\x203D";
- #endif
-#else
- const char_t* name = "\xd0\x80\xe2\x80\xbd";
-#endif
-
- xpath_variable_set set;
- set.set(name, STR("value"));
-
- std::basic_string<char_t> var = STR("$");
- var += name;
-
- CHECK_XPATH_STRING_VAR(xml_node(), var.c_str(), &set, STR("value"));
-}
-
-TEST_XML(xpath_variables_count_sum, "<node><c1>12</c1><c2>23</c2><c3>34</c3></node>")
-{
- xpath_variable_set set;
- set.set(STR("c12"), doc.select_nodes(STR("node/c1 | node/c2")));
- set.set(STR("c3"), doc.select_nodes(STR("node/c3")));
- set.set(STR("c"), doc.select_nodes(STR("node/*")));
-
- CHECK_XPATH_NUMBER_VAR(xml_node(), STR("sum($c12) * count($c) - sum($c3)"), &set, 71);
-}
-
-TEST_XML(xpath_variables_copy, "<node />")
-{
- xpath_variable_set set1;
- set1.set(STR("a"), true);
- set1.set(STR("b"), 2.0);
- set1.set(STR("c"), STR("string"));
- set1.set(STR("d"), doc.select_nodes(STR("//*")));
-
- CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set1, STR("ring"));
-
- xpath_variable_set set2 = set1;
-
- CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
-
- xpath_variable_set set3;
-
- CHECK(!set3.get(STR("a")));
-
- set3 = set1;
-
- CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
-
- set3 = set3;
-
- CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
-
- set3 = xpath_variable_set();
-
- CHECK(!set3.get(STR("a")));
-}
-
-TEST_XML(xpath_variables_copy_out_of_memory, "<node1 /><node2 />")
-{
- xpath_variable_set set1;
- set1.set(STR("a"), true);
- set1.set(STR("b"), 2.0);
- set1.set(STR("c"), STR("string"));
- set1.set(STR("d"), doc.select_nodes(STR("//*")));
-
- xpath_variable_set set2 = set1;
-
- test_runner::_memory_fail_threshold = 32768 + 75 * sizeof(void*);
-
- CHECK_ALLOC_FAIL(xpath_variable_set set3 = set1);
-
- xpath_variable_set set4;
-
- CHECK_ALLOC_FAIL(set4 = set1);
- CHECK(!set4.get(STR("a")) && !set4.get(STR("b")) && !set4.get(STR("c")) && !set4.get(STR("d")));
-
- CHECK_ALLOC_FAIL(set2 = set1);
-
- CHECK(set2.get(STR("a")) && set2.get(STR("b")) && set2.get(STR("c")) && set2.get(STR("d")));
-
- CHECK(set2.get(STR("a"))->get_boolean() == true);
- CHECK(set2.get(STR("b"))->get_number() == 2.0);
- CHECK_STRING(set2.get(STR("c"))->get_string(), STR("string"));
- CHECK(set2.get(STR("d"))->get_node_set().size() == 2);
-}
-
-#if __cplusplus >= 201103
-TEST_XML(xpath_variables_move, "<node />")
-{
- xpath_variable_set set;
- set.set(STR("a"), true);
- set.set(STR("b"), 2.0);
- set.set(STR("c"), STR("string"));
- set.set(STR("d"), doc.select_nodes(STR("//*")));
-
- xpath_variable_set copy = set;
- copy.set(STR("e"), 42.0);
-
- test_runner::_memory_fail_threshold = 1;
-
- xpath_variable_set move1 = std::move(set);
-
- CHECK(!set.get(STR("a")) && !set.get(STR("b")) && !set.get(STR("c")) && !set.get(STR("d")));
- CHECK(move1.get(STR("a")) && move1.get(STR("b")) && move1.get(STR("c")) && move1.get(STR("d")));
-
- CHECK(move1.get(STR("a"))->get_boolean() == true);
- CHECK(move1.get(STR("b"))->get_number() == 2.0);
- CHECK_STRING(move1.get(STR("c"))->get_string(), STR("string"));
- CHECK(move1.get(STR("d"))->get_node_set().size() == 1);
-
- xpath_variable_set move2;
- move2 = std::move(move1);
-
- CHECK(!move1.get(STR("a")) && !move1.get(STR("b")) && !move1.get(STR("c")) && !move1.get(STR("d")));
- CHECK(move2.get(STR("a")) && move2.get(STR("b")) && move2.get(STR("c")) && move2.get(STR("d")));
-
- CHECK(copy.get(STR("e")));
-
- copy = std::move(move2);
-
- CHECK(!move2.get(STR("a")) && !move2.get(STR("b")) && !move2.get(STR("c")) && !move2.get(STR("d")));
- CHECK(copy.get(STR("a")) && copy.get(STR("b")) && copy.get(STR("c")) && copy.get(STR("d")));
- CHECK(!copy.get(STR("e")));
-
- CHECK(copy.get(STR("a"))->get_boolean() == true);
- CHECK(copy.get(STR("b"))->get_number() == 2.0);
- CHECK_STRING(copy.get(STR("c"))->get_string(), STR("string"));
- CHECK(copy.get(STR("d"))->get_node_set().size() == 1);
-}
-#endif
-
-TEST(xpath_variables_copy_big)
-{
- xpath_variable_set set;
-
- for (int i = 0; i < 100; ++i)
- {
- char_t name[4];
- name[0] = 'a';
- name[1] = char_t('0' + i / 10);
- name[2] = char_t('0' + i % 10);
- name[3] = 0;
-
- set.set(name, double(i));
- }
-
- xpath_variable_set copy = set;
-
- for (int j = 0; j < 100; ++j)
- {
- char_t name[4];
- name[0] = 'a';
- name[1] = char_t('0' + j / 10);
- name[2] = char_t('0' + j % 10);
- name[3] = 0;
-
- CHECK(copy.get(name) && copy.get(name)->get_number() == j);
- }
-}
-
-TEST(xpath_variables_copy_big_out_of_memory)
-{
- xpath_variable_set set;
-
- for (int i = 0; i < 100; ++i)
- {
- char_t name[4];
- name[0] = 'a';
- name[1] = char_t('0' + i / 10);
- name[2] = char_t('0' + i % 10);
- name[3] = 0;
-
- set.set(name, double(i));
- }
-
- test_runner::_memory_fail_threshold = 1;
-
- xpath_variable_set copy;
- CHECK_ALLOC_FAIL(copy = set);
-
- for (int j = 0; j < 100; ++j)
- {
- char_t name[4];
- name[0] = 'a';
- name[1] = char_t('0' + j / 10);
- name[2] = char_t('0' + j % 10);
- name[3] = 0;
-
- CHECK(!copy.get(name));
- }
-}
-#endif
+#ifndef PUGIXML_NO_XPATH
+
+#include "common.hpp"
+
+#include <string>
+
+TEST(xpath_variables_type_none)
+{
+ xpath_variable_set set;
+
+ xpath_variable* var = set.add(STR("target"), xpath_type_none);
+ CHECK(!var);
+}
+
+TEST(xpath_variables_type_boolean)
+{
+ xpath_variable_set set;
+
+ xpath_variable* var = set.add(STR("target"), xpath_type_boolean);
+ CHECK(var);
+
+ CHECK(var->type() == xpath_type_boolean);
+ CHECK_STRING(var->name(), STR("target"));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE_NAN(var->get_number());
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().empty());
+
+ CHECK(var->set(true));
+ CHECK(!var->set(1.0));
+ CHECK(!var->set(STR("abc")));
+ CHECK(!var->set(xpath_node_set()));
+
+ CHECK(var->get_boolean() == true);
+ CHECK_DOUBLE_NAN(var->get_number());
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().empty());
+}
+
+TEST(xpath_variables_type_number)
+{
+ xpath_variable_set set;
+
+ xpath_variable* var = set.add(STR("target"), xpath_type_number);
+ CHECK(var);
+
+ CHECK(var->type() == xpath_type_number);
+ CHECK_STRING(var->name(), STR("target"));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE(var->get_number(), 0);
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().empty());
+
+ CHECK(!var->set(true));
+ CHECK(var->set(1.0));
+ CHECK(!var->set(STR("abc")));
+ CHECK(!var->set(xpath_node_set()));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE(var->get_number(), 1);
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().empty());
+}
+
+TEST(xpath_variables_type_string)
+{
+ xpath_variable_set set;
+
+ xpath_variable* var = set.add(STR("target"), xpath_type_string);
+ CHECK(var);
+
+ CHECK(var->type() == xpath_type_string);
+ CHECK_STRING(var->name(), STR("target"));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE_NAN(var->get_number());
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().empty());
+
+ CHECK(!var->set(true));
+ CHECK(!var->set(1.0));
+ CHECK(var->set(STR("abc")));
+ CHECK(!var->set(xpath_node_set()));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE_NAN(var->get_number());
+ CHECK_STRING(var->get_string(), STR("abc"));
+ CHECK(var->get_node_set().empty());
+
+ CHECK(var->set(STR("abcdef")));
+ CHECK_STRING(var->get_string(), STR("abcdef"));
+}
+
+TEST_XML(xpath_variables_type_node_set, "<node/>")
+{
+ xpath_variable_set set;
+
+ xpath_variable* var = set.add(STR("target"), xpath_type_node_set);
+ CHECK(var);
+
+ CHECK(var->type() == xpath_type_node_set);
+ CHECK_STRING(var->name(), STR("target"));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE_NAN(var->get_number());
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().empty());
+
+ CHECK(!var->set(true));
+ CHECK(!var->set(1.0));
+ CHECK(!var->set(STR("abc")));
+ CHECK(var->set(doc.select_nodes(STR("*"))));
+
+ CHECK(var->get_boolean() == false);
+ CHECK_DOUBLE_NAN(var->get_number());
+ CHECK_STRING(var->get_string(), STR(""));
+ CHECK(var->get_node_set().size() == 1 && var->get_node_set()[0] == doc.first_child());
+}
+
+TEST(xpath_variables_set_operations)
+{
+ xpath_variable_set set;
+
+ xpath_variable* v1 = set.add(STR("var1"), xpath_type_number);
+ CHECK(v1);
+
+ xpath_variable* v2 = set.add(STR("var2"), xpath_type_string);
+ CHECK(v2);
+
+ CHECK(v1 != v2);
+
+ CHECK(set.add(STR("var1"), xpath_type_number) == v1);
+ CHECK(set.add(STR("var2"), xpath_type_string) == v2);
+ CHECK(set.add(STR("var2"), xpath_type_node_set) == 0);
+
+ CHECK(set.get(STR("var1")) == v1);
+ CHECK(set.get(STR("var2")) == v2);
+ CHECK(set.get(STR("var")) == 0);
+ CHECK(set.get(STR("var11")) == 0);
+
+ CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var1")) == v1);
+ CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var3")) == 0);
+}
+
+TEST_XML(xpath_variables_set_operations_set, "<node/>")
+{
+ xpath_variable_set set;
+
+ xpath_variable* v1 = set.add(STR("var1"), xpath_type_number);
+ CHECK(v1);
+
+ xpath_variable* v2 = set.add(STR("var2"), xpath_type_string);
+ CHECK(v2);
+
+ CHECK(set.set(STR("var1"), 1.0));
+ CHECK_DOUBLE(v1->get_number(), 1.0);
+
+ CHECK(set.set(STR("var2"), STR("value")));
+ CHECK_STRING(v2->get_string(), STR("value"));
+
+ CHECK(!set.set(STR("var1"), true));
+
+ CHECK(set.set(STR("var3"), doc.select_nodes(STR("*"))));
+
+ xpath_variable* v3 = set.get(STR("var3"));
+
+ CHECK(v3);
+ CHECK(v3->type() == xpath_type_node_set);
+ CHECK(v3->get_node_set().size() == 1);
+}
+
+TEST(xpath_variables_set_out_of_memory)
+{
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_variable_set set;
+
+ xpath_variable* var = 0;
+ CHECK_ALLOC_FAIL(var = set.add(STR("target"), xpath_type_number));
+ CHECK(!var);
+}
+
+TEST(xpath_variables_out_of_memory)
+{
+ test_runner::_memory_fail_threshold = 64;
+
+ xpath_variable_set set;
+
+ xpath_variable* var = set.add(STR("target"), xpath_type_string);
+ CHECK(var);
+
+ CHECK_ALLOC_FAIL(CHECK(!var->set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))));
+}
+
+TEST_XML(xpath_variables_evaluate, "<node/>")
+{
+ xpath_variable_set set;
+ set.set(STR("var1"), true);
+ set.set(STR("var2"), 0.5);
+ set.set(STR("var3"), STR("value"));
+ set.set(STR("var4"), doc.select_nodes(STR("*")));
+
+ CHECK_XPATH_BOOLEAN_VAR(doc, STR("$var1"), &set, true);
+ CHECK_XPATH_NUMBER_VAR(doc, STR("$var2"), &set, 0.5);
+ CHECK_XPATH_STRING_VAR(doc, STR("$var3"), &set, STR("value"));
+ CHECK_XPATH_NODESET_VAR(doc, STR("$var4"), &set) % 2;
+}
+
+TEST_XML(xpath_variables_evaluate_conversion, "<node>3</node>")
+{
+ xpath_variable_set set;
+ set.set(STR("var"), doc.select_nodes(STR("*")));
+
+ CHECK_XPATH_BOOLEAN_VAR(doc, STR("$var"), &set, true);
+ CHECK_XPATH_NUMBER_VAR(doc, STR("$var"), &set, 3);
+ CHECK_XPATH_STRING_VAR(doc, STR("$var"), &set, STR("3"));
+ CHECK_XPATH_NODESET_VAR(doc, STR("$var"), &set) % 2;
+}
+
+TEST(xpath_variables_evaluate_node_set_fail)
+{
+ xpath_variable_set set;
+ set.set(STR("var"), false);
+
+ xpath_query q(STR("$var"), &set);
+
+#ifdef PUGIXML_NO_EXCEPTIONS
+ CHECK(q.evaluate_node_set(xml_node()).empty());
+#else
+ try
+ {
+ q.evaluate_node_set(xml_node());
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (const xpath_exception&)
+ {
+ }
+#endif
+}
+
+TEST(xpath_variables_multiple_documents)
+{
+ xml_document doc;
+ doc.append_child().set_name(STR("node"));
+
+ xml_document doc1;
+ doc1.append_child().set_name(STR("node"));
+
+ xml_document doc2;
+ doc2.append_child().set_name(STR("node"));
+
+ xpath_variable_set set;
+ set.set(STR("var1"), doc1.select_nodes(STR("*")));
+ set.set(STR("var2"), doc2.select_nodes(STR("*")));
+
+ xpath_node_set ns = doc.select_nodes(STR("$var1 | $var2 | node"), &set);
+ ns.sort();
+
+ CHECK(ns.size() == 3);
+ CHECK(ns[0] != ns[1] && ns[0] != ns[2]);
+
+ xml_node n0 = doc.child(STR("node")), n1 = doc1.child(STR("node")), n2 = doc2.child(STR("node"));
+
+ CHECK(n0 == ns[0].node() || n0 == ns[1].node() || n0 == ns[2].node());
+ CHECK(n1 == ns[0].node() || n1 == ns[1].node() || n1 == ns[2].node());
+ CHECK(n2 == ns[0].node() || n2 == ns[1].node() || n2 == ns[2].node());
+}
+
+TEST(xpath_variables_long_name)
+{
+ xpath_variable_set set;
+ set.set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), true);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set, true);
+}
+
+TEST(xpath_variables_long_name_out_of_memory)
+{
+ xpath_variable_set set;
+ set.set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), true);
+
+ test_runner::_memory_fail_threshold = 4096 + 64 + 52 * sizeof(char_t);
+
+ CHECK_ALLOC_FAIL(CHECK(!xpath_query(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set)));
+}
+
+TEST_XML(xpath_variables_select, "<node attr='1'/><node attr='2'/>")
+{
+ xpath_variable_set set;
+ set.set(STR("one"), 1.0);
+
+ xpath_node_set ns = doc.select_nodes(STR("node[@attr=$one+1]"), &set);
+ CHECK(ns.size() == 1 && ns[0].node() == doc.last_child());
+
+ xpath_node n = doc.select_node(STR("node[@attr=$one+1]"), &set);
+ CHECK(n == ns[0]);
+}
+
+TEST(xpath_variables_empty_name)
+{
+ xpath_variable_set set;
+ CHECK(!set.add(STR(""), xpath_type_number));
+}
+
+TEST_XML(xpath_variables_inside_filter, "<node key='1' value='2'/><node key='2' value='1'/><node key='1' value='1'/>")
+{
+ xpath_variable_set set;
+ set.set(STR("one"), 1.0);
+
+ xpath_node_set ns = doc.select_nodes(STR("(node[@key = $one])[@value = $one]"), &set);
+ CHECK(ns.size() == 1 && ns[0].node() == doc.last_child());
+}
+
+TEST_XML(xpath_variables_step, "<node><child/><child/><child><child/></child></node>")
+{
+ xpath_variable_set set;
+ set.set(STR("root"), doc.select_nodes(STR("node")));
+
+ CHECK_XPATH_NODESET_VAR(xml_node(), STR("$root/child"), &set) % 3 % 4 % 5;
+ CHECK_XPATH_NODESET_VAR(xml_node(), STR("$root//child"), &set) % 3 % 4 % 5 % 6;
+}
+
+TEST_XML(xpath_variables_index, "<node><child/><child/><child><child/></child></node>")
+{
+ xpath_variable_set set;
+ set.set(STR("index"), 2.0);
+
+ CHECK_XPATH_NODESET_VAR(doc, STR("node/child[$index]"), &set) % 4;
+ CHECK_XPATH_NODESET_VAR(doc, STR("node/child[position()=$index]"), &set) % 4;
+}
+
+TEST(xpath_variables_qname)
+{
+ xpath_variable_set set;
+ set.set(STR("foo:bar"), true);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$foo:bar"), &set, true);
+}
+
+TEST(xpath_variables_name_error)
+{
+ xpath_variable_set set;
+ set.set(STR("foo:"), true);
+ set.set(STR(":bar"), true);
+ set.set(STR("foo:*"), true);
+ set.set(STR("foo"), true);
+ set.set(STR("3"), true);
+
+ CHECK_XPATH_FAIL_VAR(STR("$foo:"), &set);
+ CHECK_XPATH_FAIL_VAR(STR("$:bar"), &set);
+ CHECK_XPATH_FAIL_VAR(STR("$foo:*"), &set);
+ CHECK_XPATH_FAIL_VAR(STR("$foo:bar:baz"), &set);
+ CHECK_XPATH_FAIL_VAR(STR("$ foo"), &set);
+
+ CHECK_XPATH_FAIL_VAR(STR("$3"), &set);
+}
+
+TEST(xpath_variables_empty_string)
+{
+ xpath_variable_set set;
+ set.add(STR("empty"), xpath_type_string);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$empty = substring-before('a', 'z')"), &set, true);
+}
+
+TEST(xpath_variables_name_underscore)
+{
+ xpath_variable_set set;
+ set.set(STR("_foo_bar"), true);
+
+ CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$_foo_bar"), &set, true);
+}
+
+TEST(xpath_variables_name_case)
+{
+ xpath_variable_set set;
+ set.set(STR("i"), 5.0);
+ set.set(STR("I"), 2.0);
+
+ CHECK_XPATH_NUMBER_VAR(xml_node(), STR("$i div $I"), &set, 2.5);
+}
+
+TEST(xpath_variables_name_unicode)
+{
+#ifdef PUGIXML_WCHAR_MODE
+ #ifdef U_LITERALS
+ const char_t* name = L"\u0400\u203D";
+ #else
+ const char_t* name = L"\x0400\x203D";
+ #endif
+#else
+ const char_t* name = "\xd0\x80\xe2\x80\xbd";
+#endif
+
+ xpath_variable_set set;
+ set.set(name, STR("value"));
+
+ std::basic_string<char_t> var = STR("$");
+ var += name;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), var.c_str(), &set, STR("value"));
+}
+
+TEST_XML(xpath_variables_count_sum, "<node><c1>12</c1><c2>23</c2><c3>34</c3></node>")
+{
+ xpath_variable_set set;
+ set.set(STR("c12"), doc.select_nodes(STR("node/c1 | node/c2")));
+ set.set(STR("c3"), doc.select_nodes(STR("node/c3")));
+ set.set(STR("c"), doc.select_nodes(STR("node/*")));
+
+ CHECK_XPATH_NUMBER_VAR(xml_node(), STR("sum($c12) * count($c) - sum($c3)"), &set, 71);
+}
+
+TEST_XML(xpath_variables_copy, "<node />")
+{
+ xpath_variable_set set1;
+ set1.set(STR("a"), true);
+ set1.set(STR("b"), 2.0);
+ set1.set(STR("c"), STR("string"));
+ set1.set(STR("d"), doc.select_nodes(STR("//*")));
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set1, STR("ring"));
+
+ xpath_variable_set set2 = set1;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
+
+ xpath_variable_set set3;
+
+ CHECK(!set3.get(STR("a")));
+
+ set3 = set1;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
+
+ set3 = set3;
+
+ CHECK_XPATH_STRING_VAR(xml_node(), STR("substring($c, count($d[$a]) + $b)"), &set2, STR("ring"));
+
+ set3 = xpath_variable_set();
+
+ CHECK(!set3.get(STR("a")));
+}
+
+TEST_XML(xpath_variables_copy_out_of_memory, "<node1 /><node2 />")
+{
+ xpath_variable_set set1;
+ set1.set(STR("a"), true);
+ set1.set(STR("b"), 2.0);
+ set1.set(STR("c"), STR("string"));
+ set1.set(STR("d"), doc.select_nodes(STR("//*")));
+
+ xpath_variable_set set2 = set1;
+
+ test_runner::_memory_fail_threshold = 32768 + 75 * sizeof(void*);
+
+ CHECK_ALLOC_FAIL(xpath_variable_set set3 = set1);
+
+ xpath_variable_set set4;
+
+ CHECK_ALLOC_FAIL(set4 = set1);
+ CHECK(!set4.get(STR("a")) && !set4.get(STR("b")) && !set4.get(STR("c")) && !set4.get(STR("d")));
+
+ CHECK_ALLOC_FAIL(set2 = set1);
+
+ CHECK(set2.get(STR("a")) && set2.get(STR("b")) && set2.get(STR("c")) && set2.get(STR("d")));
+
+ CHECK(set2.get(STR("a"))->get_boolean() == true);
+ CHECK(set2.get(STR("b"))->get_number() == 2.0);
+ CHECK_STRING(set2.get(STR("c"))->get_string(), STR("string"));
+ CHECK(set2.get(STR("d"))->get_node_set().size() == 2);
+}
+
+#if __cplusplus >= 201103
+TEST_XML(xpath_variables_move, "<node />")
+{
+ xpath_variable_set set;
+ set.set(STR("a"), true);
+ set.set(STR("b"), 2.0);
+ set.set(STR("c"), STR("string"));
+ set.set(STR("d"), doc.select_nodes(STR("//*")));
+
+ xpath_variable_set copy = set;
+ copy.set(STR("e"), 42.0);
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_variable_set move1 = std::move(set);
+
+ CHECK(!set.get(STR("a")) && !set.get(STR("b")) && !set.get(STR("c")) && !set.get(STR("d")));
+ CHECK(move1.get(STR("a")) && move1.get(STR("b")) && move1.get(STR("c")) && move1.get(STR("d")));
+
+ CHECK(move1.get(STR("a"))->get_boolean() == true);
+ CHECK(move1.get(STR("b"))->get_number() == 2.0);
+ CHECK_STRING(move1.get(STR("c"))->get_string(), STR("string"));
+ CHECK(move1.get(STR("d"))->get_node_set().size() == 1);
+
+ xpath_variable_set move2;
+ move2 = std::move(move1);
+
+ CHECK(!move1.get(STR("a")) && !move1.get(STR("b")) && !move1.get(STR("c")) && !move1.get(STR("d")));
+ CHECK(move2.get(STR("a")) && move2.get(STR("b")) && move2.get(STR("c")) && move2.get(STR("d")));
+
+ CHECK(copy.get(STR("e")));
+
+ copy = std::move(move2);
+
+ CHECK(!move2.get(STR("a")) && !move2.get(STR("b")) && !move2.get(STR("c")) && !move2.get(STR("d")));
+ CHECK(copy.get(STR("a")) && copy.get(STR("b")) && copy.get(STR("c")) && copy.get(STR("d")));
+ CHECK(!copy.get(STR("e")));
+
+ CHECK(copy.get(STR("a"))->get_boolean() == true);
+ CHECK(copy.get(STR("b"))->get_number() == 2.0);
+ CHECK_STRING(copy.get(STR("c"))->get_string(), STR("string"));
+ CHECK(copy.get(STR("d"))->get_node_set().size() == 1);
+}
+#endif
+
+TEST(xpath_variables_copy_big)
+{
+ xpath_variable_set set;
+
+ for (int i = 0; i < 100; ++i)
+ {
+ char_t name[4];
+ name[0] = 'a';
+ name[1] = char_t('0' + i / 10);
+ name[2] = char_t('0' + i % 10);
+ name[3] = 0;
+
+ set.set(name, double(i));
+ }
+
+ xpath_variable_set copy = set;
+
+ for (int j = 0; j < 100; ++j)
+ {
+ char_t name[4];
+ name[0] = 'a';
+ name[1] = char_t('0' + j / 10);
+ name[2] = char_t('0' + j % 10);
+ name[3] = 0;
+
+ CHECK(copy.get(name) && copy.get(name)->get_number() == j);
+ }
+}
+
+TEST(xpath_variables_copy_big_out_of_memory)
+{
+ xpath_variable_set set;
+
+ for (int i = 0; i < 100; ++i)
+ {
+ char_t name[4];
+ name[0] = 'a';
+ name[1] = char_t('0' + i / 10);
+ name[2] = char_t('0' + i % 10);
+ name[3] = 0;
+
+ set.set(name, double(i));
+ }
+
+ test_runner::_memory_fail_threshold = 1;
+
+ xpath_variable_set copy;
+ CHECK_ALLOC_FAIL(copy = set);
+
+ for (int j = 0; j < 100; ++j)
+ {
+ char_t name[4];
+ name[0] = 'a';
+ name[1] = char_t('0' + j / 10);
+ name[2] = char_t('0' + j % 10);
+ name[3] = 0;
+
+ CHECK(!copy.get(name));
+ }
+}
+#endif