* * * Schemas tests * * * ************************************************************************/
| 3375 | * * |
| 3376 | ************************************************************************/ |
| 3377 | static int |
| 3378 | rngOneTest(const char *sch, |
| 3379 | const char *filename, |
| 3380 | const char *result, |
| 3381 | int options, |
| 3382 | xmlRelaxNGPtr schemas) { |
| 3383 | xmlDocPtr doc; |
| 3384 | xmlRelaxNGValidCtxtPtr ctxt; |
| 3385 | int ret = 0; |
| 3386 | char *temp; |
| 3387 | FILE *schemasOutput; |
| 3388 | |
| 3389 | doc = xmlReadFile(filename, NULL, options); |
| 3390 | if (doc == NULL) { |
| 3391 | fprintf(stderr, "failed to parse instance %s for %s\n", filename, sch); |
| 3392 | return(-1); |
| 3393 | } |
| 3394 | |
| 3395 | temp = resultFilename(result, temp_directory, ".res"); |
| 3396 | if (temp == NULL) { |
| 3397 | fprintf(stderr, "Out of memory\n"); |
| 3398 | fatalError(); |
| 3399 | } |
| 3400 | schemasOutput = fopen(temp, "wb"); |
| 3401 | if (schemasOutput == NULL) { |
| 3402 | fprintf(stderr, "failed to open output file %s\n", temp); |
| 3403 | xmlFreeDoc(doc); |
| 3404 | free(temp); |
| 3405 | return(-1); |
| 3406 | } |
| 3407 | |
| 3408 | ctxt = xmlRelaxNGNewValidCtxt(schemas); |
| 3409 | xmlRelaxNGSetValidStructuredErrors(ctxt, testStructuredErrorHandler, NULL); |
| 3410 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 3411 | if (ret == 0) { |
| 3412 | testErrorHandler(NULL, "%s validates\n", filename); |
| 3413 | } else if (ret > 0) { |
| 3414 | testErrorHandler(NULL, "%s fails to validate\n", filename); |
| 3415 | } else { |
| 3416 | testErrorHandler(NULL, "%s validation generated an internal error\n", |
| 3417 | filename); |
| 3418 | } |
| 3419 | fclose(schemasOutput); |
| 3420 | ret = 0; |
| 3421 | if (result) { |
| 3422 | if (compareFiles(temp, result)) { |
| 3423 | fprintf(stderr, "Result for %s on %s failed\n", filename, sch); |
| 3424 | ret = 1; |
| 3425 | } |
| 3426 | } |
| 3427 | if (temp != NULL) { |
| 3428 | unlink(temp); |
| 3429 | free(temp); |
| 3430 | } |
| 3431 | |
| 3432 | xmlRelaxNGFreeValidCtxt(ctxt); |
| 3433 | xmlFreeDoc(doc); |
| 3434 | return(ret); |
no test coverage detected