diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-11-08 15:17:46 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2009-11-08 15:17:46 +0000 |
commit | 0cac815b6398d60171e992a4333ab16ad542aebc (patch) | |
tree | 303c706d29e7422b10df16ea6b97dc796b9cc022 /tests/test_xpath.cpp | |
parent | c5d97527366f9c39e84e3a4089ff74311b14c489 (diff) |
tests: More coverage tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@225 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_xpath.cpp')
-rw-r--r-- | tests/test_xpath.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index abcefd9..5f23f44 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -38,4 +38,61 @@ TEST(xpath_allocator_large_page) CHECK_XPATH_NUMBER(xml_node(), ("string-length('" + query + "')").c_str(), 8192);
}
+TEST_XML(xpath_sort_complex, "<node><child1 attr1='value1' attr2='value2'/><child2 attr1='value1'>test</child2></node>")
+{
+ // just some random union order, it should not matter probably?
+ xpath_node_set ns = doc.child("node").select_nodes("child1 | child2 | child1/@* | . | child2/@* | child2/text()");
+
+ ns.sort(false);
+ xpath_node_set sorted = ns;
+
+ ns.sort(true);
+ xpath_node_set reverse_sorted = ns;
+
+ doc.precompute_document_order();
+
+ xpath_node_set_tester(sorted, "sorted order failed") % 2 % 3 % 4 % 5 % 6 % 7 % 8;
+ xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 8 % 7 % 6 % 5 % 4 % 3 % 2;
+}
+
+TEST_XML(xpath_sort_children, "<node><child><subchild id='1'/></child><child><subchild id='2'/></child></node>")
+{
+ xpath_node_set ns = doc.child("node").select_nodes("child/subchild[@id=1] | child/subchild[@id=2]");
+
+ ns.sort(false);
+ xpath_node_set sorted = ns;
+
+ ns.sort(true);
+ xpath_node_set reverse_sorted = ns;
+
+ doc.precompute_document_order();
+
+ xpath_node_set_tester(sorted, "sorted order failed") % 4 % 7;
+ xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 7 % 4;
+}
+
+TEST_XML(xpath_sort_attributes, "<node/>")
+{
+ xml_node n = doc.child("node");
+
+ // we need to insert attributes manually since unsorted node sets are (always?) sorted via pointers because of remove_duplicates,
+ // so we need to have different document and pointer order to cover all comparator cases
+ n.append_attribute("attr2");
+ n.append_attribute("attr3");
+ n.insert_attribute_before("attr1", n.attribute("attr2"));
+
+ xpath_node_set ns = n.select_nodes("@*");
+
+ ns.sort(true);
+ xpath_node_set reverse_sorted = ns;
+
+ ns.sort(false);
+ xpath_node_set sorted = ns;
+
+ doc.precompute_document_order();
+
+ xpath_node_set_tester(sorted, "sorted order failed") % 3 % 4 % 5;
+ xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 5 % 4 % 3;
+}
+
#endif
|