summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-10-03 14:28:18 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-10-03 14:28:18 +0000
commitf725ff1170e905a914e93daf6254640896a8c517 (patch)
treee0e3df7899b3afd6c2135ed898cb97b7a19647c2 /tests
parenta6c756b8bce21d88db10fdeffcb5e87c7d66c6b9 (diff)
tests: Fixed XPath OOM tests, added parsing exception test
git-svn-id: http://pugixml.googlecode.com/svn/trunk@760 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/test_document.cpp21
-rw-r--r--tests/test_xpath_parse.cpp25
2 files changed, 43 insertions, 3 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index d67f646..d6163e2 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -845,3 +845,24 @@ TEST(document_load_buffer_inplace_short)
delete[] data;
}
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+TEST(document_load_exceptions)
+{
+ bool thrown = false;
+
+ try
+ {
+ pugi::xml_document doc;
+ if (!doc.load("<node attribute='value")) throw std::bad_alloc();
+
+ CHECK_FORCE_FAIL("Expected parsing failure");
+ }
+ catch (const std::bad_alloc&)
+ {
+ thrown = true;
+ }
+
+ CHECK(thrown);
+}
+#endif
diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp
index 476036e..6e04c8b 100644
--- a/tests/test_xpath_parse.cpp
+++ b/tests/test_xpath_parse.cpp
@@ -272,25 +272,44 @@ 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
+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(STR("1"));
+ CHECK_XPATH_FAIL_OOM(STR("1"));
}
TEST(xpath_parse_out_of_memory_second_page_node)
{
test_runner::_memory_fail_threshold = 8192;
- 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"));
+ 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"));
}
TEST(xpath_parse_out_of_memory_string_to_number)
{
test_runner::_memory_fail_threshold = 4096 + 128;
- CHECK_XPATH_FAIL(STR("0.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"));
+ CHECK_XPATH_FAIL_OOM(STR("0.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"));
}
TEST(xpath_parse_qname_error)