6 #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED)
7 #include <libxml/globals.h>
8 #include <libxml/threads.h>
9 #include <libxml/parser.h>
10 #include <libxml/catalog.h>
13 #elif defined HAVE_BEOS_THREADS
17 #if !defined(_MSC_VER)
24 static pthread_t tid[MAX_ARGC];
25 #elif defined HAVE_BEOS_THREADS
26 static thread_id tid[MAX_ARGC];
29 static const char *catalog = "test/threads/complex.xml";
30 static const char *testfiles[] = {
31 "test/threads/abc.xml",
32 "test/threads/acb.xml",
33 "test/threads/bac.xml",
34 "test/threads/bca.xml",
35 "test/threads/cab.xml",
36 "test/threads/cba.xml",
37 "test/threads/invalid.xml",
40 static const char *Okay = "OK";
41 static const char *Failed = "Failed";
43 #ifndef xmlDoValidityCheckingDefaultValue
44 #error xmlDoValidityCheckingDefaultValue is not a macro
46 #ifndef xmlGenericErrorContext
47 #error xmlGenericErrorContext is not a macro
51 thread_specific_data(void *private_data)
54 const char *filename = (const char *) private_data;
57 if (!strcmp(filename, "test/threads/invalid.xml")) {
58 xmlDoValidityCheckingDefaultValue = 0;
59 xmlGenericErrorContext = stdout;
61 xmlDoValidityCheckingDefaultValue = 1;
62 xmlGenericErrorContext = stderr;
64 #ifdef LIBXML_SAX1_ENABLED
65 myDoc = xmlParseFile(filename);
67 myDoc = xmlReadFile(filename, NULL, XML_WITH_CATALOG);
72 printf("parse failed\n");
75 if (!strcmp(filename, "test/threads/invalid.xml")) {
76 if (xmlDoValidityCheckingDefaultValue != 0) {
77 printf("ValidityCheckingDefaultValue override failed\n");
80 if (xmlGenericErrorContext != stdout) {
81 printf("xmlGenericErrorContext override failed\n");
85 if (xmlDoValidityCheckingDefaultValue != 1) {
86 printf("ValidityCheckingDefaultValue override failed\n");
89 if (xmlGenericErrorContext != stderr) {
90 printf("xmlGenericErrorContext override failed\n");
95 return((void *) Failed);
96 return ((void *) Okay);
103 unsigned int i, repeat;
104 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
105 void *results[MAX_ARGC];
109 for (repeat = 0;repeat < 500;repeat++) {
110 xmlLoadCatalog(catalog);
112 memset(results, 0, sizeof(*results)*num_threads);
113 memset(tid, 0xff, sizeof(*tid)*num_threads);
115 for (i = 0; i < num_threads; i++) {
116 ret = pthread_create(&tid[i], NULL, thread_specific_data,
117 (void *) testfiles[i]);
119 perror("pthread_create");
123 for (i = 0; i < num_threads; i++) {
124 ret = pthread_join(tid[i], &results[i]);
126 perror("pthread_join");
132 for (i = 0; i < num_threads; i++)
133 if (results[i] != (void *) Okay)
134 printf("Thread %d handling %s failed\n", i, testfiles[i]);
140 #elif defined HAVE_BEOS_THREADS
144 unsigned int i, repeat;
145 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
146 void *results[MAX_ARGC];
150 printf("Parser initialized\n");
151 for (repeat = 0;repeat < 500;repeat++) {
152 printf("repeat: %d\n",repeat);
153 xmlLoadCatalog(catalog);
154 printf("loaded catalog: %s\n", catalog);
155 for (i = 0; i < num_threads; i++) {
157 tid[i] = (thread_id) -1;
159 printf("cleaned threads\n");
160 for (i = 0; i < num_threads; i++) {
161 tid[i] = spawn_thread(thread_specific_data, "xmlTestThread", B_NORMAL_PRIORITY, (void *) testfiles[i]);
163 perror("beos_thread_create");
166 printf("beos_thread_create %d -> %d\n", i, tid[i]);
168 for (i = 0; i < num_threads; i++) {
169 ret = wait_for_thread(tid[i], &results[i]);
170 printf("beos_thread_wait %d -> %d\n", i, ret);
172 perror("beos_thread_wait");
179 for (i = 0; i < num_threads; i++)
180 if (results[i] != (void *) Okay) {
181 printf("Thread %d handling %s failed\n", i, testfiles[i]);
189 printf("testThread : BeOS : SUCCESS!\n");
191 printf("testThread : BeOS : FAILED!\n");
195 #endif /* pthreads or BeOS threads */
197 #else /* !LIBXML_THREADS_ENABLED */
201 fprintf(stderr, "libxml was not compiled with thread or catalog support\n");