From 93a409f6f62a0188dc8ac45b5488d9d18b3c7626 Mon Sep 17 00:00:00 2001 From: "Fred L. Drake, Jr." Date: Fri, 23 Aug 2002 03:35:40 +0000 Subject: [PATCH] Factor out some error reporting code used when the parser is expected to report an error, and either doesn't report an error at all or reports the wrong error. --- expat/tests/runtests.c | 56 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index fdfcd5a8..ecd19774 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -45,6 +45,20 @@ _xml_failure(XML_Parser parser, const char *file, int line) #define xml_failure(parser) _xml_failure((parser), __FILE__, __LINE__) +static void +_expect_failure(char *text, enum XML_Error errorCode, char *errorMessage, + char *file, int lineno) +{ + if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) + fail(errorMessage); + if (XML_GetErrorCode(parser) != errorCode) + _xml_failure(parser, file, lineno); +} + +#define expect_failure(text, errorCode, errorMessage) \ + _expect_failure((text), (errorCode), (errorMessage), \ + __FILE__, __LINE__) + /* * Character & encoding tests. @@ -65,13 +79,10 @@ END_TEST START_TEST(test_u0000_char) { - char *text = ""; - /* test that a NUL byte (in US-ASCII data) is an error */ - if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) - fail("Parser did not report error on NUL-byte."); - if (XML_GetErrorCode(parser) != XML_ERROR_BAD_CHAR_REF) - xml_failure(parser); + expect_failure("", + XML_ERROR_BAD_CHAR_REF, + "Parser did not report error on NUL-byte."); } END_TEST @@ -464,18 +475,11 @@ END_TEST START_TEST(test_xmldecl_misplaced) { - char *text = - "\n" - "\n" - "&eee;"; - - if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR) { - if (XML_GetErrorCode(parser) != XML_ERROR_MISPLACED_XML_PI) - xml_failure(parser); - } - else { - fail("expected XML_ERROR_MISPLACED_XML_PI with misplaced XML decl"); - } + expect_failure("\n" + "\n" + "", + XML_ERROR_MISPLACED_XML_PI, + "failed to report misplaced XML declaration"); } END_TEST @@ -525,12 +529,9 @@ END_TEST have an external subset. */ START_TEST(test_wfc_undeclared_entity_no_external_subset) { - char *text = "&entity;"; - - if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) - fail("Parser did not report error on undefined entity w/out a DTD."); - if (XML_GetErrorCode(parser) != XML_ERROR_UNDEFINED_ENTITY) - xml_failure(parser); + expect_failure("&entity;", + XML_ERROR_UNDEFINED_ENTITY, + "Parser did not report undefined entity w/out a DTD."); } END_TEST @@ -543,10 +544,9 @@ START_TEST(test_wfc_undeclared_entity_standalone) { "\n" "&entity;"; - if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) - fail("Parser did not report error on undefined entity (standalone)."); - if (XML_GetErrorCode(parser) != XML_ERROR_UNDEFINED_ENTITY) - xml_failure(parser); + expect_failure(text, + XML_ERROR_UNDEFINED_ENTITY, + "Parser did not report undefined entity (standalone)."); } END_TEST