summaryrefslogtreecommitdiff
path: root/tests/test_parse.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-06-13 19:24:20 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-06-13 19:24:20 +0000
commitab72b14d17a1f80ee049cdd8c77e973960fea108 (patch)
tree9e86e841eb0e5c2ca73198bdce2718e80e25317d /tests/test_parse.cpp
parente5014db32a79816c3a114b3de586ae28beb28c95 (diff)
Internal XML parsing error handling is done via setjmp/longjmp, all allocation errors are now handled correctly (parser returns status_out_of_memory, modification functions return errors); added tests for some out of memory situations
git-svn-id: http://pugixml.googlecode.com/svn/trunk@520 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_parse.cpp')
-rw-r--r--tests/test_parse.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index 7d4958a..735f1bc 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -585,3 +585,34 @@ TEST(parse_empty)
xml_document doc;
CHECK(doc.load(STR("")) && !doc.first_child());
}
+
+TEST(parse_out_of_memory)
+{
+ test_runner::_memory_fail_threshold = 256;
+
+ xml_document doc;
+ CHECK(doc.load(STR("<foo a='1'/>")).status == status_out_of_memory);
+ CHECK(!doc.first_child());
+}
+
+TEST(parse_out_of_memory_halfway)
+{
+ unsigned int count = 10000;
+ char_t* text = new char_t[count * 4];
+
+ for (unsigned int i = 0; i < count; ++i)
+ {
+ text[4*i + 0] = '<';
+ text[4*i + 1] = 'n';
+ text[4*i + 2] = '/';
+ text[4*i + 3] = '>';
+ }
+
+ test_runner::_memory_fail_threshold = 65536;
+
+ xml_document doc;
+ CHECK(doc.load_buffer_inplace(text, count * 4).status == status_out_of_memory);
+ CHECK_NODE(doc.first_child(), STR("<n />"));
+
+ delete[] text;
+}