From 903db8682a5f14b52adec996584c70ea072619ea Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 23 Oct 2014 07:41:07 +0000 Subject: tests: Add more tests for better coverage More tests for out-of-memory and other edge conditions git-svn-id: https://pugixml.googlecode.com/svn/trunk@1075 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/test_xpath.cpp') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 2143376..80115b8 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -606,4 +606,27 @@ TEST(xpath_sort_crossdoc_different_depth) CHECK(ns.size() == 2); CHECK((ns[0] == ns1[0] && ns[1] == ns2[0]) || (ns[0] == ns2[0] && ns[1] == ns1[0])); } + +TEST(xpath_allocate_string_out_of_memory) +{ + std::basic_string query; + + for (int i = 0; i < 1024; ++i) query += STR("abcdefgh"); + + test_runner::_memory_fail_threshold = 8*1024; + +#ifdef PUGIXML_NO_EXCEPTIONS + CHECK(!xpath_query(query.c_str())); +#else + try + { + xpath_query q(query.c_str()); + + CHECK_FORCE_FAIL("Expected out of memory exception"); + } + catch (const std::bad_alloc&) + { + } +#endif +} #endif -- cgit v1.2.3 From 546997683a9edc1b77b60ac96776668d3f57adad Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 24 Oct 2014 01:17:57 +0000 Subject: 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 --- tests/test_xpath.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'tests/test_xpath.cpp') 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, "") 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, "") xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 5 % 4 % 3; } +TEST_XML(xpath_sort_attributes_docorder, "") +{ + 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 -- cgit v1.2.3