summaryrefslogtreecommitdiff
path: root/tests/test_xpath.cpp
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-01 07:02:59 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-01 07:02:59 +0000
commit3ae516abe2d51415c9527f4f96e97b85413aa479 (patch)
tree59c6391345af77d22214a9c2a42e6f9d12a9e6f4 /tests/test_xpath.cpp
parentfebe4f0209f86225ebeedfb0874feb3cb96e7c89 (diff)
tests: Add tests for copyless copy and related potential bugs
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1033 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_xpath.cpp')
-rw-r--r--tests/test_xpath.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index f3af88a..1a9a159 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -434,4 +434,30 @@ TEST(xpath_memory_concat_massive)
CHECK(size == 5001);
}
+TEST_XML(xpath_sort_copy_share, "<node><child1 attr1='value1' attr2='value2'/><child2 attr1='value1'>test</child2></node>")
+{
+ // copy sharing shares the name/value data for nodes that can potentially make document order optimization invalid (silently)
+ xml_node node = doc.child(STR("node"));
+ xml_node child1 = node.child(STR("child1"));
+ xml_node child2 = node.child(STR("child2"));
+
+ // swap child1 & child2
+ node.prepend_copy(child2);
+ node.append_copy(child1);
+
+ node.remove_child(child1);
+ node.remove_child(child2);
+
+ // just some random union order, it should not matter probably?
+ xpath_node_set ns = doc.child(STR("node")).select_nodes(STR("child1 | child2 | child1/@* | . | child2/@* | child2/text()"));
+
+ ns.sort(false);
+ xpath_node_set sorted = ns;
+
+ ns.sort(true);
+ xpath_node_set reverse_sorted = ns;
+
+ 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;
+}
#endif