From fcf971bfe0160a55da598c3b8e0239a6e0cce1cf Mon Sep 17 00:00:00 2001 From: "Fred L. Drake, Jr." Date: Fri, 17 Aug 2001 19:16:41 +0000 Subject: [PATCH] A very small test suite for Expat; additional tests will be added as time permits. --- expat/tests/runtests.c | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 expat/tests/runtests.c diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c new file mode 100644 index 00000000..47d9654c --- /dev/null +++ b/expat/tests/runtests.c @@ -0,0 +1,93 @@ +#include +#include + +#include "expat.h" + + +static XML_Parser parser; + + +static void +basic_setup(void) +{ + parser = XML_ParserCreate("us-ascii"); +} + +static void +basic_teardown(void) +{ + if (parser != NULL) { + XML_ParserFree(parser); + } +} + + +START_TEST(test_nul_byte) +{ + char *text = "\0"; + + if (parser == NULL) + fail("Parser not created."); + + /* test that a NUL byte (in US-ASCII data) is an error */ + if (XML_Parse(parser, text, 12, 1)) + fail("Parser did not report error on NUL-byte."); + fail_unless(XML_GetErrorCode(parser) == XML_ERROR_INVALID_TOKEN, + "Got wrong error code for NUL-byte in US-ASCII encoding."); +} +END_TEST + + +START_TEST(test_u0000_char) +{ + char *text = ""; + + if (parser == NULL) + fail("Parser not created."); + + /* test that a NUL byte (in US-ASCII data) is an error */ + if (XML_Parse(parser, text, strlen(text), 1)) + fail("Parser did not report error on NUL-byte."); + fail_unless(XML_GetErrorCode(parser) == XML_ERROR_BAD_CHAR_REF, + "Got wrong error code for �."); +} +END_TEST + + +static Suite * +make_basic_suite(void) +{ + Suite *s = suite_create("basic"); + TCase *tc_nulls = tcase_create("null characters"); + + suite_add_tcase(s, tc_nulls); + tcase_set_fixture(tc_nulls, basic_setup, basic_teardown); + tcase_add_test(tc_nulls, test_nul_byte); + tcase_add_test(tc_nulls, test_u0000_char); + + return s; +} + + +int +main(int argc, char *argv[]) +{ + int nf; + int verbosity = CRNORMAL; + Suite *s = make_basic_suite(); + SRunner *sr = srunner_create(s); + + if (argc >= 2) { + char *opt = argv[1]; + if (strcmp(opt, "-v") == 0 || strcmp(opt, "--verbose") == 0) + verbosity = CRVERBOSE; + else if (strcmp(opt, "-q") == 0 || strcmp(opt, "--quiet") == 0) + verbosity = CRSILENT; + } + srunner_run_all(sr, verbosity); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + suite_free(s); + + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} -- 2.40.0