blob: deef1297e1295dda5eaf4d7b7c4d2fe4fd32989f [file] [log] [blame]
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001/*
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00002 * runsuite.c: C program to run libxml2 againts published testsuites
Daniel Veillardf2e066a2005-06-30 13:04:44 +00003 *
4 * See Copyright for the status of this software.
5 *
6 * daniel@veillard.com
7 */
8
Daniel Veillardc9352532005-07-04 14:25:34 +00009#if !defined(_WIN32) || defined(__CYGWIN__)
Daniel Veillardf2e066a2005-06-30 13:04:44 +000010#include <unistd.h>
Daniel Veillardc9352532005-07-04 14:25:34 +000011#endif
Daniel Veillardf2e066a2005-06-30 13:04:44 +000012#include <string.h>
13#include <stdio.h>
14#include <glob.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <fcntl.h>
Daniel Veillardf2e066a2005-06-30 13:04:44 +000018
19#include <libxml/parser.h>
Daniel Veillarde84f2312005-07-02 07:31:28 +000020#include <libxml/parserInternals.h>
Daniel Veillardf2e066a2005-06-30 13:04:44 +000021#include <libxml/tree.h>
22#include <libxml/uri.h>
Daniel Veillard95175012005-07-03 16:09:51 +000023#if defined(LIBXML_SCHEMAS_ENABLED) && defined(LIBXML_XPATH_ENABLED)
Daniel Veillardf2e066a2005-06-30 13:04:44 +000024#include <libxml/xmlreader.h>
25
26#include <libxml/xpath.h>
27#include <libxml/xpathInternals.h>
28
29#include <libxml/relaxng.h>
30#include <libxml/xmlschemas.h>
31#include <libxml/xmlschemastypes.h>
32
Daniel Veillardc9352532005-07-04 14:25:34 +000033#define LOGFILE "runsuite.log"
34FILE *logfile = NULL;
35int verbose = 0;
36
Daniel Veillardf2e066a2005-06-30 13:04:44 +000037/************************************************************************
38 * *
39 * File name and path utilities *
40 * *
41 ************************************************************************/
42
43static int checkTestFile(const char *filename) {
44 struct stat buf;
45
46 if (stat(filename, &buf) == -1)
47 return(0);
48
49 if (!S_ISREG(buf.st_mode))
50 return(0);
51
52 return(1);
53}
Daniel Veillarde84f2312005-07-02 07:31:28 +000054static xmlChar *composeDir(const xmlChar *dir, const xmlChar *path) {
55 char buf[500];
56
57 if (dir == NULL) return(xmlStrdup(path));
58 if (path == NULL) return(NULL);
59
60 snprintf(buf, 500, "%s/%s", (const char *) dir, (const char *) path);
61 return(xmlStrdup((const xmlChar *) buf));
62}
Daniel Veillardf2e066a2005-06-30 13:04:44 +000063
64/************************************************************************
65 * *
66 * Libxml2 specific routines *
67 * *
68 ************************************************************************/
69
70static int nb_tests = 0;
71static int nb_errors = 0;
Daniel Veillardc9352532005-07-04 14:25:34 +000072static int nb_internals = 0;
73static int nb_schematas = 0;
Daniel Veillard90837782005-07-04 15:45:10 +000074static int nb_unimplemented = 0;
Daniel Veillardf2e066a2005-06-30 13:04:44 +000075static int nb_leaks = 0;
76static long libxmlMemoryAllocatedBase = 0;
77static int extraMemoryFromResolver = 0;
78
79static int
80fatalError(void) {
81 fprintf(stderr, "Exitting tests on fatal error\n");
82 exit(1);
83}
84
85/*
Daniel Veillarde84f2312005-07-02 07:31:28 +000086 * that's needed to implement <resource>
87 */
88#define MAX_ENTITIES 20
89char *testEntitiesName[MAX_ENTITIES];
90char *testEntitiesValue[MAX_ENTITIES];
91int nb_entities = 0;
92static void resetEntities(void) {
93 int i;
94
95 for (i = 0;i < nb_entities;i++) {
96 if (testEntitiesName[i] != NULL)
97 xmlFree(testEntitiesName[i]);
98 if (testEntitiesValue[i] != NULL)
99 xmlFree(testEntitiesValue[i]);
100 }
101 nb_entities = 0;
102}
103static int addEntity(char *name, char *content) {
104 if (nb_entities >= MAX_ENTITIES) {
105 fprintf(stderr, "Too many entities defined\n");
106 return(-1);
107 }
108 testEntitiesName[nb_entities] = name;
109 testEntitiesValue[nb_entities] = content;
110 nb_entities++;
111 return(0);
112}
113
114/*
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000115 * We need to trap calls to the resolver to not account memory for the catalog
116 * which is shared to the current running test. We also don't want to have
117 * network downloads modifying tests.
118 */
119static xmlParserInputPtr
120testExternalEntityLoader(const char *URL, const char *ID,
121 xmlParserCtxtPtr ctxt) {
122 xmlParserInputPtr ret;
Daniel Veillarde84f2312005-07-02 07:31:28 +0000123 int i;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000124
Daniel Veillarde84f2312005-07-02 07:31:28 +0000125 for (i = 0;i < nb_entities;i++) {
126 if (!strcmp(testEntitiesName[i], URL)) {
127 ret = xmlNewStringInputStream(ctxt,
128 (const xmlChar *) testEntitiesValue[i]);
129 if (ret != NULL) {
130 ret->filename = (const char *)
131 xmlStrdup((xmlChar *)testEntitiesName[i]);
132 }
133 return(ret);
134 }
135 }
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000136 if (checkTestFile(URL)) {
137 ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
138 } else {
139 int memused = xmlMemUsed();
140 ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
141 extraMemoryFromResolver += xmlMemUsed() - memused;
142 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000143#if 0
Daniel Veillarde84f2312005-07-02 07:31:28 +0000144 if (ret == NULL) {
145 fprintf(stderr, "Failed to find resource %s\n", URL);
146 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000147#endif
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000148
149 return(ret);
150}
151
152/*
153 * Trapping the error messages at the generic level to grab the equivalent of
154 * stderr messages on CLI tools.
155 */
156static char testErrors[32769];
157static int testErrorsSize = 0;
158
Daniel Veillardc9352532005-07-04 14:25:34 +0000159static void test_log(const char *msg, ...) {
160 va_list args;
161 if (logfile != NULL) {
162 fprintf(logfile, "\n------------\n");
163 va_start(args, msg);
164 vfprintf(logfile, msg, args);
165 va_end(args);
166 fprintf(logfile, "%s", testErrors);
167 testErrorsSize = 0; testErrors[0] = 0;
168 }
169 if (verbose) {
170 va_start(args, msg);
171 vfprintf(stderr, msg, args);
172 va_end(args);
173 }
174}
175
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000176static void
177testErrorHandler(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
178 va_list args;
179 int res;
180
181 if (testErrorsSize >= 32768)
182 return;
183 va_start(args, msg);
184 res = vsnprintf(&testErrors[testErrorsSize],
185 32768 - testErrorsSize,
186 msg, args);
187 va_end(args);
188 if (testErrorsSize + res >= 32768) {
189 /* buffer is full */
190 testErrorsSize = 32768;
191 testErrors[testErrorsSize] = 0;
192 } else {
193 testErrorsSize += res;
194 }
195 testErrors[testErrorsSize] = 0;
196}
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000197
198xmlXPathContextPtr ctxtXPath;
199
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000200static void
201initializeLibxml2(void) {
202 xmlGetWarningsDefaultValue = 0;
203 xmlPedanticParserDefault(0);
204
205 xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
206 xmlInitParser();
207 xmlSetExternalEntityLoader(testExternalEntityLoader);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000208 ctxtXPath = xmlXPathNewContext(NULL);
209 /* used as default nanemspace in xstc tests */
210 xmlXPathRegisterNs(ctxtXPath, BAD_CAST "ts", BAD_CAST "TestSuite");
211 xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink",
212 BAD_CAST "http://www.w3.org/1999/xlink");
213 xmlSetGenericErrorFunc(NULL, testErrorHandler);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000214#ifdef LIBXML_SCHEMAS_ENABLED
215 xmlSchemaInitTypes();
216 xmlRelaxNGInitTypes();
217#endif
218 libxmlMemoryAllocatedBase = xmlMemUsed();
219}
220
221static xmlNodePtr
222getNext(xmlNodePtr cur, const char *xpath) {
223 xmlNodePtr ret = NULL;
224 xmlXPathObjectPtr res;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000225 xmlXPathCompExprPtr comp;
226
227 if ((cur == NULL) || (cur->doc == NULL) || (xpath == NULL))
228 return(NULL);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000229 ctxtXPath->doc = cur->doc;
230 ctxtXPath->node = cur;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000231 comp = xmlXPathCompile(BAD_CAST xpath);
232 if (comp == NULL) {
233 fprintf(stderr, "Failed to compile %s\n", xpath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000234 return(NULL);
235 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000236 res = xmlXPathCompiledEval(comp, ctxtXPath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000237 xmlXPathFreeCompExpr(comp);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000238 if (res == NULL)
239 return(NULL);
240 if ((res->type == XPATH_NODESET) &&
241 (res->nodesetval != NULL) &&
242 (res->nodesetval->nodeNr > 0) &&
243 (res->nodesetval->nodeTab != NULL))
244 ret = res->nodesetval->nodeTab[0];
245 xmlXPathFreeObject(res);
246 return(ret);
247}
248
249static xmlChar *
250getString(xmlNodePtr cur, const char *xpath) {
251 xmlChar *ret = NULL;
252 xmlXPathObjectPtr res;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000253 xmlXPathCompExprPtr comp;
254
255 if ((cur == NULL) || (cur->doc == NULL) || (xpath == NULL))
256 return(NULL);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000257 ctxtXPath->doc = cur->doc;
258 ctxtXPath->node = cur;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000259 comp = xmlXPathCompile(BAD_CAST xpath);
260 if (comp == NULL) {
261 fprintf(stderr, "Failed to compile %s\n", xpath);
262 return(NULL);
263 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000264 res = xmlXPathCompiledEval(comp, ctxtXPath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000265 xmlXPathFreeCompExpr(comp);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000266 if (res == NULL)
267 return(NULL);
268 if (res->type == XPATH_STRING) {
269 ret = res->stringval;
270 res->stringval = NULL;
271 }
272 xmlXPathFreeObject(res);
273 return(ret);
274}
275
276/************************************************************************
277 * *
278 * Test test/xsdtest/xsdtestsuite.xml *
279 * *
280 ************************************************************************/
281
282static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000283xsdIncorectTestCase(xmlNodePtr cur) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000284 xmlNodePtr test;
285 xmlBufferPtr buf;
286 xmlRelaxNGParserCtxtPtr pctxt;
287 xmlRelaxNGPtr rng = NULL;
288 int ret = 0, memt;
289
290 cur = getNext(cur, "./incorrect[1]");
291 if (cur == NULL) {
292 return(0);
293 }
294
295 test = getNext(cur, "./*");
296 if (test == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000297 test_log("Failed to find test in correct line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000298 xmlGetLineNo(cur));
299 return(1);
300 }
301
302 memt = xmlMemUsed();
303 extraMemoryFromResolver = 0;
304 /*
305 * dump the schemas to a buffer, then reparse it and compile the schemas
306 */
307 buf = xmlBufferCreate();
308 if (buf == NULL) {
309 fprintf(stderr, "out of memory !\n");
310 fatalError();
311 }
312 xmlNodeDump(buf, test->doc, test, 0, 0);
313 pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use);
314 xmlRelaxNGSetParserErrors(pctxt,
315 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
316 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
317 pctxt);
318 rng = xmlRelaxNGParse(pctxt);
319 xmlRelaxNGFreeParserCtxt(pctxt);
320 if (rng != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000321 test_log("Failed to detect incorect RNG line %ld\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000322 xmlGetLineNo(test));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000323 ret = 1;
324 goto done;
325 }
326
327done:
328 if (buf != NULL)
329 xmlBufferFree(buf);
330 if (rng != NULL)
331 xmlRelaxNGFree(rng);
332 xmlResetLastError();
333 if ((memt != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000334 test_log("Validation of tests starting line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000335 xmlGetLineNo(cur), xmlMemUsed() - memt);
336 nb_leaks++;
337 }
338 return(ret);
339}
340
Daniel Veillarde84f2312005-07-02 07:31:28 +0000341static void
342installResources(xmlNodePtr tst, const xmlChar *base) {
343 xmlNodePtr test;
344 xmlBufferPtr buf;
345 xmlChar *name, *content, *res;
Daniel Veillardc9352532005-07-04 14:25:34 +0000346
Daniel Veillarde84f2312005-07-02 07:31:28 +0000347 buf = xmlBufferCreate();
348 if (buf == NULL) {
349 fprintf(stderr, "out of memory !\n");
350 fatalError();
351 }
352 xmlNodeDump(buf, tst->doc, tst, 0, 0);
353
354 while (tst != NULL) {
355 test = getNext(tst, "./*");
356 if (test != NULL) {
357 xmlBufferEmpty(buf);
358 xmlNodeDump(buf, test->doc, test, 0, 0);
359 name = getString(tst, "string(@name)");
360 content = xmlStrdup(buf->content);
361 if ((name != NULL) && (content != NULL)) {
362 res = composeDir(base, name);
363 xmlFree(name);
364 addEntity((char *) res, (char *) content);
365 } else {
366 if (name != NULL) xmlFree(name);
367 if (content != NULL) xmlFree(content);
368 }
369 }
370 tst = getNext(tst, "following-sibling::resource[1]");
371 }
372 if (buf != NULL)
373 xmlBufferFree(buf);
374}
375
376static void
377installDirs(xmlNodePtr tst, const xmlChar *base) {
378 xmlNodePtr test;
379 xmlChar *name, *res;
380
381 name = getString(tst, "string(@name)");
382 if (name == NULL)
383 return;
384 res = composeDir(base, name);
385 xmlFree(name);
386 if (res == NULL) {
387 return;
388 }
389 /* Now process resources and subdir recursively */
390 test = getNext(tst, "./resource[1]");
391 if (test != NULL) {
392 installResources(test, res);
393 }
394 test = getNext(tst, "./dir[1]");
395 while (test != NULL) {
396 installDirs(test, res);
397 test = getNext(test, "following-sibling::dir[1]");
398 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000399 xmlFree(res);
Daniel Veillarde84f2312005-07-02 07:31:28 +0000400}
401
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000402static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000403xsdTestCase(xmlNodePtr tst) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000404 xmlNodePtr test, tmp, cur;
405 xmlBufferPtr buf;
406 xmlDocPtr doc = NULL;
407 xmlRelaxNGParserCtxtPtr pctxt;
408 xmlRelaxNGValidCtxtPtr ctxt;
409 xmlRelaxNGPtr rng = NULL;
410 int ret = 0, mem, memt;
Daniel Veillarde84f2312005-07-02 07:31:28 +0000411 xmlChar *dtd;
412
413 resetEntities();
Daniel Veillardc9352532005-07-04 14:25:34 +0000414 testErrorsSize = 0; testErrors[0] = 0;
Daniel Veillarde84f2312005-07-02 07:31:28 +0000415
416 tmp = getNext(tst, "./dir[1]");
417 if (tmp != NULL) {
418 installDirs(tmp, NULL);
419 }
420 tmp = getNext(tst, "./resource[1]");
421 if (tmp != NULL) {
422 installResources(tmp, NULL);
423 }
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000424
425 cur = getNext(tst, "./correct[1]");
426 if (cur == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000427 return(xsdIncorectTestCase(tst));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000428 }
429
430 test = getNext(cur, "./*");
431 if (test == NULL) {
432 fprintf(stderr, "Failed to find test in correct line %ld\n",
433 xmlGetLineNo(cur));
434 return(1);
435 }
436
437 memt = xmlMemUsed();
438 extraMemoryFromResolver = 0;
439 /*
440 * dump the schemas to a buffer, then reparse it and compile the schemas
441 */
442 buf = xmlBufferCreate();
443 if (buf == NULL) {
444 fprintf(stderr, "out of memory !\n");
445 fatalError();
446 }
447 xmlNodeDump(buf, test->doc, test, 0, 0);
448 pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use);
449 xmlRelaxNGSetParserErrors(pctxt,
450 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
451 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
452 pctxt);
453 rng = xmlRelaxNGParse(pctxt);
454 xmlRelaxNGFreeParserCtxt(pctxt);
455 if (extraMemoryFromResolver)
456 memt = 0;
457
458 if (rng == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000459 test_log("Failed to parse RNGtest line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000460 xmlGetLineNo(test));
461 nb_errors++;
462 ret = 1;
463 goto done;
464 }
465 /*
466 * now scan all the siblings of correct to process the <valid> tests
467 */
468 tmp = getNext(cur, "following-sibling::valid[1]");
469 while (tmp != NULL) {
Daniel Veillarde84f2312005-07-02 07:31:28 +0000470 dtd = xmlGetProp(tmp, BAD_CAST "dtd");
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000471 test = getNext(tmp, "./*");
472 if (test == NULL) {
473 fprintf(stderr, "Failed to find test in <valid> line %ld\n",
474 xmlGetLineNo(tmp));
475
476 } else {
477 xmlBufferEmpty(buf);
Daniel Veillarde84f2312005-07-02 07:31:28 +0000478 if (dtd != NULL)
479 xmlBufferAdd(buf, dtd, -1);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000480 xmlNodeDump(buf, test->doc, test, 0, 0);
481
482 /*
483 * We are ready to run the test
484 */
485 mem = xmlMemUsed();
486 extraMemoryFromResolver = 0;
487 doc = xmlReadMemory((const char *)buf->content, buf->use,
488 "test", NULL, 0);
489 if (doc == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000490 test_log("Failed to parse valid instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000491 xmlGetLineNo(tmp));
492 nb_errors++;
493 } else {
494 nb_tests++;
495 ctxt = xmlRelaxNGNewValidCtxt(rng);
496 xmlRelaxNGSetValidErrors(ctxt,
497 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
498 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
499 ctxt);
500 ret = xmlRelaxNGValidateDoc(ctxt, doc);
501 xmlRelaxNGFreeValidCtxt(ctxt);
502 if (ret > 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000503 test_log("Failed to validate valid instance line %ld\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000504 xmlGetLineNo(tmp));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000505 nb_errors++;
506 } else if (ret < 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000507 test_log("Internal error validating instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000508 xmlGetLineNo(tmp));
509 nb_errors++;
510 }
511 xmlFreeDoc(doc);
512 }
513 xmlResetLastError();
514 if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000515 test_log("Validation of instance line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000516 xmlGetLineNo(tmp), xmlMemUsed() - mem);
517 xmlMemoryDump();
518 nb_leaks++;
519 }
520 }
Daniel Veillarde84f2312005-07-02 07:31:28 +0000521 if (dtd != NULL)
522 xmlFree(dtd);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000523 tmp = getNext(tmp, "following-sibling::valid[1]");
524 }
525 /*
526 * now scan all the siblings of correct to process the <invalid> tests
527 */
528 tmp = getNext(cur, "following-sibling::invalid[1]");
529 while (tmp != NULL) {
530 test = getNext(tmp, "./*");
531 if (test == NULL) {
532 fprintf(stderr, "Failed to find test in <invalid> line %ld\n",
533 xmlGetLineNo(tmp));
534
535 } else {
536 xmlBufferEmpty(buf);
537 xmlNodeDump(buf, test->doc, test, 0, 0);
538
539 /*
540 * We are ready to run the test
541 */
542 mem = xmlMemUsed();
543 extraMemoryFromResolver = 0;
544 doc = xmlReadMemory((const char *)buf->content, buf->use,
545 "test", NULL, 0);
546 if (doc == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000547 test_log("Failed to parse valid instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000548 xmlGetLineNo(tmp));
549 nb_errors++;
550 } else {
551 nb_tests++;
552 ctxt = xmlRelaxNGNewValidCtxt(rng);
553 xmlRelaxNGSetValidErrors(ctxt,
554 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
555 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
556 ctxt);
557 ret = xmlRelaxNGValidateDoc(ctxt, doc);
558 xmlRelaxNGFreeValidCtxt(ctxt);
559 if (ret == 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000560 test_log("Failed to detect invalid instance line %ld\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000561 xmlGetLineNo(tmp));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000562 nb_errors++;
563 } else if (ret < 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000564 test_log("Internal error validating instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000565 xmlGetLineNo(tmp));
566 nb_errors++;
567 }
568 xmlFreeDoc(doc);
569 }
570 xmlResetLastError();
571 if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000572 test_log("Validation of instance line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000573 xmlGetLineNo(tmp), xmlMemUsed() - mem);
574 xmlMemoryDump();
575 nb_leaks++;
576 }
577 }
578 tmp = getNext(tmp, "following-sibling::invalid[1]");
579 }
580
581done:
582 if (buf != NULL)
583 xmlBufferFree(buf);
584 if (rng != NULL)
585 xmlRelaxNGFree(rng);
586 xmlResetLastError();
587 if ((memt != xmlMemUsed()) && (memt != 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000588 test_log("Validation of tests starting line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000589 xmlGetLineNo(cur), xmlMemUsed() - memt);
590 nb_leaks++;
591 }
592 return(ret);
593}
594
595static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000596xsdTestSuite(xmlNodePtr cur) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000597 if (verbose) {
598 xmlChar *doc = getString(cur, "string(documentation)");
599
600 if (doc != NULL) {
601 printf("Suite %s\n", doc);
602 xmlFree(doc);
603 }
604 }
605 cur = getNext(cur, "./testCase[1]");
606 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000607 xsdTestCase(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000608 cur = getNext(cur, "following-sibling::testCase[1]");
609 }
610
611 return(0);
612}
613
614static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000615xsdTest(void) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000616 xmlDocPtr doc;
617 xmlNodePtr cur;
618 const char *filename = "test/xsdtest/xsdtestsuite.xml";
619 int ret = 0;
620
621 doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
622 if (doc == NULL) {
623 fprintf(stderr, "Failed to parse %s\n", filename);
624 return(-1);
625 }
626 printf("## XML Schemas datatypes test suite from James Clark\n");
627
628 cur = xmlDocGetRootElement(doc);
629 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
630 fprintf(stderr, "Unexpected format %s\n", filename);
631 ret = -1;
632 goto done;
633 }
634
635 cur = getNext(cur, "./testSuite[1]");
636 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
637 fprintf(stderr, "Unexpected format %s\n", filename);
638 ret = -1;
639 goto done;
640 }
641 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000642 xsdTestSuite(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000643 cur = getNext(cur, "following-sibling::testSuite[1]");
644 }
645
646done:
647 if (doc != NULL)
648 xmlFreeDoc(doc);
649 return(ret);
650}
651
652static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000653rngTestSuite(xmlNodePtr cur) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000654 if (verbose) {
655 xmlChar *doc = getString(cur, "string(documentation)");
656
657 if (doc != NULL) {
658 printf("Suite %s\n", doc);
659 xmlFree(doc);
660 } else {
661 doc = getString(cur, "string(section)");
662 if (doc != NULL) {
663 printf("Section %s\n", doc);
664 xmlFree(doc);
665 }
666 }
667 }
668 cur = getNext(cur, "./testSuite[1]");
669 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000670 xsdTestSuite(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000671 cur = getNext(cur, "following-sibling::testSuite[1]");
672 }
673
674 return(0);
675}
676
677static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000678rngTest1(void) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000679 xmlDocPtr doc;
680 xmlNodePtr cur;
681 const char *filename = "test/relaxng/OASIS/spectest.xml";
682 int ret = 0;
683
684 doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
685 if (doc == NULL) {
686 fprintf(stderr, "Failed to parse %s\n", filename);
687 return(-1);
688 }
Daniel Veillarde84f2312005-07-02 07:31:28 +0000689 printf("## Relax NG test suite from James Clark\n");
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000690
691 cur = xmlDocGetRootElement(doc);
692 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
693 fprintf(stderr, "Unexpected format %s\n", filename);
694 ret = -1;
695 goto done;
696 }
697
698 cur = getNext(cur, "./testSuite[1]");
699 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
700 fprintf(stderr, "Unexpected format %s\n", filename);
701 ret = -1;
702 goto done;
703 }
704 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000705 rngTestSuite(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000706 cur = getNext(cur, "following-sibling::testSuite[1]");
707 }
708
709done:
710 if (doc != NULL)
711 xmlFreeDoc(doc);
712 return(ret);
713}
714
Daniel Veillarde84f2312005-07-02 07:31:28 +0000715static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000716rngTest2(void) {
Daniel Veillarde84f2312005-07-02 07:31:28 +0000717 xmlDocPtr doc;
718 xmlNodePtr cur;
719 const char *filename = "test/relaxng/testsuite.xml";
720 int ret = 0;
721
722 doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
723 if (doc == NULL) {
724 fprintf(stderr, "Failed to parse %s\n", filename);
725 return(-1);
726 }
727 printf("## Relax NG test suite for libxml2\n");
728
729 cur = xmlDocGetRootElement(doc);
730 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
731 fprintf(stderr, "Unexpected format %s\n", filename);
732 ret = -1;
733 goto done;
734 }
735
736 cur = getNext(cur, "./testSuite[1]");
737 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
738 fprintf(stderr, "Unexpected format %s\n", filename);
739 ret = -1;
740 goto done;
741 }
742 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000743 xsdTestSuite(cur);
Daniel Veillarde84f2312005-07-02 07:31:28 +0000744 cur = getNext(cur, "following-sibling::testSuite[1]");
745 }
746
747done:
748 if (doc != NULL)
749 xmlFreeDoc(doc);
750 return(ret);
751}
752
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000753/************************************************************************
754 * *
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000755 * Schemas test suites from W3C/NIST/MS/Sun *
756 * *
757 ************************************************************************/
758
759static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000760xstcTestInstance(xmlNodePtr cur, xmlSchemaPtr schemas,
Daniel Veillard6b6d6802005-07-03 21:00:34 +0000761 const xmlChar *spath, const char *base) {
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000762 xmlChar *href = NULL;
763 xmlChar *path = NULL;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000764 xmlChar *validity = NULL;
765 xmlSchemaValidCtxtPtr ctxt = NULL;
766 xmlDocPtr doc = NULL;
767 int ret = 0, mem;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000768
Daniel Veillardde0e4982005-07-03 14:35:44 +0000769 xmlResetLastError();
Daniel Veillardc9352532005-07-04 14:25:34 +0000770 testErrorsSize = 0; testErrors[0] = 0;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000771 mem = xmlMemUsed();
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000772 href = getString(cur,
Daniel Veillardde0e4982005-07-03 14:35:44 +0000773 "string(ts:instanceDocument/@xlink:href)");
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000774 if ((href == NULL) || (href[0] == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000775 test_log("testGroup line %ld misses href for schemaDocument\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000776 xmlGetLineNo(cur));
777 ret = -1;
778 goto done;
779 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000780 path = xmlBuildURI(href, BAD_CAST base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000781 if (path == NULL) {
782 fprintf(stderr,
783 "Failed to build path to schemas testGroup line %ld : %s\n",
784 xmlGetLineNo(cur), href);
785 ret = -1;
786 goto done;
787 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000788 if (checkTestFile((const char *) path) <= 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000789 test_log("schemas for testGroup line %ld is missing: %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000790 xmlGetLineNo(cur), path);
791 ret = -1;
792 goto done;
793 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000794 validity = getString(cur,
795 "string(ts:expected/@validity)");
796 if (validity == NULL) {
797 fprintf(stderr, "instanceDocument line %ld misses expected validity\n",
798 xmlGetLineNo(cur));
799 ret = -1;
800 goto done;
801 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000802 nb_tests++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000803 doc = xmlReadFile((const char *) path, NULL, XML_PARSE_NOENT);
804 if (doc == NULL) {
805 fprintf(stderr, "instance %s fails to parse\n", path);
806 ret = -1;
807 nb_errors++;
808 goto done;
809 }
810
811 ctxt = xmlSchemaNewValidCtxt(schemas);
812 xmlSchemaSetValidErrors(ctxt,
813 (xmlSchemaValidityErrorFunc) testErrorHandler,
814 (xmlSchemaValidityWarningFunc) testErrorHandler,
815 ctxt);
816 ret = xmlSchemaValidateDoc(ctxt, doc);
817
818 if (xmlStrEqual(validity, BAD_CAST "valid")) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000819 if (ret > 0) {
820 test_log("valid instance %s failed to validate against %s\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000821 path, spath);
822 nb_errors++;
Daniel Veillardc9352532005-07-04 14:25:34 +0000823 } else if (ret < 0) {
824 test_log("valid instance %s got internal error validating %s\n",
825 path, spath);
826 nb_internals++;
827 nb_errors++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000828 }
829 } else if (xmlStrEqual(validity, BAD_CAST "invalid")) {
830 if (ret == 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000831 test_log("Failed to detect invalid instance %s against %s\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000832 path, spath);
833 nb_errors++;
834 }
835 } else {
Daniel Veillardc9352532005-07-04 14:25:34 +0000836 test_log("instanceDocument line %ld has unexpected validity value%s\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000837 xmlGetLineNo(cur), validity);
838 ret = -1;
839 goto done;
840 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000841
842done:
843 if (href != NULL) xmlFree(href);
844 if (path != NULL) xmlFree(path);
Daniel Veillardde0e4982005-07-03 14:35:44 +0000845 if (validity != NULL) xmlFree(validity);
846 if (ctxt != NULL) xmlSchemaFreeValidCtxt(ctxt);
847 if (doc != NULL) xmlFreeDoc(doc);
848 xmlResetLastError();
849 if (mem != xmlMemUsed()) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000850 test_log("Validation of tests starting line %ld leaked %d\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000851 xmlGetLineNo(cur), xmlMemUsed() - mem);
852 nb_leaks++;
853 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000854 return(ret);
855}
Daniel Veillardde0e4982005-07-03 14:35:44 +0000856
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000857static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000858xstcTestGroup(xmlNodePtr cur, const char *base) {
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000859 xmlChar *href = NULL;
860 xmlChar *path = NULL;
861 xmlChar *validity = NULL;
862 xmlSchemaPtr schemas = NULL;
863 xmlSchemaParserCtxtPtr ctxt;
864 xmlNodePtr instance;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000865 int ret = 0, mem;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000866
Daniel Veillardde0e4982005-07-03 14:35:44 +0000867 xmlResetLastError();
Daniel Veillardc9352532005-07-04 14:25:34 +0000868 testErrorsSize = 0; testErrors[0] = 0;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000869 mem = xmlMemUsed();
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000870 href = getString(cur,
871 "string(ts:schemaTest/ts:schemaDocument/@xlink:href)");
872 if ((href == NULL) || (href[0] == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000873 test_log("testGroup line %ld misses href for schemaDocument\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000874 xmlGetLineNo(cur));
875 ret = -1;
876 goto done;
877 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000878 path = xmlBuildURI(href, BAD_CAST base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000879 if (path == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000880 test_log("Failed to build path to schemas testGroup line %ld : %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000881 xmlGetLineNo(cur), href);
882 ret = -1;
883 goto done;
884 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000885 if (checkTestFile((const char *) path) <= 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000886 test_log("schemas for testGroup line %ld is missing: %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000887 xmlGetLineNo(cur), path);
888 ret = -1;
889 goto done;
890 }
891 validity = getString(cur,
892 "string(ts:schemaTest/ts:expected/@validity)");
893 if (validity == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000894 test_log("testGroup line %ld misses expected validity\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000895 xmlGetLineNo(cur));
896 ret = -1;
897 goto done;
898 }
Daniel Veillardc9352532005-07-04 14:25:34 +0000899 nb_tests++;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000900 if (xmlStrEqual(validity, BAD_CAST "valid")) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000901 nb_schematas++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000902 ctxt = xmlSchemaNewParserCtxt((const char *) path);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000903 xmlSchemaSetParserErrors(ctxt,
904 (xmlSchemaValidityErrorFunc) testErrorHandler,
905 (xmlSchemaValidityWarningFunc) testErrorHandler,
906 ctxt);
907 schemas = xmlSchemaParse(ctxt);
908 xmlSchemaFreeParserCtxt(ctxt);
909 if (schemas == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000910 test_log("valid schemas %s failed to parse\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000911 path);
Daniel Veillard90837782005-07-04 15:45:10 +0000912 ret = 1;
913 nb_errors++;
914 }
915 if ((ret == 0) && (strstr(testErrors, "nimplemented") != NULL)) {
916 test_log("valid schemas %s hit an unimplemented block\n",
917 path);
918 ret = 1;
919 nb_unimplemented++;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000920 nb_errors++;
921 }
922 instance = getNext(cur, "./ts:instanceTest[1]");
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000923 while (instance != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000924 xstcTestInstance(instance, schemas, path, base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000925 instance = getNext(instance,
926 "following-sibling::ts:instanceTest[1]");
927 }
928 } else if (xmlStrEqual(validity, BAD_CAST "invalid")) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000929 nb_schematas++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000930 ctxt = xmlSchemaNewParserCtxt((const char *) path);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000931 xmlSchemaSetParserErrors(ctxt,
932 (xmlSchemaValidityErrorFunc) testErrorHandler,
933 (xmlSchemaValidityWarningFunc) testErrorHandler,
934 ctxt);
935 schemas = xmlSchemaParse(ctxt);
936 xmlSchemaFreeParserCtxt(ctxt);
Daniel Veillard4ac5f9a2005-07-04 15:20:27 +0000937 if (schemas != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000938 test_log("Failed to detect error in schemas %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000939 path);
940 nb_errors++;
Daniel Veillard90837782005-07-04 15:45:10 +0000941 ret = 1;
942 }
943 if ((ret == 0) && (strstr(testErrors, "nimplemented") != NULL)) {
944 nb_unimplemented++;
945 test_log("invalid schemas %s hit an unimplemented block\n",
946 path);
947 ret = 1;
948 nb_errors++;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000949 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000950 } else {
Daniel Veillardc9352532005-07-04 14:25:34 +0000951 test_log("testGroup line %ld misses unexpected validity value%s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000952 xmlGetLineNo(cur), validity);
953 ret = -1;
954 goto done;
955 }
956
957done:
958 if (href != NULL) xmlFree(href);
959 if (path != NULL) xmlFree(path);
960 if (validity != NULL) xmlFree(validity);
961 if (schemas != NULL) xmlSchemaFree(schemas);
Daniel Veillardde0e4982005-07-03 14:35:44 +0000962 xmlResetLastError();
963 if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000964 test_log("Processing test line %ld %s leaked %d\n",
965 xmlGetLineNo(cur), path, xmlMemUsed() - mem);
Daniel Veillardde0e4982005-07-03 14:35:44 +0000966 nb_leaks++;
967 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000968 return(ret);
969}
970
971static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000972xstcMetadata(const char *metadata, const char *base) {
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000973 xmlDocPtr doc;
974 xmlNodePtr cur;
975 xmlChar *contributor;
976 xmlChar *name;
Daniel Veillard6b6d6802005-07-03 21:00:34 +0000977 int ret = 0;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000978
979 doc = xmlReadFile(metadata, NULL, XML_PARSE_NOENT);
980 if (doc == NULL) {
981 fprintf(stderr, "Failed to parse %s\n", metadata);
982 return(-1);
983 }
984
985 cur = xmlDocGetRootElement(doc);
986 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSet"))) {
987 fprintf(stderr, "Unexpected format %s\n", metadata);
988 return(-1);
989 }
990 contributor = xmlGetProp(cur, BAD_CAST "contributor");
991 if (contributor == NULL) {
992 contributor = xmlStrdup(BAD_CAST "Unknown");
993 }
994 name = xmlGetProp(cur, BAD_CAST "name");
995 if (name == NULL) {
996 name = xmlStrdup(BAD_CAST "Unknown");
997 }
998 printf("## %s test suite for Schemas version %s\n", contributor, name);
999 xmlFree(contributor);
1000 xmlFree(name);
1001
1002 cur = getNext(cur, "./ts:testGroup[1]");
1003 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testGroup"))) {
1004 fprintf(stderr, "Unexpected format %s\n", metadata);
1005 ret = -1;
1006 goto done;
1007 }
1008 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +00001009 xstcTestGroup(cur, base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001010 cur = getNext(cur, "following-sibling::ts:testGroup[1]");
1011 }
1012
1013done:
1014 xmlFreeDoc(doc);
1015 return(ret);
1016}
1017
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001018/************************************************************************
1019 * *
1020 * The driver for the tests *
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001021 * *
1022 ************************************************************************/
1023
1024int
1025main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
1026 int res, ret = 0;
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001027 int old_errors, old_tests, old_leaks;
1028
Daniel Veillardc9352532005-07-04 14:25:34 +00001029 logfile = fopen(LOGFILE, "w");
1030 if (logfile == NULL) {
1031 fprintf(stderr,
1032 "Could not open the log file, running in verbose mode\n");
1033 verbose = 1;
1034 }
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001035 initializeLibxml2();
1036
1037 if ((argc >= 2) && (!strcmp(argv[1], "-v")))
1038 verbose = 1;
1039
1040
Daniel Veillarde84f2312005-07-02 07:31:28 +00001041 old_errors = nb_errors;
1042 old_tests = nb_tests;
1043 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001044 res = xsdTest();
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001045 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
1046 printf("Ran %d tests, no errors\n", nb_tests - old_tests);
1047 else
1048 printf("Ran %d tests, %d errors, %d leaks\n",
1049 nb_tests - old_tests,
1050 nb_errors - old_errors,
1051 nb_leaks - old_leaks);
1052 old_errors = nb_errors;
1053 old_tests = nb_tests;
1054 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001055 res = rngTest1();
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001056 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
1057 printf("Ran %d tests, no errors\n", nb_tests - old_tests);
1058 else
1059 printf("Ran %d tests, %d errors, %d leaks\n",
1060 nb_tests - old_tests,
1061 nb_errors - old_errors,
1062 nb_leaks - old_leaks);
1063 old_errors = nb_errors;
1064 old_tests = nb_tests;
1065 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001066 res = rngTest2();
Daniel Veillarde84f2312005-07-02 07:31:28 +00001067 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
1068 printf("Ran %d tests, no errors\n", nb_tests - old_tests);
1069 else
1070 printf("Ran %d tests, %d errors, %d leaks\n",
1071 nb_tests - old_tests,
1072 nb_errors - old_errors,
1073 nb_leaks - old_leaks);
1074 old_errors = nb_errors;
1075 old_tests = nb_tests;
1076 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001077 nb_internals = 0;
1078 nb_schematas = 0;
1079 res = xstcMetadata(
Daniel Veillardde0e4982005-07-03 14:35:44 +00001080 "xstc/Tests/Metadata/NISTXMLSchemaDatatypes.testSet",
1081 "xstc/Tests/Metadata/");
1082 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
Daniel Veillardc9352532005-07-04 14:25:34 +00001083 printf("Ran %d tests (%d schemata), no errors\n",
1084 nb_tests - old_tests, nb_schematas);
Daniel Veillardde0e4982005-07-03 14:35:44 +00001085 else
Daniel Veillardc9352532005-07-04 14:25:34 +00001086 printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +00001087 nb_tests - old_tests,
Daniel Veillardc9352532005-07-04 14:25:34 +00001088 nb_schematas,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001089 nb_errors - old_errors,
Daniel Veillardc9352532005-07-04 14:25:34 +00001090 nb_internals,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001091 nb_leaks - old_leaks);
1092 old_errors = nb_errors;
1093 old_tests = nb_tests;
1094 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001095 nb_internals = 0;
1096 nb_schematas = 0;
1097 res = xstcMetadata(
Daniel Veillardde0e4982005-07-03 14:35:44 +00001098 "xstc/Tests/Metadata/SunXMLSchema1-0-20020116.testSet",
Daniel Veillardc9352532005-07-04 14:25:34 +00001099 "xstc/Tests/");
Daniel Veillardde0e4982005-07-03 14:35:44 +00001100 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
Daniel Veillardc9352532005-07-04 14:25:34 +00001101 printf("Ran %d tests (%d schemata), no errors\n",
1102 nb_tests - old_tests, nb_schematas);
Daniel Veillardde0e4982005-07-03 14:35:44 +00001103 else
Daniel Veillardc9352532005-07-04 14:25:34 +00001104 printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +00001105 nb_tests - old_tests,
Daniel Veillardc9352532005-07-04 14:25:34 +00001106 nb_schematas,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001107 nb_errors - old_errors,
Daniel Veillardc9352532005-07-04 14:25:34 +00001108 nb_internals,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001109 nb_leaks - old_leaks);
1110 old_errors = nb_errors;
1111 old_tests = nb_tests;
1112 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001113 nb_internals = 0;
1114 nb_schematas = 0;
1115 res = xstcMetadata(
Daniel Veillardde0e4982005-07-03 14:35:44 +00001116 "xstc/Tests/Metadata/MSXMLSchema1-0-20020116.testSet",
1117 "xstc/Tests/");
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001118 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
Daniel Veillardc9352532005-07-04 14:25:34 +00001119 printf("Ran %d tests (%d schemata), no errors\n",
1120 nb_tests - old_tests, nb_schematas);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001121 else
Daniel Veillardc9352532005-07-04 14:25:34 +00001122 printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001123 nb_tests - old_tests,
Daniel Veillardc9352532005-07-04 14:25:34 +00001124 nb_schematas,
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001125 nb_errors - old_errors,
Daniel Veillardc9352532005-07-04 14:25:34 +00001126 nb_internals,
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001127 nb_leaks - old_leaks);
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001128
1129 if ((nb_errors == 0) && (nb_leaks == 0)) {
1130 ret = 0;
1131 printf("Total %d tests, no errors\n",
1132 nb_tests);
1133 } else {
1134 ret = 1;
1135 printf("Total %d tests, %d errors, %d leaks\n",
1136 nb_tests, nb_errors, nb_leaks);
1137 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001138
1139 xmlXPathFreeContext(ctxtXPath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001140 xmlCleanupParser();
1141 xmlMemoryDump();
1142
Daniel Veillardc9352532005-07-04 14:25:34 +00001143 if (logfile != NULL)
1144 fclose(logfile);
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001145 return(ret);
1146}
Daniel Veillard95175012005-07-03 16:09:51 +00001147#else /* !SCHEMAS */
1148int
1149main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
1150 fprintf(stderr, "runsuite requires support for schemas and xpath in libxml2\n");
1151}
1152#endif