mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-07 22:19:12 +00:00
Move (some) epilog tests out of runtests.c
This commit is contained in:
parent
b55c5df683
commit
9bece1957f
4 changed files with 60 additions and 56 deletions
|
@ -3256,6 +3256,48 @@ START_TEST(test_suspend_xdecl) {
|
|||
}
|
||||
END_TEST
|
||||
|
||||
/* Test aborting the parse in an epilog works */
|
||||
START_TEST(test_abort_epilog) {
|
||||
const char *text = "<doc></doc>\n\r\n";
|
||||
XML_Char match[] = XCS("\r");
|
||||
|
||||
XML_SetDefaultHandler(g_parser, selective_aborting_default_handler);
|
||||
XML_SetUserData(g_parser, match);
|
||||
g_resumable = XML_FALSE;
|
||||
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
|
||||
!= XML_STATUS_ERROR)
|
||||
fail("Abort not triggered");
|
||||
if (XML_GetErrorCode(g_parser) != XML_ERROR_ABORTED)
|
||||
xml_failure(g_parser);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* Test a different code path for abort in the epilog */
|
||||
START_TEST(test_abort_epilog_2) {
|
||||
const char *text = "<doc></doc>\n";
|
||||
XML_Char match[] = XCS("\n");
|
||||
|
||||
XML_SetDefaultHandler(g_parser, selective_aborting_default_handler);
|
||||
XML_SetUserData(g_parser, match);
|
||||
g_resumable = XML_FALSE;
|
||||
expect_failure(text, XML_ERROR_ABORTED, "Abort not triggered");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* Test suspension from the epilog */
|
||||
START_TEST(test_suspend_epilog) {
|
||||
const char *text = "<doc></doc>\n";
|
||||
XML_Char match[] = XCS("\n");
|
||||
|
||||
XML_SetDefaultHandler(g_parser, selective_aborting_default_handler);
|
||||
XML_SetUserData(g_parser, match);
|
||||
g_resumable = XML_TRUE;
|
||||
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
|
||||
!= XML_STATUS_SUSPENDED)
|
||||
xml_failure(g_parser);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
TCase *
|
||||
make_basic_test_case(Suite *s) {
|
||||
TCase *tc_basic = tcase_create("basic tests");
|
||||
|
@ -3402,6 +3444,9 @@ make_basic_test_case(Suite *s) {
|
|||
test_recursive_external_parameter_entity);
|
||||
tcase_add_test(tc_basic, test_undefined_ext_entity_in_external_dtd);
|
||||
tcase_add_test(tc_basic, test_suspend_xdecl);
|
||||
tcase_add_test(tc_basic, test_abort_epilog);
|
||||
tcase_add_test(tc_basic, test_abort_epilog_2);
|
||||
tcase_add_test(tc_basic, test_suspend_epilog);
|
||||
|
||||
return tc_basic; /* TEMPORARY: this will become a void function */
|
||||
}
|
||||
|
|
|
@ -1145,3 +1145,14 @@ data_check_comment_handler(void *userData, const XML_Char *data) {
|
|||
fail("User data in parser not correctly set");
|
||||
g_comment_count++;
|
||||
}
|
||||
|
||||
void XMLCALL
|
||||
selective_aborting_default_handler(void *userData, const XML_Char *s, int len) {
|
||||
const XML_Char *match = (const XML_Char *)userData;
|
||||
|
||||
if (match == NULL
|
||||
|| (xcstrlen(match) == (unsigned)len && ! xcstrncmp(match, s, len))) {
|
||||
XML_StopParser(g_parser, g_resumable);
|
||||
XML_SetDefaultHandler(g_parser, NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -357,6 +357,10 @@ extern void XMLCALL param_check_skip_handler(void *userData,
|
|||
extern void XMLCALL data_check_comment_handler(void *userData,
|
||||
const XML_Char *data);
|
||||
|
||||
extern void XMLCALL selective_aborting_default_handler(void *userData,
|
||||
const XML_Char *s,
|
||||
int len);
|
||||
|
||||
#endif /* XML_HANDLERS_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -74,59 +74,6 @@
|
|||
|
||||
XML_Parser g_parser = NULL;
|
||||
|
||||
/* Test aborting the parse in an epilog works */
|
||||
static void XMLCALL
|
||||
selective_aborting_default_handler(void *userData, const XML_Char *s, int len) {
|
||||
const XML_Char *match = (const XML_Char *)userData;
|
||||
|
||||
if (match == NULL
|
||||
|| (xcstrlen(match) == (unsigned)len && ! xcstrncmp(match, s, len))) {
|
||||
XML_StopParser(g_parser, g_resumable);
|
||||
XML_SetDefaultHandler(g_parser, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(test_abort_epilog) {
|
||||
const char *text = "<doc></doc>\n\r\n";
|
||||
XML_Char match[] = XCS("\r");
|
||||
|
||||
XML_SetDefaultHandler(g_parser, selective_aborting_default_handler);
|
||||
XML_SetUserData(g_parser, match);
|
||||
g_resumable = XML_FALSE;
|
||||
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
|
||||
!= XML_STATUS_ERROR)
|
||||
fail("Abort not triggered");
|
||||
if (XML_GetErrorCode(g_parser) != XML_ERROR_ABORTED)
|
||||
xml_failure(g_parser);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* Test a different code path for abort in the epilog */
|
||||
START_TEST(test_abort_epilog_2) {
|
||||
const char *text = "<doc></doc>\n";
|
||||
XML_Char match[] = XCS("\n");
|
||||
|
||||
XML_SetDefaultHandler(g_parser, selective_aborting_default_handler);
|
||||
XML_SetUserData(g_parser, match);
|
||||
g_resumable = XML_FALSE;
|
||||
expect_failure(text, XML_ERROR_ABORTED, "Abort not triggered");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
/* Test suspension from the epilog */
|
||||
START_TEST(test_suspend_epilog) {
|
||||
const char *text = "<doc></doc>\n";
|
||||
XML_Char match[] = XCS("\n");
|
||||
|
||||
XML_SetDefaultHandler(g_parser, selective_aborting_default_handler);
|
||||
XML_SetUserData(g_parser, match);
|
||||
g_resumable = XML_TRUE;
|
||||
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
|
||||
!= XML_STATUS_SUSPENDED)
|
||||
xml_failure(g_parser);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static void XMLCALL
|
||||
suspending_end_handler(void *userData, const XML_Char *s) {
|
||||
UNUSED_P(s);
|
||||
|
@ -7317,9 +7264,6 @@ make_suite(void) {
|
|||
TCase *tc_accounting = tcase_create("accounting tests");
|
||||
#endif
|
||||
|
||||
tcase_add_test(tc_basic, test_abort_epilog);
|
||||
tcase_add_test(tc_basic, test_abort_epilog_2);
|
||||
tcase_add_test(tc_basic, test_suspend_epilog);
|
||||
tcase_add_test(tc_basic, test_suspend_in_sole_empty_tag);
|
||||
tcase_add_test(tc_basic, test_unfinished_epilog);
|
||||
tcase_add_test(tc_basic, test_partial_char_in_epilog);
|
||||
|
|
Loading…
Add table
Reference in a new issue