2007-01-31 18:38:56 +00:00
# include "libxml.h"
2001-10-17 11:30:37 +00:00
# include <stdlib.h>
2001-10-17 15:58:35 +00:00
# include <stdio.h>
2001-10-17 11:30:37 +00:00
2017-06-16 21:27:47 +02:00
# if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED)
2001-10-17 11:30:37 +00:00
# include <libxml/globals.h>
# include <libxml/threads.h>
# include <libxml/parser.h>
# include <libxml/catalog.h>
2003-10-29 13:39:15 +00:00
# ifdef HAVE_PTHREAD_H
2001-10-17 11:30:37 +00:00
# include <pthread.h>
2003-10-29 13:39:15 +00:00
# elif defined HAVE_BEOS_THREADS
# include <OS.h>
# endif
2001-10-17 11:30:37 +00:00
# include <string.h>
2002-10-31 15:59:09 +00:00
# if !defined(_MSC_VER)
2001-10-17 11:30:37 +00:00
# include <unistd.h>
2002-10-31 15:59:09 +00:00
# endif
2001-10-17 11:30:37 +00:00
# include <assert.h>
# define MAX_ARGC 20
2003-10-29 13:39:15 +00:00
# ifdef HAVE_PTHREAD_H
2001-10-17 11:30:37 +00:00
static pthread_t tid [ MAX_ARGC ] ;
2003-10-29 13:39:15 +00:00
# elif defined HAVE_BEOS_THREADS
static thread_id tid [ MAX_ARGC ] ;
# endif
2001-10-17 11:30:37 +00:00
static const char * catalog = " test/threads/complex.xml " ;
static const char * testfiles [ ] = {
" test/threads/abc.xml " ,
" test/threads/acb.xml " ,
" test/threads/bac.xml " ,
" test/threads/bca.xml " ,
" test/threads/cab.xml " ,
" test/threads/cba.xml " ,
" test/threads/invalid.xml " ,
} ;
2005-07-28 23:49:35 +00:00
static const char * Okay = " OK " ;
static const char * Failed = " Failed " ;
2001-10-17 15:58:35 +00:00
# ifndef xmlDoValidityCheckingDefaultValue
# error xmlDoValidityCheckingDefaultValue is not a macro
# endif
# ifndef xmlGenericErrorContext
# error xmlGenericErrorContext is not a macro
# endif
2001-10-17 11:30:37 +00:00
static void *
thread_specific_data ( void * private_data )
{
xmlDocPtr myDoc ;
const char * filename = ( const char * ) private_data ;
2001-10-17 15:58:35 +00:00
int okay = 1 ;
2001-10-17 11:30:37 +00:00
2001-10-17 15:58:35 +00:00
if ( ! strcmp ( filename , " test/threads/invalid.xml " ) ) {
2001-10-17 11:30:37 +00:00
xmlDoValidityCheckingDefaultValue = 0 ;
xmlGenericErrorContext = stdout ;
} else {
xmlDoValidityCheckingDefaultValue = 1 ;
xmlGenericErrorContext = stderr ;
}
2017-06-16 21:27:47 +02:00
# ifdef LIBXML_SAX1_ENABLED
2001-10-17 11:30:37 +00:00
myDoc = xmlParseFile ( filename ) ;
2017-06-16 21:27:47 +02:00
# else
myDoc = xmlReadFile ( filename , NULL , XML_WITH_CATALOG ) ;
# endif
2001-10-17 11:30:37 +00:00
if ( myDoc ) {
xmlFreeDoc ( myDoc ) ;
2001-10-17 15:58:35 +00:00
} else {
2001-10-17 11:30:37 +00:00
printf ( " parse failed \n " ) ;
2001-10-17 15:58:35 +00:00
okay = 0 ;
}
if ( ! strcmp ( filename , " test/threads/invalid.xml " ) ) {
if ( xmlDoValidityCheckingDefaultValue ! = 0 ) {
2001-10-17 11:30:37 +00:00
printf ( " ValidityCheckingDefaultValue override failed \n " ) ;
2001-10-17 15:58:35 +00:00
okay = 0 ;
}
if ( xmlGenericErrorContext ! = stdout ) {
printf ( " xmlGenericErrorContext override failed \n " ) ;
okay = 0 ;
}
2001-10-17 11:30:37 +00:00
} else {
2001-10-17 15:58:35 +00:00
if ( xmlDoValidityCheckingDefaultValue ! = 1 ) {
2001-10-17 11:30:37 +00:00
printf ( " ValidityCheckingDefaultValue override failed \n " ) ;
2001-10-17 15:58:35 +00:00
okay = 0 ;
}
if ( xmlGenericErrorContext ! = stderr ) {
printf ( " xmlGenericErrorContext override failed \n " ) ;
okay = 0 ;
}
2001-10-17 11:30:37 +00:00
}
2001-10-17 15:58:35 +00:00
if ( okay = = 0 )
return ( ( void * ) Failed ) ;
return ( ( void * ) Okay ) ;
2001-10-17 11:30:37 +00:00
}
2003-10-29 13:39:15 +00:00
# ifdef HAVE_PTHREAD_H
2001-10-17 11:30:37 +00:00
int
2003-08-06 04:43:55 +00:00
main ( void )
2001-10-17 11:30:37 +00:00
{
2001-10-17 15:58:35 +00:00
unsigned int i , repeat ;
2001-10-17 11:30:37 +00:00
unsigned int num_threads = sizeof ( testfiles ) / sizeof ( testfiles [ 0 ] ) ;
2001-10-17 15:58:35 +00:00
void * results [ MAX_ARGC ] ;
int ret ;
2001-10-17 11:30:37 +00:00
xmlInitParser ( ) ;
2001-10-22 09:46:13 +00:00
for ( repeat = 0 ; repeat < 500 ; repeat + + ) {
2001-10-17 15:58:35 +00:00
xmlLoadCatalog ( catalog ) ;
2001-10-17 11:30:37 +00:00
2010-11-15 13:00:29 +01:00
memset ( results , 0 , sizeof ( * results ) * num_threads ) ;
memset ( tid , 0xff , sizeof ( * tid ) * num_threads ) ;
2001-10-17 11:30:37 +00:00
2001-10-17 15:58:35 +00:00
for ( i = 0 ; i < num_threads ; i + + ) {
2005-07-28 23:49:35 +00:00
ret = pthread_create ( & tid [ i ] , NULL , thread_specific_data ,
2001-10-17 15:58:35 +00:00
( void * ) testfiles [ i ] ) ;
if ( ret ! = 0 ) {
perror ( " pthread_create " ) ;
exit ( 1 ) ;
}
}
for ( i = 0 ; i < num_threads ; i + + ) {
ret = pthread_join ( tid [ i ] , & results [ i ] ) ;
if ( ret ! = 0 ) {
perror ( " pthread_join " ) ;
exit ( 1 ) ;
}
}
xmlCatalogCleanup ( ) ;
for ( i = 0 ; i < num_threads ; i + + )
if ( results [ i ] ! = ( void * ) Okay )
printf ( " Thread %d handling %s failed \n " , i , testfiles [ i ] ) ;
}
2001-10-17 11:30:37 +00:00
xmlCleanupParser ( ) ;
xmlMemoryDump ( ) ;
return ( 0 ) ;
}
2003-10-29 13:39:15 +00:00
# elif defined HAVE_BEOS_THREADS
int
main ( void )
{
unsigned int i , repeat ;
unsigned int num_threads = sizeof ( testfiles ) / sizeof ( testfiles [ 0 ] ) ;
void * results [ MAX_ARGC ] ;
status_t ret ;
xmlInitParser ( ) ;
printf ( " Parser initialized \n " ) ;
for ( repeat = 0 ; repeat < 500 ; repeat + + ) {
printf ( " repeat: %d \n " , repeat ) ;
xmlLoadCatalog ( catalog ) ;
printf ( " loaded catalog: %s \n " , catalog ) ;
for ( i = 0 ; i < num_threads ; i + + ) {
results [ i ] = NULL ;
tid [ i ] = ( thread_id ) - 1 ;
}
printf ( " cleaned threads \n " ) ;
for ( i = 0 ; i < num_threads ; i + + ) {
tid [ i ] = spawn_thread ( thread_specific_data , " xmlTestThread " , B_NORMAL_PRIORITY , ( void * ) testfiles [ i ] ) ;
if ( tid [ i ] < B_OK ) {
perror ( " beos_thread_create " ) ;
exit ( 1 ) ;
}
printf ( " beos_thread_create %d -> %d \n " , i , tid [ i ] ) ;
}
for ( i = 0 ; i < num_threads ; i + + ) {
ret = wait_for_thread ( tid [ i ] , & results [ i ] ) ;
printf ( " beos_thread_wait %d -> %d \n " , i , ret ) ;
if ( ret ! = B_OK ) {
perror ( " beos_thread_wait " ) ;
exit ( 1 ) ;
}
}
xmlCatalogCleanup ( ) ;
ret = B_OK ;
for ( i = 0 ; i < num_threads ; i + + )
if ( results [ i ] ! = ( void * ) Okay ) {
printf ( " Thread %d handling %s failed \n " , i , testfiles [ i ] ) ;
ret = B_ERROR ;
}
}
xmlCleanupParser ( ) ;
xmlMemoryDump ( ) ;
if ( ret = = B_OK )
printf ( " testThread : BeOS : SUCCESS! \n " ) ;
else
printf ( " testThread : BeOS : FAILED! \n " ) ;
return ( 0 ) ;
}
# endif /* pthreads or BeOS threads */
2001-10-17 11:30:37 +00:00
# else /* !LIBXML_THREADS_ENABLED */
int
2002-09-24 14:13:13 +00:00
main ( void )
2001-10-17 11:30:37 +00:00
{
2001-11-04 20:19:12 +00:00
fprintf ( stderr , " libxml was not compiled with thread or catalog support \n " ) ;
2001-10-17 11:30:37 +00:00
return ( 0 ) ;
}
# endif