diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-06-13 20:00:51 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-06-13 20:00:51 +0000 |
commit | 2b29b15573e0c4d2a76378db3788a481ec2393c8 (patch) | |
tree | d30f55990602d5cda7ced8b58d999d1290c51b00 /tests | |
parent | ab72b14d17a1f80ee049cdd8c77e973960fea108 (diff) |
tests: Added tests for parsing offset values
git-svn-id: http://pugixml.googlecode.com/svn/trunk@521 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_parse.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 735f1bc..d8aabd3 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -616,3 +616,52 @@ TEST(parse_out_of_memory_halfway) delete[] text;
}
+
+static bool test_offset(const char_t* contents, unsigned int options, pugi::xml_parse_status status, ptrdiff_t offset)
+{
+ xml_document doc;
+ xml_parse_result res = doc.load(contents, options);
+
+ return res.status == status && res.offset == offset;
+}
+
+#define CHECK_OFFSET(contents, options, status, offset) CHECK(test_offset(STR(contents), options, status, offset))
+
+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);
+ test_runner::_memory_fail_threshold = 0;
+
+ CHECK_OFFSET("<3d/>", parse_default, status_unrecognized_tag, 1);
+ CHECK_OFFSET(" <3d/>", parse_default, status_unrecognized_tag, 2);
+ CHECK_OFFSET(" <", parse_default, status_unrecognized_tag, 2);
+
+ CHECK_OFFSET("<?pi", parse_default, status_bad_pi, 3);
+ CHECK_OFFSET("<?pi", parse_default | parse_pi, status_bad_pi, 3);
+ CHECK_OFFSET("<?xml", parse_default | parse_declaration, status_bad_pi, 4);
+
+ CHECK_OFFSET("<!----", parse_default, status_bad_comment, 5);
+ CHECK_OFFSET("<!----", parse_default | parse_comments, status_bad_comment, 4);
+
+ CHECK_OFFSET("<![CDA", parse_default, status_bad_cdata, 5);
+ CHECK_OFFSET("<![CDATA[non-terminated]]", parse_default, status_bad_cdata, 9);
+
+ CHECK_OFFSET("<!DOCTYPE doc", parse_default, status_bad_doctype, 12);
+ CHECK_OFFSET("<!DOCTYPE greeting [ <!ATTLIST list type (bullets|ordered|glossary) \"orde", parse_default, status_bad_doctype, 76);
+
+ CHECK_OFFSET("<node", parse_default, status_bad_start_element, 4);
+ CHECK_OFFSET("<node ", parse_default, status_bad_start_element, 5);
+ CHECK_OFFSET("<nod%>", parse_default, status_bad_start_element, 5);
+
+ CHECK_OFFSET("<node a=2>", parse_default, status_bad_attribute, 8);
+ CHECK_OFFSET("<node a='2>", parse_default, status_bad_attribute, 9);
+
+ CHECK_OFFSET("<n></n $>", parse_default, status_bad_end_element, 7);
+ CHECK_OFFSET("<n></n", parse_default, status_bad_end_element, 5);
+
+ CHECK_OFFSET("<no></na>", parse_default, status_end_element_mismatch, 8);
+ CHECK_OFFSET("<no></nod>", parse_default, status_end_element_mismatch, 9);
+}
|