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
for (i = 0; i < num_threads; i++) {
110
tid[i] = (pthread_t) -1;
113
for (i = 0; i < num_threads; i++) {
114
ret = pthread_create(&tid[i], NULL, thread_specific_data,
115
(void *) testfiles[i]);
117
perror("pthread_create");
121
for (i = 0; i < num_threads; i++) {
122
ret = pthread_join(tid[i], &results[i]);
124
perror("pthread_join");
130
for (i = 0; i < num_threads; i++)
131
if (results[i] != (void *) Okay)
132
printf("Thread %d handling %s failed\n", i, testfiles[i]);
138
#elif defined HAVE_BEOS_THREADS
142
unsigned int i, repeat;
143
unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
144
void *results[MAX_ARGC];
148
printf("Parser initialized\n");
149
for (repeat = 0;repeat < 500;repeat++) {
150
printf("repeat: %d\n",repeat);
151
xmlLoadCatalog(catalog);
152
printf("loaded catalog: %s\n", catalog);
153
for (i = 0; i < num_threads; i++) {
155
tid[i] = (thread_id) -1;
157
printf("cleaned threads\n");
158
for (i = 0; i < num_threads; i++) {
159
tid[i] = spawn_thread(thread_specific_data, "xmlTestThread", B_NORMAL_PRIORITY, (void *) testfiles[i]);
161
perror("beos_thread_create");
164
printf("beos_thread_create %d -> %d\n", i, tid[i]);
166
for (i = 0; i < num_threads; i++) {
167
ret = wait_for_thread(tid[i], &results[i]);
168
printf("beos_thread_wait %d -> %d\n", i, ret);
170
perror("beos_thread_wait");
177
for (i = 0; i < num_threads; i++)
178
if (results[i] != (void *) Okay) {
179
printf("Thread %d handling %s failed\n", i, testfiles[i]);
187
printf("testThread : BeOS : SUCCESS!\n");
189
printf("testThread : BeOS : FAILED!\n");
193
#endif /* pthreads or BeOS threads */
195
#else /* !LIBXML_THREADS_ENABLED */
199
fprintf(stderr, "libxml was not compiled with thread or catalog support\n");