2005-06-30 17:04:44 +04:00
/*
2019-09-30 18:04:54 +03:00
* runsuite . c : C program to run libxml2 against published testsuites
2005-06-30 17:04:44 +04:00
*
* See Copyright for the status of this software .
*
* daniel @ veillard . com
*/
2024-06-15 20:13:08 +03:00
# include "libxml.h"
2005-10-28 20:37:05 +04:00
# include <stdio.h>
2023-09-21 01:44:50 +03:00
# include <stdlib.h>
2005-06-30 17:04:44 +04:00
# include <string.h>
# include <sys/stat.h>
2024-06-11 12:34:48 +03:00
# include <libxml/catalog.h>
2005-06-30 17:04:44 +04:00
# include <libxml/parser.h>
2005-07-02 11:31:28 +04:00
# include <libxml/parserInternals.h>
2005-06-30 17:04:44 +04:00
# include <libxml/tree.h>
# include <libxml/uri.h>
2005-07-03 20:09:51 +04:00
# if defined(LIBXML_SCHEMAS_ENABLED) && defined(LIBXML_XPATH_ENABLED)
2005-06-30 17:04:44 +04:00
# include <libxml/xmlreader.h>
# include <libxml/xpath.h>
# include <libxml/xpathInternals.h>
# include <libxml/relaxng.h>
# include <libxml/xmlschemas.h>
# include <libxml/xmlschemastypes.h>
2005-07-04 18:25:34 +04:00
# define LOGFILE "runsuite.log"
2005-07-29 03:49:35 +04:00
static FILE * logfile = NULL ;
2005-12-09 13:03:27 +03:00
static int verbose = 0 ;
2005-06-30 17:04:44 +04:00
/************************************************************************
* *
* File name and path utilities *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int checkTestFile ( const char * filename ) {
struct stat buf ;
if ( stat ( filename , & buf ) = = - 1 )
return ( 0 ) ;
2022-03-01 00:42:10 +03:00
# if defined(_WIN32)
2005-07-04 21:12:01 +04:00
if ( ! ( buf . st_mode & _S_IFREG ) )
return ( 0 ) ;
# else
2005-06-30 17:04:44 +04:00
if ( ! S_ISREG ( buf . st_mode ) )
return ( 0 ) ;
2005-07-04 21:12:01 +04:00
# endif
2005-06-30 17:04:44 +04:00
return ( 1 ) ;
}
2005-07-04 21:12:01 +04:00
2005-07-02 11:31:28 +04:00
static xmlChar * composeDir ( const xmlChar * dir , const xmlChar * path ) {
char buf [ 500 ] ;
if ( dir = = NULL ) return ( xmlStrdup ( path ) ) ;
if ( path = = NULL ) return ( NULL ) ;
snprintf ( buf , 500 , " %s/%s " , ( const char * ) dir , ( const char * ) path ) ;
return ( xmlStrdup ( ( const xmlChar * ) buf ) ) ;
}
2005-06-30 17:04:44 +04:00
/************************************************************************
* *
* Libxml2 specific routines *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int nb_tests = 0 ;
static int nb_errors = 0 ;
2005-07-04 18:25:34 +04:00
static int nb_internals = 0 ;
static int nb_schematas = 0 ;
2005-07-04 19:45:10 +04:00
static int nb_unimplemented = 0 ;
2005-06-30 17:04:44 +04:00
static int nb_leaks = 0 ;
static int
fatalError ( void ) {
fprintf ( stderr , " Exitting tests on fatal error \n " ) ;
exit ( 1 ) ;
}
2005-07-02 11:31:28 +04:00
/*
* that ' s needed to implement < resource >
*/
# define MAX_ENTITIES 20
2005-07-29 03:49:35 +04:00
static char * testEntitiesName [ MAX_ENTITIES ] ;
static char * testEntitiesValue [ MAX_ENTITIES ] ;
static int nb_entities = 0 ;
2005-07-02 11:31:28 +04:00
static void resetEntities ( void ) {
int i ;
for ( i = 0 ; i < nb_entities ; i + + ) {
if ( testEntitiesName [ i ] ! = NULL )
xmlFree ( testEntitiesName [ i ] ) ;
if ( testEntitiesValue [ i ] ! = NULL )
xmlFree ( testEntitiesValue [ i ] ) ;
}
nb_entities = 0 ;
}
static int addEntity ( char * name , char * content ) {
if ( nb_entities > = MAX_ENTITIES ) {
fprintf ( stderr , " Too many entities defined \n " ) ;
return ( - 1 ) ;
}
testEntitiesName [ nb_entities ] = name ;
testEntitiesValue [ nb_entities ] = content ;
nb_entities + + ;
return ( 0 ) ;
}
2024-06-11 13:54:12 +03:00
static int
testResourceLoader ( void * vctxt ATTRIBUTE_UNUSED , const char * URL ,
2024-06-11 20:10:41 +03:00
const char * ID ATTRIBUTE_UNUSED ,
xmlResourceType type ATTRIBUTE_UNUSED ,
2024-06-11 13:54:12 +03:00
int flags ATTRIBUTE_UNUSED , xmlParserInputPtr * out ) {
2005-07-02 11:31:28 +04:00
int i ;
2024-06-11 13:54:12 +03:00
for ( i = 0 ; i < nb_entities ; i + + ) {
2005-07-02 11:31:28 +04:00
if ( ! strcmp ( testEntitiesName [ i ] , URL ) ) {
2024-06-11 13:54:12 +03:00
* out = xmlInputCreateString ( testEntitiesName [ i ] ,
testEntitiesValue [ i ] ,
XML_INPUT_BUF_STATIC ) ;
return ( XML_ERR_OK ) ;
2005-07-02 11:31:28 +04:00
}
}
2012-09-11 09:26:36 +04:00
2024-06-11 13:54:12 +03:00
return ( xmlInputCreateUrl ( URL , 0 , out ) ) ;
2005-06-30 17:04:44 +04:00
}
/*
* Trapping the error messages at the generic level to grab the equivalent of
* stderr messages on CLI tools .
*/
static char testErrors [ 32769 ] ;
static int testErrorsSize = 0 ;
2005-07-04 18:25:34 +04:00
static void test_log ( const char * msg , . . . ) {
va_list args ;
if ( logfile ! = NULL ) {
fprintf ( logfile , " \n ------------ \n " ) ;
va_start ( args , msg ) ;
vfprintf ( logfile , msg , args ) ;
va_end ( args ) ;
fprintf ( logfile , " %s " , testErrors ) ;
testErrorsSize = 0 ; testErrors [ 0 ] = 0 ;
}
if ( verbose ) {
va_start ( args , msg ) ;
vfprintf ( stderr , msg , args ) ;
va_end ( args ) ;
}
}
2005-06-30 17:04:44 +04:00
static void
testErrorHandler ( void * ctx ATTRIBUTE_UNUSED , const char * msg , . . . ) {
va_list args ;
int res ;
if ( testErrorsSize > = 32768 )
return ;
va_start ( args , msg ) ;
res = vsnprintf ( & testErrors [ testErrorsSize ] ,
32768 - testErrorsSize ,
msg , args ) ;
va_end ( args ) ;
if ( testErrorsSize + res > = 32768 ) {
/* buffer is full */
testErrorsSize = 32768 ;
testErrors [ testErrorsSize ] = 0 ;
} else {
testErrorsSize + = res ;
}
testErrors [ testErrorsSize ] = 0 ;
}
2005-07-03 01:39:06 +04:00
2005-07-29 03:49:35 +04:00
static xmlXPathContextPtr ctxtXPath ;
2005-07-03 01:39:06 +04:00
2005-06-30 17:04:44 +04:00
static void
initializeLibxml2 ( void ) {
xmlMemSetup ( xmlMemFree , xmlMemMalloc , xmlMemRealloc , xmlMemoryStrdup ) ;
xmlInitParser ( ) ;
2005-07-03 01:39:06 +04:00
ctxtXPath = xmlXPathNewContext ( NULL ) ;
2006-05-29 20:15:36 +04:00
/*
* Deactivate the cache if created ; otherwise we have to create / free it
* for every test , since it will confuse the memory leak detection .
* Note that normally this need not be done , since the cache is not
2019-09-30 18:04:54 +03:00
* created until set explicitly with xmlXPathContextSetCache ( ) ;
* but for test purposes it is sometimes useful to activate the
2006-05-29 20:15:36 +04:00
* cache by default for the whole library .
*/
2006-05-31 16:37:28 +04:00
if ( ctxtXPath - > cache ! = NULL )
xmlXPathContextSetCache ( ctxtXPath , 0 , - 1 , 0 ) ;
2019-09-30 18:04:54 +03:00
/* used as default namespace in xstc tests */
2005-07-03 01:39:06 +04:00
xmlXPathRegisterNs ( ctxtXPath , BAD_CAST " ts " , BAD_CAST " TestSuite " ) ;
xmlXPathRegisterNs ( ctxtXPath , BAD_CAST " xlink " ,
BAD_CAST " http://www.w3.org/1999/xlink " ) ;
xmlSetGenericErrorFunc ( NULL , testErrorHandler ) ;
2024-06-11 12:34:48 +03:00
# ifdef LIBXML_CATALOG_ENABLED
xmlInitializeCatalog ( ) ;
xmlCatalogSetDefaults ( XML_CATA_ALLOW_NONE ) ;
# endif
2005-06-30 17:04:44 +04:00
# ifdef LIBXML_SCHEMAS_ENABLED
xmlSchemaInitTypes ( ) ;
xmlRelaxNGInitTypes ( ) ;
# endif
}
static xmlNodePtr
getNext ( xmlNodePtr cur , const char * xpath ) {
xmlNodePtr ret = NULL ;
xmlXPathObjectPtr res ;
xmlXPathCompExprPtr comp ;
if ( ( cur = = NULL ) | | ( cur - > doc = = NULL ) | | ( xpath = = NULL ) )
return ( NULL ) ;
2005-07-03 01:39:06 +04:00
ctxtXPath - > doc = cur - > doc ;
ctxtXPath - > node = cur ;
2005-06-30 17:04:44 +04:00
comp = xmlXPathCompile ( BAD_CAST xpath ) ;
if ( comp = = NULL ) {
fprintf ( stderr , " Failed to compile %s \n " , xpath ) ;
return ( NULL ) ;
}
2005-07-03 01:39:06 +04:00
res = xmlXPathCompiledEval ( comp , ctxtXPath ) ;
2005-06-30 17:04:44 +04:00
xmlXPathFreeCompExpr ( comp ) ;
if ( res = = NULL )
return ( NULL ) ;
if ( ( res - > type = = XPATH_NODESET ) & &
( res - > nodesetval ! = NULL ) & &
( res - > nodesetval - > nodeNr > 0 ) & &
( res - > nodesetval - > nodeTab ! = NULL ) )
ret = res - > nodesetval - > nodeTab [ 0 ] ;
xmlXPathFreeObject ( res ) ;
return ( ret ) ;
}
static xmlChar *
getString ( xmlNodePtr cur , const char * xpath ) {
xmlChar * ret = NULL ;
xmlXPathObjectPtr res ;
xmlXPathCompExprPtr comp ;
if ( ( cur = = NULL ) | | ( cur - > doc = = NULL ) | | ( xpath = = NULL ) )
return ( NULL ) ;
2005-07-03 01:39:06 +04:00
ctxtXPath - > doc = cur - > doc ;
ctxtXPath - > node = cur ;
2005-06-30 17:04:44 +04:00
comp = xmlXPathCompile ( BAD_CAST xpath ) ;
if ( comp = = NULL ) {
fprintf ( stderr , " Failed to compile %s \n " , xpath ) ;
return ( NULL ) ;
}
2005-07-03 01:39:06 +04:00
res = xmlXPathCompiledEval ( comp , ctxtXPath ) ;
2005-06-30 17:04:44 +04:00
xmlXPathFreeCompExpr ( comp ) ;
if ( res = = NULL )
return ( NULL ) ;
if ( res - > type = = XPATH_STRING ) {
ret = res - > stringval ;
res - > stringval = NULL ;
}
xmlXPathFreeObject ( res ) ;
return ( ret ) ;
}
/************************************************************************
* *
* Test test / xsdtest / xsdtestsuite . xml *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-09-07 13:19:33 +04:00
static int
2019-09-30 18:04:54 +03:00
xsdIncorrectTestCase ( xmlNodePtr cur ) {
2005-06-30 17:04:44 +04:00
xmlNodePtr test ;
xmlBufferPtr buf ;
xmlRelaxNGParserCtxtPtr pctxt ;
xmlRelaxNGPtr rng = NULL ;
int ret = 0 , memt ;
cur = getNext ( cur , " ./incorrect[1] " ) ;
if ( cur = = NULL ) {
return ( 0 ) ;
}
2009-09-07 13:19:33 +04:00
2005-06-30 17:04:44 +04:00
test = getNext ( cur , " ./* " ) ;
if ( test = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to find test in correct line %ld \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( cur ) ) ;
return ( 1 ) ;
}
memt = xmlMemUsed ( ) ;
/*
* dump the schemas to a buffer , then reparse it and compile the schemas
*/
buf = xmlBufferCreate ( ) ;
if ( buf = = NULL ) {
fprintf ( stderr , " out of memory ! \n " ) ;
fatalError ( ) ;
}
2022-03-05 23:46:40 +03:00
xmlBufferSetAllocationScheme ( buf , XML_BUFFER_ALLOC_DOUBLEIT ) ;
2005-06-30 17:04:44 +04:00
xmlNodeDump ( buf , test - > doc , test , 0 , 0 ) ;
2024-06-11 00:20:22 +03:00
pctxt = xmlRelaxNGNewMemParserCtxt (
( const char * ) xmlBufferContent ( buf ) , xmlBufferLength ( buf ) ) ;
2019-01-01 18:48:40 +03:00
xmlRelaxNGSetParserErrors ( pctxt , testErrorHandler , testErrorHandler ,
pctxt ) ;
2024-06-11 13:54:12 +03:00
xmlRelaxNGSetResourceLoader ( pctxt , testResourceLoader , NULL ) ;
2005-06-30 17:04:44 +04:00
rng = xmlRelaxNGParse ( pctxt ) ;
xmlRelaxNGFreeParserCtxt ( pctxt ) ;
if ( rng ! = NULL ) {
2019-09-30 18:04:54 +03:00
test_log ( " Failed to detect incorrect RNG line %ld \n " ,
2005-07-03 18:35:44 +04:00
xmlGetLineNo ( test ) ) ;
2005-06-30 17:04:44 +04:00
ret = 1 ;
goto done ;
}
done :
if ( buf ! = NULL )
xmlBufferFree ( buf ) ;
if ( rng ! = NULL )
xmlRelaxNGFree ( rng ) ;
xmlResetLastError ( ) ;
2024-06-11 12:34:48 +03:00
if ( memt ! = xmlMemUsed ( ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " Validation of tests starting line %ld leaked %d \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( cur ) , xmlMemUsed ( ) - memt ) ;
nb_leaks + + ;
}
return ( ret ) ;
}
2005-07-02 11:31:28 +04:00
static void
installResources ( xmlNodePtr tst , const xmlChar * base ) {
xmlNodePtr test ;
xmlBufferPtr buf ;
xmlChar * name , * content , * res ;
2005-07-04 18:25:34 +04:00
2005-07-02 11:31:28 +04:00
buf = xmlBufferCreate ( ) ;
if ( buf = = NULL ) {
fprintf ( stderr , " out of memory ! \n " ) ;
fatalError ( ) ;
}
2022-03-05 23:46:40 +03:00
xmlBufferSetAllocationScheme ( buf , XML_BUFFER_ALLOC_DOUBLEIT ) ;
2005-07-02 11:31:28 +04:00
xmlNodeDump ( buf , tst - > doc , tst , 0 , 0 ) ;
while ( tst ! = NULL ) {
test = getNext ( tst , " ./* " ) ;
if ( test ! = NULL ) {
xmlBufferEmpty ( buf ) ;
xmlNodeDump ( buf , test - > doc , test , 0 , 0 ) ;
name = getString ( tst , " string(@name) " ) ;
2024-06-11 00:20:22 +03:00
content = xmlStrdup ( xmlBufferContent ( buf ) ) ;
2005-07-02 11:31:28 +04:00
if ( ( name ! = NULL ) & & ( content ! = NULL ) ) {
res = composeDir ( base , name ) ;
xmlFree ( name ) ;
addEntity ( ( char * ) res , ( char * ) content ) ;
} else {
if ( name ! = NULL ) xmlFree ( name ) ;
if ( content ! = NULL ) xmlFree ( content ) ;
}
}
tst = getNext ( tst , " following-sibling::resource[1] " ) ;
}
if ( buf ! = NULL )
xmlBufferFree ( buf ) ;
}
static void
installDirs ( xmlNodePtr tst , const xmlChar * base ) {
xmlNodePtr test ;
xmlChar * name , * res ;
name = getString ( tst , " string(@name) " ) ;
if ( name = = NULL )
return ;
res = composeDir ( base , name ) ;
xmlFree ( name ) ;
if ( res = = NULL ) {
return ;
}
/* Now process resources and subdir recursively */
test = getNext ( tst , " ./resource[1] " ) ;
if ( test ! = NULL ) {
installResources ( test , res ) ;
}
test = getNext ( tst , " ./dir[1] " ) ;
while ( test ! = NULL ) {
installDirs ( test , res ) ;
test = getNext ( test , " following-sibling::dir[1] " ) ;
}
2005-07-03 01:39:06 +04:00
xmlFree ( res ) ;
2005-07-02 11:31:28 +04:00
}
2012-09-11 09:26:36 +04:00
static int
2005-07-04 18:25:34 +04:00
xsdTestCase ( xmlNodePtr tst ) {
2005-06-30 17:04:44 +04:00
xmlNodePtr test , tmp , cur ;
xmlBufferPtr buf ;
xmlDocPtr doc = NULL ;
xmlRelaxNGParserCtxtPtr pctxt ;
xmlRelaxNGValidCtxtPtr ctxt ;
xmlRelaxNGPtr rng = NULL ;
int ret = 0 , mem , memt ;
2005-07-02 11:31:28 +04:00
xmlChar * dtd ;
resetEntities ( ) ;
2005-07-04 18:25:34 +04:00
testErrorsSize = 0 ; testErrors [ 0 ] = 0 ;
2005-07-02 11:31:28 +04:00
tmp = getNext ( tst , " ./dir[1] " ) ;
if ( tmp ! = NULL ) {
installDirs ( tmp , NULL ) ;
}
tmp = getNext ( tst , " ./resource[1] " ) ;
if ( tmp ! = NULL ) {
installResources ( tmp , NULL ) ;
}
2005-06-30 17:04:44 +04:00
cur = getNext ( tst , " ./correct[1] " ) ;
if ( cur = = NULL ) {
2019-09-30 18:04:54 +03:00
return ( xsdIncorrectTestCase ( tst ) ) ;
2005-06-30 17:04:44 +04:00
}
2012-09-11 09:26:36 +04:00
2005-06-30 17:04:44 +04:00
test = getNext ( cur , " ./* " ) ;
if ( test = = NULL ) {
fprintf ( stderr , " Failed to find test in correct line %ld \n " ,
xmlGetLineNo ( cur ) ) ;
return ( 1 ) ;
}
memt = xmlMemUsed ( ) ;
/*
* dump the schemas to a buffer , then reparse it and compile the schemas
*/
buf = xmlBufferCreate ( ) ;
if ( buf = = NULL ) {
fprintf ( stderr , " out of memory ! \n " ) ;
fatalError ( ) ;
}
2022-03-05 23:46:40 +03:00
xmlBufferSetAllocationScheme ( buf , XML_BUFFER_ALLOC_DOUBLEIT ) ;
2005-06-30 17:04:44 +04:00
xmlNodeDump ( buf , test - > doc , test , 0 , 0 ) ;
2024-06-11 00:20:22 +03:00
pctxt = xmlRelaxNGNewMemParserCtxt (
( const char * ) xmlBufferContent ( buf ) , xmlBufferLength ( buf ) ) ;
2019-01-01 18:48:40 +03:00
xmlRelaxNGSetParserErrors ( pctxt , testErrorHandler , testErrorHandler ,
pctxt ) ;
2024-06-11 13:54:12 +03:00
xmlRelaxNGSetResourceLoader ( pctxt , testResourceLoader , NULL ) ;
2005-06-30 17:04:44 +04:00
rng = xmlRelaxNGParse ( pctxt ) ;
xmlRelaxNGFreeParserCtxt ( pctxt ) ;
if ( rng = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to parse RNGtest line %ld \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( test ) ) ;
nb_errors + + ;
ret = 1 ;
goto done ;
}
/*
* now scan all the siblings of correct to process the < valid > tests
*/
tmp = getNext ( cur , " following-sibling::valid[1] " ) ;
while ( tmp ! = NULL ) {
2005-07-02 11:31:28 +04:00
dtd = xmlGetProp ( tmp , BAD_CAST " dtd " ) ;
2005-06-30 17:04:44 +04:00
test = getNext ( tmp , " ./* " ) ;
if ( test = = NULL ) {
fprintf ( stderr , " Failed to find test in <valid> line %ld \n " ,
xmlGetLineNo ( tmp ) ) ;
2012-09-11 09:26:36 +04:00
2005-06-30 17:04:44 +04:00
} else {
xmlBufferEmpty ( buf ) ;
2005-07-02 11:31:28 +04:00
if ( dtd ! = NULL )
xmlBufferAdd ( buf , dtd , - 1 ) ;
2005-06-30 17:04:44 +04:00
xmlNodeDump ( buf , test - > doc , test , 0 , 0 ) ;
/*
* We are ready to run the test
*/
mem = xmlMemUsed ( ) ;
2024-06-11 00:20:22 +03:00
doc = xmlReadMemory ( ( const char * ) xmlBufferContent ( buf ) ,
xmlBufferLength ( buf ) , " test " , NULL , 0 ) ;
2005-06-30 17:04:44 +04:00
if ( doc = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to parse valid instance line %ld \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( tmp ) ) ;
nb_errors + + ;
} else {
nb_tests + + ;
ctxt = xmlRelaxNGNewValidCtxt ( rng ) ;
xmlRelaxNGSetValidErrors ( ctxt ,
2019-01-01 18:48:40 +03:00
testErrorHandler , testErrorHandler , ctxt ) ;
2005-06-30 17:04:44 +04:00
ret = xmlRelaxNGValidateDoc ( ctxt , doc ) ;
xmlRelaxNGFreeValidCtxt ( ctxt ) ;
if ( ret > 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to validate valid instance line %ld \n " ,
2005-07-03 18:35:44 +04:00
xmlGetLineNo ( tmp ) ) ;
2005-06-30 17:04:44 +04:00
nb_errors + + ;
} else if ( ret < 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " Internal error validating instance line %ld \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( tmp ) ) ;
nb_errors + + ;
}
xmlFreeDoc ( doc ) ;
}
xmlResetLastError ( ) ;
2024-06-11 12:34:48 +03:00
if ( mem ! = xmlMemUsed ( ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " Validation of instance line %ld leaked %d \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( tmp ) , xmlMemUsed ( ) - mem ) ;
nb_leaks + + ;
}
}
2005-07-02 11:31:28 +04:00
if ( dtd ! = NULL )
xmlFree ( dtd ) ;
2005-06-30 17:04:44 +04:00
tmp = getNext ( tmp , " following-sibling::valid[1] " ) ;
}
/*
* now scan all the siblings of correct to process the < invalid > tests
*/
tmp = getNext ( cur , " following-sibling::invalid[1] " ) ;
while ( tmp ! = NULL ) {
test = getNext ( tmp , " ./* " ) ;
if ( test = = NULL ) {
fprintf ( stderr , " Failed to find test in <invalid> line %ld \n " ,
xmlGetLineNo ( tmp ) ) ;
2012-09-11 09:26:36 +04:00
2005-06-30 17:04:44 +04:00
} else {
xmlBufferEmpty ( buf ) ;
xmlNodeDump ( buf , test - > doc , test , 0 , 0 ) ;
/*
* We are ready to run the test
*/
mem = xmlMemUsed ( ) ;
2024-06-11 00:20:22 +03:00
doc = xmlReadMemory ( ( const char * ) xmlBufferContent ( buf ) ,
xmlBufferLength ( buf ) , " test " , NULL , 0 ) ;
2005-06-30 17:04:44 +04:00
if ( doc = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to parse valid instance line %ld \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( tmp ) ) ;
nb_errors + + ;
} else {
nb_tests + + ;
ctxt = xmlRelaxNGNewValidCtxt ( rng ) ;
xmlRelaxNGSetValidErrors ( ctxt ,
2019-01-01 18:48:40 +03:00
testErrorHandler , testErrorHandler , ctxt ) ;
2005-06-30 17:04:44 +04:00
ret = xmlRelaxNGValidateDoc ( ctxt , doc ) ;
xmlRelaxNGFreeValidCtxt ( ctxt ) ;
if ( ret = = 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to detect invalid instance line %ld \n " ,
2005-07-03 18:35:44 +04:00
xmlGetLineNo ( tmp ) ) ;
2005-06-30 17:04:44 +04:00
nb_errors + + ;
} else if ( ret < 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " Internal error validating instance line %ld \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( tmp ) ) ;
nb_errors + + ;
}
xmlFreeDoc ( doc ) ;
}
xmlResetLastError ( ) ;
2024-06-11 12:34:48 +03:00
if ( mem ! = xmlMemUsed ( ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " Validation of instance line %ld leaked %d \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( tmp ) , xmlMemUsed ( ) - mem ) ;
nb_leaks + + ;
}
}
tmp = getNext ( tmp , " following-sibling::invalid[1] " ) ;
}
done :
if ( buf ! = NULL )
xmlBufferFree ( buf ) ;
if ( rng ! = NULL )
xmlRelaxNGFree ( rng ) ;
xmlResetLastError ( ) ;
if ( ( memt ! = xmlMemUsed ( ) ) & & ( memt ! = 0 ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " Validation of tests starting line %ld leaked %d \n " ,
2005-06-30 17:04:44 +04:00
xmlGetLineNo ( cur ) , xmlMemUsed ( ) - memt ) ;
nb_leaks + + ;
}
return ( ret ) ;
}
2012-09-11 09:26:36 +04:00
static int
2005-07-04 18:25:34 +04:00
xsdTestSuite ( xmlNodePtr cur ) {
2005-06-30 17:04:44 +04:00
if ( verbose ) {
xmlChar * doc = getString ( cur , " string(documentation) " ) ;
if ( doc ! = NULL ) {
printf ( " Suite %s \n " , doc ) ;
xmlFree ( doc ) ;
}
}
cur = getNext ( cur , " ./testCase[1] " ) ;
while ( cur ! = NULL ) {
2005-07-04 18:25:34 +04:00
xsdTestCase ( cur ) ;
2005-06-30 17:04:44 +04:00
cur = getNext ( cur , " following-sibling::testCase[1] " ) ;
}
2012-09-11 09:26:36 +04:00
2005-06-30 17:04:44 +04:00
return ( 0 ) ;
}
2012-09-11 09:26:36 +04:00
static int
2005-07-04 18:25:34 +04:00
xsdTest ( void ) {
2005-06-30 17:04:44 +04:00
xmlDocPtr doc ;
xmlNodePtr cur ;
const char * filename = " test/xsdtest/xsdtestsuite.xml " ;
int ret = 0 ;
doc = xmlReadFile ( filename , NULL , XML_PARSE_NOENT ) ;
if ( doc = = NULL ) {
fprintf ( stderr , " Failed to parse %s \n " , filename ) ;
return ( - 1 ) ;
}
printf ( " ## XML Schemas datatypes test suite from James Clark \n " ) ;
cur = xmlDocGetRootElement ( doc ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSuite " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , filename ) ;
ret = - 1 ;
goto done ;
}
cur = getNext ( cur , " ./testSuite[1] " ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSuite " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , filename ) ;
ret = - 1 ;
goto done ;
}
while ( cur ! = NULL ) {
2005-07-04 18:25:34 +04:00
xsdTestSuite ( cur ) ;
2005-06-30 17:04:44 +04:00
cur = getNext ( cur , " following-sibling::testSuite[1] " ) ;
}
done :
if ( doc ! = NULL )
xmlFreeDoc ( doc ) ;
return ( ret ) ;
}
2012-09-11 09:26:36 +04:00
static int
2005-07-04 18:25:34 +04:00
rngTestSuite ( xmlNodePtr cur ) {
2005-06-30 17:04:44 +04:00
if ( verbose ) {
xmlChar * doc = getString ( cur , " string(documentation) " ) ;
if ( doc ! = NULL ) {
printf ( " Suite %s \n " , doc ) ;
xmlFree ( doc ) ;
} else {
doc = getString ( cur , " string(section) " ) ;
if ( doc ! = NULL ) {
printf ( " Section %s \n " , doc ) ;
xmlFree ( doc ) ;
}
}
}
cur = getNext ( cur , " ./testSuite[1] " ) ;
while ( cur ! = NULL ) {
2005-07-04 18:25:34 +04:00
xsdTestSuite ( cur ) ;
2005-06-30 17:04:44 +04:00
cur = getNext ( cur , " following-sibling::testSuite[1] " ) ;
}
2012-09-11 09:26:36 +04:00
2005-06-30 17:04:44 +04:00
return ( 0 ) ;
}
2012-09-11 09:26:36 +04:00
static int
2005-07-04 18:25:34 +04:00
rngTest1 ( void ) {
2005-06-30 17:04:44 +04:00
xmlDocPtr doc ;
xmlNodePtr cur ;
const char * filename = " test/relaxng/OASIS/spectest.xml " ;
int ret = 0 ;
doc = xmlReadFile ( filename , NULL , XML_PARSE_NOENT ) ;
if ( doc = = NULL ) {
fprintf ( stderr , " Failed to parse %s \n " , filename ) ;
return ( - 1 ) ;
}
2005-07-02 11:31:28 +04:00
printf ( " ## Relax NG test suite from James Clark \n " ) ;
2005-06-30 17:04:44 +04:00
cur = xmlDocGetRootElement ( doc ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSuite " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , filename ) ;
ret = - 1 ;
goto done ;
}
cur = getNext ( cur , " ./testSuite[1] " ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSuite " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , filename ) ;
ret = - 1 ;
goto done ;
}
while ( cur ! = NULL ) {
2005-07-04 18:25:34 +04:00
rngTestSuite ( cur ) ;
2005-06-30 17:04:44 +04:00
cur = getNext ( cur , " following-sibling::testSuite[1] " ) ;
}
done :
if ( doc ! = NULL )
xmlFreeDoc ( doc ) ;
return ( ret ) ;
}
2012-09-11 09:26:36 +04:00
static int
2005-07-04 18:25:34 +04:00
rngTest2 ( void ) {
2005-07-02 11:31:28 +04:00
xmlDocPtr doc ;
xmlNodePtr cur ;
const char * filename = " test/relaxng/testsuite.xml " ;
int ret = 0 ;
doc = xmlReadFile ( filename , NULL , XML_PARSE_NOENT ) ;
if ( doc = = NULL ) {
fprintf ( stderr , " Failed to parse %s \n " , filename ) ;
return ( - 1 ) ;
}
printf ( " ## Relax NG test suite for libxml2 \n " ) ;
cur = xmlDocGetRootElement ( doc ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSuite " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , filename ) ;
ret = - 1 ;
goto done ;
}
cur = getNext ( cur , " ./testSuite[1] " ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSuite " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , filename ) ;
ret = - 1 ;
goto done ;
}
while ( cur ! = NULL ) {
2005-07-04 18:25:34 +04:00
xsdTestSuite ( cur ) ;
2005-07-02 11:31:28 +04:00
cur = getNext ( cur , " following-sibling::testSuite[1] " ) ;
}
done :
if ( doc ! = NULL )
xmlFreeDoc ( doc ) ;
return ( ret ) ;
}
2005-06-30 17:04:44 +04:00
/************************************************************************
* *
2005-07-03 01:39:06 +04:00
* Schemas test suites from W3C / NIST / MS / Sun *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int
2005-07-04 18:25:34 +04:00
xstcTestInstance ( xmlNodePtr cur , xmlSchemaPtr schemas ,
2005-07-04 01:00:34 +04:00
const xmlChar * spath , const char * base ) {
2005-07-03 01:39:06 +04:00
xmlChar * href = NULL ;
xmlChar * path = NULL ;
2005-07-03 18:35:44 +04:00
xmlChar * validity = NULL ;
xmlSchemaValidCtxtPtr ctxt = NULL ;
xmlDocPtr doc = NULL ;
int ret = 0 , mem ;
2005-07-03 01:39:06 +04:00
2005-07-03 18:35:44 +04:00
xmlResetLastError ( ) ;
2005-07-04 18:25:34 +04:00
testErrorsSize = 0 ; testErrors [ 0 ] = 0 ;
2005-07-03 18:35:44 +04:00
mem = xmlMemUsed ( ) ;
2005-07-03 01:39:06 +04:00
href = getString ( cur ,
2005-07-03 18:35:44 +04:00
" string(ts:instanceDocument/@xlink:href) " ) ;
2005-07-03 01:39:06 +04:00
if ( ( href = = NULL ) | | ( href [ 0 ] = = 0 ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " testGroup line %ld misses href for schemaDocument \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 18:35:44 +04:00
path = xmlBuildURI ( href , BAD_CAST base ) ;
2005-07-03 01:39:06 +04:00
if ( path = = NULL ) {
fprintf ( stderr ,
" Failed to build path to schemas testGroup line %ld : %s \n " ,
xmlGetLineNo ( cur ) , href ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 18:35:44 +04:00
if ( checkTestFile ( ( const char * ) path ) < = 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " schemas for testGroup line %ld is missing: %s \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) , path ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 18:35:44 +04:00
validity = getString ( cur ,
" string(ts:expected/@validity) " ) ;
if ( validity = = NULL ) {
fprintf ( stderr , " instanceDocument line %ld misses expected validity \n " ,
xmlGetLineNo ( cur ) ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 01:39:06 +04:00
nb_tests + + ;
2005-07-03 18:35:44 +04:00
doc = xmlReadFile ( ( const char * ) path , NULL , XML_PARSE_NOENT ) ;
if ( doc = = NULL ) {
fprintf ( stderr , " instance %s fails to parse \n " , path ) ;
ret = - 1 ;
nb_errors + + ;
goto done ;
}
ctxt = xmlSchemaNewValidCtxt ( schemas ) ;
2019-01-01 18:48:40 +03:00
xmlSchemaSetValidErrors ( ctxt , testErrorHandler , testErrorHandler , ctxt ) ;
2005-07-03 18:35:44 +04:00
ret = xmlSchemaValidateDoc ( ctxt , doc ) ;
if ( xmlStrEqual ( validity , BAD_CAST " valid " ) ) {
2005-07-04 18:25:34 +04:00
if ( ret > 0 ) {
test_log ( " valid instance %s failed to validate against %s \n " ,
path , spath ) ;
nb_errors + + ;
} else if ( ret < 0 ) {
test_log ( " valid instance %s got internal error validating %s \n " ,
2005-07-03 18:35:44 +04:00
path , spath ) ;
2005-07-04 18:25:34 +04:00
nb_internals + + ;
2005-07-03 18:35:44 +04:00
nb_errors + + ;
}
} else if ( xmlStrEqual ( validity , BAD_CAST " invalid " ) ) {
if ( ret = = 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to detect invalid instance %s against %s \n " ,
2005-07-03 18:35:44 +04:00
path , spath ) ;
nb_errors + + ;
}
} else {
2005-07-04 18:25:34 +04:00
test_log ( " instanceDocument line %ld has unexpected validity value%s \n " ,
2005-07-03 18:35:44 +04:00
xmlGetLineNo ( cur ) , validity ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 01:39:06 +04:00
done :
if ( href ! = NULL ) xmlFree ( href ) ;
if ( path ! = NULL ) xmlFree ( path ) ;
2005-07-03 18:35:44 +04:00
if ( validity ! = NULL ) xmlFree ( validity ) ;
if ( ctxt ! = NULL ) xmlSchemaFreeValidCtxt ( ctxt ) ;
if ( doc ! = NULL ) xmlFreeDoc ( doc ) ;
xmlResetLastError ( ) ;
if ( mem ! = xmlMemUsed ( ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " Validation of tests starting line %ld leaked %d \n " ,
2005-07-03 18:35:44 +04:00
xmlGetLineNo ( cur ) , xmlMemUsed ( ) - mem ) ;
nb_leaks + + ;
}
2005-07-03 01:39:06 +04:00
return ( ret ) ;
}
2005-07-03 18:35:44 +04:00
2005-07-03 01:39:06 +04:00
static int
2005-07-04 18:25:34 +04:00
xstcTestGroup ( xmlNodePtr cur , const char * base ) {
2005-07-03 01:39:06 +04:00
xmlChar * href = NULL ;
xmlChar * path = NULL ;
xmlChar * validity = NULL ;
xmlSchemaPtr schemas = NULL ;
xmlSchemaParserCtxtPtr ctxt ;
xmlNodePtr instance ;
2005-07-03 18:35:44 +04:00
int ret = 0 , mem ;
2005-07-03 01:39:06 +04:00
2005-07-03 18:35:44 +04:00
xmlResetLastError ( ) ;
2005-07-04 18:25:34 +04:00
testErrorsSize = 0 ; testErrors [ 0 ] = 0 ;
2005-07-03 18:35:44 +04:00
mem = xmlMemUsed ( ) ;
2005-07-03 01:39:06 +04:00
href = getString ( cur ,
" string(ts:schemaTest/ts:schemaDocument/@xlink:href) " ) ;
if ( ( href = = NULL ) | | ( href [ 0 ] = = 0 ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " testGroup line %ld misses href for schemaDocument \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 18:35:44 +04:00
path = xmlBuildURI ( href , BAD_CAST base ) ;
2005-07-03 01:39:06 +04:00
if ( path = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to build path to schemas testGroup line %ld : %s \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) , href ) ;
ret = - 1 ;
goto done ;
}
2005-07-03 18:35:44 +04:00
if ( checkTestFile ( ( const char * ) path ) < = 0 ) {
2005-07-04 18:25:34 +04:00
test_log ( " schemas for testGroup line %ld is missing: %s \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) , path ) ;
ret = - 1 ;
goto done ;
}
validity = getString ( cur ,
" string(ts:schemaTest/ts:expected/@validity) " ) ;
if ( validity = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " testGroup line %ld misses expected validity \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) ) ;
ret = - 1 ;
goto done ;
}
2005-07-04 18:25:34 +04:00
nb_tests + + ;
2005-07-03 01:39:06 +04:00
if ( xmlStrEqual ( validity , BAD_CAST " valid " ) ) {
2005-07-04 18:25:34 +04:00
nb_schematas + + ;
2005-07-03 18:35:44 +04:00
ctxt = xmlSchemaNewParserCtxt ( ( const char * ) path ) ;
2019-01-01 18:48:40 +03:00
xmlSchemaSetParserErrors ( ctxt , testErrorHandler , testErrorHandler ,
ctxt ) ;
2005-07-03 01:39:06 +04:00
schemas = xmlSchemaParse ( ctxt ) ;
xmlSchemaFreeParserCtxt ( ctxt ) ;
if ( schemas = = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " valid schemas %s failed to parse \n " ,
2005-07-03 01:39:06 +04:00
path ) ;
2005-07-04 19:45:10 +04:00
ret = 1 ;
nb_errors + + ;
}
if ( ( ret = = 0 ) & & ( strstr ( testErrors , " nimplemented " ) ! = NULL ) ) {
test_log ( " valid schemas %s hit an unimplemented block \n " ,
path ) ;
ret = 1 ;
nb_unimplemented + + ;
2005-07-03 01:39:06 +04:00
nb_errors + + ;
}
instance = getNext ( cur , " ./ts:instanceTest[1] " ) ;
while ( instance ! = NULL ) {
2005-12-09 13:03:27 +03:00
if ( schemas ! = NULL ) {
2012-09-11 09:26:36 +04:00
xstcTestInstance ( instance , schemas , path , base ) ;
2005-12-09 13:03:27 +03:00
} else {
/*
* We ' ll automatically mark the instances as failed
* if the schema was broken .
*/
nb_errors + + ;
}
2005-07-03 01:39:06 +04:00
instance = getNext ( instance ,
2005-12-09 13:03:27 +03:00
" following-sibling::ts:instanceTest[1] " ) ;
2005-07-03 01:39:06 +04:00
}
} else if ( xmlStrEqual ( validity , BAD_CAST " invalid " ) ) {
2005-07-04 18:25:34 +04:00
nb_schematas + + ;
2005-07-03 18:35:44 +04:00
ctxt = xmlSchemaNewParserCtxt ( ( const char * ) path ) ;
2019-01-01 18:48:40 +03:00
xmlSchemaSetParserErrors ( ctxt , testErrorHandler , testErrorHandler ,
ctxt ) ;
2005-07-03 01:39:06 +04:00
schemas = xmlSchemaParse ( ctxt ) ;
xmlSchemaFreeParserCtxt ( ctxt ) ;
2005-07-04 19:20:27 +04:00
if ( schemas ! = NULL ) {
2005-07-04 18:25:34 +04:00
test_log ( " Failed to detect error in schemas %s \n " ,
2005-07-03 01:39:06 +04:00
path ) ;
nb_errors + + ;
2005-07-04 19:45:10 +04:00
ret = 1 ;
}
if ( ( ret = = 0 ) & & ( strstr ( testErrors , " nimplemented " ) ! = NULL ) ) {
nb_unimplemented + + ;
test_log ( " invalid schemas %s hit an unimplemented block \n " ,
path ) ;
ret = 1 ;
nb_errors + + ;
2005-07-03 01:39:06 +04:00
}
} else {
2005-07-04 18:25:34 +04:00
test_log ( " testGroup line %ld misses unexpected validity value%s \n " ,
2005-07-03 01:39:06 +04:00
xmlGetLineNo ( cur ) , validity ) ;
ret = - 1 ;
goto done ;
}
done :
if ( href ! = NULL ) xmlFree ( href ) ;
if ( path ! = NULL ) xmlFree ( path ) ;
if ( validity ! = NULL ) xmlFree ( validity ) ;
if ( schemas ! = NULL ) xmlSchemaFree ( schemas ) ;
2005-07-03 18:35:44 +04:00
xmlResetLastError ( ) ;
2024-06-11 12:34:48 +03:00
if ( mem ! = xmlMemUsed ( ) ) {
2005-07-04 18:25:34 +04:00
test_log ( " Processing test line %ld %s leaked %d \n " ,
xmlGetLineNo ( cur ) , path , xmlMemUsed ( ) - mem ) ;
2005-07-03 18:35:44 +04:00
nb_leaks + + ;
}
2005-07-03 01:39:06 +04:00
return ( ret ) ;
}
static int
2005-07-04 18:25:34 +04:00
xstcMetadata ( const char * metadata , const char * base ) {
2005-07-03 01:39:06 +04:00
xmlDocPtr doc ;
xmlNodePtr cur ;
xmlChar * contributor ;
xmlChar * name ;
2005-07-04 01:00:34 +04:00
int ret = 0 ;
2005-07-03 01:39:06 +04:00
doc = xmlReadFile ( metadata , NULL , XML_PARSE_NOENT ) ;
if ( doc = = NULL ) {
fprintf ( stderr , " Failed to parse %s \n " , metadata ) ;
return ( - 1 ) ;
}
cur = xmlDocGetRootElement ( doc ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testSet " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , metadata ) ;
return ( - 1 ) ;
}
contributor = xmlGetProp ( cur , BAD_CAST " contributor " ) ;
if ( contributor = = NULL ) {
contributor = xmlStrdup ( BAD_CAST " Unknown " ) ;
}
name = xmlGetProp ( cur , BAD_CAST " name " ) ;
if ( name = = NULL ) {
name = xmlStrdup ( BAD_CAST " Unknown " ) ;
}
printf ( " ## %s test suite for Schemas version %s \n " , contributor , name ) ;
xmlFree ( contributor ) ;
xmlFree ( name ) ;
cur = getNext ( cur , " ./ts:testGroup[1] " ) ;
if ( ( cur = = NULL ) | | ( ! xmlStrEqual ( cur - > name , BAD_CAST " testGroup " ) ) ) {
fprintf ( stderr , " Unexpected format %s \n " , metadata ) ;
ret = - 1 ;
goto done ;
}
while ( cur ! = NULL ) {
2005-07-04 18:25:34 +04:00
xstcTestGroup ( cur , base ) ;
2005-07-03 01:39:06 +04:00
cur = getNext ( cur , " following-sibling::ts:testGroup[1] " ) ;
}
done :
xmlFreeDoc ( doc ) ;
return ( ret ) ;
}
/************************************************************************
* *
* The driver for the tests *
2005-06-30 17:04:44 +04:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int
main ( int argc ATTRIBUTE_UNUSED , char * * argv ATTRIBUTE_UNUSED ) {
2005-12-10 14:11:12 +03:00
int ret = 0 ;
2023-11-07 23:08:01 +03:00
int old_errors , old_tests , old_leaks , expected_errors ;
2005-06-30 17:04:44 +04:00
2024-06-22 22:28:40 +03:00
logfile = fopen ( LOGFILE , " wb " ) ;
2005-07-04 18:25:34 +04:00
if ( logfile = = NULL ) {
fprintf ( stderr ,
" Could not open the log file, running in verbose mode \n " ) ;
verbose = 1 ;
}
2005-06-30 17:04:44 +04:00
initializeLibxml2 ( ) ;
if ( ( argc > = 2 ) & & ( ! strcmp ( argv [ 1 ] , " -v " ) ) )
verbose = 1 ;
2005-07-02 11:31:28 +04:00
old_errors = nb_errors ;
old_tests = nb_tests ;
old_leaks = nb_leaks ;
2005-12-10 14:11:12 +03:00
xsdTest ( ) ;
2023-11-07 23:08:01 +03:00
expected_errors = 3 ;
2022-12-08 02:24:53 +03:00
printf ( " Ran %d tests, %d errors, %d leaks \n " ,
nb_tests - old_tests ,
nb_errors - old_errors ,
nb_leaks - old_leaks ) ;
2023-11-07 23:08:01 +03:00
if ( nb_errors - old_errors = = expected_errors ) {
printf ( " %d errors were expected \n " , expected_errors ) ;
2022-12-08 02:24:53 +03:00
nb_errors = old_errors ;
} else {
2023-11-07 23:08:01 +03:00
printf ( " %d errors were expected, got %d errors \n " ,
expected_errors , nb_errors - old_errors ) ;
2022-12-08 02:24:53 +03:00
nb_errors = old_errors + 1 ;
}
2022-12-22 17:35:28 +03:00
2005-06-30 17:04:44 +04:00
old_errors = nb_errors ;
old_tests = nb_tests ;
old_leaks = nb_leaks ;
2005-12-10 14:11:12 +03:00
rngTest1 ( ) ;
2005-06-30 17:04:44 +04:00
if ( ( nb_errors = = old_errors ) & & ( nb_leaks = = old_leaks ) )
printf ( " Ran %d tests, no errors \n " , nb_tests - old_tests ) ;
else
printf ( " Ran %d tests, %d errors, %d leaks \n " ,
nb_tests - old_tests ,
nb_errors - old_errors ,
nb_leaks - old_leaks ) ;
2022-12-22 17:35:28 +03:00
2005-06-30 17:04:44 +04:00
old_errors = nb_errors ;
old_tests = nb_tests ;
old_leaks = nb_leaks ;
2005-12-10 14:11:12 +03:00
rngTest2 ( ) ;
2005-07-02 11:31:28 +04:00
if ( ( nb_errors = = old_errors ) & & ( nb_leaks = = old_leaks ) )
printf ( " Ran %d tests, no errors \n " , nb_tests - old_tests ) ;
else
printf ( " Ran %d tests, %d errors, %d leaks \n " ,
nb_tests - old_tests ,
nb_errors - old_errors ,
nb_leaks - old_leaks ) ;
2022-12-22 17:35:28 +03:00
2005-07-02 11:31:28 +04:00
old_errors = nb_errors ;
old_tests = nb_tests ;
old_leaks = nb_leaks ;
2005-07-04 18:25:34 +04:00
nb_internals = 0 ;
nb_schematas = 0 ;
2005-12-10 14:11:12 +03:00
xstcMetadata ( " xstc/Tests/Metadata/NISTXMLSchemaDatatypes.testSet " ,
2005-07-03 18:35:44 +04:00
" xstc/Tests/Metadata/ " ) ;
if ( ( nb_errors = = old_errors ) & & ( nb_leaks = = old_leaks ) )
2005-07-04 18:25:34 +04:00
printf ( " Ran %d tests (%d schemata), no errors \n " ,
nb_tests - old_tests , nb_schematas ) ;
2005-07-03 18:35:44 +04:00
else
2005-07-04 18:25:34 +04:00
printf ( " Ran %d tests (%d schemata), %d errors (%d internals), %d leaks \n " ,
2005-07-03 18:35:44 +04:00
nb_tests - old_tests ,
2005-07-04 18:25:34 +04:00
nb_schematas ,
2005-07-03 18:35:44 +04:00
nb_errors - old_errors ,
2005-07-04 18:25:34 +04:00
nb_internals ,
2005-07-03 18:35:44 +04:00
nb_leaks - old_leaks ) ;
2022-12-22 17:35:28 +03:00
2005-07-03 18:35:44 +04:00
old_errors = nb_errors ;
old_tests = nb_tests ;
old_leaks = nb_leaks ;
2005-07-04 18:25:34 +04:00
nb_internals = 0 ;
nb_schematas = 0 ;
2005-12-10 14:11:12 +03:00
xstcMetadata ( " xstc/Tests/Metadata/SunXMLSchema1-0-20020116.testSet " ,
2005-07-04 18:25:34 +04:00
" xstc/Tests/ " ) ;
2022-12-22 17:35:28 +03:00
if ( ( nb_errors = = old_errors ) & & ( nb_leaks = = old_leaks ) ) {
2005-07-04 18:25:34 +04:00
printf ( " Ran %d tests (%d schemata), no errors \n " ,
nb_tests - old_tests , nb_schematas ) ;
2022-12-22 17:35:28 +03:00
} else {
2005-07-04 18:25:34 +04:00
printf ( " Ran %d tests (%d schemata), %d errors (%d internals), %d leaks \n " ,
2005-07-03 18:35:44 +04:00
nb_tests - old_tests ,
2005-07-04 18:25:34 +04:00
nb_schematas ,
2005-07-03 18:35:44 +04:00
nb_errors - old_errors ,
2005-07-04 18:25:34 +04:00
nb_internals ,
2005-07-03 18:35:44 +04:00
nb_leaks - old_leaks ) ;
2022-12-22 17:35:28 +03:00
printf ( " Some errors were expected. \n " ) ;
nb_errors = old_errors ;
}
2005-07-03 18:35:44 +04:00
old_errors = nb_errors ;
old_tests = nb_tests ;
old_leaks = nb_leaks ;
2005-07-04 18:25:34 +04:00
nb_internals = 0 ;
nb_schematas = 0 ;
2005-12-10 14:11:12 +03:00
xstcMetadata ( " xstc/Tests/Metadata/MSXMLSchema1-0-20020116.testSet " ,
2005-07-03 18:35:44 +04:00
" xstc/Tests/ " ) ;
2022-12-22 17:35:28 +03:00
if ( ( nb_errors = = old_errors ) & & ( nb_leaks = = old_leaks ) ) {
2005-07-04 18:25:34 +04:00
printf ( " Ran %d tests (%d schemata), no errors \n " ,
nb_tests - old_tests , nb_schematas ) ;
2022-12-22 17:35:28 +03:00
} else {
2005-07-04 18:25:34 +04:00
printf ( " Ran %d tests (%d schemata), %d errors (%d internals), %d leaks \n " ,
2005-07-03 01:39:06 +04:00
nb_tests - old_tests ,
2005-07-04 18:25:34 +04:00
nb_schematas ,
2005-07-03 01:39:06 +04:00
nb_errors - old_errors ,
2005-07-04 18:25:34 +04:00
nb_internals ,
2005-07-03 01:39:06 +04:00
nb_leaks - old_leaks ) ;
2022-12-22 17:35:28 +03:00
printf ( " Some errors were expected. \n " ) ;
nb_errors = old_errors ;
}
2005-06-30 17:04:44 +04:00
if ( ( nb_errors = = 0 ) & & ( nb_leaks = = 0 ) ) {
ret = 0 ;
printf ( " Total %d tests, no errors \n " ,
nb_tests ) ;
} else {
ret = 1 ;
printf ( " Total %d tests, %d errors, %d leaks \n " ,
nb_tests , nb_errors , nb_leaks ) ;
}
2005-07-03 01:39:06 +04:00
xmlXPathFreeContext ( ctxtXPath ) ;
2005-06-30 17:04:44 +04:00
xmlCleanupParser ( ) ;
2005-07-04 18:25:34 +04:00
if ( logfile ! = NULL )
fclose ( logfile ) ;
2005-06-30 17:04:44 +04:00
return ( ret ) ;
}
2005-07-03 20:09:51 +04:00
# else /* !SCHEMAS */
int
main ( int argc ATTRIBUTE_UNUSED , char * * argv ATTRIBUTE_UNUSED ) {
fprintf ( stderr , " runsuite requires support for schemas and xpath in libxml2 \n " ) ;
}
# endif