Merge branch 'coverage-review'
This commit is contained in:
commit
5354505d4c
@ -2122,6 +2122,167 @@ START_TEST(test_subordinate_suspend)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* Test suspending a subordinate parser from an XML declaration */
|
||||
/* Increases code coverage of the tests */
|
||||
static void XMLCALL
|
||||
entity_suspending_xdecl_handler(void *userData,
|
||||
const XML_Char *UNUSED_P(version),
|
||||
const XML_Char *UNUSED_P(encoding),
|
||||
int UNUSED_P(standalone))
|
||||
{
|
||||
XML_Parser ext_parser = (XML_Parser)userData;
|
||||
|
||||
XML_StopParser(ext_parser, resumable);
|
||||
XML_SetXmlDeclHandler(ext_parser, NULL);
|
||||
}
|
||||
|
||||
static int XMLCALL
|
||||
external_entity_suspend_xmldecl(XML_Parser parser,
|
||||
const XML_Char *context,
|
||||
const XML_Char *UNUSED_P(base),
|
||||
const XML_Char *UNUSED_P(systemId),
|
||||
const XML_Char *UNUSED_P(publicId))
|
||||
{
|
||||
const char *text = "<?xml version='1.0' encoding='us-ascii'?>";
|
||||
XML_Parser ext_parser;
|
||||
XML_ParsingStatus status;
|
||||
enum XML_Status rc;
|
||||
|
||||
ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL);
|
||||
if (ext_parser == NULL)
|
||||
fail("Could not create external entity parser");
|
||||
XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler);
|
||||
XML_SetUserData(ext_parser, ext_parser);
|
||||
rc = _XML_Parse_SINGLE_BYTES(ext_parser, text, strlen(text), XML_TRUE);
|
||||
XML_GetParsingStatus(ext_parser, &status);
|
||||
if (resumable) {
|
||||
if (rc == XML_STATUS_ERROR)
|
||||
xml_failure(ext_parser);
|
||||
if (status.parsing != XML_SUSPENDED)
|
||||
fail("Ext Parsing status not SUSPENDED");
|
||||
} else {
|
||||
if (rc != XML_STATUS_ERROR)
|
||||
fail("Ext parsing not aborted");
|
||||
if (XML_GetErrorCode(ext_parser) != XML_ERROR_ABORTED)
|
||||
xml_failure(ext_parser);
|
||||
if (status.parsing != XML_FINISHED)
|
||||
fail("Ext Parsing status not FINISHED");
|
||||
}
|
||||
|
||||
XML_ParserFree(ext_parser);
|
||||
return XML_STATUS_OK;
|
||||
}
|
||||
|
||||
START_TEST(test_subordinate_xdecl_suspend)
|
||||
{
|
||||
const char *text =
|
||||
"<!DOCTYPE doc [\n"
|
||||
" <!ENTITY entity SYSTEM 'http://xml.libexpat.org/dummy.ent'>\n"
|
||||
"]>\n"
|
||||
"<doc>&entity;</doc>";
|
||||
|
||||
XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
XML_SetExternalEntityRefHandler(parser,
|
||||
external_entity_suspend_xmldecl);
|
||||
resumable = XML_TRUE;
|
||||
if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text),
|
||||
XML_TRUE) == XML_STATUS_ERROR)
|
||||
xml_failure(parser);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_subordinate_xdecl_abort)
|
||||
{
|
||||
const char *text =
|
||||
"<!DOCTYPE doc [\n"
|
||||
" <!ENTITY entity SYSTEM 'http://xml.libexpat.org/dummy.ent'>\n"
|
||||
"]>\n"
|
||||
"<doc>&entity;</doc>";
|
||||
|
||||
XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
XML_SetExternalEntityRefHandler(parser,
|
||||
external_entity_suspend_xmldecl);
|
||||
resumable = XML_FALSE;
|
||||
if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text),
|
||||
XML_TRUE) == XML_STATUS_ERROR)
|
||||
xml_failure(parser);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* Test external entity fault handling with suspension */
|
||||
static int XMLCALL
|
||||
external_entity_suspending_faulter(XML_Parser parser,
|
||||
const XML_Char *context,
|
||||
const XML_Char *UNUSED_P(base),
|
||||
const XML_Char *UNUSED_P(systemId),
|
||||
const XML_Char *UNUSED_P(publicId))
|
||||
{
|
||||
XML_Parser ext_parser;
|
||||
ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser);
|
||||
void *buffer;
|
||||
int parse_len = strlen(fault->parse_text);
|
||||
|
||||
ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL);
|
||||
if (ext_parser == NULL)
|
||||
fail("Could not create external entity parser");
|
||||
XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler);
|
||||
XML_SetUserData(ext_parser, ext_parser);
|
||||
resumable = XML_TRUE;
|
||||
buffer = XML_GetBuffer(ext_parser, parse_len);
|
||||
if (buffer == NULL)
|
||||
fail("Could not allocate parse buffer");
|
||||
memcpy(buffer, fault->parse_text, parse_len);
|
||||
if (XML_ParseBuffer(ext_parser, parse_len,
|
||||
XML_FALSE) != XML_STATUS_SUSPENDED)
|
||||
fail("XML declaration did not suspend");
|
||||
if (XML_ResumeParser(ext_parser) != XML_STATUS_OK)
|
||||
xml_failure(ext_parser);
|
||||
if (XML_ParseBuffer(ext_parser, 0, XML_TRUE) != XML_STATUS_ERROR)
|
||||
fail(fault->fail_text);
|
||||
if (XML_GetErrorCode(ext_parser) != fault->error)
|
||||
xml_failure(ext_parser);
|
||||
|
||||
XML_ParserFree(ext_parser);
|
||||
return XML_STATUS_ERROR;
|
||||
}
|
||||
|
||||
START_TEST(test_ext_entity_invalid_suspended_parse)
|
||||
{
|
||||
const char *text =
|
||||
"<!DOCTYPE doc [\n"
|
||||
" <!ENTITY en SYSTEM 'http://xml.libexpat.org/dummy.ent'>\n"
|
||||
"]>\n"
|
||||
"<doc>&en;</doc>";
|
||||
ExtFaults faults[] = {
|
||||
{
|
||||
"<?xml version='1.0' encoding='us-ascii'?><",
|
||||
"Incomplete element declaration not faulted",
|
||||
XML_ERROR_UNCLOSED_TOKEN
|
||||
},
|
||||
{
|
||||
/* First two bytes of a three-byte char */
|
||||
"<?xml version='1.0' encoding='utf-8'?>\xe2\x82",
|
||||
"Incomplete character not faulted",
|
||||
XML_ERROR_PARTIAL_CHAR
|
||||
},
|
||||
{ NULL, NULL, XML_ERROR_NONE }
|
||||
};
|
||||
ExtFaults *fault;
|
||||
|
||||
for (fault = &faults[0]; fault->parse_text != NULL; fault++) {
|
||||
XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
|
||||
XML_SetExternalEntityRefHandler(parser,
|
||||
external_entity_suspending_faulter);
|
||||
XML_SetUserData(parser, fault);
|
||||
expect_failure(text,
|
||||
XML_ERROR_EXTERNAL_ENTITY_HANDLING,
|
||||
"Parser did not report external entity error");
|
||||
XML_ParserReset(parser, NULL);
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
|
||||
/* Test setting an explicit encoding */
|
||||
START_TEST(test_explicit_encoding)
|
||||
@ -3744,6 +3905,7 @@ make_suite(void)
|
||||
tcase_add_test(tc_basic, test_ext_entity_set_bom);
|
||||
tcase_add_test(tc_basic, test_ext_entity_bad_encoding);
|
||||
tcase_add_test(tc_basic, test_ext_entity_invalid_parse);
|
||||
tcase_add_test(tc_basic, test_ext_entity_invalid_suspended_parse);
|
||||
tcase_add_test(tc_basic, test_dtd_default_handling);
|
||||
tcase_add_test(tc_basic, test_empty_ns_without_namespaces);
|
||||
tcase_add_test(tc_basic, test_ns_in_attribute_default_without_namespaces);
|
||||
@ -3764,6 +3926,8 @@ make_suite(void)
|
||||
tcase_add_test(tc_basic, test_resume_resuspended);
|
||||
tcase_add_test(tc_basic, test_subordinate_reset);
|
||||
tcase_add_test(tc_basic, test_subordinate_suspend);
|
||||
tcase_add_test(tc_basic, test_subordinate_xdecl_suspend);
|
||||
tcase_add_test(tc_basic, test_subordinate_xdecl_abort);
|
||||
tcase_add_test(tc_basic, test_explicit_encoding);
|
||||
tcase_add_test(tc_basic, test_user_parameters);
|
||||
tcase_add_test(tc_basic, test_ext_entity_ref_parameter);
|
||||
|
Loading…
Reference in New Issue
Block a user