Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame^] | 1 | #include <stdlib.h> |
| 2 | #include <features.h> |
| 3 | #include <libxml/xmlversion.h> |
| 4 | |
| 5 | #ifdef LIBXML_THREAD_ENABLED |
| 6 | #include <libxml/globals.h> |
| 7 | #include <libxml/threads.h> |
| 8 | #include <libxml/parser.h> |
| 9 | #include <libxml/catalog.h> |
| 10 | #include <pthread.h> |
| 11 | #include <string.h> |
| 12 | #include <unistd.h> |
| 13 | #include <assert.h> |
| 14 | |
| 15 | #define MAX_ARGC 20 |
| 16 | static pthread_t tid[MAX_ARGC]; |
| 17 | |
| 18 | static const char *catalog = "test/threads/complex.xml"; |
| 19 | static const char *testfiles[] = { |
| 20 | "test/threads/abc.xml", |
| 21 | "test/threads/acb.xml", |
| 22 | "test/threads/bac.xml", |
| 23 | "test/threads/bca.xml", |
| 24 | "test/threads/cab.xml", |
| 25 | "test/threads/cba.xml", |
| 26 | "test/threads/invalid.xml", |
| 27 | }; |
| 28 | |
| 29 | static void * |
| 30 | thread_specific_data(void *private_data) |
| 31 | { |
| 32 | xmlDocPtr myDoc; |
| 33 | const char *filename = (const char *) private_data; |
| 34 | |
| 35 | if (!strcmp(filename, "test/thread/invalid.xml") == 0) { |
| 36 | xmlDoValidityCheckingDefaultValue = 0; |
| 37 | xmlGenericErrorContext = stdout; |
| 38 | } else { |
| 39 | xmlDoValidityCheckingDefaultValue = 1; |
| 40 | xmlGenericErrorContext = stderr; |
| 41 | } |
| 42 | myDoc = xmlParseFile(filename); |
| 43 | if (myDoc) { |
| 44 | xmlFreeDoc(myDoc); |
| 45 | } else |
| 46 | printf("parse failed\n"); |
| 47 | if (!strcmp(filename, "test/thread/invalid.xml") == 0) { |
| 48 | if (xmlDoValidityCheckingDefaultValue != 0) |
| 49 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 50 | if (xmlGenericErrorContext != stdout) |
| 51 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 52 | } else { |
| 53 | if (xmlDoValidityCheckingDefaultValue != 1) |
| 54 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 55 | if (xmlGenericErrorContext != stderr) |
| 56 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 57 | } |
| 58 | return (NULL); |
| 59 | } |
| 60 | |
| 61 | int |
| 62 | main() |
| 63 | { |
| 64 | unsigned int i; |
| 65 | unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); |
| 66 | |
| 67 | xmlInitParser(); |
| 68 | xmlLoadCatalog(catalog); |
| 69 | |
| 70 | for (i = 0; i < num_threads; i++) |
| 71 | pthread_create(&tid[i], 0, thread_specific_data, (void *) testfiles[i]); |
| 72 | for (i = 0; i < num_threads; i++) |
| 73 | pthread_join(tid[i], NULL); |
| 74 | |
| 75 | xmlCleanupParser(); |
| 76 | xmlMemoryDump(); |
| 77 | return (0); |
| 78 | } |
| 79 | |
| 80 | #else /* !LIBXML_THREADS_ENABLED */ |
| 81 | int |
| 82 | main() |
| 83 | { |
| 84 | fprintf(stderr, "libxml was not compiled with thread support\n"); |
| 85 | return (0); |
| 86 | } |
| 87 | #endif |