From b17501c3fb01530aae790228850ac6122227d8a8 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 5 Oct 2014 04:20:52 +0000 Subject: 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 --- tests/test_xpath.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test_xpath_paths.cpp | 8 +++++ 2 files changed, 86 insertions(+) (limited to 'tests') 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, "") 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(""))); + + xml_document doc2; + CHECK(doc2.load(STR(""))); + + 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, "") +{ + 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 -- cgit v1.2.3