summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-24 01:17:57 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-24 01:17:57 +0000
commit546997683a9edc1b77b60ac96776668d3f57adad (patch)
treefb2a3ee75cd05718e488d0a5ceda3bd4353bfa1e /tests
parent903db8682a5f14b52adec996584c70ea072619ea (diff)
tests: Add even more coverage tests
Also fix MSVC6 compilation (make convertions to function pointers explicit). git-svn-id: https://pugixml.googlecode.com/svn/trunk@1076 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dom_traverse.cpp10
-rw-r--r--tests/test_xpath.cpp43
-rw-r--r--tests/test_xpath_variables.cpp23
3 files changed, 70 insertions, 6 deletions
diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp
index e42846f..83afec8 100644
--- a/tests/test_dom_traverse.cpp
+++ b/tests/test_dom_traverse.cpp
@@ -1048,14 +1048,14 @@ TEST_XML(dom_unspecified_bool_coverage, "<node attr='value'>text</node>")
{
xml_node node = doc.first_child();
- node(0);
- node.first_attribute()(0);
- node.text()(0);
+ static_cast<void (*)(xml_node***)>(node)(0);
+ static_cast<void (*)(xml_attribute***)>(node.first_attribute())(0);
+ static_cast<void (*)(xml_text***)>(node.text())(0);
#ifndef PUGIXML_NO_XPATH
xpath_query q(STR("/node"));
- q(0);
- q.evaluate_node(doc)(0);
+ static_cast<void (*)(xpath_query***)>(q)(0);
+ static_cast<void (*)(xpath_node***)>(q.evaluate_node(doc))(0);
#endif
}
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index 80115b8..a65ee37 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -110,7 +110,7 @@ TEST_XML(xpath_sort_attributes, "<node/>")
n.append_attribute(STR("attr3"));
n.insert_attribute_before(STR("attr1"), n.attribute(STR("attr2")));
- xpath_node_set ns = n.select_nodes(STR("@*"));
+ xpath_node_set ns = n.select_nodes(STR("@* | @*"));
ns.sort(true);
xpath_node_set reverse_sorted = ns;
@@ -122,6 +122,25 @@ TEST_XML(xpath_sort_attributes, "<node/>")
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 5 % 4 % 3;
}
+TEST_XML(xpath_sort_attributes_docorder, "<node attr1='' attr2='value' attr4='value' />")
+{
+ xml_node n = doc.child(STR("node"));
+
+ n.first_attribute().set_name(STR("attribute1"));
+ n.insert_attribute_after(STR("attr3"), n.attribute(STR("attr2")));
+
+ xpath_node_set ns = n.select_nodes(STR("@* | @*"));
+
+ ns.sort(true);
+ xpath_node_set reverse_sorted = ns;
+
+ ns.sort(false);
+ xpath_node_set sorted = ns;
+
+ xpath_node_set_tester(sorted, "sorted order failed") % 3 % 4 % 5 % 6;
+ xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 6 % 5 % 4 % 3;
+}
+
TEST(xpath_sort_random_medium)
{
xml_document doc;
@@ -629,4 +648,26 @@ TEST(xpath_allocate_string_out_of_memory)
}
#endif
}
+
+TEST(xpath_remove_duplicates)
+{
+ xml_document doc;
+
+ for (int i = 0; i < 20; ++i)
+ {
+ doc.append_child(STR("node2"));
+ doc.prepend_child(STR("node1"));
+ }
+
+ xpath_node_set ns = doc.select_nodes(STR("/node2/preceding::* | //node1 | /node() | /* | /node1/following-sibling::*"));
+
+ ns.sort();
+
+ {
+ xpath_node_set_tester tester(ns, "sorted order failed");
+
+ for (int i = 0; i < 40; ++i)
+ tester % (2 + i);
+ }
+}
#endif
diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp
index 39a4f05..728eaa9 100644
--- a/tests/test_xpath_variables.cpp
+++ b/tests/test_xpath_variables.cpp
@@ -276,6 +276,29 @@ TEST(xpath_variables_long_name)
CHECK_XPATH_BOOLEAN_VAR(xml_node(), STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set, true);
}
+TEST(xpath_variables_long_name_out_of_memory)
+{
+ xpath_variable_set set;
+ set.set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), true);
+
+ test_runner::_memory_fail_threshold = 4096 + 128;
+
+#ifdef PUGIXML_NO_EXCEPTIONS
+ xpath_query q(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set);
+ CHECK(!q);
+#else
+ try
+ {
+ xpath_query q(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set);
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (const xpath_exception&)
+ {
+ }
+#endif
+}
+
TEST_XML(xpath_variables_select, "<node attr='1'/><node attr='2'/>")
{
xpath_variable_set set;