Move null loader and more tests out of runtests.c
diff --git a/expat/tests/basic_tests.c b/expat/tests/basic_tests.c index 4c4b430..fb24c6b 100644 --- a/expat/tests/basic_tests.c +++ b/expat/tests/basic_tests.c
@@ -2104,6 +2104,51 @@ } END_TEST +/* Test XML_UseForeignDTD with no external subset present */ +START_TEST(test_foreign_dtd_without_external_subset) { + const char *text = "<!DOCTYPE doc [<!ENTITY foo 'bar'>]>\n" + "<doc>&foo;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, NULL); + XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); + XML_UseForeignDTD(g_parser, XML_TRUE); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_empty_foreign_dtd) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); + XML_UseForeignDTD(g_parser, XML_TRUE); + expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, + "Undefined entity not faulted"); +} +END_TEST + +/* Test XML Base is set and unset appropriately */ +START_TEST(test_set_base) { + const XML_Char *old_base; + const XML_Char *new_base = XCS("/local/file/name.xml"); + + old_base = XML_GetBase(g_parser); + if (XML_SetBase(g_parser, new_base) != XML_STATUS_OK) + fail("Unable to set base"); + if (xcstrcmp(XML_GetBase(g_parser), new_base) != 0) + fail("Base setting not correct"); + if (XML_SetBase(g_parser, NULL) != XML_STATUS_OK) + fail("Unable to NULL base"); + if (XML_GetBase(g_parser) != NULL) + fail("Base setting not nulled"); + XML_SetBase(g_parser, old_base); +} +END_TEST + TCase * make_basic_test_case(Suite *s) { TCase *tc_basic = tcase_create("basic tests"); @@ -2195,6 +2240,10 @@ tcase_add_test__ifdef_xml_dtd(tc_basic, test_foreign_dtd_not_standalone); tcase_add_test__ifdef_xml_dtd(tc_basic, test_invalid_foreign_dtd); tcase_add_test__ifdef_xml_dtd(tc_basic, test_foreign_dtd_with_doctype); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_foreign_dtd_without_external_subset); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_empty_foreign_dtd); + tcase_add_test(tc_basic, test_set_base); return tc_basic; /* TEMPORARY: this will become a void function */ }
diff --git a/expat/tests/handlers.c b/expat/tests/handlers.c index d395da8..0172a38 100644 --- a/expat/tests/handlers.c +++ b/expat/tests/handlers.c
@@ -215,6 +215,18 @@ return XML_STATUS_ERROR; } +int XMLCALL +external_entity_null_loader(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(parser); + UNUSED_P(context); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + return XML_STATUS_OK; +} + /* NotStandalone handlers */ int XMLCALL
diff --git a/expat/tests/handlers.h b/expat/tests/handlers.h index e08d34e..488c92e 100644 --- a/expat/tests/handlers.h +++ b/expat/tests/handlers.h
@@ -112,6 +112,11 @@ const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId); +extern int XMLCALL external_entity_null_loader(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); /* NotStandalone handlers */
diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index ef7e76c..98b3f31 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c
@@ -74,63 +74,6 @@ XML_Parser g_parser = NULL; -/* Test XML_UseForeignDTD with no external subset present */ -static int XMLCALL -external_entity_null_loader(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - UNUSED_P(parser); - UNUSED_P(context); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - return XML_STATUS_OK; -} - -START_TEST(test_foreign_dtd_without_external_subset) { - const char *text = "<!DOCTYPE doc [<!ENTITY foo 'bar'>]>\n" - "<doc>&foo;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, NULL); - XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); - XML_UseForeignDTD(g_parser, XML_TRUE); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_empty_foreign_dtd) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); - XML_UseForeignDTD(g_parser, XML_TRUE); - expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, - "Undefined entity not faulted"); -} -END_TEST - -/* Test XML Base is set and unset appropriately */ -START_TEST(test_set_base) { - const XML_Char *old_base; - const XML_Char *new_base = XCS("/local/file/name.xml"); - - old_base = XML_GetBase(g_parser); - if (XML_SetBase(g_parser, new_base) != XML_STATUS_OK) - fail("Unable to set base"); - if (xcstrcmp(XML_GetBase(g_parser), new_base) != 0) - fail("Base setting not correct"); - if (XML_SetBase(g_parser, NULL) != XML_STATUS_OK) - fail("Unable to NULL base"); - if (XML_GetBase(g_parser) != NULL) - fail("Base setting not nulled"); - XML_SetBase(g_parser, old_base); -} -END_TEST - /* Test attribute counts, indexing, etc */ typedef struct attrInfo { const XML_Char *name; @@ -9296,10 +9239,6 @@ tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_invalid_suspended_parse); - tcase_add_test__ifdef_xml_dtd(tc_basic, - test_foreign_dtd_without_external_subset); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_empty_foreign_dtd); - tcase_add_test(tc_basic, test_set_base); tcase_add_test(tc_basic, test_attributes); tcase_add_test(tc_basic, test_reset_in_entity); tcase_add_test(tc_basic, test_resume_invalid_parse);