summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-07-22 08:04:02 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-07-22 08:04:02 +0000
commitf889bf88c09ecfe7f68deab6db53fa979110824c (patch)
tree1c440427db4ed69bcf41e4ccdd2ae52916dc4cbf
parent546a0f756104fc9ae89207750c6a9eb566f5ea63 (diff)
tests: Removed invalid document order test, improved document order coverage by adding tests that are not subject to document order optimization
git-svn-id: http://pugixml.googlecode.com/svn/trunk@615 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--tests/test_deprecated.cpp9
-rw-r--r--tests/test_xpath.cpp43
2 files changed, 43 insertions, 9 deletions
diff --git a/tests/test_deprecated.cpp b/tests/test_deprecated.cpp
index 4d97b2a..f28dd55 100644
--- a/tests/test_deprecated.cpp
+++ b/tests/test_deprecated.cpp
@@ -192,12 +192,3 @@ TEST_XML(dom_node_wildcard_star, "<node cd='1'/>")
CHECK(node.attribute_w(STR("*?*c*")).as_int() == 0);
CHECK(node.attribute_w(STR("*?*d*")).as_int() == 1);
}
-
-// document order
-TEST_XML(document_order_coverage, "<node id='1'/>")
-{
- doc.precompute_document_order();
-
- CHECK(doc.child(STR("node")).document_order() == 0);
- CHECK(doc.child(STR("node")).attribute(STR("id")).document_order() == 0);
-}
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 608859f..c615f36 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -8,6 +8,14 @@
#include <string>
+static void load_document_copy(xml_document& doc, const char_t* text)
+{
+ xml_document source;
+ CHECK(source.load(text));
+
+ doc.append_copy(source.first_child());
+}
+
TEST(xpath_allocator_many_pages)
{
pugi::string_t query = STR("0");
@@ -41,6 +49,24 @@ TEST_XML(xpath_sort_complex, "<node><child1 attr1='value1' attr2='value2'/><chil
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 8 % 7 % 6 % 5 % 4 % 3 % 2;
}
+TEST(xpath_sort_complex_copy) // copy the document so that document order optimization does not work
+{
+ xml_document doc;
+ load_document_copy(doc, "<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(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;
+}
+
TEST_XML(xpath_sort_children, "<node><child><subchild id='1'/></child><child><subchild id='2'/></child></node>")
{
xpath_node_set ns = doc.child(STR("node")).select_nodes(STR("child/subchild[@id=1] | child/subchild[@id=2]"));
@@ -55,6 +81,23 @@ TEST_XML(xpath_sort_children, "<node><child><subchild id='1'/></child><child><su
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 7 % 4;
}
+TEST(xpath_sort_children_copy) // copy the document so that document order optimization does not work
+{
+ xml_document doc;
+ load_document_copy(doc, "<node><child><subchild id='1'/></child><child><subchild id='2'/></child></node>");
+
+ xpath_node_set ns = doc.child(STR("node")).select_nodes(STR("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;
+
+ 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(STR("node"));