summaryrefslogtreecommitdiff
path: root/tests/test_parse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_parse.cpp')
-rw-r--r--tests/test_parse.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index 2094ef9..c45b783 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -876,7 +876,7 @@ TEST(parse_out_of_memory)
CHECK(!doc.first_child());
}
-TEST(parse_out_of_memory_halfway)
+TEST(parse_out_of_memory_halfway_node)
{
const unsigned int count = 10000;
static char_t text[count * 4];
@@ -896,6 +896,35 @@ TEST(parse_out_of_memory_halfway)
CHECK_NODE(doc.first_child(), STR("<n />"));
}
+TEST(parse_out_of_memory_halfway_attr)
+{
+ const unsigned int count = 10000;
+ static char_t text[count * 5 + 4];
+
+ text[0] = '<';
+ text[1] = 'n';
+
+ for (unsigned int i = 0; i < count; ++i)
+ {
+ text[5*i + 2] = ' ';
+ text[5*i + 3] = 'a';
+ text[5*i + 4] = '=';
+ text[5*i + 5] = '"';
+ text[5*i + 6] = '"';
+ }
+
+ text[5 * count + 2] = '/';
+ text[5 * count + 3] = '>';
+
+ test_runner::_memory_fail_threshold = 65536;
+
+ xml_document doc;
+ 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"));
+}
+
static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset)
{
xml_document doc;
@@ -1039,3 +1068,25 @@ TEST(parse_pcdata_gap_fragment)
CHECK(doc.load(STR("a&amp;b"), parse_fragment | parse_escapes));
CHECK_STRING(doc.text().get(), STR("a&b"));
}
+
+TEST(parse_name_end_eof)
+{
+ char_t test[] = STR("<node>");
+
+ xml_document doc;
+ CHECK(doc.load_buffer_inplace(test, 6 * sizeof(char_t)).status == status_end_element_mismatch);
+ CHECK_STRING(doc.first_child().name(), STR("node"));
+}
+
+TEST(parse_close_tag_eof)
+{
+ char_t test1[] = STR("<node></node");
+ char_t test2[] = STR("<node></nodx");
+
+ xml_document doc;
+ CHECK(doc.load_buffer_inplace(test1, 12 * sizeof(char_t)).status == status_bad_end_element);
+ CHECK_STRING(doc.first_child().name(), STR("node"));
+
+ CHECK(doc.load_buffer_inplace(test2, 12 * sizeof(char_t)).status == status_end_element_mismatch);
+ CHECK_STRING(doc.first_child().name(), STR("node"));
+}