summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-20 18:06:58 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-20 18:06:58 +0000
commit4878d937d961dc4618b3f13b3eba655dab29d61a (patch)
tree1671201c4a1648b7f6320cdb0c19c419bece2739
parentd3195470bae88cabac134e2840fcfb7d8d790cd5 (diff)
tests: Added progressive truncation test
git-svn-id: http://pugixml.googlecode.com/svn/trunk@436 99668b35-9821-0410-8761-19e4c4f06640
-rw-r--r--tests/test_document.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index 3b9c135..eab2be9 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -626,3 +626,27 @@ TEST(document_load_buffer_empty)
CHECK(doc.load_buffer_inplace_own(0, 0, parse_default, encoding) && !doc.first_child());
}
}
+
+TEST(document_progressive_truncation)
+{
+ char* original_data;
+ size_t original_size;
+
+ CHECK(load_file_in_memory("tests/data/utftest_utf8.xml", original_data, original_size));
+
+ for (size_t i = 1; i < original_size; ++i)
+ {
+ char* truncated_data = new char[i];
+ memcpy(truncated_data, original_data, i);
+
+ xml_document doc;
+ bool result = doc.load_buffer(truncated_data, i);
+
+ // some truncate locations are parseable - those that come after declaration, declaration + doctype, declaration + doctype + comment and eof
+ CHECK(((i - 21) < 3 || (i - 66) < 3 || (i - 95) < 3 || i >= 3325) ? result : !result);
+
+ delete[] truncated_data;
+ }
+
+ delete[] original_data;
+}