From 398628cf4a7e47c03a04211dff25bc6691b26cb3 Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Thu, 2 Feb 2017 14:22:57 +0000 Subject: [PATCH] Test XML_DefaultCurrent() passes on handling correctly --- expat/tests/runtests.c | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 174d6c52..fdd695f1 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -1310,6 +1310,98 @@ START_TEST(test_memory_allocation) } END_TEST +static void XMLCALL +record_default_handler(void *userData, + const XML_Char *UNUSED_P(s), + int UNUSED_P(len)) +{ + CharData_AppendString((CharData *)userData, "D"); +} + +static void XMLCALL +record_cdata_handler(void *userData, + const XML_Char *UNUSED_P(s), + int UNUSED_P(len)) +{ + CharData_AppendString((CharData *)userData, "C"); + XML_DefaultCurrent(parser); +} + +static void XMLCALL +record_cdata_nodefault_handler(void *userData, + const XML_Char *UNUSED_P(s), + int UNUSED_P(len)) +{ + CharData_AppendString((CharData *)userData, "c"); +} + +/* Test XML_DefaultCurrent() passes handling on correctly */ +START_TEST(test_default_current) +{ + const char *text = "hello"; + const char *entity_text = + "\n" + "]>\n" + "&entity;"; + CharData storage; + + XML_SetDefaultHandler(parser, record_default_handler); + XML_SetCharacterDataHandler(parser, record_cdata_handler); + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(parser); + CharData_CheckString(&storage, "DCDCDCDCDCDD"); + + /* Again, without the defaulting */ + XML_ParserReset(parser, NULL); + XML_SetDefaultHandler(parser, record_default_handler); + XML_SetCharacterDataHandler(parser, record_cdata_nodefault_handler); + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(parser); + CharData_CheckString(&storage, "DcccccD"); + + /* Now with an internal entity to complicate matters */ + XML_ParserReset(parser, NULL); + XML_SetDefaultHandler(parser, record_default_handler); + XML_SetCharacterDataHandler(parser, record_cdata_handler); + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + if (_XML_Parse_SINGLE_BYTES(parser, entity_text, strlen(entity_text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(parser); + /* The default handler suppresses the entity */ + CharData_CheckString(&storage, "DDDDDDDDDDDDDDDDDDD"); + + /* This time, allow the entity through */ + XML_ParserReset(parser, NULL); + XML_SetDefaultHandlerExpand(parser, record_default_handler); + XML_SetCharacterDataHandler(parser, record_cdata_handler); + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + if (_XML_Parse_SINGLE_BYTES(parser, entity_text, strlen(entity_text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(parser); + CharData_CheckString(&storage, "DDDDDDDDDDDDDDDDDCDD"); + + /* Finally, without passing the cdata to the default handler */ + XML_ParserReset(parser, NULL); + XML_SetDefaultHandlerExpand(parser, record_default_handler); + XML_SetCharacterDataHandler(parser, record_cdata_nodefault_handler); + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + if (_XML_Parse_SINGLE_BYTES(parser, entity_text, strlen(entity_text), + XML_TRUE) == XML_STATUS_ERROR) + xml_failure(parser); + CharData_CheckString(&storage, "DDDDDDDDDDDDDDDDDcD"); +} +END_TEST + /* * Namespaces tests. @@ -2185,6 +2277,7 @@ make_suite(void) tcase_add_test(tc_basic, test_good_cdata_utf16); tcase_add_test(tc_basic, test_bad_cdata); tcase_add_test(tc_basic, test_memory_allocation); + tcase_add_test(tc_basic, test_default_current); suite_add_tcase(s, tc_namespace); tcase_add_checked_fixture(tc_namespace, -- 2.40.0