From 2b29b15573e0c4d2a76378db3788a481ec2393c8 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 13 Jun 2010 20:00:51 +0000 Subject: tests: Added tests for parsing offset values git-svn-id: http://pugixml.googlecode.com/svn/trunk@521 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_parse.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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("", parse_default, status_ok, 0); + + test_runner::_memory_fail_threshold = 1; + CHECK_OFFSET("", 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("", parse_default, status_bad_start_element, 5); + + CHECK_OFFSET("", parse_default, status_bad_attribute, 8); + CHECK_OFFSET("