blob: da63e267849dcd7ce05301ade698cfe603352b88 [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 Veillardf2e066a2005-06-30 13:04:44 +000074static int nb_leaks = 0;
75static long libxmlMemoryAllocatedBase = 0;
76static int extraMemoryFromResolver = 0;
77
78static int
79fatalError(void) {
80 fprintf(stderr, "Exitting tests on fatal error\n");
81 exit(1);
82}
83
84/*
Daniel Veillarde84f2312005-07-02 07:31:28 +000085 * that's needed to implement <resource>
86 */
87#define MAX_ENTITIES 20
88char *testEntitiesName[MAX_ENTITIES];
89char *testEntitiesValue[MAX_ENTITIES];
90int nb_entities = 0;
91static void resetEntities(void) {
92 int i;
93
94 for (i = 0;i < nb_entities;i++) {
95 if (testEntitiesName[i] != NULL)
96 xmlFree(testEntitiesName[i]);
97 if (testEntitiesValue[i] != NULL)
98 xmlFree(testEntitiesValue[i]);
99 }
100 nb_entities = 0;
101}
102static int addEntity(char *name, char *content) {
103 if (nb_entities >= MAX_ENTITIES) {
104 fprintf(stderr, "Too many entities defined\n");
105 return(-1);
106 }
107 testEntitiesName[nb_entities] = name;
108 testEntitiesValue[nb_entities] = content;
109 nb_entities++;
110 return(0);
111}
112
113/*
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000114 * We need to trap calls to the resolver to not account memory for the catalog
115 * which is shared to the current running test. We also don't want to have
116 * network downloads modifying tests.
117 */
118static xmlParserInputPtr
119testExternalEntityLoader(const char *URL, const char *ID,
120 xmlParserCtxtPtr ctxt) {
121 xmlParserInputPtr ret;
Daniel Veillarde84f2312005-07-02 07:31:28 +0000122 int i;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000123
Daniel Veillarde84f2312005-07-02 07:31:28 +0000124 for (i = 0;i < nb_entities;i++) {
125 if (!strcmp(testEntitiesName[i], URL)) {
126 ret = xmlNewStringInputStream(ctxt,
127 (const xmlChar *) testEntitiesValue[i]);
128 if (ret != NULL) {
129 ret->filename = (const char *)
130 xmlStrdup((xmlChar *)testEntitiesName[i]);
131 }
132 return(ret);
133 }
134 }
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000135 if (checkTestFile(URL)) {
136 ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
137 } else {
138 int memused = xmlMemUsed();
139 ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
140 extraMemoryFromResolver += xmlMemUsed() - memused;
141 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000142#if 0
Daniel Veillarde84f2312005-07-02 07:31:28 +0000143 if (ret == NULL) {
144 fprintf(stderr, "Failed to find resource %s\n", URL);
145 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000146#endif
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000147
148 return(ret);
149}
150
151/*
152 * Trapping the error messages at the generic level to grab the equivalent of
153 * stderr messages on CLI tools.
154 */
155static char testErrors[32769];
156static int testErrorsSize = 0;
157
Daniel Veillardc9352532005-07-04 14:25:34 +0000158static void test_log(const char *msg, ...) {
159 va_list args;
160 if (logfile != NULL) {
161 fprintf(logfile, "\n------------\n");
162 va_start(args, msg);
163 vfprintf(logfile, msg, args);
164 va_end(args);
165 fprintf(logfile, "%s", testErrors);
166 testErrorsSize = 0; testErrors[0] = 0;
167 }
168 if (verbose) {
169 va_start(args, msg);
170 vfprintf(stderr, msg, args);
171 va_end(args);
172 }
173}
174
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000175static void
176testErrorHandler(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
177 va_list args;
178 int res;
179
180 if (testErrorsSize >= 32768)
181 return;
182 va_start(args, msg);
183 res = vsnprintf(&testErrors[testErrorsSize],
184 32768 - testErrorsSize,
185 msg, args);
186 va_end(args);
187 if (testErrorsSize + res >= 32768) {
188 /* buffer is full */
189 testErrorsSize = 32768;
190 testErrors[testErrorsSize] = 0;
191 } else {
192 testErrorsSize += res;
193 }
194 testErrors[testErrorsSize] = 0;
195}
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000196
197xmlXPathContextPtr ctxtXPath;
198
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000199static void
200initializeLibxml2(void) {
201 xmlGetWarningsDefaultValue = 0;
202 xmlPedanticParserDefault(0);
203
204 xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
205 xmlInitParser();
206 xmlSetExternalEntityLoader(testExternalEntityLoader);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000207 ctxtXPath = xmlXPathNewContext(NULL);
208 /* used as default nanemspace in xstc tests */
209 xmlXPathRegisterNs(ctxtXPath, BAD_CAST "ts", BAD_CAST "TestSuite");
210 xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink",
211 BAD_CAST "http://www.w3.org/1999/xlink");
212 xmlSetGenericErrorFunc(NULL, testErrorHandler);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000213#ifdef LIBXML_SCHEMAS_ENABLED
214 xmlSchemaInitTypes();
215 xmlRelaxNGInitTypes();
216#endif
217 libxmlMemoryAllocatedBase = xmlMemUsed();
218}
219
220static xmlNodePtr
221getNext(xmlNodePtr cur, const char *xpath) {
222 xmlNodePtr ret = NULL;
223 xmlXPathObjectPtr res;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000224 xmlXPathCompExprPtr comp;
225
226 if ((cur == NULL) || (cur->doc == NULL) || (xpath == NULL))
227 return(NULL);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000228 ctxtXPath->doc = cur->doc;
229 ctxtXPath->node = cur;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000230 comp = xmlXPathCompile(BAD_CAST xpath);
231 if (comp == NULL) {
232 fprintf(stderr, "Failed to compile %s\n", xpath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000233 return(NULL);
234 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000235 res = xmlXPathCompiledEval(comp, ctxtXPath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000236 xmlXPathFreeCompExpr(comp);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000237 if (res == NULL)
238 return(NULL);
239 if ((res->type == XPATH_NODESET) &&
240 (res->nodesetval != NULL) &&
241 (res->nodesetval->nodeNr > 0) &&
242 (res->nodesetval->nodeTab != NULL))
243 ret = res->nodesetval->nodeTab[0];
244 xmlXPathFreeObject(res);
245 return(ret);
246}
247
248static xmlChar *
249getString(xmlNodePtr cur, const char *xpath) {
250 xmlChar *ret = NULL;
251 xmlXPathObjectPtr res;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000252 xmlXPathCompExprPtr comp;
253
254 if ((cur == NULL) || (cur->doc == NULL) || (xpath == NULL))
255 return(NULL);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000256 ctxtXPath->doc = cur->doc;
257 ctxtXPath->node = cur;
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000258 comp = xmlXPathCompile(BAD_CAST xpath);
259 if (comp == NULL) {
260 fprintf(stderr, "Failed to compile %s\n", xpath);
261 return(NULL);
262 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000263 res = xmlXPathCompiledEval(comp, ctxtXPath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000264 xmlXPathFreeCompExpr(comp);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000265 if (res == NULL)
266 return(NULL);
267 if (res->type == XPATH_STRING) {
268 ret = res->stringval;
269 res->stringval = NULL;
270 }
271 xmlXPathFreeObject(res);
272 return(ret);
273}
274
275/************************************************************************
276 * *
277 * Test test/xsdtest/xsdtestsuite.xml *
278 * *
279 ************************************************************************/
280
281static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000282xsdIncorectTestCase(xmlNodePtr cur) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000283 xmlNodePtr test;
284 xmlBufferPtr buf;
285 xmlRelaxNGParserCtxtPtr pctxt;
286 xmlRelaxNGPtr rng = NULL;
287 int ret = 0, memt;
288
289 cur = getNext(cur, "./incorrect[1]");
290 if (cur == NULL) {
291 return(0);
292 }
293
294 test = getNext(cur, "./*");
295 if (test == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000296 test_log("Failed to find test in correct line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000297 xmlGetLineNo(cur));
298 return(1);
299 }
300
301 memt = xmlMemUsed();
302 extraMemoryFromResolver = 0;
303 /*
304 * dump the schemas to a buffer, then reparse it and compile the schemas
305 */
306 buf = xmlBufferCreate();
307 if (buf == NULL) {
308 fprintf(stderr, "out of memory !\n");
309 fatalError();
310 }
311 xmlNodeDump(buf, test->doc, test, 0, 0);
312 pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use);
313 xmlRelaxNGSetParserErrors(pctxt,
314 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
315 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
316 pctxt);
317 rng = xmlRelaxNGParse(pctxt);
318 xmlRelaxNGFreeParserCtxt(pctxt);
319 if (rng != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000320 test_log("Failed to detect incorect RNG line %ld\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000321 xmlGetLineNo(test));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000322 ret = 1;
323 goto done;
324 }
325
326done:
327 if (buf != NULL)
328 xmlBufferFree(buf);
329 if (rng != NULL)
330 xmlRelaxNGFree(rng);
331 xmlResetLastError();
332 if ((memt != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000333 test_log("Validation of tests starting line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000334 xmlGetLineNo(cur), xmlMemUsed() - memt);
335 nb_leaks++;
336 }
337 return(ret);
338}
339
Daniel Veillarde84f2312005-07-02 07:31:28 +0000340static void
341installResources(xmlNodePtr tst, const xmlChar *base) {
342 xmlNodePtr test;
343 xmlBufferPtr buf;
344 xmlChar *name, *content, *res;
Daniel Veillardc9352532005-07-04 14:25:34 +0000345
Daniel Veillarde84f2312005-07-02 07:31:28 +0000346 buf = xmlBufferCreate();
347 if (buf == NULL) {
348 fprintf(stderr, "out of memory !\n");
349 fatalError();
350 }
351 xmlNodeDump(buf, tst->doc, tst, 0, 0);
352
353 while (tst != NULL) {
354 test = getNext(tst, "./*");
355 if (test != NULL) {
356 xmlBufferEmpty(buf);
357 xmlNodeDump(buf, test->doc, test, 0, 0);
358 name = getString(tst, "string(@name)");
359 content = xmlStrdup(buf->content);
360 if ((name != NULL) && (content != NULL)) {
361 res = composeDir(base, name);
362 xmlFree(name);
363 addEntity((char *) res, (char *) content);
364 } else {
365 if (name != NULL) xmlFree(name);
366 if (content != NULL) xmlFree(content);
367 }
368 }
369 tst = getNext(tst, "following-sibling::resource[1]");
370 }
371 if (buf != NULL)
372 xmlBufferFree(buf);
373}
374
375static void
376installDirs(xmlNodePtr tst, const xmlChar *base) {
377 xmlNodePtr test;
378 xmlChar *name, *res;
379
380 name = getString(tst, "string(@name)");
381 if (name == NULL)
382 return;
383 res = composeDir(base, name);
384 xmlFree(name);
385 if (res == NULL) {
386 return;
387 }
388 /* Now process resources and subdir recursively */
389 test = getNext(tst, "./resource[1]");
390 if (test != NULL) {
391 installResources(test, res);
392 }
393 test = getNext(tst, "./dir[1]");
394 while (test != NULL) {
395 installDirs(test, res);
396 test = getNext(test, "following-sibling::dir[1]");
397 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000398 xmlFree(res);
Daniel Veillarde84f2312005-07-02 07:31:28 +0000399}
400
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000401static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000402xsdTestCase(xmlNodePtr tst) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000403 xmlNodePtr test, tmp, cur;
404 xmlBufferPtr buf;
405 xmlDocPtr doc = NULL;
406 xmlRelaxNGParserCtxtPtr pctxt;
407 xmlRelaxNGValidCtxtPtr ctxt;
408 xmlRelaxNGPtr rng = NULL;
409 int ret = 0, mem, memt;
Daniel Veillarde84f2312005-07-02 07:31:28 +0000410 xmlChar *dtd;
411
412 resetEntities();
Daniel Veillardc9352532005-07-04 14:25:34 +0000413 testErrorsSize = 0; testErrors[0] = 0;
Daniel Veillarde84f2312005-07-02 07:31:28 +0000414
415 tmp = getNext(tst, "./dir[1]");
416 if (tmp != NULL) {
417 installDirs(tmp, NULL);
418 }
419 tmp = getNext(tst, "./resource[1]");
420 if (tmp != NULL) {
421 installResources(tmp, NULL);
422 }
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000423
424 cur = getNext(tst, "./correct[1]");
425 if (cur == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000426 return(xsdIncorectTestCase(tst));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000427 }
428
429 test = getNext(cur, "./*");
430 if (test == NULL) {
431 fprintf(stderr, "Failed to find test in correct line %ld\n",
432 xmlGetLineNo(cur));
433 return(1);
434 }
435
436 memt = xmlMemUsed();
437 extraMemoryFromResolver = 0;
438 /*
439 * dump the schemas to a buffer, then reparse it and compile the schemas
440 */
441 buf = xmlBufferCreate();
442 if (buf == NULL) {
443 fprintf(stderr, "out of memory !\n");
444 fatalError();
445 }
446 xmlNodeDump(buf, test->doc, test, 0, 0);
447 pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use);
448 xmlRelaxNGSetParserErrors(pctxt,
449 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
450 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
451 pctxt);
452 rng = xmlRelaxNGParse(pctxt);
453 xmlRelaxNGFreeParserCtxt(pctxt);
454 if (extraMemoryFromResolver)
455 memt = 0;
456
457 if (rng == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000458 test_log("Failed to parse RNGtest line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000459 xmlGetLineNo(test));
460 nb_errors++;
461 ret = 1;
462 goto done;
463 }
464 /*
465 * now scan all the siblings of correct to process the <valid> tests
466 */
467 tmp = getNext(cur, "following-sibling::valid[1]");
468 while (tmp != NULL) {
Daniel Veillarde84f2312005-07-02 07:31:28 +0000469 dtd = xmlGetProp(tmp, BAD_CAST "dtd");
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000470 test = getNext(tmp, "./*");
471 if (test == NULL) {
472 fprintf(stderr, "Failed to find test in <valid> line %ld\n",
473 xmlGetLineNo(tmp));
474
475 } else {
476 xmlBufferEmpty(buf);
Daniel Veillarde84f2312005-07-02 07:31:28 +0000477 if (dtd != NULL)
478 xmlBufferAdd(buf, dtd, -1);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000479 xmlNodeDump(buf, test->doc, test, 0, 0);
480
481 /*
482 * We are ready to run the test
483 */
484 mem = xmlMemUsed();
485 extraMemoryFromResolver = 0;
486 doc = xmlReadMemory((const char *)buf->content, buf->use,
487 "test", NULL, 0);
488 if (doc == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000489 test_log("Failed to parse valid instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000490 xmlGetLineNo(tmp));
491 nb_errors++;
492 } else {
493 nb_tests++;
494 ctxt = xmlRelaxNGNewValidCtxt(rng);
495 xmlRelaxNGSetValidErrors(ctxt,
496 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
497 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
498 ctxt);
499 ret = xmlRelaxNGValidateDoc(ctxt, doc);
500 xmlRelaxNGFreeValidCtxt(ctxt);
501 if (ret > 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000502 test_log("Failed to validate valid instance line %ld\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000503 xmlGetLineNo(tmp));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000504 nb_errors++;
505 } else if (ret < 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000506 test_log("Internal error validating instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000507 xmlGetLineNo(tmp));
508 nb_errors++;
509 }
510 xmlFreeDoc(doc);
511 }
512 xmlResetLastError();
513 if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000514 test_log("Validation of instance line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000515 xmlGetLineNo(tmp), xmlMemUsed() - mem);
516 xmlMemoryDump();
517 nb_leaks++;
518 }
519 }
Daniel Veillarde84f2312005-07-02 07:31:28 +0000520 if (dtd != NULL)
521 xmlFree(dtd);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000522 tmp = getNext(tmp, "following-sibling::valid[1]");
523 }
524 /*
525 * now scan all the siblings of correct to process the <invalid> tests
526 */
527 tmp = getNext(cur, "following-sibling::invalid[1]");
528 while (tmp != NULL) {
529 test = getNext(tmp, "./*");
530 if (test == NULL) {
531 fprintf(stderr, "Failed to find test in <invalid> line %ld\n",
532 xmlGetLineNo(tmp));
533
534 } else {
535 xmlBufferEmpty(buf);
536 xmlNodeDump(buf, test->doc, test, 0, 0);
537
538 /*
539 * We are ready to run the test
540 */
541 mem = xmlMemUsed();
542 extraMemoryFromResolver = 0;
543 doc = xmlReadMemory((const char *)buf->content, buf->use,
544 "test", NULL, 0);
545 if (doc == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000546 test_log("Failed to parse valid instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000547 xmlGetLineNo(tmp));
548 nb_errors++;
549 } else {
550 nb_tests++;
551 ctxt = xmlRelaxNGNewValidCtxt(rng);
552 xmlRelaxNGSetValidErrors(ctxt,
553 (xmlRelaxNGValidityErrorFunc) testErrorHandler,
554 (xmlRelaxNGValidityWarningFunc) testErrorHandler,
555 ctxt);
556 ret = xmlRelaxNGValidateDoc(ctxt, doc);
557 xmlRelaxNGFreeValidCtxt(ctxt);
558 if (ret == 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000559 test_log("Failed to detect invalid instance line %ld\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000560 xmlGetLineNo(tmp));
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000561 nb_errors++;
562 } else if (ret < 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000563 test_log("Internal error validating instance line %ld\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000564 xmlGetLineNo(tmp));
565 nb_errors++;
566 }
567 xmlFreeDoc(doc);
568 }
569 xmlResetLastError();
570 if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000571 test_log("Validation of instance line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000572 xmlGetLineNo(tmp), xmlMemUsed() - mem);
573 xmlMemoryDump();
574 nb_leaks++;
575 }
576 }
577 tmp = getNext(tmp, "following-sibling::invalid[1]");
578 }
579
580done:
581 if (buf != NULL)
582 xmlBufferFree(buf);
583 if (rng != NULL)
584 xmlRelaxNGFree(rng);
585 xmlResetLastError();
586 if ((memt != xmlMemUsed()) && (memt != 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000587 test_log("Validation of tests starting line %ld leaked %d\n",
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000588 xmlGetLineNo(cur), xmlMemUsed() - memt);
589 nb_leaks++;
590 }
591 return(ret);
592}
593
594static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000595xsdTestSuite(xmlNodePtr cur) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000596 if (verbose) {
597 xmlChar *doc = getString(cur, "string(documentation)");
598
599 if (doc != NULL) {
600 printf("Suite %s\n", doc);
601 xmlFree(doc);
602 }
603 }
604 cur = getNext(cur, "./testCase[1]");
605 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000606 xsdTestCase(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000607 cur = getNext(cur, "following-sibling::testCase[1]");
608 }
609
610 return(0);
611}
612
613static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000614xsdTest(void) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000615 xmlDocPtr doc;
616 xmlNodePtr cur;
617 const char *filename = "test/xsdtest/xsdtestsuite.xml";
618 int ret = 0;
619
620 doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
621 if (doc == NULL) {
622 fprintf(stderr, "Failed to parse %s\n", filename);
623 return(-1);
624 }
625 printf("## XML Schemas datatypes test suite from James Clark\n");
626
627 cur = xmlDocGetRootElement(doc);
628 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
629 fprintf(stderr, "Unexpected format %s\n", filename);
630 ret = -1;
631 goto done;
632 }
633
634 cur = getNext(cur, "./testSuite[1]");
635 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
636 fprintf(stderr, "Unexpected format %s\n", filename);
637 ret = -1;
638 goto done;
639 }
640 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000641 xsdTestSuite(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000642 cur = getNext(cur, "following-sibling::testSuite[1]");
643 }
644
645done:
646 if (doc != NULL)
647 xmlFreeDoc(doc);
648 return(ret);
649}
650
651static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000652rngTestSuite(xmlNodePtr cur) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000653 if (verbose) {
654 xmlChar *doc = getString(cur, "string(documentation)");
655
656 if (doc != NULL) {
657 printf("Suite %s\n", doc);
658 xmlFree(doc);
659 } else {
660 doc = getString(cur, "string(section)");
661 if (doc != NULL) {
662 printf("Section %s\n", doc);
663 xmlFree(doc);
664 }
665 }
666 }
667 cur = getNext(cur, "./testSuite[1]");
668 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000669 xsdTestSuite(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000670 cur = getNext(cur, "following-sibling::testSuite[1]");
671 }
672
673 return(0);
674}
675
676static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000677rngTest1(void) {
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000678 xmlDocPtr doc;
679 xmlNodePtr cur;
680 const char *filename = "test/relaxng/OASIS/spectest.xml";
681 int ret = 0;
682
683 doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
684 if (doc == NULL) {
685 fprintf(stderr, "Failed to parse %s\n", filename);
686 return(-1);
687 }
Daniel Veillarde84f2312005-07-02 07:31:28 +0000688 printf("## Relax NG test suite from James Clark\n");
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000689
690 cur = xmlDocGetRootElement(doc);
691 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
692 fprintf(stderr, "Unexpected format %s\n", filename);
693 ret = -1;
694 goto done;
695 }
696
697 cur = getNext(cur, "./testSuite[1]");
698 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
699 fprintf(stderr, "Unexpected format %s\n", filename);
700 ret = -1;
701 goto done;
702 }
703 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000704 rngTestSuite(cur);
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000705 cur = getNext(cur, "following-sibling::testSuite[1]");
706 }
707
708done:
709 if (doc != NULL)
710 xmlFreeDoc(doc);
711 return(ret);
712}
713
Daniel Veillarde84f2312005-07-02 07:31:28 +0000714static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000715rngTest2(void) {
Daniel Veillarde84f2312005-07-02 07:31:28 +0000716 xmlDocPtr doc;
717 xmlNodePtr cur;
718 const char *filename = "test/relaxng/testsuite.xml";
719 int ret = 0;
720
721 doc = xmlReadFile(filename, NULL, XML_PARSE_NOENT);
722 if (doc == NULL) {
723 fprintf(stderr, "Failed to parse %s\n", filename);
724 return(-1);
725 }
726 printf("## Relax NG test suite for libxml2\n");
727
728 cur = xmlDocGetRootElement(doc);
729 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
730 fprintf(stderr, "Unexpected format %s\n", filename);
731 ret = -1;
732 goto done;
733 }
734
735 cur = getNext(cur, "./testSuite[1]");
736 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSuite"))) {
737 fprintf(stderr, "Unexpected format %s\n", filename);
738 ret = -1;
739 goto done;
740 }
741 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000742 xsdTestSuite(cur);
Daniel Veillarde84f2312005-07-02 07:31:28 +0000743 cur = getNext(cur, "following-sibling::testSuite[1]");
744 }
745
746done:
747 if (doc != NULL)
748 xmlFreeDoc(doc);
749 return(ret);
750}
751
Daniel Veillardf2e066a2005-06-30 13:04:44 +0000752/************************************************************************
753 * *
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000754 * Schemas test suites from W3C/NIST/MS/Sun *
755 * *
756 ************************************************************************/
757
758static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000759xstcTestInstance(xmlNodePtr cur, xmlSchemaPtr schemas,
Daniel Veillard6b6d6802005-07-03 21:00:34 +0000760 const xmlChar *spath, const char *base) {
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000761 xmlChar *href = NULL;
762 xmlChar *path = NULL;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000763 xmlChar *validity = NULL;
764 xmlSchemaValidCtxtPtr ctxt = NULL;
765 xmlDocPtr doc = NULL;
766 int ret = 0, mem;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000767
Daniel Veillardde0e4982005-07-03 14:35:44 +0000768 xmlResetLastError();
Daniel Veillardc9352532005-07-04 14:25:34 +0000769 testErrorsSize = 0; testErrors[0] = 0;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000770 mem = xmlMemUsed();
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000771 href = getString(cur,
Daniel Veillardde0e4982005-07-03 14:35:44 +0000772 "string(ts:instanceDocument/@xlink:href)");
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000773 if ((href == NULL) || (href[0] == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000774 test_log("testGroup line %ld misses href for schemaDocument\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000775 xmlGetLineNo(cur));
776 ret = -1;
777 goto done;
778 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000779 path = xmlBuildURI(href, BAD_CAST base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000780 if (path == NULL) {
781 fprintf(stderr,
782 "Failed to build path to schemas testGroup line %ld : %s\n",
783 xmlGetLineNo(cur), href);
784 ret = -1;
785 goto done;
786 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000787 if (checkTestFile((const char *) path) <= 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000788 test_log("schemas for testGroup line %ld is missing: %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000789 xmlGetLineNo(cur), path);
790 ret = -1;
791 goto done;
792 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000793 validity = getString(cur,
794 "string(ts:expected/@validity)");
795 if (validity == NULL) {
796 fprintf(stderr, "instanceDocument line %ld misses expected validity\n",
797 xmlGetLineNo(cur));
798 ret = -1;
799 goto done;
800 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000801 nb_tests++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000802 doc = xmlReadFile((const char *) path, NULL, XML_PARSE_NOENT);
803 if (doc == NULL) {
804 fprintf(stderr, "instance %s fails to parse\n", path);
805 ret = -1;
806 nb_errors++;
807 goto done;
808 }
809
810 ctxt = xmlSchemaNewValidCtxt(schemas);
811 xmlSchemaSetValidErrors(ctxt,
812 (xmlSchemaValidityErrorFunc) testErrorHandler,
813 (xmlSchemaValidityWarningFunc) testErrorHandler,
814 ctxt);
815 ret = xmlSchemaValidateDoc(ctxt, doc);
816
817 if (xmlStrEqual(validity, BAD_CAST "valid")) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000818 if (ret > 0) {
819 test_log("valid instance %s failed to validate against %s\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000820 path, spath);
821 nb_errors++;
Daniel Veillardc9352532005-07-04 14:25:34 +0000822 } else if (ret < 0) {
823 test_log("valid instance %s got internal error validating %s\n",
824 path, spath);
825 nb_internals++;
826 nb_errors++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000827 }
828 } else if (xmlStrEqual(validity, BAD_CAST "invalid")) {
829 if (ret == 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000830 test_log("Failed to detect invalid instance %s against %s\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000831 path, spath);
832 nb_errors++;
833 }
834 } else {
Daniel Veillardc9352532005-07-04 14:25:34 +0000835 test_log("instanceDocument line %ld has unexpected validity value%s\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000836 xmlGetLineNo(cur), validity);
837 ret = -1;
838 goto done;
839 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000840
841done:
842 if (href != NULL) xmlFree(href);
843 if (path != NULL) xmlFree(path);
Daniel Veillardde0e4982005-07-03 14:35:44 +0000844 if (validity != NULL) xmlFree(validity);
845 if (ctxt != NULL) xmlSchemaFreeValidCtxt(ctxt);
846 if (doc != NULL) xmlFreeDoc(doc);
847 xmlResetLastError();
848 if (mem != xmlMemUsed()) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000849 test_log("Validation of tests starting line %ld leaked %d\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +0000850 xmlGetLineNo(cur), xmlMemUsed() - mem);
851 nb_leaks++;
852 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000853 return(ret);
854}
Daniel Veillardde0e4982005-07-03 14:35:44 +0000855
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000856static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000857xstcTestGroup(xmlNodePtr cur, const char *base) {
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000858 xmlChar *href = NULL;
859 xmlChar *path = NULL;
860 xmlChar *validity = NULL;
861 xmlSchemaPtr schemas = NULL;
862 xmlSchemaParserCtxtPtr ctxt;
863 xmlNodePtr instance;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000864 int ret = 0, mem;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000865
Daniel Veillardde0e4982005-07-03 14:35:44 +0000866 xmlResetLastError();
Daniel Veillardc9352532005-07-04 14:25:34 +0000867 testErrorsSize = 0; testErrors[0] = 0;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000868 mem = xmlMemUsed();
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000869 href = getString(cur,
870 "string(ts:schemaTest/ts:schemaDocument/@xlink:href)");
871 if ((href == NULL) || (href[0] == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000872 test_log("testGroup line %ld misses href for schemaDocument\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000873 xmlGetLineNo(cur));
874 ret = -1;
875 goto done;
876 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000877 path = xmlBuildURI(href, BAD_CAST base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000878 if (path == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000879 test_log("Failed to build path to schemas testGroup line %ld : %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000880 xmlGetLineNo(cur), href);
881 ret = -1;
882 goto done;
883 }
Daniel Veillardde0e4982005-07-03 14:35:44 +0000884 if (checkTestFile((const char *) path) <= 0) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000885 test_log("schemas for testGroup line %ld is missing: %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000886 xmlGetLineNo(cur), path);
887 ret = -1;
888 goto done;
889 }
890 validity = getString(cur,
891 "string(ts:schemaTest/ts:expected/@validity)");
892 if (validity == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000893 test_log("testGroup line %ld misses expected validity\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000894 xmlGetLineNo(cur));
895 ret = -1;
896 goto done;
897 }
Daniel Veillardc9352532005-07-04 14:25:34 +0000898 nb_tests++;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000899 if (xmlStrEqual(validity, BAD_CAST "valid")) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000900 nb_schematas++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000901 ctxt = xmlSchemaNewParserCtxt((const char *) path);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000902 xmlSchemaSetParserErrors(ctxt,
903 (xmlSchemaValidityErrorFunc) testErrorHandler,
904 (xmlSchemaValidityWarningFunc) testErrorHandler,
905 ctxt);
906 schemas = xmlSchemaParse(ctxt);
907 xmlSchemaFreeParserCtxt(ctxt);
908 if (schemas == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000909 test_log("valid schemas %s failed to parse\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000910 path);
911 nb_errors++;
912 }
913 instance = getNext(cur, "./ts:instanceTest[1]");
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000914 while (instance != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000915 xstcTestInstance(instance, schemas, path, base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000916 instance = getNext(instance,
917 "following-sibling::ts:instanceTest[1]");
918 }
919 } else if (xmlStrEqual(validity, BAD_CAST "invalid")) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000920 nb_schematas++;
Daniel Veillardde0e4982005-07-03 14:35:44 +0000921 ctxt = xmlSchemaNewParserCtxt((const char *) path);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000922 xmlSchemaSetParserErrors(ctxt,
923 (xmlSchemaValidityErrorFunc) testErrorHandler,
924 (xmlSchemaValidityWarningFunc) testErrorHandler,
925 ctxt);
926 schemas = xmlSchemaParse(ctxt);
927 xmlSchemaFreeParserCtxt(ctxt);
928 if (schemas == NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000929 test_log("Failed to detect error in schemas %s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000930 path);
931 nb_errors++;
932 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000933 } else {
Daniel Veillardc9352532005-07-04 14:25:34 +0000934 test_log("testGroup line %ld misses unexpected validity value%s\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000935 xmlGetLineNo(cur), validity);
936 ret = -1;
937 goto done;
938 }
939
940done:
941 if (href != NULL) xmlFree(href);
942 if (path != NULL) xmlFree(path);
943 if (validity != NULL) xmlFree(validity);
944 if (schemas != NULL) xmlSchemaFree(schemas);
Daniel Veillardde0e4982005-07-03 14:35:44 +0000945 xmlResetLastError();
946 if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000947 test_log("Processing test line %ld %s leaked %d\n",
948 xmlGetLineNo(cur), path, xmlMemUsed() - mem);
Daniel Veillardde0e4982005-07-03 14:35:44 +0000949 nb_leaks++;
950 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000951 return(ret);
952}
953
954static int
Daniel Veillardc9352532005-07-04 14:25:34 +0000955xstcMetadata(const char *metadata, const char *base) {
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000956 xmlDocPtr doc;
957 xmlNodePtr cur;
958 xmlChar *contributor;
959 xmlChar *name;
Daniel Veillard6b6d6802005-07-03 21:00:34 +0000960 int ret = 0;
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000961
962 doc = xmlReadFile(metadata, NULL, XML_PARSE_NOENT);
963 if (doc == NULL) {
964 fprintf(stderr, "Failed to parse %s\n", metadata);
965 return(-1);
966 }
967
968 cur = xmlDocGetRootElement(doc);
969 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testSet"))) {
970 fprintf(stderr, "Unexpected format %s\n", metadata);
971 return(-1);
972 }
973 contributor = xmlGetProp(cur, BAD_CAST "contributor");
974 if (contributor == NULL) {
975 contributor = xmlStrdup(BAD_CAST "Unknown");
976 }
977 name = xmlGetProp(cur, BAD_CAST "name");
978 if (name == NULL) {
979 name = xmlStrdup(BAD_CAST "Unknown");
980 }
981 printf("## %s test suite for Schemas version %s\n", contributor, name);
982 xmlFree(contributor);
983 xmlFree(name);
984
985 cur = getNext(cur, "./ts:testGroup[1]");
986 if ((cur == NULL) || (!xmlStrEqual(cur->name, BAD_CAST "testGroup"))) {
987 fprintf(stderr, "Unexpected format %s\n", metadata);
988 ret = -1;
989 goto done;
990 }
991 while (cur != NULL) {
Daniel Veillardc9352532005-07-04 14:25:34 +0000992 xstcTestGroup(cur, base);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +0000993 cur = getNext(cur, "following-sibling::ts:testGroup[1]");
994 }
995
996done:
997 xmlFreeDoc(doc);
998 return(ret);
999}
1000
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001001/************************************************************************
1002 * *
1003 * The driver for the tests *
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001004 * *
1005 ************************************************************************/
1006
1007int
1008main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
1009 int res, ret = 0;
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001010 int old_errors, old_tests, old_leaks;
1011
Daniel Veillardc9352532005-07-04 14:25:34 +00001012 logfile = fopen(LOGFILE, "w");
1013 if (logfile == NULL) {
1014 fprintf(stderr,
1015 "Could not open the log file, running in verbose mode\n");
1016 verbose = 1;
1017 }
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001018 initializeLibxml2();
1019
1020 if ((argc >= 2) && (!strcmp(argv[1], "-v")))
1021 verbose = 1;
1022
1023
Daniel Veillarde84f2312005-07-02 07:31:28 +00001024 old_errors = nb_errors;
1025 old_tests = nb_tests;
1026 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001027 res = xsdTest();
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001028 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
1029 printf("Ran %d tests, no errors\n", nb_tests - old_tests);
1030 else
1031 printf("Ran %d tests, %d errors, %d leaks\n",
1032 nb_tests - old_tests,
1033 nb_errors - old_errors,
1034 nb_leaks - old_leaks);
1035 old_errors = nb_errors;
1036 old_tests = nb_tests;
1037 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001038 res = rngTest1();
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001039 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
1040 printf("Ran %d tests, no errors\n", nb_tests - old_tests);
1041 else
1042 printf("Ran %d tests, %d errors, %d leaks\n",
1043 nb_tests - old_tests,
1044 nb_errors - old_errors,
1045 nb_leaks - old_leaks);
1046 old_errors = nb_errors;
1047 old_tests = nb_tests;
1048 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001049 res = rngTest2();
Daniel Veillarde84f2312005-07-02 07:31:28 +00001050 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
1051 printf("Ran %d tests, no errors\n", nb_tests - old_tests);
1052 else
1053 printf("Ran %d tests, %d errors, %d leaks\n",
1054 nb_tests - old_tests,
1055 nb_errors - old_errors,
1056 nb_leaks - old_leaks);
1057 old_errors = nb_errors;
1058 old_tests = nb_tests;
1059 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001060 nb_internals = 0;
1061 nb_schematas = 0;
1062 res = xstcMetadata(
Daniel Veillardde0e4982005-07-03 14:35:44 +00001063 "xstc/Tests/Metadata/NISTXMLSchemaDatatypes.testSet",
1064 "xstc/Tests/Metadata/");
1065 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
Daniel Veillardc9352532005-07-04 14:25:34 +00001066 printf("Ran %d tests (%d schemata), no errors\n",
1067 nb_tests - old_tests, nb_schematas);
Daniel Veillardde0e4982005-07-03 14:35:44 +00001068 else
Daniel Veillardc9352532005-07-04 14:25:34 +00001069 printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +00001070 nb_tests - old_tests,
Daniel Veillardc9352532005-07-04 14:25:34 +00001071 nb_schematas,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001072 nb_errors - old_errors,
Daniel Veillardc9352532005-07-04 14:25:34 +00001073 nb_internals,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001074 nb_leaks - old_leaks);
1075 old_errors = nb_errors;
1076 old_tests = nb_tests;
1077 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001078 nb_internals = 0;
1079 nb_schematas = 0;
1080 res = xstcMetadata(
Daniel Veillardde0e4982005-07-03 14:35:44 +00001081 "xstc/Tests/Metadata/SunXMLSchema1-0-20020116.testSet",
Daniel Veillardc9352532005-07-04 14:25:34 +00001082 "xstc/Tests/");
Daniel Veillardde0e4982005-07-03 14:35:44 +00001083 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
Daniel Veillardc9352532005-07-04 14:25:34 +00001084 printf("Ran %d tests (%d schemata), no errors\n",
1085 nb_tests - old_tests, nb_schematas);
Daniel Veillardde0e4982005-07-03 14:35:44 +00001086 else
Daniel Veillardc9352532005-07-04 14:25:34 +00001087 printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n",
Daniel Veillardde0e4982005-07-03 14:35:44 +00001088 nb_tests - old_tests,
Daniel Veillardc9352532005-07-04 14:25:34 +00001089 nb_schematas,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001090 nb_errors - old_errors,
Daniel Veillardc9352532005-07-04 14:25:34 +00001091 nb_internals,
Daniel Veillardde0e4982005-07-03 14:35:44 +00001092 nb_leaks - old_leaks);
1093 old_errors = nb_errors;
1094 old_tests = nb_tests;
1095 old_leaks = nb_leaks;
Daniel Veillardc9352532005-07-04 14:25:34 +00001096 nb_internals = 0;
1097 nb_schematas = 0;
1098 res = xstcMetadata(
Daniel Veillardde0e4982005-07-03 14:35:44 +00001099 "xstc/Tests/Metadata/MSXMLSchema1-0-20020116.testSet",
1100 "xstc/Tests/");
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001101 if ((nb_errors == old_errors) && (nb_leaks == old_leaks))
Daniel Veillardc9352532005-07-04 14:25:34 +00001102 printf("Ran %d tests (%d schemata), no errors\n",
1103 nb_tests - old_tests, nb_schematas);
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001104 else
Daniel Veillardc9352532005-07-04 14:25:34 +00001105 printf("Ran %d tests (%d schemata), %d errors (%d internals), %d leaks\n",
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001106 nb_tests - old_tests,
Daniel Veillardc9352532005-07-04 14:25:34 +00001107 nb_schematas,
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001108 nb_errors - old_errors,
Daniel Veillardc9352532005-07-04 14:25:34 +00001109 nb_internals,
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001110 nb_leaks - old_leaks);
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001111
1112 if ((nb_errors == 0) && (nb_leaks == 0)) {
1113 ret = 0;
1114 printf("Total %d tests, no errors\n",
1115 nb_tests);
1116 } else {
1117 ret = 1;
1118 printf("Total %d tests, %d errors, %d leaks\n",
1119 nb_tests, nb_errors, nb_leaks);
1120 }
Daniel Veillard3fe1e8a2005-07-02 21:39:06 +00001121
1122 xmlXPathFreeContext(ctxtXPath);
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001123 xmlCleanupParser();
1124 xmlMemoryDump();
1125
Daniel Veillardc9352532005-07-04 14:25:34 +00001126 if (logfile != NULL)
1127 fclose(logfile);
Daniel Veillardf2e066a2005-06-30 13:04:44 +00001128 return(ret);
1129}
Daniel Veillard95175012005-07-03 16:09:51 +00001130#else /* !SCHEMAS */
1131int
1132main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
1133 fprintf(stderr, "runsuite requires support for schemas and xpath in libxml2\n");
1134}
1135#endif