ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

testThreadsWin32.c
Go to the documentation of this file.
00001 #include "libxml.h"
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 
00005 #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED)
00006 #include <libxml/globals.h>
00007 #include <libxml/threads.h>
00008 #include <libxml/parser.h>
00009 #include <libxml/catalog.h>
00010 #include <windows.h>
00011 #include <string.h>
00012 #include <assert.h>
00013 
00014 #define MAX_ARGC    20
00015 #define TEST_REPEAT_COUNT 500
00016 
00017 static HANDLE tid[MAX_ARGC];
00018 
00019 static const char *catalog = "test/threads/complex.xml";
00020 static char *testfiles[] = {
00021     "test/threads/abc.xml",
00022     "test/threads/acb.xml",
00023     "test/threads/bac.xml",
00024     "test/threads/bca.xml",
00025     "test/threads/cab.xml",
00026     "test/threads/cba.xml",
00027     "test/threads/invalid.xml",
00028 };
00029 
00030 const char *Okay = "OK";
00031 const char *Failed = "Failed";
00032 
00033 #ifndef xmlDoValidityCheckingDefaultValue
00034 #error xmlDoValidityCheckingDefaultValue is not a macro
00035 #endif
00036 #ifndef xmlGenericErrorContext
00037 #error xmlGenericErrorContext is not a macro
00038 #endif
00039 
00040 static DWORD WINAPI
00041 thread_specific_data(void *private_data)
00042 {
00043     xmlDocPtr myDoc;
00044     const char *filename = (const char *) private_data;
00045     int okay = 1;
00046 
00047     if (!strcmp(filename, "test/threads/invalid.xml")) {
00048         xmlDoValidityCheckingDefaultValue = 0;
00049         xmlGenericErrorContext = stdout;
00050     } else {
00051         xmlDoValidityCheckingDefaultValue = 1;
00052         xmlGenericErrorContext = stderr;
00053     }
00054     myDoc = xmlParseFile(filename);
00055     if (myDoc) {
00056         xmlFreeDoc(myDoc);
00057     } else {
00058         printf("parse failed\n");
00059     okay = 0;
00060     }
00061     if (!strcmp(filename, "test/threads/invalid.xml")) {
00062         if (xmlDoValidityCheckingDefaultValue != 0) {
00063         printf("ValidityCheckingDefaultValue override failed\n");
00064         okay = 0;
00065     }
00066         if (xmlGenericErrorContext != stdout) {
00067         printf("xmlGenericErrorContext override failed\n");
00068         okay = 0;
00069     }
00070     } else {
00071         if (xmlDoValidityCheckingDefaultValue != 1) {
00072         printf("ValidityCheckingDefaultValue override failed\n");
00073         okay = 0;
00074     }
00075         if (xmlGenericErrorContext != stderr) {
00076         printf("xmlGenericErrorContext override failed\n");
00077         okay = 0;
00078     }
00079     }
00080     if (okay == 0)
00081     return ((DWORD) Failed);
00082     return ((DWORD) Okay);
00083 }
00084 
00085 int
00086 main()
00087 {
00088     unsigned int i, repeat;
00089     unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
00090     DWORD results[MAX_ARGC];
00091     BOOL ret;
00092 
00093     xmlInitParser();
00094     for (repeat = 0;repeat < TEST_REPEAT_COUNT;repeat++)
00095     {
00096         xmlLoadCatalog(catalog);
00097 
00098         for (i = 0; i < num_threads; i++)
00099         {
00100             results[i] = 0;
00101             tid[i] = (HANDLE) -1;
00102         }
00103 
00104         for (i = 0; i < num_threads; i++)
00105         {
00106             DWORD useless;
00107             tid[i] = CreateThread(NULL, 0, 
00108                 thread_specific_data, testfiles[i], 0, &useless);
00109             if (tid[i] == NULL)
00110             {
00111                 perror("CreateThread");
00112                 exit(1);
00113             }
00114         }
00115 
00116         if (WaitForMultipleObjects (num_threads, tid, TRUE, INFINITE) == WAIT_FAILED) 
00117             perror ("WaitForMultipleObjects failed");
00118 
00119         for (i = 0; i < num_threads; i++)
00120         {
00121             ret = GetExitCodeThread (tid[i], &results[i]);
00122             if (ret == 0)
00123             {
00124                 perror("GetExitCodeThread");
00125                 exit(1);
00126             }
00127             CloseHandle (tid[i]);
00128         }
00129 
00130         xmlCatalogCleanup();
00131         for (i = 0; i < num_threads; i++) {
00132             if (results[i] != (DWORD) Okay) 
00133             printf("Thread %d handling %s failed\n", i, testfiles[i]);
00134         }
00135     }
00136 
00137     xmlCleanupParser();
00138     xmlMemoryDump();
00139 
00140     return (0);
00141 }
00142 
00143 #else /* !LIBXML_THREADS_ENABLED */
00144 int
00145 main()
00146 {
00147     fprintf(stderr, "libxml was not compiled with thread or catalog support\n");
00148     return (0);
00149 }
00150 #endif

Generated on Fri May 25 2012 04:33:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.