From 8d3fe6ce741ae1e9ab53ca2c268c0ed5b611ff2c Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 28 Oct 2022 20:16:05 +0100 Subject: [PATCH] Move test_ext_entity_not_standalone out of runtests.c --- expat/tests/basic_tests.c | 13 ++++++++++ expat/tests/handlers.c | 37 +++++++++++++++++++++++++++++ expat/tests/handlers.h | 6 +++++ expat/tests/runtests.c | 50 --------------------------------------- 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/expat/tests/basic_tests.c b/expat/tests/basic_tests.c index d018ff31..5b530168 100644 --- a/expat/tests/basic_tests.c +++ b/expat/tests/basic_tests.c @@ -2992,6 +2992,18 @@ START_TEST(test_external_entity_values) { } END_TEST +/* Test the recursive parse interacts with a not standalone handler */ +START_TEST(test_ext_entity_not_standalone) { + const char *text = "\n" + ""; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_not_standalone); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Standalone rejection not caught"); +} +END_TEST + TCase * make_basic_test_case(Suite *s) { TCase *tc_basic = tcase_create("basic tests"); @@ -3123,6 +3135,7 @@ make_basic_test_case(Suite *s) { tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section_utf16_be); tcase_add_test__ifdef_xml_dtd(tc_basic, test_bad_ignore_section); tcase_add_test__ifdef_xml_dtd(tc_basic, test_external_entity_values); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_not_standalone); return tc_basic; /* TEMPORARY: this will become a void function */ } diff --git a/expat/tests/handlers.c b/expat/tests/handlers.c index 83fa9fe5..d25ff7db 100644 --- a/expat/tests/handlers.c +++ b/expat/tests/handlers.c @@ -773,6 +773,43 @@ external_entity_valuer(XML_Parser parser, const XML_Char *context, return XML_STATUS_OK; } +int XMLCALL +external_entity_not_standalone(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text1 = "\n" + "\n" + "%e1;\n"; + const char *text2 = ""; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL) + return XML_STATUS_OK; + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (! xcstrcmp(systemId, XCS("foo"))) { + XML_SetNotStandaloneHandler(ext_parser, reject_not_standalone_handler); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) + != XML_STATUS_ERROR) + fail("Expected not standalone rejection"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_NOT_STANDALONE) + xml_failure(ext_parser); + XML_SetNotStandaloneHandler(ext_parser, NULL); + XML_ParserFree(ext_parser); + return XML_STATUS_ERROR; + } else if (! xcstrcmp(systemId, XCS("bar"))) { + if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + } + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + /* NotStandalone handlers */ int XMLCALL diff --git a/expat/tests/handlers.h b/expat/tests/handlers.h index d249194f..a3a77318 100644 --- a/expat/tests/handlers.h +++ b/expat/tests/handlers.h @@ -242,6 +242,12 @@ extern int XMLCALL external_entity_valuer(XML_Parser parser, const XML_Char *systemId, const XML_Char *publicId); +extern int XMLCALL external_entity_not_standalone(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + /* NotStandalone handlers */ extern int XMLCALL reject_not_standalone_handler(void *userData); diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 015311d4..e9d9e8e2 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -74,55 +74,6 @@ XML_Parser g_parser = NULL; -/* Test the recursive parse interacts with a not standalone handler */ -static int XMLCALL -external_entity_not_standalone(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text1 = "\n" - "\n" - "%e1;\n"; - const char *text2 = ""; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(publicId); - if (systemId == NULL) - return XML_STATUS_OK; - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (! xcstrcmp(systemId, XCS("foo"))) { - XML_SetNotStandaloneHandler(ext_parser, reject_not_standalone_handler); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) - != XML_STATUS_ERROR) - fail("Expected not standalone rejection"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_NOT_STANDALONE) - xml_failure(ext_parser); - XML_SetNotStandaloneHandler(ext_parser, NULL); - XML_ParserFree(ext_parser); - return XML_STATUS_ERROR; - } else if (! xcstrcmp(systemId, XCS("bar"))) { - if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - } - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_not_standalone) { - const char *text = "\n" - ""; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_not_standalone); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Standalone rejection not caught"); -} -END_TEST - static int XMLCALL external_entity_value_aborter(XML_Parser parser, const XML_Char *context, const XML_Char *base, const XML_Char *systemId, @@ -7728,7 +7679,6 @@ make_suite(void) { TCase *tc_accounting = tcase_create("accounting tests"); #endif - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_not_standalone); tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_value_abort); tcase_add_test(tc_basic, test_bad_public_doctype); tcase_add_test(tc_basic, test_attribute_enum_value);