5 #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED)
6 #include <libxml/globals.h>
7 #include <libxml/threads.h>
8 #include <libxml/parser.h>
9 #include <libxml/catalog.h>
15 #define TEST_REPEAT_COUNT 500
17 static HANDLE tid[MAX_ARGC];
19 static const char *catalog = "test/threads/complex.xml";
20 static char *testfiles[] = {
21 "test/threads/abc.xml",
22 "test/threads/acb.xml",
23 "test/threads/bac.xml",
24 "test/threads/bca.xml",
25 "test/threads/cab.xml",
26 "test/threads/cba.xml",
27 "test/threads/invalid.xml",
30 const char *Okay = "OK";
31 const char *Failed = "Failed";
33 #ifndef xmlDoValidityCheckingDefaultValue
34 #error xmlDoValidityCheckingDefaultValue is not a macro
36 #ifndef xmlGenericErrorContext
37 #error xmlGenericErrorContext is not a macro
41 thread_specific_data(void *private_data)
44 const char *filename = (const char *) private_data;
47 if (!strcmp(filename, "test/threads/invalid.xml")) {
48 xmlDoValidityCheckingDefaultValue = 0;
49 xmlGenericErrorContext = stdout;
51 xmlDoValidityCheckingDefaultValue = 1;
52 xmlGenericErrorContext = stderr;
54 myDoc = xmlParseFile(filename);
58 printf("parse failed\n");
61 if (!strcmp(filename, "test/threads/invalid.xml")) {
62 if (xmlDoValidityCheckingDefaultValue != 0) {
63 printf("ValidityCheckingDefaultValue override failed\n");
66 if (xmlGenericErrorContext != stdout) {
67 printf("xmlGenericErrorContext override failed\n");
71 if (xmlDoValidityCheckingDefaultValue != 1) {
72 printf("ValidityCheckingDefaultValue override failed\n");
75 if (xmlGenericErrorContext != stderr) {
76 printf("xmlGenericErrorContext override failed\n");
81 return ((DWORD) Failed);
82 return ((DWORD) Okay);
88 unsigned int i, repeat;
89 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
90 DWORD results[MAX_ARGC];
94 for (repeat = 0;repeat < TEST_REPEAT_COUNT;repeat++)
96 xmlLoadCatalog(catalog);
98 for (i = 0; i < num_threads; i++)
101 tid[i] = (HANDLE) -1;
104 for (i = 0; i < num_threads; i++)
107 tid[i] = CreateThread(NULL, 0,
108 thread_specific_data, testfiles[i], 0, &useless);
111 perror("CreateThread");
116 if (WaitForMultipleObjects (num_threads, tid, TRUE, INFINITE) == WAIT_FAILED)
117 perror ("WaitForMultipleObjects failed");
119 for (i = 0; i < num_threads; i++)
121 ret = GetExitCodeThread (tid[i], &results[i]);
124 perror("GetExitCodeThread");
127 CloseHandle (tid[i]);
131 for (i = 0; i < num_threads; i++) {
132 if (results[i] != (DWORD) Okay)
133 printf("Thread %d handling %s failed\n", i, testfiles[i]);
143 #else /* !LIBXML_THREADS_ENABLED */
147 fprintf(stderr, "libxml was not compiled with thread or catalog support\n");