Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 2 | #include <stdio.h> |
Daniel Veillard | 2a90682 | 2001-12-06 14:34:08 +0000 | [diff] [blame] | 3 | #include "libxml.h" |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 4 | |
Daniel Veillard | a4617b8 | 2001-11-04 20:19:12 +0000 | [diff] [blame] | 5 | #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED) |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 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> |
Igor Zlatkovic | 082ff50 | 2002-10-31 15:59:09 +0000 | [diff] [blame] | 12 | #if !defined(_MSC_VER) |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 13 | #include <unistd.h> |
Igor Zlatkovic | 082ff50 | 2002-10-31 15:59:09 +0000 | [diff] [blame] | 14 | #endif |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 15 | #include <assert.h> |
| 16 | |
| 17 | #define MAX_ARGC 20 |
| 18 | static pthread_t tid[MAX_ARGC]; |
| 19 | |
| 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", |
| 29 | }; |
| 30 | |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 31 | const char *Okay = "OK"; |
| 32 | const char *Failed = "Failed"; |
| 33 | |
| 34 | #ifndef xmlDoValidityCheckingDefaultValue |
| 35 | #error xmlDoValidityCheckingDefaultValue is not a macro |
| 36 | #endif |
| 37 | #ifndef xmlGenericErrorContext |
| 38 | #error xmlGenericErrorContext is not a macro |
| 39 | #endif |
| 40 | |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 41 | static void * |
| 42 | thread_specific_data(void *private_data) |
| 43 | { |
| 44 | xmlDocPtr myDoc; |
| 45 | const char *filename = (const char *) private_data; |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 46 | int okay = 1; |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 47 | |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 48 | if (!strcmp(filename, "test/threads/invalid.xml")) { |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 49 | xmlDoValidityCheckingDefaultValue = 0; |
| 50 | xmlGenericErrorContext = stdout; |
| 51 | } else { |
| 52 | xmlDoValidityCheckingDefaultValue = 1; |
| 53 | xmlGenericErrorContext = stderr; |
| 54 | } |
| 55 | myDoc = xmlParseFile(filename); |
| 56 | if (myDoc) { |
| 57 | xmlFreeDoc(myDoc); |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 58 | } else { |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 59 | printf("parse failed\n"); |
| 60 | okay = 0; |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 61 | } |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 62 | if (!strcmp(filename, "test/threads/invalid.xml")) { |
| 63 | if (xmlDoValidityCheckingDefaultValue != 0) { |
| 64 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 65 | okay = 0; |
| 66 | } |
| 67 | if (xmlGenericErrorContext != stdout) { |
| 68 | printf("xmlGenericErrorContext override failed\n"); |
| 69 | okay = 0; |
| 70 | } |
| 71 | } else { |
| 72 | if (xmlDoValidityCheckingDefaultValue != 1) { |
| 73 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 74 | okay = 0; |
| 75 | } |
| 76 | if (xmlGenericErrorContext != stderr) { |
| 77 | printf("xmlGenericErrorContext override failed\n"); |
| 78 | okay = 0; |
| 79 | } |
| 80 | } |
| 81 | if (okay == 0) |
| 82 | return((void *) Failed); |
| 83 | return ((void *) Okay); |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | int |
| 87 | main() |
| 88 | { |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 89 | unsigned int i, repeat; |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 90 | unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 91 | void *results[MAX_ARGC]; |
| 92 | int ret; |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 93 | |
| 94 | xmlInitParser(); |
Daniel Veillard | 89cad53 | 2001-10-22 09:46:13 +0000 | [diff] [blame] | 95 | for (repeat = 0;repeat < 500;repeat++) { |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 96 | xmlLoadCatalog(catalog); |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 97 | |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 98 | for (i = 0; i < num_threads; i++) { |
| 99 | results[i] = NULL; |
Daniel Veillard | d3b0882 | 2001-12-05 12:03:33 +0000 | [diff] [blame] | 100 | tid[i] = (pthread_t) -1; |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 101 | } |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 102 | |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 103 | for (i = 0; i < num_threads; i++) { |
| 104 | ret = pthread_create(&tid[i], 0, thread_specific_data, |
| 105 | (void *) testfiles[i]); |
| 106 | if (ret != 0) { |
| 107 | perror("pthread_create"); |
| 108 | exit(1); |
| 109 | } |
| 110 | } |
| 111 | for (i = 0; i < num_threads; i++) { |
| 112 | ret = pthread_join(tid[i], &results[i]); |
| 113 | if (ret != 0) { |
| 114 | perror("pthread_join"); |
| 115 | exit(1); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | xmlCatalogCleanup(); |
| 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]); |
| 123 | } |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 124 | xmlCleanupParser(); |
| 125 | xmlMemoryDump(); |
| 126 | return (0); |
| 127 | } |
| 128 | |
| 129 | #else /* !LIBXML_THREADS_ENABLED */ |
| 130 | int |
Daniel Veillard | 118aed7 | 2002-09-24 14:13:13 +0000 | [diff] [blame] | 131 | main(void) |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 132 | { |
Daniel Veillard | a4617b8 | 2001-11-04 20:19:12 +0000 | [diff] [blame] | 133 | fprintf(stderr, "libxml was not compiled with thread or catalog support\n"); |
Daniel Veillard | ab7488e | 2001-10-17 11:30:37 +0000 | [diff] [blame] | 134 | return (0); |
| 135 | } |
| 136 | #endif |