diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-10-05 04:20:52 +0000 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2014-10-05 04:20:52 +0000 |
commit | b17501c3fb01530aae790228850ac6122227d8a8 (patch) | |
tree | 0dec0d7d15e82eb6d109966e9ba0a9eacb2743cb | |
parent | a3b23751aeb6c9e84829010e20b44545ef4da9ff (diff) |
tests: Add XPath sorting tests and a simple test for numeric predicates
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1051 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r-- | tests/test_xpath.cpp | 78 | ||||
-rw-r--r-- | tests/test_xpath_paths.cpp | 8 |
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 4296d48..f7da258 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -506,4 +506,82 @@ TEST_XML(xpath_sort_append_buffer, "<node /><node />") xpath_node_set_tester(sorted, "sorted order failed") % 2 % 3 % 4 % 5 % 6 % 7 % 8 % 9; xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 9 % 8 % 7 % 6 % 5 % 4 % 3 % 2; } + +TEST(xpath_sort_crossdoc) +{ + xml_document doc1; + CHECK(doc1.load(STR("<node />"))); + + xml_document doc2; + CHECK(doc2.load(STR("<node />"))); + + xpath_node_set ns1 = doc1.select_nodes(STR("*")); + CHECK(ns1.size() == 1); + + xpath_node_set ns2 = doc2.select_nodes(STR("*")); + CHECK(ns2.size() == 1); + + xpath_variable_set set; + set.set(STR("ns1"), ns1); + set.set(STR("ns2"), ns2); + + xpath_node_set ns = xpath_query(STR("$ns1 | $ns2"), &set).evaluate_node_set(xpath_node()); + + ns.sort(); + + CHECK(ns.size() == 2); + CHECK((ns[0] == ns1[0] && ns[1] == ns2[0]) || (ns[0] == ns2[0] && ns[1] == ns1[0])); +} + +TEST(xpath_sort_crossdoc_dynamic) +{ + xml_document doc1; + doc1.append_child(STR("node")); + + xml_document doc2; + doc2.append_child(STR("node")); + + xpath_node_set ns1 = doc1.select_nodes(STR("*")); + CHECK(ns1.size() == 1); + + xpath_node_set ns2 = doc2.select_nodes(STR("*")); + CHECK(ns2.size() == 1); + + xpath_variable_set set; + set.set(STR("ns1"), ns1); + set.set(STR("ns2"), ns2); + + xpath_node_set ns = xpath_query(STR("$ns1 | $ns2"), &set).evaluate_node_set(xpath_node()); + + ns.sort(); + + CHECK(ns.size() == 2); + CHECK((ns[0] == ns1[0] && ns[1] == ns2[0]) || (ns[0] == ns2[0] && ns[1] == ns1[0])); +} + +TEST(xpath_sort_crossdoc_different_depth) +{ + xml_document doc1; + doc1.append_child(STR("node")); + + xml_document doc2; + doc2.append_child(STR("node")).append_child(STR("node")); + + xpath_node_set ns1 = doc1.select_nodes(STR("*")); + CHECK(ns1.size() == 1); + + xpath_node_set ns2 = doc2.select_nodes(STR("*/*")); + CHECK(ns2.size() == 1); + + xpath_variable_set set; + set.set(STR("ns1"), ns1); + set.set(STR("ns2"), ns2); + + xpath_node_set ns = xpath_query(STR("$ns1 | $ns2"), &set).evaluate_node_set(xpath_node()); + + ns.sort(); + + CHECK(ns.size() == 2); + CHECK((ns[0] == ns1[0] && ns[1] == ns2[0]) || (ns[0] == ns2[0] && ns[1] == ns1[0])); +} #endif diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp index 40bd68c..45579a9 100644 --- a/tests/test_xpath_paths.cpp +++ b/tests/test_xpath_paths.cpp @@ -531,4 +531,12 @@ TEST_XML(xpath_paths_descendant_optimize, "<node><para><para/><para/><para><para CHECK_XPATH_NODESET(doc, STR("/descendant-or-self::node()[3]/child::para")) % 4 % 5 % 6; } +TEST_XML(xpath_paths_precision, "<node><para/><para/><para/><para/><para/></node>") +{ + CHECK_XPATH_NODESET(doc, STR("//para[1]")) % 3; + CHECK_XPATH_NODESET(doc, STR("//para[3 div 3]")) % 3; + CHECK_XPATH_NODESET(doc, STR("//para[6 div 3 - 1]")) % 3; + CHECK_XPATH_NODESET(doc, STR("//para[6 * (1 div 3) - 1]")) % 3; +} + #endif |