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>
12 #if !defined(_MSC_VER)
18 static pthread_t tid
[MAX_ARGC
];
20 static const char *catalog
= "test/threads/complex.xml";
21 static const char *testfiles
[] = {
22 "test/threads/abc.xml",
23 "test/threads/acb.xml",
24 "test/threads/bac.xml",
25 "test/threads/bca.xml",
26 "test/threads/cab.xml",
27 "test/threads/cba.xml",
28 "test/threads/invalid.xml",
31 const char *Okay
= "OK";
32 const char *Failed
= "Failed";
34 #ifndef xmlDoValidityCheckingDefaultValue
35 #error xmlDoValidityCheckingDefaultValue is not a macro
37 #ifndef xmlGenericErrorContext
38 #error xmlGenericErrorContext is not a macro
42 thread_specific_data(void *private_data
)
45 const char *filename
= (const char *) private_data
;
48 if (!strcmp(filename
, "test/threads/invalid.xml")) {
49 xmlDoValidityCheckingDefaultValue
= 0;
50 xmlGenericErrorContext
= stdout
;
52 xmlDoValidityCheckingDefaultValue
= 1;
53 xmlGenericErrorContext
= stderr
;
55 myDoc
= xmlParseFile(filename
);
59 printf("parse failed\n");
62 if (!strcmp(filename
, "test/threads/invalid.xml")) {
63 if (xmlDoValidityCheckingDefaultValue
!= 0) {
64 printf("ValidityCheckingDefaultValue override failed\n");
67 if (xmlGenericErrorContext
!= stdout
) {
68 printf("xmlGenericErrorContext override failed\n");
72 if (xmlDoValidityCheckingDefaultValue
!= 1) {
73 printf("ValidityCheckingDefaultValue override failed\n");
76 if (xmlGenericErrorContext
!= stderr
) {
77 printf("xmlGenericErrorContext override failed\n");
82 return((void *) Failed
);
83 return ((void *) Okay
);
89 unsigned int i
, repeat
;
90 unsigned int num_threads
= sizeof(testfiles
) / sizeof(testfiles
[0]);
91 void *results
[MAX_ARGC
];
95 for (repeat
= 0;repeat
< 500;repeat
++) {
96 xmlLoadCatalog(catalog
);
98 for (i
= 0; i
< num_threads
; i
++) {
100 tid
[i
] = (pthread_t
) -1;
103 for (i
= 0; i
< num_threads
; i
++) {
104 ret
= pthread_create(&tid
[i
], 0, thread_specific_data
,
105 (void *) testfiles
[i
]);
107 perror("pthread_create");
111 for (i
= 0; i
< num_threads
; i
++) {
112 ret
= pthread_join(tid
[i
], &results
[i
]);
114 perror("pthread_join");
120 for (i
= 0; i
< num_threads
; i
++)
121 if (results
[i
] != (void *) Okay
)
122 printf("Thread %d handling %s failed\n", i
, testfiles
[i
]);
129 #else /* !LIBXML_THREADS_ENABLED */
133 fprintf(stderr
, "libxml was not compiled with thread or catalog support\n");