6 #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_SAX1_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 myDoc = xmlParseFile(filename);
68 printf("parse failed\n");
71 if (!strcmp(filename, "test/threads/invalid.xml")) {
72 if (xmlDoValidityCheckingDefaultValue != 0) {
73 printf("ValidityCheckingDefaultValue override failed\n");
76 if (xmlGenericErrorContext != stdout) {
77 printf("xmlGenericErrorContext override failed\n");
81 if (xmlDoValidityCheckingDefaultValue != 1) {
82 printf("ValidityCheckingDefaultValue override failed\n");
85 if (xmlGenericErrorContext != stderr) {
86 printf("xmlGenericErrorContext override failed\n");
91 return((void *) Failed);
92 return ((void *) Okay);
99 unsigned int i, repeat;
100 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
101 void *results[MAX_ARGC];
105 for (repeat = 0;repeat < 500;repeat++) {
106 xmlLoadCatalog(catalog);
108 memset(results, 0, sizeof(*results)*num_threads);
109 memset(tid, 0xff, sizeof(*tid)*num_threads);
111 for (i = 0; i < num_threads; i++) {
112 ret = pthread_create(&tid[i], NULL, thread_specific_data,
113 (void *) testfiles[i]);
115 perror("pthread_create");
119 for (i = 0; i < num_threads; i++) {
120 ret = pthread_join(tid[i], &results[i]);
122 perror("pthread_join");
128 for (i = 0; i < num_threads; i++)
129 if (results[i] != (void *) Okay)
130 printf("Thread %d handling %s failed\n", i, testfiles[i]);
136 #elif defined HAVE_BEOS_THREADS
140 unsigned int i, repeat;
141 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
142 void *results[MAX_ARGC];
146 printf("Parser initialized\n");
147 for (repeat = 0;repeat < 500;repeat++) {
148 printf("repeat: %d\n",repeat);
149 xmlLoadCatalog(catalog);
150 printf("loaded catalog: %s\n", catalog);
151 for (i = 0; i < num_threads; i++) {
153 tid[i] = (thread_id) -1;
155 printf("cleaned threads\n");
156 for (i = 0; i < num_threads; i++) {
157 tid[i] = spawn_thread(thread_specific_data, "xmlTestThread", B_NORMAL_PRIORITY, (void *) testfiles[i]);
159 perror("beos_thread_create");
162 printf("beos_thread_create %d -> %d\n", i, tid[i]);
164 for (i = 0; i < num_threads; i++) {
165 ret = wait_for_thread(tid[i], &results[i]);
166 printf("beos_thread_wait %d -> %d\n", i, ret);
168 perror("beos_thread_wait");
175 for (i = 0; i < num_threads; i++)
176 if (results[i] != (void *) Okay) {
177 printf("Thread %d handling %s failed\n", i, testfiles[i]);
185 printf("testThread : BeOS : SUCCESS!\n");
187 printf("testThread : BeOS : FAILED!\n");
191 #endif /* pthreads or BeOS threads */
193 #else /* !LIBXML_THREADS_ENABLED */
197 fprintf(stderr, "libxml was not compiled with thread or catalog support\n");