summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp9
-rw-r--r--tests/test.hpp6
-rw-r--r--tests/test_document.cpp14
-rw-r--r--tests/test_dom_modify.cpp67
-rw-r--r--tests/test_parse.cpp10
-rw-r--r--tests/test_xpath.cpp72
-rw-r--r--tests/test_xpath_api.cpp32
-rw-r--r--tests/test_xpath_parse.cpp25
-rw-r--r--tests/test_xpath_variables.cpp20
9 files changed, 76 insertions, 179 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index c4c9341..6996eb9 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -27,11 +27,13 @@ const char* test_runner::_temp_path;
static size_t g_memory_total_size = 0;
static size_t g_memory_total_count = 0;
+static size_t g_memory_fail_triggered = false;
static void* custom_allocate(size_t size)
{
if (test_runner::_memory_fail_threshold > 0 && test_runner::_memory_fail_threshold < g_memory_total_size + size)
{
+ g_memory_fail_triggered = true;
test_runner::_memory_fail_triggered = true;
return 0;
@@ -88,6 +90,7 @@ static bool run_test(test_runner* test)
#endif
g_memory_total_size = 0;
g_memory_total_count = 0;
+ g_memory_fail_triggered = false;
test_runner::_memory_fail_threshold = 0;
test_runner::_memory_fail_triggered = false;
@@ -113,6 +116,12 @@ static bool run_test(test_runner* test)
test->run();
+ if (test_runner::_memory_fail_triggered)
+ {
+ printf("Test %s failed: unguarded memory fail triggered\n", test->_name);
+ return false;
+ }
+
if (g_memory_total_size != 0 || g_memory_total_count != 0)
{
printf("Test %s failed: memory leaks found (%u bytes in %u allocations)\n", test->_name, static_cast<unsigned int>(g_memory_total_size), static_cast<unsigned int>(g_memory_total_count));
diff --git a/tests/test.hpp b/tests/test.hpp
index 4222638..46c3330 100644
--- a/tests/test.hpp
+++ b/tests/test.hpp
@@ -142,6 +142,12 @@ struct dummy_fixture {};
#define CHECK_XPATH_FAIL(query) CHECK_XPATH_FAIL_VAR(query, 0)
#endif
+#ifdef PUGIXML_NO_EXCEPTIONS
+#define CHECK_ALLOC_FAIL(code) CHECK(!test_runner::_memory_fail_triggered); code; CHECK(test_runner::_memory_fail_triggered); test_runner::_memory_fail_triggered = false
+#else
+#define CHECK_ALLOC_FAIL(code) CHECK(!test_runner::_memory_fail_triggered); try { code; } catch (std::bad_alloc&) {} CHECK(test_runner::_memory_fail_triggered); test_runner::_memory_fail_triggered = false
+#endif
+
#define STR(text) PUGIXML_TEXT(text)
#ifdef __DMC__
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index 09d89d7..2c52030 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -110,7 +110,7 @@ TEST(document_load_stream_error)
std::istringstream iss("<node/>");
test_runner::_memory_fail_threshold = 1;
- CHECK(doc.load(iss).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load(iss).status == status_out_of_memory));
}
TEST(document_load_stream_empty)
@@ -237,7 +237,7 @@ TEST(document_load_stream_nonseekable_out_of_memory)
test_runner::_memory_fail_threshold = 1;
pugi::xml_document doc;
- CHECK(doc.load(in).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory));
}
TEST(document_load_stream_nonseekable_out_of_memory_large)
@@ -253,7 +253,7 @@ TEST(document_load_stream_nonseekable_out_of_memory_large)
test_runner::_memory_fail_threshold = 10000 * 8 * 3 / 2;
pugi::xml_document doc;
- CHECK(doc.load(in).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory));
}
#endif
@@ -302,7 +302,7 @@ TEST(document_load_file_error)
CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found);
test_runner::_memory_fail_threshold = 1;
- CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory));
}
TEST(document_load_file_error_previous)
@@ -339,7 +339,9 @@ TEST(document_load_file_wide_out_of_memory)
pugi::xml_document doc;
- pugi::xml_parse_result result = doc.load_file(L"tests/data/small.xml");
+ pugi::xml_parse_result result;
+ result.status = status_out_of_memory;
+ CHECK_ALLOC_FAIL(result = doc.load_file(L"tests/data/small.xml"));
CHECK(result.status == status_out_of_memory || result.status == status_file_not_found);
}
@@ -1320,7 +1322,7 @@ TEST(document_convert_out_of_memory)
for (unsigned int src = 0; src < sizeof(files) / sizeof(files[0]); ++src)
{
xml_document doc;
- CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default, files[src].encoding).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load_buffer(files[src].data, files[src].size, parse_default, files[src].encoding).status == status_out_of_memory));
}
// cleanup
diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp
index af833a6..ae18171 100644
--- a/tests/test_dom_modify.cpp
+++ b/tests/test_dom_modify.cpp
@@ -858,10 +858,10 @@ TEST(dom_string_out_of_memory)
// no value => long value
test_runner::_memory_fail_threshold = 32;
- CHECK(!node.set_name(string));
- CHECK(!text.set_value(string));
- CHECK(!attr.set_name(string));
- CHECK(!attr.set_value(string));
+ CHECK_ALLOC_FAIL(CHECK(!node.set_name(string)));
+ CHECK_ALLOC_FAIL(CHECK(!text.set_value(string)));
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_name(string)));
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_value(string)));
// set some names/values
test_runner::_memory_fail_threshold = 0;
@@ -873,10 +873,10 @@ TEST(dom_string_out_of_memory)
// some value => long value
test_runner::_memory_fail_threshold = 32;
- CHECK(!node.set_name(string));
- CHECK(!text.set_value(string));
- CHECK(!attr.set_name(string));
- CHECK(!attr.set_value(string));
+ CHECK_ALLOC_FAIL(CHECK(!node.set_name(string)));
+ CHECK_ALLOC_FAIL(CHECK(!text.set_value(string)));
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_name(string)));
+ CHECK_ALLOC_FAIL(CHECK(!attr.set_value(string)));
// check that original state was preserved
test_runner::_memory_fail_threshold = 0;
@@ -897,30 +897,27 @@ TEST(dom_node_out_of_memory)
xml_attribute a = n.append_attribute(STR("a"));
CHECK(a);
- while (n.append_child(node_comment) || n.append_attribute(STR("b")))
- {
- // nop
- }
+ CHECK_ALLOC_FAIL(while (n.append_child(node_comment) || n.append_attribute(STR("b"))) { /* nop */ });
// verify all node modification operations
- CHECK(!n.append_child());
- CHECK(!n.prepend_child());
- CHECK(!n.insert_child_after(node_element, n.first_child()));
- CHECK(!n.insert_child_before(node_element, n.first_child()));
- CHECK(!n.append_attribute(STR("")));
- CHECK(!n.prepend_attribute(STR("")));
- CHECK(!n.insert_attribute_after(STR(""), a));
- CHECK(!n.insert_attribute_before(STR(""), a));
+ CHECK_ALLOC_FAIL(CHECK(!n.append_child()));
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_child()));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_child_after(node_element, n.first_child())));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_child_before(node_element, n.first_child())));
+ CHECK_ALLOC_FAIL(CHECK(!n.append_attribute(STR(""))));
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_attribute(STR(""))));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_attribute_after(STR(""), a)));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_attribute_before(STR(""), a)));
// verify node copy operations
- CHECK(!n.append_copy(n.first_child()));
- CHECK(!n.prepend_copy(n.first_child()));
- CHECK(!n.insert_copy_after(n.first_child(), n.first_child()));
- CHECK(!n.insert_copy_before(n.first_child(), n.first_child()));
- CHECK(!n.append_copy(a));
- CHECK(!n.prepend_copy(a));
- CHECK(!n.insert_copy_after(a, a));
- CHECK(!n.insert_copy_before(a, a));
+ CHECK_ALLOC_FAIL(CHECK(!n.append_copy(n.first_child())));
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_copy(n.first_child())));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_after(n.first_child(), n.first_child())));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_before(n.first_child(), n.first_child())));
+ CHECK_ALLOC_FAIL(CHECK(!n.append_copy(a)));
+ CHECK_ALLOC_FAIL(CHECK(!n.prepend_copy(a)));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_after(a, a)));
+ CHECK_ALLOC_FAIL(CHECK(!n.insert_copy_before(a, a)));
}
TEST(dom_node_memory_limit)
@@ -1085,7 +1082,7 @@ TEST(dom_node_append_buffer_out_of_memory_extra)
test_runner::_memory_fail_threshold = 1;
xml_document doc;
- CHECK(doc.append_buffer("<n/>", 4).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.append_buffer("<n/>", 4).status == status_out_of_memory));
CHECK(!doc.first_child());
}
@@ -1096,7 +1093,7 @@ TEST(dom_node_append_buffer_out_of_memory_buffer)
char data[128] = {0};
xml_document doc;
- CHECK(doc.append_buffer(data, sizeof(data)).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.append_buffer(data, sizeof(data)).status == status_out_of_memory));
CHECK(!doc.first_child());
}
@@ -1111,7 +1108,7 @@ TEST(dom_node_append_buffer_out_of_memory_nodes)
test_runner::_memory_fail_threshold = 32768 + 128 + data.length() * sizeof(char_t) + 32;
xml_document doc;
- CHECK(doc.append_buffer(data.c_str(), data.length() * sizeof(char_t), parse_fragment).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.append_buffer(data.c_str(), data.length() * sizeof(char_t), parse_fragment).status == status_out_of_memory));
unsigned int valid = 0;
@@ -1132,7 +1129,7 @@ TEST(dom_node_append_buffer_out_of_memory_name)
xml_document doc;
CHECK(doc.append_child(STR("root")));
- CHECK(doc.first_child().append_buffer(data, sizeof(data)).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.first_child().append_buffer(data, sizeof(data)).status == status_out_of_memory));
CHECK_STRING(doc.first_child().name(), STR("root"));
}
@@ -1441,8 +1438,7 @@ TEST_XML(dom_node_copy_out_of_memory_node, "<node><child1 /><child2 /><child3>te
test_runner::_memory_fail_threshold = 32768 * 2 + 4096;
xml_document copy;
- for (int i = 0; i < 1000; ++i)
- copy.append_copy(doc.first_child());
+ CHECK_ALLOC_FAIL(for (int i = 0; i < 1000; ++i) copy.append_copy(doc.first_child()));
}
TEST_XML(dom_node_copy_out_of_memory_attr, "<node attr1='' attr2='' attr3='' attr4='' attr5='' attr6='' attr7='' attr8='' attr9='' attr10='' attr11='' attr12='' attr13='' attr14='' attr15='' />")
@@ -1450,8 +1446,7 @@ TEST_XML(dom_node_copy_out_of_memory_attr, "<node attr1='' attr2='' attr3='' att
test_runner::_memory_fail_threshold = 32768 * 2 + 4096;
xml_document copy;
- for (int i = 0; i < 1000; ++i)
- copy.append_copy(doc.first_child());
+ CHECK_ALLOC_FAIL(for (int i = 0; i < 1000; ++i) copy.append_copy(doc.first_child()));
}
TEST_XML(dom_node_remove_deallocate, "<node attr='value'>text</node>")
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index 3ae96d1..08ddee4 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -873,7 +873,7 @@ TEST(parse_out_of_memory)
test_runner::_memory_fail_threshold = 256;
xml_document doc;
- CHECK(doc.load_string(STR("<foo a='1'/>")).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load_string(STR("<foo a='1'/>")).status == status_out_of_memory));
CHECK(!doc.first_child());
}
@@ -893,7 +893,7 @@ TEST(parse_out_of_memory_halfway_node)
test_runner::_memory_fail_threshold = 65536;
xml_document doc;
- CHECK(doc.load_buffer_inplace(text, count * 4).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load_buffer_inplace(text, count * 4).status == status_out_of_memory));
CHECK_NODE(doc.first_child(), STR("<n />"));
}
@@ -920,7 +920,7 @@ TEST(parse_out_of_memory_halfway_attr)
test_runner::_memory_fail_threshold = 65536;
xml_document doc;
- CHECK(doc.load_buffer_inplace(text, count * 5 + 4).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load_buffer_inplace(text, count * 5 + 4).status == status_out_of_memory));
CHECK_STRING(doc.first_child().name(), STR("n"));
CHECK_STRING(doc.first_child().first_attribute().name(), STR("a"));
CHECK_STRING(doc.first_child().last_attribute().name(), STR("a"));
@@ -931,7 +931,7 @@ TEST(parse_out_of_memory_conversion)
test_runner::_memory_fail_threshold = 256;
xml_document doc;
- CHECK(doc.load_buffer("<foo\x90/>", 7, parse_default, encoding_latin1).status == status_out_of_memory);
+ CHECK_ALLOC_FAIL(CHECK(doc.load_buffer("<foo\x90/>", 7, parse_default, encoding_latin1).status == status_out_of_memory));
CHECK(!doc.first_child());
}
@@ -950,7 +950,7 @@ TEST(parse_error_offset)
CHECK_OFFSET("<node/>", parse_default, status_ok, 0);
test_runner::_memory_fail_threshold = 1;
- CHECK_OFFSET("<node/>", parse_default, status_out_of_memory, 0);
+ CHECK_ALLOC_FAIL(CHECK_OFFSET("<node/>", parse_default, status_out_of_memory, 0));
test_runner::_memory_fail_threshold = 0;
CHECK_OFFSET("<3d/>", parse_default, status_unrecognized_tag, 1);
diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp
index f5b4c66..57fa95b 100644
--- a/tests/test_xpath.cpp
+++ b/tests/test_xpath.cpp
@@ -378,19 +378,7 @@ TEST(xpath_out_of_memory_evaluate_concat)
pugi::xpath_query q(query.c_str());
-#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK(q.evaluate_string(0, 0, xml_node()) == 1);
-#else
- try
- {
- q.evaluate_string(0, 0, xml_node());
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
-#endif
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1));
}
TEST(xpath_out_of_memory_evaluate_substring)
@@ -404,19 +392,7 @@ TEST(xpath_out_of_memory_evaluate_substring)
pugi::xpath_query q(query.c_str());
-#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK(q.evaluate_string(0, 0, xml_node()) == 1);
-#else
- try
- {
- q.evaluate_string(0, 0, xml_node());
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
-#endif
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1));
}
TEST_XML(xpath_out_of_memory_evaluate_union, "<node><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/></node>")
@@ -425,19 +401,7 @@ TEST_XML(xpath_out_of_memory_evaluate_union, "<node><a/><a/><a/><a/><a/><a/><a/>
pugi::xpath_query q(STR("a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|(a|a)))))))))))))))))))"));
-#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty());
-#else
- try
- {
- q.evaluate_node_set(doc.child(STR("node")));
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
-#endif
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc.child(STR("node"))).empty()));
}
TEST_XML(xpath_out_of_memory_evaluate_predicate, "<node><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/><a/></node>")
@@ -446,19 +410,7 @@ TEST_XML(xpath_out_of_memory_evaluate_predicate, "<node><a/><a/><a/><a/><a/><a/>
pugi::xpath_query q(STR("//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[//a[true()]]]]]]]]]]]]]]"));
-#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK(q.evaluate_node_set(doc).empty());
-#else
- try
- {
- q.evaluate_node_set(doc);
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
-#endif
+ CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc).empty()));
}
TEST(xpath_memory_concat_massive)
@@ -634,20 +586,8 @@ TEST(xpath_allocate_string_out_of_memory)
test_runner::_memory_fail_threshold = 8*1024;
-#ifdef PUGIXML_NO_EXCEPTIONS
- CHECK(!xpath_query(query.c_str()));
-#else
- try
- {
- #ifndef __DMC__ // DigitalMars exception handling crashes instead of catching the exception...
- xpath_query q(query.c_str());
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- #endif
- }
- catch (const std::bad_alloc&)
- {
- }
+#ifndef __DMC__ // DigitalMars exception handling crashes instead of catching the exception...
+ CHECK_ALLOC_FAIL(CHECK(!xpath_query(query.c_str())));
#endif
}
diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp
index deb3beb..df078a0 100644
--- a/tests/test_xpath_api.cpp
+++ b/tests/test_xpath_api.cpp
@@ -356,6 +356,7 @@ TEST(xpath_api_exception_what)
CHECK(e.what()[0] != 0);
}
}
+#endif
TEST(xpath_api_node_set_ctor_out_of_memory)
{
@@ -363,15 +364,7 @@ TEST(xpath_api_node_set_ctor_out_of_memory)
xpath_node data[2];
- try
- {
- xpath_node_set ns(data, data + 2);
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
+ CHECK_ALLOC_FAIL(xpath_node_set ns(data, data + 2));
}
TEST(xpath_api_node_set_copy_ctor_out_of_memory)
@@ -381,15 +374,7 @@ TEST(xpath_api_node_set_copy_ctor_out_of_memory)
test_runner::_memory_fail_threshold = 1;
- try
- {
- xpath_node_set copy = ns;
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
+ CHECK_ALLOC_FAIL(xpath_node_set copy = ns);
}
TEST_XML(xpath_api_node_set_assign_out_of_memory_preserve, "<node><a/><b/></node>")
@@ -402,19 +387,10 @@ TEST_XML(xpath_api_node_set_assign_out_of_memory_preserve, "<node><a/><b/></node
test_runner::_memory_fail_threshold = 1;
- try
- {
- ns = nsall;
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
+ CHECK_ALLOC_FAIL(ns = nsall);
CHECK(ns.size() == 2 && ns[0] == doc.child(STR("node")).child(STR("a")) && ns[1] == doc.child(STR("node")).child(STR("b")));
}
-#endif
TEST_XML(xpath_api_deprecated_select_single_node, "<node><head/><foo id='1'/><foo/><tail/></node>")
{
diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp
index 2c2af5a..b6de42e 100644
--- a/tests/test_xpath_parse.cpp
+++ b/tests/test_xpath_parse.cpp
@@ -272,44 +272,25 @@ TEST_XML(xpath_parse_absolute, "<div><s/></div>")
CHECK_XPATH_NODESET(doc, STR("/*[/]")) % 2;
}
-#ifdef PUGIXML_NO_EXCEPTIONS
-# define CHECK_XPATH_FAIL_OOM(query) CHECK_XPATH_FAIL(query)
-#else
-static void test_xpath_fail_oom(const char_t* query)
-{
- try
- {
- pugi::xpath_query q(query);
-
- CHECK_FORCE_FAIL("Expected out of memory exception");
- }
- catch (const std::bad_alloc&)
- {
- }
-}
-
-# define CHECK_XPATH_FAIL_OOM(query) test_xpath_fail_oom(query)
-#endif
-
TEST(xpath_parse_out_of_memory_first_page)
{
test_runner::_memory_fail_threshold = 1;
- CHECK_XPATH_FAIL_OOM(STR("1"));
+ CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(STR("1")));
}
TEST(xpath_parse_out_of_memory_second_page_node)
{
test_runner::_memory_fail_threshold = 8192;
- CHECK_XPATH_FAIL_OOM(STR("1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1"));
+ CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(STR("1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1")));
}
TEST(xpath_parse_out_of_memory_string_to_number)
{
test_runner::_memory_fail_threshold = 4096 + 128;
- CHECK_XPATH_FAIL_OOM(STR("0.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"));
+ CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(STR("0.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")));
}
TEST(xpath_parse_qname_error)
diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp
index 7a099c4..0d33312 100644
--- a/tests/test_xpath_variables.cpp
+++ b/tests/test_xpath_variables.cpp
@@ -177,7 +177,8 @@ TEST(xpath_variables_set_out_of_memory)
xpath_variable_set set;
- xpath_variable* var = set.add(STR("target"), xpath_type_number);
+ xpath_variable* var = 0;
+ CHECK_ALLOC_FAIL(var = set.add(STR("target"), xpath_type_number));
CHECK(!var);
}
@@ -190,7 +191,7 @@ TEST(xpath_variables_out_of_memory)
xpath_variable* var = set.add(STR("target"), xpath_type_string);
CHECK(var);
- CHECK(!var->set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")));
+ CHECK_ALLOC_FAIL(CHECK(!var->set(STR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))));
}
TEST_XML(xpath_variables_evaluate, "<node/>")
@@ -283,20 +284,7 @@ TEST(xpath_variables_long_name_out_of_memory)
test_runner::_memory_fail_threshold = 4096 + 64 + 52 * sizeof(char_t);
-#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 std::bad_alloc&)
- {
- }
-#endif
+ CHECK_ALLOC_FAIL(CHECK(!xpath_query(STR("$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &set)));
}
TEST_XML(xpath_variables_select, "<node attr='1'/><node attr='2'/>")