Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > DoxygentestThreads.c
Go to the documentation of this file.
00001 #include "libxml.h" 00002 00003 #include <stdlib.h> 00004 #include <stdio.h> 00005 00006 #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED) && defined(LIBXML_SAX1_ENABLED) 00007 #include <libxml/globals.h> 00008 #include <libxml/threads.h> 00009 #include <libxml/parser.h> 00010 #include <libxml/catalog.h> 00011 #ifdef HAVE_PTHREAD_H 00012 #include <pthread.h> 00013 #elif defined HAVE_BEOS_THREADS 00014 #include <OS.h> 00015 #endif 00016 #include <string.h> 00017 #if !defined(_MSC_VER) 00018 #include <unistd.h> 00019 #endif 00020 #include <assert.h> 00021 00022 #define MAX_ARGC 20 00023 #ifdef HAVE_PTHREAD_H 00024 static pthread_t tid[MAX_ARGC]; 00025 #elif defined HAVE_BEOS_THREADS 00026 static thread_id tid[MAX_ARGC]; 00027 #endif 00028 00029 static const char *catalog = "test/threads/complex.xml"; 00030 static const char *testfiles[] = { 00031 "test/threads/abc.xml", 00032 "test/threads/acb.xml", 00033 "test/threads/bac.xml", 00034 "test/threads/bca.xml", 00035 "test/threads/cab.xml", 00036 "test/threads/cba.xml", 00037 "test/threads/invalid.xml", 00038 }; 00039 00040 static const char *Okay = "OK"; 00041 static const char *Failed = "Failed"; 00042 00043 #ifndef xmlDoValidityCheckingDefaultValue 00044 #error xmlDoValidityCheckingDefaultValue is not a macro 00045 #endif 00046 #ifndef xmlGenericErrorContext 00047 #error xmlGenericErrorContext is not a macro 00048 #endif 00049 00050 static void * 00051 thread_specific_data(void *private_data) 00052 { 00053 xmlDocPtr myDoc; 00054 const char *filename = (const char *) private_data; 00055 int okay = 1; 00056 00057 if (!strcmp(filename, "test/threads/invalid.xml")) { 00058 xmlDoValidityCheckingDefaultValue = 0; 00059 xmlGenericErrorContext = stdout; 00060 } else { 00061 xmlDoValidityCheckingDefaultValue = 1; 00062 xmlGenericErrorContext = stderr; 00063 } 00064 myDoc = xmlParseFile(filename); 00065 if (myDoc) { 00066 xmlFreeDoc(myDoc); 00067 } else { 00068 printf("parse failed\n"); 00069 okay = 0; 00070 } 00071 if (!strcmp(filename, "test/threads/invalid.xml")) { 00072 if (xmlDoValidityCheckingDefaultValue != 0) { 00073 printf("ValidityCheckingDefaultValue override failed\n"); 00074 okay = 0; 00075 } 00076 if (xmlGenericErrorContext != stdout) { 00077 printf("xmlGenericErrorContext override failed\n"); 00078 okay = 0; 00079 } 00080 } else { 00081 if (xmlDoValidityCheckingDefaultValue != 1) { 00082 printf("ValidityCheckingDefaultValue override failed\n"); 00083 okay = 0; 00084 } 00085 if (xmlGenericErrorContext != stderr) { 00086 printf("xmlGenericErrorContext override failed\n"); 00087 okay = 0; 00088 } 00089 } 00090 if (okay == 0) 00091 return((void *) Failed); 00092 return ((void *) Okay); 00093 } 00094 00095 #ifdef HAVE_PTHREAD_H 00096 int 00097 main(void) 00098 { 00099 unsigned int i, repeat; 00100 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); 00101 void *results[MAX_ARGC]; 00102 int ret; 00103 00104 xmlInitParser(); 00105 for (repeat = 0;repeat < 500;repeat++) { 00106 xmlLoadCatalog(catalog); 00107 00108 for (i = 0; i < num_threads; i++) { 00109 results[i] = NULL; 00110 tid[i] = (pthread_t) -1; 00111 } 00112 00113 for (i = 0; i < num_threads; i++) { 00114 ret = pthread_create(&tid[i], NULL, thread_specific_data, 00115 (void *) testfiles[i]); 00116 if (ret != 0) { 00117 perror("pthread_create"); 00118 exit(1); 00119 } 00120 } 00121 for (i = 0; i < num_threads; i++) { 00122 ret = pthread_join(tid[i], &results[i]); 00123 if (ret != 0) { 00124 perror("pthread_join"); 00125 exit(1); 00126 } 00127 } 00128 00129 xmlCatalogCleanup(); 00130 for (i = 0; i < num_threads; i++) 00131 if (results[i] != (void *) Okay) 00132 printf("Thread %d handling %s failed\n", i, testfiles[i]); 00133 } 00134 xmlCleanupParser(); 00135 xmlMemoryDump(); 00136 return (0); 00137 } 00138 #elif defined HAVE_BEOS_THREADS 00139 int 00140 main(void) 00141 { 00142 unsigned int i, repeat; 00143 unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); 00144 void *results[MAX_ARGC]; 00145 status_t ret; 00146 00147 xmlInitParser(); 00148 printf("Parser initialized\n"); 00149 for (repeat = 0;repeat < 500;repeat++) { 00150 printf("repeat: %d\n",repeat); 00151 xmlLoadCatalog(catalog); 00152 printf("loaded catalog: %s\n", catalog); 00153 for (i = 0; i < num_threads; i++) { 00154 results[i] = NULL; 00155 tid[i] = (thread_id) -1; 00156 } 00157 printf("cleaned threads\n"); 00158 for (i = 0; i < num_threads; i++) { 00159 tid[i] = spawn_thread(thread_specific_data, "xmlTestThread", B_NORMAL_PRIORITY, (void *) testfiles[i]); 00160 if (tid[i] < B_OK) { 00161 perror("beos_thread_create"); 00162 exit(1); 00163 } 00164 printf("beos_thread_create %d -> %d\n", i, tid[i]); 00165 } 00166 for (i = 0; i < num_threads; i++) { 00167 ret = wait_for_thread(tid[i], &results[i]); 00168 printf("beos_thread_wait %d -> %d\n", i, ret); 00169 if (ret != B_OK) { 00170 perror("beos_thread_wait"); 00171 exit(1); 00172 } 00173 } 00174 00175 xmlCatalogCleanup(); 00176 ret = B_OK; 00177 for (i = 0; i < num_threads; i++) 00178 if (results[i] != (void *) Okay) { 00179 printf("Thread %d handling %s failed\n", i, testfiles[i]); 00180 ret = B_ERROR; 00181 } 00182 } 00183 xmlCleanupParser(); 00184 xmlMemoryDump(); 00185 00186 if (ret == B_OK) 00187 printf("testThread : BeOS : SUCCESS!\n"); 00188 else 00189 printf("testThread : BeOS : FAILED!\n"); 00190 00191 return (0); 00192 } 00193 #endif /* pthreads or BeOS threads */ 00194 00195 #else /* !LIBXML_THREADS_ENABLED */ 00196 int 00197 main(void) 00198 { 00199 fprintf(stderr, "libxml was not compiled with thread or catalog support\n"); 00200 return (0); 00201 } 00202 #endif Generated on Sun May 27 2012 04:34:42 for ReactOS by
1.7.6.1
|