Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 2 | * runsuite.c: C program to run libxml2 againts published testsuites |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
| 6 | * daniel@veillard.com |
| 7 | */ |
| 8 | |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 9 | #if !defined(_WIN32) || defined(__CYGWIN__) |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 10 | #include <unistd.h> |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 11 | #endif |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 12 | #include <string.h> |
| 13 | #include <stdio.h> |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 14 | #include <sys/types.h> |
| 15 | #include <sys/stat.h> |
| 16 | #include <fcntl.h> |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 17 | |
| 18 | #include <libxml/parser.h> |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 19 | #include <libxml/parserInternals.h> |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 20 | #include <libxml/tree.h> |
| 21 | #include <libxml/uri.h> |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 22 | #if defined(LIBXML_SCHEMAS_ENABLED) && defined(LIBXML_XPATH_ENABLED) |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 23 | #include <libxml/xmlreader.h> |
| 24 | |
| 25 | #include <libxml/xpath.h> |
| 26 | #include <libxml/xpathInternals.h> |
| 27 | |
| 28 | #include <libxml/relaxng.h> |
| 29 | #include <libxml/xmlschemas.h> |
| 30 | #include <libxml/xmlschemastypes.h> |
| 31 | |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 32 | #define LOGFILE "runsuite.log" |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 33 | static FILE *logfile = NULL; |
| 34 | static int verbose = 0;
|
Kasimier T. Buchcik | 87db1cf | 2005-07-05 10:40:52 +0000 | [diff] [blame] | 35 |
|
| 36 | #if defined(_WIN32) && !defined(__CYGWIN__)
|
| 37 | #define vsnprintf _vsnprintf
|
| 38 | #define snprintf _snprintf
|
| 39 | #endif |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 40 | |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 41 | /************************************************************************ |
| 42 | * * |
| 43 | * File name and path utilities * |
| 44 | * * |
| 45 | ************************************************************************/ |
| 46 | |
| 47 | static int checkTestFile(const char *filename) { |
| 48 | struct stat buf; |
| 49 | |
| 50 | if (stat(filename, &buf) == -1) |
| 51 | return(0); |
| 52 | |
Daniel Veillard | cfbb0dd | 2005-07-04 17:12:01 +0000 | [diff] [blame] | 53 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 54 | if (!(buf.st_mode & _S_IFREG)) |
| 55 | return(0); |
| 56 | #else |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 57 | if (!S_ISREG(buf.st_mode)) |
| 58 | return(0); |
Daniel Veillard | cfbb0dd | 2005-07-04 17:12:01 +0000 | [diff] [blame] | 59 | #endif |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 60 | |
| 61 | return(1); |
| 62 | } |
Daniel Veillard | cfbb0dd | 2005-07-04 17:12:01 +0000 | [diff] [blame] | 63 | |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 64 | static xmlChar *composeDir(const xmlChar *dir, const xmlChar *path) { |
| 65 | char buf[500]; |
| 66 | |
| 67 | if (dir == NULL) return(xmlStrdup(path)); |
| 68 | if (path == NULL) return(NULL); |
| 69 | |
| 70 | snprintf(buf, 500, "%s/%s", (const char *) dir, (const char *) path); |
| 71 | return(xmlStrdup((const xmlChar *) buf)); |
| 72 | } |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 73 | |
| 74 | /************************************************************************ |
| 75 | * * |
| 76 | * Libxml2 specific routines * |
| 77 | * * |
| 78 | ************************************************************************/ |
| 79 | |
| 80 | static int nb_tests = 0; |
| 81 | static int nb_errors = 0; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 82 | static int nb_internals = 0; |
| 83 | static int nb_schematas = 0; |
Daniel Veillard | 9083778 | 2005-07-04 15:45:10 +0000 | [diff] [blame] | 84 | static int nb_unimplemented = 0; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 85 | static int nb_leaks = 0; |
| 86 | static long libxmlMemoryAllocatedBase = 0; |
| 87 | static int extraMemoryFromResolver = 0; |
| 88 | |
| 89 | static int |
| 90 | fatalError(void) { |
| 91 | fprintf(stderr, "Exitting tests on fatal error\n"); |
| 92 | exit(1); |
| 93 | } |
| 94 | |
| 95 | /* |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 96 | * that's needed to implement <resource> |
| 97 | */ |
| 98 | #define MAX_ENTITIES 20 |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 99 | static char *testEntitiesName[MAX_ENTITIES]; |
| 100 | static char *testEntitiesValue[MAX_ENTITIES]; |
| 101 | static int nb_entities = 0; |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 102 | static void resetEntities(void) { |
| 103 | int i; |
| 104 | |
| 105 | for (i = 0;i < nb_entities;i++) { |
| 106 | if (testEntitiesName[i] != NULL) |
| 107 | xmlFree(testEntitiesName[i]); |
| 108 | if (testEntitiesValue[i] != NULL) |
| 109 | xmlFree(testEntitiesValue[i]); |
| 110 | } |
| 111 | nb_entities = 0; |
| 112 | } |
| 113 | static int addEntity(char *name, char *content) { |
| 114 | if (nb_entities >= MAX_ENTITIES) { |
| 115 | fprintf(stderr, "Too many entities defined\n"); |
| 116 | return(-1); |
| 117 | } |
| 118 | testEntitiesName[nb_entities] = name; |
| 119 | testEntitiesValue[nb_entities] = content; |
| 120 | nb_entities++; |
| 121 | return(0); |
| 122 | } |
| 123 | |
| 124 | /* |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 125 | * We need to trap calls to the resolver to not account memory for the catalog |
| 126 | * which is shared to the current running test. We also don't want to have |
| 127 | * network downloads modifying tests. |
| 128 | */ |
| 129 | static xmlParserInputPtr |
| 130 | testExternalEntityLoader(const char *URL, const char *ID, |
| 131 | xmlParserCtxtPtr ctxt) { |
| 132 | xmlParserInputPtr ret; |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 133 | int i; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 134 | |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 135 | for (i = 0;i < nb_entities;i++) { |
| 136 | if (!strcmp(testEntitiesName[i], URL)) { |
| 137 | ret = xmlNewStringInputStream(ctxt, |
| 138 | (const xmlChar *) testEntitiesValue[i]); |
| 139 | if (ret != NULL) { |
| 140 | ret->filename = (const char *) |
| 141 | xmlStrdup((xmlChar *)testEntitiesName[i]); |
| 142 | } |
| 143 | return(ret); |
| 144 | } |
| 145 | } |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 146 | if (checkTestFile(URL)) { |
| 147 | ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt); |
| 148 | } else { |
| 149 | int memused = xmlMemUsed(); |
| 150 | ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt); |
| 151 | extraMemoryFromResolver += xmlMemUsed() - memused; |
| 152 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 153 | #if 0 |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 154 | if (ret == NULL) { |
| 155 | fprintf(stderr, "Failed to find resource %s\n", URL); |
| 156 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 157 | #endif |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 158 | |
| 159 | return(ret); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Trapping the error messages at the generic level to grab the equivalent of |
| 164 | * stderr messages on CLI tools. |
| 165 | */ |
| 166 | static char testErrors[32769]; |
| 167 | static int testErrorsSize = 0; |
| 168 | |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 169 | static void test_log(const char *msg, ...) { |
| 170 | va_list args; |
| 171 | if (logfile != NULL) { |
| 172 | fprintf(logfile, "\n------------\n"); |
| 173 | va_start(args, msg); |
| 174 | vfprintf(logfile, msg, args); |
| 175 | va_end(args); |
| 176 | fprintf(logfile, "%s", testErrors); |
| 177 | testErrorsSize = 0; testErrors[0] = 0; |
| 178 | } |
| 179 | if (verbose) { |
| 180 | va_start(args, msg); |
| 181 | vfprintf(stderr, msg, args); |
| 182 | va_end(args); |
| 183 | } |
| 184 | } |
| 185 | |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 186 | static void |
| 187 | testErrorHandler(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) { |
| 188 | va_list args; |
| 189 | int res; |
| 190 | |
| 191 | if (testErrorsSize >= 32768) |
| 192 | return; |
| 193 | va_start(args, msg); |
| 194 | res = vsnprintf(&testErrors[testErrorsSize], |
| 195 | 32768 - testErrorsSize, |
| 196 | msg, args); |
| 197 | va_end(args); |
| 198 | if (testErrorsSize + res >= 32768) { |
| 199 | /* buffer is full */ |
| 200 | testErrorsSize = 32768; |
| 201 | testErrors[testErrorsSize] = 0; |
| 202 | } else { |
| 203 | testErrorsSize += res; |
| 204 | } |
| 205 | testErrors[testErrorsSize] = 0; |
| 206 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 207 | |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 208 | static xmlXPathContextPtr ctxtXPath; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 209 | |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 210 | static void |
| 211 | initializeLibxml2(void) { |
| 212 | xmlGetWarningsDefaultValue = 0; |
| 213 | xmlPedanticParserDefault(0); |
| 214 | |
| 215 | xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup); |
| 216 | xmlInitParser(); |
| 217 | xmlSetExternalEntityLoader(testExternalEntityLoader); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 218 | ctxtXPath = xmlXPathNewContext(NULL); |
| 219 | /* used as default nanemspace in xstc tests */ |
| 220 | xmlXPathRegisterNs(ctxtXPath, BAD_CAST "ts", BAD_CAST "TestSuite"); |
| 221 | xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink", |
| 222 | BAD_CAST "http://www.w3.org/1999/xlink"); |
| 223 | xmlSetGenericErrorFunc(NULL, testErrorHandler); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 224 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 225 | xmlSchemaInitTypes(); |
| 226 | xmlRelaxNGInitTypes(); |
| 227 | #endif |
| 228 | libxmlMemoryAllocatedBase = xmlMemUsed(); |
| 229 | } |
| 230 | |
| 231 | static xmlNodePtr |
| 232 | getNext(xmlNodePtr cur, const char *xpath) { |
| 233 | xmlNodePtr ret = NULL; |
| 234 | xmlXPathObjectPtr res; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 235 | xmlXPathCompExprPtr comp; |
| 236 | |
| 237 | if ((cur == NULL) || (cur->doc == NULL) || (xpath == NULL)) |
| 238 | return(NULL); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 239 | ctxtXPath->doc = cur->doc; |
| 240 | ctxtXPath->node = cur; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 241 | comp = xmlXPathCompile(BAD_CAST xpath); |
| 242 | if (comp == NULL) { |
| 243 | fprintf(stderr, "Failed to compile %s\n", xpath); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 244 | return(NULL); |
| 245 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 246 | res = xmlXPathCompiledEval(comp, ctxtXPath); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 247 | xmlXPathFreeCompExpr(comp); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 248 | if (res == NULL) |
| 249 | return(NULL); |
| 250 | if ((res->type == XPATH_NODESET) && |
| 251 | (res->nodesetval != NULL) && |
| 252 | (res->nodesetval->nodeNr > 0) && |
| 253 | (res->nodesetval->nodeTab != NULL)) |
| 254 | ret = res->nodesetval->nodeTab[0]; |
| 255 | xmlXPathFreeObject(res); |
| 256 | return(ret); |
| 257 | } |
| 258 | |
| 259 | static xmlChar * |
| 260 | getString(xmlNodePtr cur, const char *xpath) { |
| 261 | xmlChar *ret = NULL; |
| 262 | xmlXPathObjectPtr res; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 263 | xmlXPathCompExprPtr comp; |
| 264 | |
| 265 | if ((cur == NULL) || (cur->doc == NULL) || (xpath == NULL)) |
| 266 | return(NULL); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 267 | ctxtXPath->doc = cur->doc; |
| 268 | ctxtXPath->node = cur; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 269 | comp = xmlXPathCompile(BAD_CAST xpath); |
| 270 | if (comp == NULL) { |
| 271 | fprintf(stderr, "Failed to compile %s\n", xpath); |
| 272 | return(NULL); |
| 273 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 274 | res = xmlXPathCompiledEval(comp, ctxtXPath); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 275 | xmlXPathFreeCompExpr(comp); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 276 | if (res == NULL) |
| 277 | return(NULL); |
| 278 | if (res->type == XPATH_STRING) { |
| 279 | ret = res->stringval; |
| 280 | res->stringval = NULL; |
| 281 | } |
| 282 | xmlXPathFreeObject(res); |
| 283 | return(ret); |
| 284 | } |
| 285 | |
| 286 | /************************************************************************ |
| 287 | * * |
| 288 | * Test test/xsdtest/xsdtestsuite.xml * |
| 289 | * * |
| 290 | ************************************************************************/ |
| 291 | |
| 292 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 293 | xsdIncorectTestCase(xmlNodePtr cur) { |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 294 | xmlNodePtr test; |
| 295 | xmlBufferPtr buf; |
| 296 | xmlRelaxNGParserCtxtPtr pctxt; |
| 297 | xmlRelaxNGPtr rng = NULL; |
| 298 | int ret = 0, memt; |
| 299 | |
| 300 | cur = getNext(cur, "./incorrect[1]"); |
| 301 | if (cur == NULL) { |
| 302 | return(0); |
| 303 | } |
| 304 | |
| 305 | test = getNext(cur, "./*"); |
| 306 | if (test == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 307 | test_log("Failed to find test in correct line %ld\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 308 | xmlGetLineNo(cur)); |
| 309 | return(1); |
| 310 | } |
| 311 | |
| 312 | memt = xmlMemUsed(); |
| 313 | extraMemoryFromResolver = 0; |
| 314 | /* |
| 315 | * dump the schemas to a buffer, then reparse it and compile the schemas |
| 316 | */ |
| 317 | buf = xmlBufferCreate(); |
| 318 | if (buf == NULL) { |
| 319 | fprintf(stderr, "out of memory !\n"); |
| 320 | fatalError(); |
| 321 | } |
| 322 | xmlNodeDump(buf, test->doc, test, 0, 0); |
| 323 | pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use); |
| 324 | xmlRelaxNGSetParserErrors(pctxt, |
| 325 | (xmlRelaxNGValidityErrorFunc) testErrorHandler, |
| 326 | (xmlRelaxNGValidityWarningFunc) testErrorHandler, |
| 327 | pctxt); |
| 328 | rng = xmlRelaxNGParse(pctxt); |
| 329 | xmlRelaxNGFreeParserCtxt(pctxt); |
| 330 | if (rng != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 331 | test_log("Failed to detect incorect RNG line %ld\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 332 | xmlGetLineNo(test)); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 333 | ret = 1; |
| 334 | goto done; |
| 335 | } |
| 336 | |
| 337 | done: |
| 338 | if (buf != NULL) |
| 339 | xmlBufferFree(buf); |
| 340 | if (rng != NULL) |
| 341 | xmlRelaxNGFree(rng); |
| 342 | xmlResetLastError(); |
| 343 | if ((memt != xmlMemUsed()) && (extraMemoryFromResolver == 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 344 | test_log("Validation of tests starting line %ld leaked %d\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 345 | xmlGetLineNo(cur), xmlMemUsed() - memt); |
| 346 | nb_leaks++; |
| 347 | } |
| 348 | return(ret); |
| 349 | } |
| 350 | |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 351 | static void |
| 352 | installResources(xmlNodePtr tst, const xmlChar *base) { |
| 353 | xmlNodePtr test; |
| 354 | xmlBufferPtr buf; |
| 355 | xmlChar *name, *content, *res; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 356 | |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 357 | buf = xmlBufferCreate(); |
| 358 | if (buf == NULL) { |
| 359 | fprintf(stderr, "out of memory !\n"); |
| 360 | fatalError(); |
| 361 | } |
| 362 | xmlNodeDump(buf, tst->doc, tst, 0, 0); |
| 363 | |
| 364 | while (tst != NULL) { |
| 365 | test = getNext(tst, "./*"); |
| 366 | if (test != NULL) { |
| 367 | xmlBufferEmpty(buf); |
| 368 | xmlNodeDump(buf, test->doc, test, 0, 0); |
| 369 | name = getString(tst, "string(@name)"); |
| 370 | content = xmlStrdup(buf->content); |
| 371 | if ((name != NULL) && (content != NULL)) { |
| 372 | res = composeDir(base, name); |
| 373 | xmlFree(name); |
| 374 | addEntity((char *) res, (char *) content); |
| 375 | } else { |
| 376 | if (name != NULL) xmlFree(name); |
| 377 | if (content != NULL) xmlFree(content); |
| 378 | } |
| 379 | } |
| 380 | tst = getNext(tst, "following-sibling::resource[1]"); |
| 381 | } |
| 382 | if (buf != NULL) |
| 383 | xmlBufferFree(buf); |
| 384 | } |
| 385 | |
| 386 | static void |
| 387 | installDirs(xmlNodePtr tst, const xmlChar *base) { |
| 388 | xmlNodePtr test; |
| 389 | xmlChar *name, *res; |
| 390 | |
| 391 | name = getString(tst, "string(@name)"); |
| 392 | if (name == NULL) |
| 393 | return; |
| 394 | res = composeDir(base, name); |
| 395 | xmlFree(name); |
| 396 | if (res == NULL) { |
| 397 | return; |
| 398 | } |
| 399 | /* Now process resources and subdir recursively */ |
| 400 | test = getNext(tst, "./resource[1]"); |
| 401 | if (test != NULL) { |
| 402 | installResources(test, res); |
| 403 | } |
| 404 | test = getNext(tst, "./dir[1]"); |
| 405 | while (test != NULL) { |
| 406 | installDirs(test, res); |
| 407 | test = getNext(test, "following-sibling::dir[1]"); |
| 408 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 409 | xmlFree(res); |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 412 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 413 | xsdTestCase(xmlNodePtr tst) { |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 414 | xmlNodePtr test, tmp, cur; |
| 415 | xmlBufferPtr buf; |
| 416 | xmlDocPtr doc = NULL; |
| 417 | xmlRelaxNGParserCtxtPtr pctxt; |
| 418 | xmlRelaxNGValidCtxtPtr ctxt; |
| 419 | xmlRelaxNGPtr rng = NULL; |
| 420 | int ret = 0, mem, memt; |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 421 | xmlChar *dtd; |
| 422 | |
| 423 | resetEntities(); |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 424 | testErrorsSize = 0; testErrors[0] = 0; |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 425 | |
| 426 | tmp = getNext(tst, "./dir[1]"); |
| 427 | if (tmp != NULL) { |
| 428 | installDirs(tmp, NULL); |
| 429 | } |
| 430 | tmp = getNext(tst, "./resource[1]"); |
| 431 | if (tmp != NULL) { |
| 432 | installResources(tmp, NULL); |
| 433 | } |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 434 | |
| 435 | cur = getNext(tst, "./correct[1]"); |
| 436 | if (cur == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 437 | return(xsdIncorectTestCase(tst)); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | test = getNext(cur, "./*"); |
| 441 | if (test == NULL) { |
| 442 | fprintf(stderr, "Failed to find test in correct line %ld\n", |
| 443 | xmlGetLineNo(cur)); |
| 444 | return(1); |
| 445 | } |
| 446 | |
| 447 | memt = xmlMemUsed(); |
| 448 | extraMemoryFromResolver = 0; |
| 449 | /* |
| 450 | * dump the schemas to a buffer, then reparse it and compile the schemas |
| 451 | */ |
| 452 | buf = xmlBufferCreate(); |
| 453 | if (buf == NULL) { |
| 454 | fprintf(stderr, "out of memory !\n"); |
| 455 | fatalError(); |
| 456 | } |
| 457 | xmlNodeDump(buf, test->doc, test, 0, 0); |
| 458 | pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use); |
| 459 | xmlRelaxNGSetParserErrors(pctxt, |
| 460 | (xmlRelaxNGValidityErrorFunc) testErrorHandler, |
| 461 | (xmlRelaxNGValidityWarningFunc) testErrorHandler, |
| 462 | pctxt); |
| 463 | rng = xmlRelaxNGParse(pctxt); |
| 464 | xmlRelaxNGFreeParserCtxt(pctxt); |
| 465 | if (extraMemoryFromResolver) |
| 466 | memt = 0; |
| 467 | |
| 468 | if (rng == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 469 | test_log("Failed to parse RNGtest line %ld\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 470 | xmlGetLineNo(test)); |
| 471 | nb_errors++; |
| 472 | ret = 1; |
| 473 | goto done; |
| 474 | } |
| 475 | /* |
| 476 | * now scan all the siblings of correct to process the <valid> tests |
| 477 | */ |
| 478 | tmp = getNext(cur, "following-sibling::valid[1]"); |
| 479 | while (tmp != NULL) { |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 480 | dtd = xmlGetProp(tmp, BAD_CAST "dtd"); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 481 | test = getNext(tmp, "./*"); |
| 482 | if (test == NULL) { |
| 483 | fprintf(stderr, "Failed to find test in <valid> line %ld\n", |
| 484 | xmlGetLineNo(tmp)); |
| 485 | |
| 486 | } else { |
| 487 | xmlBufferEmpty(buf); |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 488 | if (dtd != NULL) |
| 489 | xmlBufferAdd(buf, dtd, -1); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 490 | xmlNodeDump(buf, test->doc, test, 0, 0); |
| 491 | |
| 492 | /* |
| 493 | * We are ready to run the test |
| 494 | */ |
| 495 | mem = xmlMemUsed(); |
| 496 | extraMemoryFromResolver = 0; |
| 497 | doc = xmlReadMemory((const char *)buf->content, buf->use, |
| 498 | "test", NULL, 0); |
| 499 | if (doc == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 500 | test_log("Failed to parse valid instance line %ld\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 501 | xmlGetLineNo(tmp)); |
| 502 | nb_errors++; |
| 503 | } else { |
| 504 | nb_tests++; |
| 505 | ctxt = xmlRelaxNGNewValidCtxt(rng); |
| 506 | xmlRelaxNGSetValidErrors(ctxt, |
| 507 | (xmlRelaxNGValidityErrorFunc) testErrorHandler, |
| 508 | (xmlRelaxNGValidityWarningFunc) testErrorHandler, |
| 509 | ctxt); |
| 510 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 511 | xmlRelaxNGFreeValidCtxt(ctxt); |
| 512 | if (ret > 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 513 | test_log("Failed to validate valid instance line %ld\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 514 | xmlGetLineNo(tmp)); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 515 | nb_errors++; |
| 516 | } else if (ret < 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 517 | test_log("Internal error validating instance line %ld\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 518 | xmlGetLineNo(tmp)); |
| 519 | nb_errors++; |
| 520 | } |
| 521 | xmlFreeDoc(doc); |
| 522 | } |
| 523 | xmlResetLastError(); |
| 524 | if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 525 | test_log("Validation of instance line %ld leaked %d\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 526 | xmlGetLineNo(tmp), xmlMemUsed() - mem); |
| 527 | xmlMemoryDump(); |
| 528 | nb_leaks++; |
| 529 | } |
| 530 | } |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 531 | if (dtd != NULL) |
| 532 | xmlFree(dtd); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 533 | tmp = getNext(tmp, "following-sibling::valid[1]"); |
| 534 | } |
| 535 | /* |
| 536 | * now scan all the siblings of correct to process the <invalid> tests |
| 537 | */ |
| 538 | tmp = getNext(cur, "following-sibling::invalid[1]"); |
| 539 | while (tmp != NULL) { |
| 540 | test = getNext(tmp, "./*"); |
| 541 | if (test == NULL) { |
| 542 | fprintf(stderr, "Failed to find test in <invalid> line %ld\n", |
| 543 | xmlGetLineNo(tmp)); |
| 544 | |
| 545 | } else { |
| 546 | xmlBufferEmpty(buf); |
| 547 | xmlNodeDump(buf, test->doc, test, 0, 0); |
| 548 | |
| 549 | /* |
| 550 | * We are ready to run the test |
| 551 | */ |
| 552 | mem = xmlMemUsed(); |
| 553 | extraMemoryFromResolver = 0; |
| 554 | doc = xmlReadMemory((const char *)buf->content, buf->use, |
| 555 | "test", NULL, 0); |
| 556 | if (doc == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 557 | test_log("Failed to parse valid instance line %ld\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 558 | xmlGetLineNo(tmp)); |
| 559 | nb_errors++; |
| 560 | } else { |
| 561 | nb_tests++; |
| 562 | ctxt = xmlRelaxNGNewValidCtxt(rng); |
| 563 | xmlRelaxNGSetValidErrors(ctxt, |
| 564 | (xmlRelaxNGValidityErrorFunc) testErrorHandler, |
| 565 | (xmlRelaxNGValidityWarningFunc) testErrorHandler, |
| 566 | ctxt); |
| 567 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 568 | xmlRelaxNGFreeValidCtxt(ctxt); |
| 569 | if (ret == 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 570 | test_log("Failed to detect invalid instance line %ld\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 571 | xmlGetLineNo(tmp)); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 572 | nb_errors++; |
| 573 | } else if (ret < 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 574 | test_log("Internal error validating instance line %ld\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 575 | xmlGetLineNo(tmp)); |
| 576 | nb_errors++; |
| 577 | } |
| 578 | xmlFreeDoc(doc); |
| 579 | } |
| 580 | xmlResetLastError(); |
| 581 | if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 582 | test_log("Validation of instance line %ld leaked %d\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 583 | xmlGetLineNo(tmp), xmlMemUsed() - mem); |
| 584 | xmlMemoryDump(); |
| 585 | nb_leaks++; |
| 586 | } |
| 587 | } |
| 588 | tmp = getNext(tmp, "following-sibling::invalid[1]"); |
| 589 | } |
| 590 | |
| 591 | done: |
| 592 | if (buf != NULL) |
| 593 | xmlBufferFree(buf); |
| 594 | if (rng != NULL) |
| 595 | xmlRelaxNGFree(rng); |
| 596 | xmlResetLastError(); |
| 597 | if ((memt != xmlMemUsed()) && (memt != 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 598 | test_log("Validation of tests starting line %ld leaked %d\n", |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 599 | xmlGetLineNo(cur), xmlMemUsed() - memt); |
| 600 | nb_leaks++; |
| 601 | } |
| 602 | return(ret); |
| 603 | } |
| 604 | |
| 605 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 606 | xsdTestSuite(xmlNodePtr cur) { |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 607 | if (verbose) { |
| 608 | xmlChar *doc = getString(cur, "string(documentation)"); |
| 609 | |
| 610 | if (doc != NULL) { |
| 611 | printf("Suite %s\n", doc); |
| 612 | xmlFree(doc); |
| 613 | } |
| 614 | } |
| 615 | cur = getNext(cur, "./testCase[1]"); |
| 616 | while (cur != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 617 | xsdTestCase(cur); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 618 | cur = getNext(cur, "following-sibling::testCase[1]"); |
| 619 | } |
| 620 | |
| 621 | return(0); |
| 622 | } |
| 623 | |
| 624 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 625 | xsdTest(void) { |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 626 | xmlDocPtr doc; |
| 627 | xmlNodePtr cur; |
| 628 | const char *filename = "test/xsdtest/xsdtestsuite.xml"; |
| 629 | int ret = 0; |
| 630 | |
| 631 | doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT); |
| 632 | if (doc == NULL) { |
| 633 | fprintf(stderr, "Failed to parse %s\n", filename); |
| 634 | return(-1); |
| 635 | } |
| 636 | printf("## XML Schemas datatypes test suite from James Clark\n"); |
| 637 | |
| 638 | cur = xmlDocGetRootElement(doc); |
| 639 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) { |
| 640 | fprintf(stderr, "Unexpected format %s\n", filename); |
| 641 | ret = -1; |
| 642 | goto done; |
| 643 | } |
| 644 | |
| 645 | cur = getNext(cur, "./testSuite[1]"); |
| 646 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) { |
| 647 | fprintf(stderr, "Unexpected format %s\n", filename); |
| 648 | ret = -1; |
| 649 | goto done; |
| 650 | } |
| 651 | while (cur != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 652 | xsdTestSuite(cur); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 653 | cur = getNext(cur, "following-sibling::testSuite[1]"); |
| 654 | } |
| 655 | |
| 656 | done: |
| 657 | if (doc != NULL) |
| 658 | xmlFreeDoc(doc); |
| 659 | return(ret); |
| 660 | } |
| 661 | |
| 662 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 663 | rngTestSuite(xmlNodePtr cur) { |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 664 | if (verbose) { |
| 665 | xmlChar *doc = getString(cur, "string(documentation)"); |
| 666 | |
| 667 | if (doc != NULL) { |
| 668 | printf("Suite %s\n", doc); |
| 669 | xmlFree(doc); |
| 670 | } else { |
| 671 | doc = getString(cur, "string(section)"); |
| 672 | if (doc != NULL) { |
| 673 | printf("Section %s\n", doc); |
| 674 | xmlFree(doc); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | cur = getNext(cur, "./testSuite[1]"); |
| 679 | while (cur != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 680 | xsdTestSuite(cur); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 681 | cur = getNext(cur, "following-sibling::testSuite[1]"); |
| 682 | } |
| 683 | |
| 684 | return(0); |
| 685 | } |
| 686 | |
| 687 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 688 | rngTest1(void) { |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 689 | xmlDocPtr doc; |
| 690 | xmlNodePtr cur; |
| 691 | const char *filename = "test/relaxng/OASIS/spectest.xml"; |
| 692 | int ret = 0; |
| 693 | |
| 694 | doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT); |
| 695 | if (doc == NULL) { |
| 696 | fprintf(stderr, "Failed to parse %s\n", filename); |
| 697 | return(-1); |
| 698 | } |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 699 | printf("## Relax NG test suite from James Clark\n"); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 700 | |
| 701 | cur = xmlDocGetRootElement(doc); |
| 702 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) { |
| 703 | fprintf(stderr, "Unexpected format %s\n", filename); |
| 704 | ret = -1; |
| 705 | goto done; |
| 706 | } |
| 707 | |
| 708 | cur = getNext(cur, "./testSuite[1]"); |
| 709 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) { |
| 710 | fprintf(stderr, "Unexpected format %s\n", filename); |
| 711 | ret = -1; |
| 712 | goto done; |
| 713 | } |
| 714 | while (cur != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 715 | rngTestSuite(cur); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 716 | cur = getNext(cur, "following-sibling::testSuite[1]"); |
| 717 | } |
| 718 | |
| 719 | done: |
| 720 | if (doc != NULL) |
| 721 | xmlFreeDoc(doc); |
| 722 | return(ret); |
| 723 | } |
| 724 | |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 725 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 726 | rngTest2(void) { |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 727 | xmlDocPtr doc; |
| 728 | xmlNodePtr cur; |
| 729 | const char *filename = "test/relaxng/testsuite.xml"; |
| 730 | int ret = 0; |
| 731 | |
| 732 | doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT); |
| 733 | if (doc == NULL) { |
| 734 | fprintf(stderr, "Failed to parse %s\n", filename); |
| 735 | return(-1); |
| 736 | } |
| 737 | printf("## Relax NG test suite for libxml2\n"); |
| 738 | |
| 739 | cur = xmlDocGetRootElement(doc); |
| 740 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) { |
| 741 | fprintf(stderr, "Unexpected format %s\n", filename); |
| 742 | ret = -1; |
| 743 | goto done; |
| 744 | } |
| 745 | |
| 746 | cur = getNext(cur, "./testSuite[1]"); |
| 747 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) { |
| 748 | fprintf(stderr, "Unexpected format %s\n", filename); |
| 749 | ret = -1; |
| 750 | goto done; |
| 751 | } |
| 752 | while (cur != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 753 | xsdTestSuite(cur); |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 754 | cur = getNext(cur, "following-sibling::testSuite[1]"); |
| 755 | } |
| 756 | |
| 757 | done: |
| 758 | if (doc != NULL) |
| 759 | xmlFreeDoc(doc); |
| 760 | return(ret); |
| 761 | } |
| 762 | |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 763 | /************************************************************************ |
| 764 | * * |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 765 | * Schemas test suites from W3C/NIST/MS/Sun * |
| 766 | * * |
| 767 | ************************************************************************/ |
| 768 | |
| 769 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 770 | xstcTestInstance(xmlNodePtr cur, xmlSchemaPtr schemas, |
Daniel Veillard | 6b6d680 | 2005-07-03 21:00:34 +0000 | [diff] [blame] | 771 | const xmlChar *spath, const char *base) { |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 772 | xmlChar *href = NULL; |
| 773 | xmlChar *path = NULL; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 774 | xmlChar *validity = NULL; |
| 775 | xmlSchemaValidCtxtPtr ctxt = NULL; |
| 776 | xmlDocPtr doc = NULL; |
| 777 | int ret = 0, mem; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 778 | |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 779 | xmlResetLastError(); |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 780 | testErrorsSize = 0; testErrors[0] = 0; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 781 | mem = xmlMemUsed(); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 782 | href = getString(cur, |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 783 | "string(ts:instanceDocument/@xlink:href)"); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 784 | if ((href == NULL) || (href[0] == 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 785 | test_log("testGroup line %ld misses href for schemaDocument\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 786 | xmlGetLineNo(cur)); |
| 787 | ret = -1; |
| 788 | goto done; |
| 789 | } |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 790 | path = xmlBuildURI(href, BAD_CAST base); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 791 | if (path == NULL) { |
| 792 | fprintf(stderr, |
| 793 | "Failed to build path to schemas testGroup line %ld : %s\n", |
| 794 | xmlGetLineNo(cur), href); |
| 795 | ret = -1; |
| 796 | goto done; |
| 797 | } |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 798 | if (checkTestFile((const char *) path) <= 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 799 | test_log("schemas for testGroup line %ld is missing: %s\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 800 | xmlGetLineNo(cur), path); |
| 801 | ret = -1; |
| 802 | goto done; |
| 803 | } |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 804 | validity = getString(cur, |
| 805 | "string(ts:expected/@validity)"); |
| 806 | if (validity == NULL) { |
| 807 | fprintf(stderr, "instanceDocument line %ld misses expected validity\n", |
| 808 | xmlGetLineNo(cur)); |
| 809 | ret = -1; |
| 810 | goto done; |
| 811 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 812 | nb_tests++; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 813 | doc = xmlReadFile((const char *) path, NULL, XML_PARSE_NOENT); |
| 814 | if (doc == NULL) { |
| 815 | fprintf(stderr, "instance %s fails to parse\n", path); |
| 816 | ret = -1; |
| 817 | nb_errors++; |
| 818 | goto done; |
| 819 | } |
| 820 | |
| 821 | ctxt = xmlSchemaNewValidCtxt(schemas); |
| 822 | xmlSchemaSetValidErrors(ctxt, |
| 823 | (xmlSchemaValidityErrorFunc) testErrorHandler, |
| 824 | (xmlSchemaValidityWarningFunc) testErrorHandler, |
| 825 | ctxt); |
| 826 | ret = xmlSchemaValidateDoc(ctxt, doc); |
| 827 | |
| 828 | if (xmlStrEqual(validity, BAD_CAST "valid")) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 829 | if (ret > 0) { |
| 830 | test_log("valid instance %s failed to validate against %s\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 831 | path, spath); |
| 832 | nb_errors++; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 833 | } else if (ret < 0) { |
| 834 | test_log("valid instance %s got internal error validating %s\n", |
| 835 | path, spath); |
| 836 | nb_internals++; |
| 837 | nb_errors++; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 838 | } |
| 839 | } else if (xmlStrEqual(validity, BAD_CAST "invalid")) { |
| 840 | if (ret == 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 841 | test_log("Failed to detect invalid instance %s against %s\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 842 | path, spath); |
| 843 | nb_errors++; |
| 844 | } |
| 845 | } else { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 846 | test_log("instanceDocument line %ld has unexpected validity value%s\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 847 | xmlGetLineNo(cur), validity); |
| 848 | ret = -1; |
| 849 | goto done; |
| 850 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 851 | |
| 852 | done: |
| 853 | if (href != NULL) xmlFree(href); |
| 854 | if (path != NULL) xmlFree(path); |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 855 | if (validity != NULL) xmlFree(validity); |
| 856 | if (ctxt != NULL) xmlSchemaFreeValidCtxt(ctxt); |
| 857 | if (doc != NULL) xmlFreeDoc(doc); |
| 858 | xmlResetLastError(); |
| 859 | if (mem != xmlMemUsed()) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 860 | test_log("Validation of tests starting line %ld leaked %d\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 861 | xmlGetLineNo(cur), xmlMemUsed() - mem); |
| 862 | nb_leaks++; |
| 863 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 864 | return(ret); |
| 865 | } |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 866 | |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 867 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 868 | xstcTestGroup(xmlNodePtr cur, const char *base) { |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 869 | xmlChar *href = NULL; |
| 870 | xmlChar *path = NULL; |
| 871 | xmlChar *validity = NULL; |
| 872 | xmlSchemaPtr schemas = NULL; |
| 873 | xmlSchemaParserCtxtPtr ctxt; |
| 874 | xmlNodePtr instance; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 875 | int ret = 0, mem; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 876 | |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 877 | xmlResetLastError(); |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 878 | testErrorsSize = 0; testErrors[0] = 0; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 879 | mem = xmlMemUsed(); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 880 | href = getString(cur, |
| 881 | "string(ts:schemaTest/ts:schemaDocument/@xlink:href)"); |
| 882 | if ((href == NULL) || (href[0] == 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 883 | test_log("testGroup line %ld misses href for schemaDocument\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 884 | xmlGetLineNo(cur)); |
| 885 | ret = -1; |
| 886 | goto done; |
| 887 | } |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 888 | path = xmlBuildURI(href, BAD_CAST base); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 889 | if (path == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 890 | test_log("Failed to build path to schemas testGroup line %ld : %s\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 891 | xmlGetLineNo(cur), href); |
| 892 | ret = -1; |
| 893 | goto done; |
| 894 | } |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 895 | if (checkTestFile((const char *) path) <= 0) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 896 | test_log("schemas for testGroup line %ld is missing: %s\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 897 | xmlGetLineNo(cur), path); |
| 898 | ret = -1; |
| 899 | goto done; |
| 900 | } |
| 901 | validity = getString(cur, |
| 902 | "string(ts:schemaTest/ts:expected/@validity)"); |
| 903 | if (validity == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 904 | test_log("testGroup line %ld misses expected validity\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 905 | xmlGetLineNo(cur)); |
| 906 | ret = -1; |
| 907 | goto done; |
| 908 | } |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 909 | nb_tests++; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 910 | if (xmlStrEqual(validity, BAD_CAST "valid")) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 911 | nb_schematas++; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 912 | ctxt = xmlSchemaNewParserCtxt((const char *) path); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 913 | xmlSchemaSetParserErrors(ctxt, |
| 914 | (xmlSchemaValidityErrorFunc) testErrorHandler, |
| 915 | (xmlSchemaValidityWarningFunc) testErrorHandler, |
| 916 | ctxt); |
| 917 | schemas = xmlSchemaParse(ctxt); |
| 918 | xmlSchemaFreeParserCtxt(ctxt); |
| 919 | if (schemas == NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 920 | test_log("valid schemas %s failed to parse\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 921 | path); |
Daniel Veillard | 9083778 | 2005-07-04 15:45:10 +0000 | [diff] [blame] | 922 | ret = 1; |
| 923 | nb_errors++; |
| 924 | } |
| 925 | if ((ret == 0) && (strstr(testErrors, "nimplemented") != NULL)) { |
| 926 | test_log("valid schemas %s hit an unimplemented block\n", |
| 927 | path); |
| 928 | ret = 1; |
| 929 | nb_unimplemented++; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 930 | nb_errors++; |
| 931 | } |
| 932 | instance = getNext(cur, "./ts:instanceTest[1]"); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 933 | while (instance != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 934 | xstcTestInstance(instance, schemas, path, base); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 935 | instance = getNext(instance, |
| 936 | "following-sibling::ts:instanceTest[1]"); |
| 937 | } |
| 938 | } else if (xmlStrEqual(validity, BAD_CAST "invalid")) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 939 | nb_schematas++; |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 940 | ctxt = xmlSchemaNewParserCtxt((const char *) path); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 941 | xmlSchemaSetParserErrors(ctxt, |
| 942 | (xmlSchemaValidityErrorFunc) testErrorHandler, |
| 943 | (xmlSchemaValidityWarningFunc) testErrorHandler, |
| 944 | ctxt); |
| 945 | schemas = xmlSchemaParse(ctxt); |
| 946 | xmlSchemaFreeParserCtxt(ctxt); |
Daniel Veillard | 4ac5f9a | 2005-07-04 15:20:27 +0000 | [diff] [blame] | 947 | if (schemas != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 948 | test_log("Failed to detect error in schemas %s\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 949 | path); |
| 950 | nb_errors++; |
Daniel Veillard | 9083778 | 2005-07-04 15:45:10 +0000 | [diff] [blame] | 951 | ret = 1; |
| 952 | } |
| 953 | if ((ret == 0) && (strstr(testErrors, "nimplemented") != NULL)) { |
| 954 | nb_unimplemented++; |
| 955 | test_log("invalid schemas %s hit an unimplemented block\n", |
| 956 | path); |
| 957 | ret = 1; |
| 958 | nb_errors++; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 959 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 960 | } else { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 961 | test_log("testGroup line %ld misses unexpected validity value%s\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 962 | xmlGetLineNo(cur), validity); |
| 963 | ret = -1; |
| 964 | goto done; |
| 965 | } |
| 966 | |
| 967 | done: |
| 968 | if (href != NULL) xmlFree(href); |
| 969 | if (path != NULL) xmlFree(path); |
| 970 | if (validity != NULL) xmlFree(validity); |
| 971 | if (schemas != NULL) xmlSchemaFree(schemas); |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 972 | xmlResetLastError(); |
| 973 | if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 974 | test_log("Processing test line %ld %s leaked %d\n", |
| 975 | xmlGetLineNo(cur), path, xmlMemUsed() - mem); |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 976 | nb_leaks++; |
| 977 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 978 | return(ret); |
| 979 | } |
| 980 | |
| 981 | static int |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 982 | xstcMetadata(const char *metadata, const char *base) { |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 983 | xmlDocPtr doc; |
| 984 | xmlNodePtr cur; |
| 985 | xmlChar *contributor; |
| 986 | xmlChar *name; |
Daniel Veillard | 6b6d680 | 2005-07-03 21:00:34 +0000 | [diff] [blame] | 987 | int ret = 0; |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 988 | |
| 989 | doc = xmlReadFile(metadata, NULL, XML_PARSE_NOENT); |
| 990 | if (doc == NULL) { |
| 991 | fprintf(stderr, "Failed to parse %s\n", metadata); |
| 992 | return(-1); |
| 993 | } |
| 994 | |
| 995 | cur = xmlDocGetRootElement(doc); |
| 996 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSet"))) { |
| 997 | fprintf(stderr, "Unexpected format %s\n", metadata); |
| 998 | return(-1); |
| 999 | } |
| 1000 | contributor = xmlGetProp(cur, BAD_CAST "contributor"); |
| 1001 | if (contributor == NULL) { |
| 1002 | contributor = xmlStrdup(BAD_CAST "Unknown"); |
| 1003 | } |
| 1004 | name = xmlGetProp(cur, BAD_CAST "name"); |
| 1005 | if (name == NULL) { |
| 1006 | name = xmlStrdup(BAD_CAST "Unknown"); |
| 1007 | } |
| 1008 | printf("## %s test suite for Schemas version %s\n", contributor, name); |
| 1009 | xmlFree(contributor); |
| 1010 | xmlFree(name); |
| 1011 | |
| 1012 | cur = getNext(cur, "./ts:testGroup[1]"); |
| 1013 | if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testGroup"))) { |
| 1014 | fprintf(stderr, "Unexpected format %s\n", metadata); |
| 1015 | ret = -1; |
| 1016 | goto done; |
| 1017 | } |
| 1018 | while (cur != NULL) { |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1019 | xstcTestGroup(cur, base); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1020 | cur = getNext(cur, "following-sibling::ts:testGroup[1]"); |
| 1021 | } |
| 1022 | |
| 1023 | done: |
| 1024 | xmlFreeDoc(doc); |
| 1025 | return(ret); |
| 1026 | } |
| 1027 | |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1028 | /************************************************************************ |
| 1029 | * * |
| 1030 | * The driver for the tests * |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1031 | * * |
| 1032 | ************************************************************************/ |
| 1033 | |
| 1034 | int |
| 1035 | main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 1036 | int res, ret = 0; |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1037 | int old_errors, old_tests, old_leaks; |
| 1038 | |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1039 | logfile = fopen(LOGFILE, "w"); |
| 1040 | if (logfile == NULL) { |
| 1041 | fprintf(stderr, |
| 1042 | "Could not open the log file, running in verbose mode\n"); |
| 1043 | verbose = 1; |
| 1044 | } |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1045 | initializeLibxml2(); |
| 1046 | |
| 1047 | if ((argc >= 2) && (!strcmp(argv[1], "-v"))) |
| 1048 | verbose = 1; |
| 1049 | |
| 1050 | |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 1051 | old_errors = nb_errors; |
| 1052 | old_tests = nb_tests; |
| 1053 | old_leaks = nb_leaks; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1054 | res = xsdTest(); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1055 | if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) |
| 1056 | printf("Ran %d tests, no errors\n", nb_tests - old_tests); |
| 1057 | else |
| 1058 | printf("Ran %d tests, %d errors, %d leaks\n", |
| 1059 | nb_tests - old_tests, |
| 1060 | nb_errors - old_errors, |
| 1061 | nb_leaks - old_leaks); |
| 1062 | old_errors = nb_errors; |
| 1063 | old_tests = nb_tests; |
| 1064 | old_leaks = nb_leaks; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1065 | res = rngTest1(); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1066 | if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) |
| 1067 | printf("Ran %d tests, no errors\n", nb_tests - old_tests); |
| 1068 | else |
| 1069 | printf("Ran %d tests, %d errors, %d leaks\n", |
| 1070 | nb_tests - old_tests, |
| 1071 | nb_errors - old_errors, |
| 1072 | nb_leaks - old_leaks); |
| 1073 | old_errors = nb_errors; |
| 1074 | old_tests = nb_tests; |
| 1075 | old_leaks = nb_leaks; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1076 | res = rngTest2(); |
Daniel Veillard | e84f231 | 2005-07-02 07:31:28 +0000 | [diff] [blame] | 1077 | if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) |
| 1078 | printf("Ran %d tests, no errors\n", nb_tests - old_tests); |
| 1079 | else |
| 1080 | printf("Ran %d tests, %d errors, %d leaks\n", |
| 1081 | nb_tests - old_tests, |
| 1082 | nb_errors - old_errors, |
| 1083 | nb_leaks - old_leaks); |
| 1084 | old_errors = nb_errors; |
| 1085 | old_tests = nb_tests; |
| 1086 | old_leaks = nb_leaks; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1087 | nb_internals = 0; |
| 1088 | nb_schematas = 0; |
| 1089 | res = xstcMetadata( |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1090 | "xstc/Tests/Metadata/NISTXMLSchemaDatatypes.testSet", |
| 1091 | "xstc/Tests/Metadata/"); |
| 1092 | if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1093 | printf("Ran %d tests (%d schemata), no errors\n", |
| 1094 | nb_tests - old_tests, nb_schematas); |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1095 | else |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1096 | printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1097 | nb_tests - old_tests, |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1098 | nb_schematas, |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1099 | nb_errors - old_errors, |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1100 | nb_internals, |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1101 | nb_leaks - old_leaks); |
| 1102 | old_errors = nb_errors; |
| 1103 | old_tests = nb_tests; |
| 1104 | old_leaks = nb_leaks; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1105 | nb_internals = 0; |
| 1106 | nb_schematas = 0; |
| 1107 | res = xstcMetadata( |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1108 | "xstc/Tests/Metadata/SunXMLSchema1-0-20020116.testSet", |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1109 | "xstc/Tests/"); |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1110 | if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1111 | printf("Ran %d tests (%d schemata), no errors\n", |
| 1112 | nb_tests - old_tests, nb_schematas); |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1113 | else |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1114 | printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n", |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1115 | nb_tests - old_tests, |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1116 | nb_schematas, |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1117 | nb_errors - old_errors, |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1118 | nb_internals, |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1119 | nb_leaks - old_leaks); |
| 1120 | old_errors = nb_errors; |
| 1121 | old_tests = nb_tests; |
| 1122 | old_leaks = nb_leaks; |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1123 | nb_internals = 0; |
| 1124 | nb_schematas = 0; |
| 1125 | res = xstcMetadata( |
Daniel Veillard | de0e498 | 2005-07-03 14:35:44 +0000 | [diff] [blame] | 1126 | "xstc/Tests/Metadata/MSXMLSchema1-0-20020116.testSet", |
| 1127 | "xstc/Tests/"); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1128 | if ((nb_errors == old_errors) && (nb_leaks == old_leaks)) |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1129 | printf("Ran %d tests (%d schemata), no errors\n", |
| 1130 | nb_tests - old_tests, nb_schematas); |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1131 | else |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1132 | printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n", |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1133 | nb_tests - old_tests, |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1134 | nb_schematas, |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1135 | nb_errors - old_errors, |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1136 | nb_internals, |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1137 | nb_leaks - old_leaks); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1138 | |
| 1139 | if ((nb_errors == 0) && (nb_leaks == 0)) { |
| 1140 | ret = 0; |
| 1141 | printf("Total %d tests, no errors\n", |
| 1142 | nb_tests); |
| 1143 | } else { |
| 1144 | ret = 1; |
| 1145 | printf("Total %d tests, %d errors, %d leaks\n", |
| 1146 | nb_tests, nb_errors, nb_leaks); |
| 1147 | } |
Daniel Veillard | 3fe1e8a | 2005-07-02 21:39:06 +0000 | [diff] [blame] | 1148 | |
| 1149 | xmlXPathFreeContext(ctxtXPath); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1150 | xmlCleanupParser(); |
| 1151 | xmlMemoryDump(); |
| 1152 | |
Daniel Veillard | c935253 | 2005-07-04 14:25:34 +0000 | [diff] [blame] | 1153 | if (logfile != NULL) |
| 1154 | fclose(logfile); |
Daniel Veillard | f2e066a | 2005-06-30 13:04:44 +0000 | [diff] [blame] | 1155 | return(ret); |
| 1156 | } |
Daniel Veillard | 9517501 | 2005-07-03 16:09:51 +0000 | [diff] [blame] | 1157 | #else /* !SCHEMAS */ |
| 1158 | int |
| 1159 | main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 1160 | fprintf(stderr, "runsuite requires support for schemas and xpath in libxml2\n"); |
| 1161 | } |
| 1162 | #endif |