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.
This commit is contained in:
Fred L. Drake, Jr. 2002-08-23 03:35:40 +00:00
parent 80cac4a780
commit 93a409f6f6

View File

@ -45,6 +45,20 @@ _xml_failure(XML_Parser parser, const char *file, int line)
#define xml_failure(parser) _xml_failure((parser), __FILE__, __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. * Character & encoding tests.
@ -65,13 +79,10 @@ END_TEST
START_TEST(test_u0000_char) START_TEST(test_u0000_char)
{ {
char *text = "<doc>&#0;</doc>";
/* test that a NUL byte (in US-ASCII data) is an error */ /* test that a NUL byte (in US-ASCII data) is an error */
if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) expect_failure("<doc>&#0;</doc>",
fail("Parser did not report error on NUL-byte."); XML_ERROR_BAD_CHAR_REF,
if (XML_GetErrorCode(parser) != XML_ERROR_BAD_CHAR_REF) "Parser did not report error on NUL-byte.");
xml_failure(parser);
} }
END_TEST END_TEST
@ -464,18 +475,11 @@ END_TEST
START_TEST(test_xmldecl_misplaced) START_TEST(test_xmldecl_misplaced)
{ {
char *text = expect_failure("\n"
"\n" "<?xml version='1.0'?>\n"
"<?xml version='1.0'?>\n" "<a/>",
"<a>&eee;</a>"; XML_ERROR_MISPLACED_XML_PI,
"failed to report misplaced XML declaration");
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");
}
} }
END_TEST END_TEST
@ -525,12 +529,9 @@ END_TEST
have an external subset. have an external subset.
*/ */
START_TEST(test_wfc_undeclared_entity_no_external_subset) { START_TEST(test_wfc_undeclared_entity_no_external_subset) {
char *text = "<doc>&entity;</doc>"; expect_failure("<doc>&entity;</doc>",
XML_ERROR_UNDEFINED_ENTITY,
if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) "Parser did not report undefined entity w/out a DTD.");
fail("Parser did not report error on undefined entity w/out a DTD.");
if (XML_GetErrorCode(parser) != XML_ERROR_UNDEFINED_ENTITY)
xml_failure(parser);
} }
END_TEST END_TEST
@ -543,10 +544,9 @@ START_TEST(test_wfc_undeclared_entity_standalone) {
"<!DOCTYPE doc SYSTEM 'foo'>\n" "<!DOCTYPE doc SYSTEM 'foo'>\n"
"<doc>&entity;</doc>"; "<doc>&entity;</doc>";
if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_OK) expect_failure(text,
fail("Parser did not report error on undefined entity (standalone)."); XML_ERROR_UNDEFINED_ENTITY,
if (XML_GetErrorCode(parser) != XML_ERROR_UNDEFINED_ENTITY) "Parser did not report undefined entity (standalone).");
xml_failure(parser);
} }
END_TEST END_TEST