summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-09-25 16:04:37 -0700
committerElliott Hughes <enh@google.com>2009-09-25 16:04:37 -0700
commitd07d5a72938fd52415368c2320fc29575ae9a0c3 (patch)
tree0c51b66a56e624bcd9729cec0454f4e3febddeb8 /tests
parentc5b20fe9deacede72276a0c39142fa8397aa4602 (diff)
downloadexpat-d07d5a72938fd52415368c2320fc29575ae9a0c3.tar.gz
Update expat to 2.0.1.
We had one local patch relative to 2.0.0, in "xmltok_impl.c". That fix isn't in 2.0.1, but an equivalent patch is in expat CVS. I've gone with the upstream change, and surrounded it with BEGIN/END android-changed comments. Bug: 2086506
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmark/benchmark.c22
-rw-r--r--tests/minicheck.c12
-rw-r--r--tests/minicheck.h9
-rw-r--r--tests/runtests.c108
4 files changed, 110 insertions, 41 deletions
diff --git a/tests/benchmark/benchmark.c b/tests/benchmark/benchmark.c
index 86266a00..0f0fd18c 100644
--- a/tests/benchmark/benchmark.c
+++ b/tests/benchmark/benchmark.c
@@ -4,6 +4,10 @@
#include <time.h>
#include "expat.h"
+#if defined(__amigaos__) && defined(__USE_INLINE__)
+#include <proto/expat.h>
+#endif
+
#ifdef XML_LARGE_SIZE
#define XML_FMT_INT_MOD "ll"
#else
@@ -18,13 +22,7 @@ usage(const char *prog, int rc)
exit(rc);
}
-#ifdef AMIGA_SHARED_LIB
-#include <proto/expat.h>
-int
-amiga_main(int argc, char *argv[])
-#else
int main (int argc, char *argv[])
-#endif
{
XML_Parser parser;
char *XMLBuf, *XMLBufEnd, *XMLBufPtr;
@@ -72,15 +70,16 @@ int main (int argc, char *argv[])
fileSize = fread (XMLBuf, sizeof (char), fileAttr.st_size, fd);
fclose (fd);
+ if (ns)
+ parser = XML_ParserCreateNS(NULL, '!');
+ else
+ parser = XML_ParserCreate(NULL);
+
i = 0;
XMLBufEnd = XMLBuf + fileSize;
while (i < nrOfLoops) {
XMLBufPtr = XMLBuf;
isFinal = 0;
- if (ns)
- parser = XML_ParserCreateNS(NULL, '!');
- else
- parser = XML_ParserCreate(NULL);
tstart = clock();
do {
int parseBufferSize = XMLBufEnd - XMLBufPtr;
@@ -102,10 +101,11 @@ int main (int argc, char *argv[])
} while (!isFinal);
tend = clock();
cpuTime += ((double) (tend - tstart)) / CLOCKS_PER_SEC;
- XML_ParserFree (parser);
+ XML_ParserReset(parser, NULL);
i++;
}
+ XML_ParserFree (parser);
free (XMLBuf);
printf ("%d loops, with buffer size %d. Average time per loop: %f\n",
diff --git a/tests/minicheck.c b/tests/minicheck.c
index 25fbf858..d2f4295f 100644
--- a/tests/minicheck.c
+++ b/tests/minicheck.c
@@ -82,12 +82,6 @@ srunner_create(Suite *suite)
return runner;
}
-void
-srunner_set_fork_status(SRunner *runner, int status)
-{
- /* We ignore this. */
-}
-
static jmp_buf env;
static char const *_check_current_function = NULL;
@@ -164,6 +158,12 @@ srunner_run_all(SRunner *runner, int verbosity)
void
_fail_unless(int condition, const char *file, int line, char *msg)
{
+ /* Always print the error message so it isn't lost. In this case,
+ we have a failure, so there's no reason to be quiet about what
+ it is.
+ */
+ if (msg != NULL)
+ printf("%s", msg);
longjmp(env, 1);
}
diff --git a/tests/minicheck.h b/tests/minicheck.h
index c8a1d5e9..f846bead 100644
--- a/tests/minicheck.h
+++ b/tests/minicheck.h
@@ -18,6 +18,13 @@ extern "C" {
#define CK_NORMAL 1
#define CK_VERBOSE 2
+/* Workaround for Tru64 Unix systems where the C compiler has a working
+ __func__, but the C++ compiler only has a working __FUNCTION__. This
+ could be fixed in configure.in, but it's not worth it right now. */
+#if defined(__osf__) && defined(__cplusplus)
+#define __func__ __FUNCTION__
+#endif
+
#define START_TEST(testname) static void testname(void) { \
_check_set_test_info(__func__, __FILE__, __LINE__); \
{
@@ -35,7 +42,6 @@ typedef struct TCase TCase;
struct SRunner {
Suite *suite;
- int forking;
int nchecks;
int nfailures;
};
@@ -74,7 +80,6 @@ void tcase_add_checked_fixture(TCase *,
tcase_teardown_function);
void tcase_add_test(TCase *tc, tcase_test_function test);
SRunner *srunner_create(Suite *suite);
-void srunner_set_fork_status(SRunner *runner, int forking);
void srunner_run_all(SRunner *runner, int verbosity);
int srunner_ntests_failed(SRunner *runner);
void srunner_free(SRunner *runner);
diff --git a/tests/runtests.c b/tests/runtests.c
index 088fe6f7..3521c086 100644
--- a/tests/runtests.c
+++ b/tests/runtests.c
@@ -17,7 +17,7 @@
#include "chardata.h"
#include "minicheck.h"
-#ifdef AMIGA_SHARED_LIB
+#if defined(__amigaos__) && defined(__USE_INLINE__)
#include <proto/expat.h>
#endif
@@ -53,10 +53,12 @@ static void
_xml_failure(XML_Parser parser, const char *file, int line)
{
char buffer[1024];
+ enum XML_Error err = XML_GetErrorCode(parser);
sprintf(buffer,
- "\n %s (line %" XML_FMT_INT_MOD "u, offset %"\
- XML_FMT_INT_MOD "u)\n reported from %s, line %d",
- XML_ErrorString(XML_GetErrorCode(parser)),
+ " %d: %s (line %" XML_FMT_INT_MOD "u, offset %"\
+ XML_FMT_INT_MOD "u)\n reported from %s, line %d\n",
+ err,
+ XML_ErrorString(err),
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser),
file, line);
@@ -362,7 +364,7 @@ END_TEST
START_TEST(test_utf16_le_epilog_newline)
{
- int first_chunk_bytes = 17;
+ unsigned int first_chunk_bytes = 17;
char text[] =
"\xFF\xFE" /* BOM */
"<\000e\000/\000>\000" /* document element */
@@ -982,6 +984,82 @@ START_TEST(test_ns_in_attribute_default_without_namespaces)
}
END_TEST
+static char *long_character_data_text =
+ "<?xml version='1.0' encoding='iso-8859-1'?><s>"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "</s>";
+
+static XML_Bool resumable = XML_FALSE;
+
+static void
+clearing_aborting_character_handler(void *userData,
+ const XML_Char *s, int len)
+{
+ XML_StopParser(parser, resumable);
+ XML_SetCharacterDataHandler(parser, NULL);
+}
+
+/* Regression test for SF bug #1515266: missing check of stopped
+ parser in doContext() 'for' loop. */
+START_TEST(test_stop_parser_between_char_data_calls)
+{
+ /* The sample data must be big enough that there are two calls to
+ the character data handler from within the inner "for" loop of
+ the XML_TOK_DATA_CHARS case in doContent(), and the character
+ handler must stop the parser and clear the character data
+ handler.
+ */
+ char *text = long_character_data_text;
+
+ XML_SetCharacterDataHandler(parser, clearing_aborting_character_handler);
+ resumable = XML_FALSE;
+ if (XML_Parse(parser, text, strlen(text), XML_TRUE) != XML_STATUS_ERROR)
+ xml_failure(parser);
+ if (XML_GetErrorCode(parser) != XML_ERROR_ABORTED)
+ xml_failure(parser);
+}
+END_TEST
+
+/* Regression test for SF bug #1515266: missing check of stopped
+ parser in doContext() 'for' loop. */
+START_TEST(test_suspend_parser_between_char_data_calls)
+{
+ /* The sample data must be big enough that there are two calls to
+ the character data handler from within the inner "for" loop of
+ the XML_TOK_DATA_CHARS case in doContent(), and the character
+ handler must stop the parser and clear the character data
+ handler.
+ */
+ char *text = long_character_data_text;
+
+ XML_SetCharacterDataHandler(parser, clearing_aborting_character_handler);
+ resumable = XML_TRUE;
+ if (XML_Parse(parser, text, strlen(text), XML_TRUE) != XML_STATUS_SUSPENDED)
+ xml_failure(parser);
+ if (XML_GetErrorCode(parser) != XML_ERROR_NONE)
+ xml_failure(parser);
+}
+END_TEST
+
/*
* Namespaces tests.
@@ -1176,7 +1254,7 @@ external_entity_handler(XML_Parser parser,
const XML_Char *systemId,
const XML_Char *publicId)
{
- int callno = 1 + (int)XML_GetUserData(parser);
+ long callno = 1 + (long)XML_GetUserData(parser);
char *text;
XML_Parser p2;
@@ -1380,6 +1458,8 @@ make_suite(void)
tcase_add_test(tc_basic, test_dtd_default_handling);
tcase_add_test(tc_basic, test_empty_ns_without_namespaces);
tcase_add_test(tc_basic, test_ns_in_attribute_default_without_namespaces);
+ tcase_add_test(tc_basic, test_stop_parser_between_char_data_calls);
+ tcase_add_test(tc_basic, test_suspend_parser_between_char_data_calls);
suite_add_tcase(s, tc_namespace);
tcase_add_checked_fixture(tc_namespace,
@@ -1402,16 +1482,10 @@ make_suite(void)
}
-#ifdef AMIGA_SHARED_LIB
-int
-amiga_main(int argc, char *argv[])
-#else
int
main(int argc, char *argv[])
-#endif
{
int i, nf;
- int forking = 0, forking_set = 0;
int verbosity = CK_NORMAL;
Suite *s = make_suite();
SRunner *sr = srunner_create(s);
@@ -1425,21 +1499,11 @@ main(int argc, char *argv[])
verbosity = CK_VERBOSE;
else if (strcmp(opt, "-q") == 0 || strcmp(opt, "--quiet") == 0)
verbosity = CK_SILENT;
- else if (strcmp(opt, "-f") == 0 || strcmp(opt, "--fork") == 0) {
- forking = 1;
- forking_set = 1;
- }
- else if (strcmp(opt, "-n") == 0 || strcmp(opt, "--no-fork") == 0) {
- forking = 0;
- forking_set = 1;
- }
else {
fprintf(stderr, "runtests: unknown option '%s'\n", opt);
return 2;
}
}
- if (forking_set)
- srunner_set_fork_status(sr, forking ? CK_FORK : CK_NOFORK);
if (verbosity != CK_SILENT)
printf("Expat version: %s\n", XML_ExpatVersion());
srunner_run_all(sr, verbosity);