| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifdef HAVE_CONFIG_H1 |
| 15 | #include "libxml.h" |
| 16 | #else |
| 17 | #include <stdio.h> |
| 18 | #endif |
| 19 | |
| 20 | #if !defined(_WIN32) || defined(__CYGWIN__) |
| 21 | #include <unistd.h> |
| 22 | #endif |
| 23 | #include <string.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <fcntl.h> |
| 27 | |
| 28 | #include <libxml/parser.h> |
| 29 | #include <libxml/tree.h> |
| 30 | #include <libxml/uri.h> |
| 31 | |
| 32 | #ifdef LIBXML_OUTPUT_ENABLED |
| 33 | #ifdef LIBXML_READER_ENABLED |
| 34 | #include <libxml/xmlreader.h> |
| 35 | #endif |
| 36 | |
| 37 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 38 | #include <libxml/xinclude.h> |
| 39 | #endif |
| 40 | |
| 41 | #ifdef LIBXML_XPATH_ENABLED |
| 42 | #include <libxml/xpath.h> |
| 43 | #include <libxml/xpathInternals.h> |
| 44 | #ifdef LIBXML_XPTR_ENABLED |
| 45 | #include <libxml/xpointer.h> |
| 46 | #endif |
| 47 | #endif |
| 48 | |
| 49 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 50 | #include <libxml/relaxng.h> |
| 51 | #include <libxml/xmlschemas.h> |
| 52 | #include <libxml/xmlschemastypes.h> |
| 53 | #endif |
| 54 | |
| 55 | #ifdef LIBXML_PATTERN_ENABLED |
| 56 | #include <libxml/pattern.h> |
| 57 | #endif |
| 58 | |
| 59 | #ifdef LIBXML_C14N_ENABLED |
| 60 | #include <libxml/c14n.h> |
| 61 | #endif |
| 62 | |
| 63 | #ifdef LIBXML_HTML_ENABLED |
| 64 | #include <libxml/HTMLparser.h> |
| 65 | #include <libxml/HTMLtree.h> |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | #define XML_PARSE_HTML1 << 24 1 << 24 |
| 71 | #endif |
| 72 | |
| 73 | #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED) |
| 74 | #include <libxml/globals.h> |
| 75 | #include <libxml/threads.h> |
| 76 | #include <libxml/parser.h> |
| 77 | #include <libxml/catalog.h> |
| 78 | #include <string.h> |
| 79 | #endif |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | #ifdef O_BINARY |
| 86 | #define RD_FLAGS00 O_RDONLY00 | O_BINARY |
| 87 | #else |
| 88 | #define RD_FLAGS00 O_RDONLY00 |
| 89 | #endif |
| 90 | |
| 91 | typedef int (*functest) (const char *filename, const char *result, |
| 92 | const char *error, int options); |
| 93 | |
| 94 | typedef struct testDesc testDesc; |
| 95 | typedef testDesc *testDescPtr; |
| 96 | struct testDesc { |
| 97 | const char *desc; |
| 98 | functest func; |
| 99 | const char *in; |
| 100 | const char *out; |
| 101 | const char *suffix; |
| 102 | const char *err; |
| 103 | int options; |
| 104 | }; |
| 105 | |
| 106 | static int checkTestFile(const char *filename); |
| 107 | |
| 108 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 109 | |
| 110 | #include <windows.h> |
| 111 | #include <io.h> |
| 112 | |
| 113 | typedef struct |
| 114 | { |
| 115 | size_t gl_pathc; |
| 116 | char **gl_pathv; |
| 117 | size_t gl_offs; |
| 118 | } glob_t; |
| 119 | |
| 120 | #define GLOB_DOOFFS(1 << 3) 0 |
| 121 | static int glob(const char *pattern, int flags, |
| 122 | int errfunc(const char *epath, int eerrno), |
| 123 | glob_t *pglob) { |
| 124 | glob_t *ret; |
| 125 | WIN32_FIND_DATA FindFileData; |
| 126 | HANDLE hFind; |
| 127 | unsigned int nb_paths = 0; |
| 128 | char directory[500]; |
| 129 | int len; |
| 130 | |
| 131 | if ((pattern == NULL((void*)0)) || (pglob == NULL((void*)0))) return(-1); |
| 132 | |
| 133 | strncpy(directory, pattern, 499); |
| 134 | for (len = strlen(directory);len >= 0;len--) { |
| 135 | if (directory[len] == '/') { |
| 136 | len++; |
| 137 | directory[len] = 0; |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | if (len <= 0) |
| 142 | len = 0; |
| 143 | |
| 144 | |
| 145 | ret = pglob; |
| 146 | memset(ret, 0, sizeof(glob_t)); |
| 147 | |
| 148 | hFind = FindFirstFileA(pattern, &FindFileData); |
| 149 | if (hFind == INVALID_HANDLE_VALUE) |
| 150 | return(0); |
| 151 | nb_paths = 20; |
| 152 | ret->gl_pathv = (char **) malloc(nb_paths * sizeof(char *)); |
| 153 | if (ret->gl_pathv == NULL((void*)0)) { |
| 154 | FindClose(hFind); |
| 155 | return(-1); |
| 156 | } |
| 157 | strncpy(directory + len, FindFileData.cFileName, 499 - len); |
| 158 | ret->gl_pathv[ret->gl_pathc] = strdup(directory); |
| 159 | if (ret->gl_pathv[ret->gl_pathc] == NULL((void*)0)) |
| 160 | goto done; |
| 161 | ret->gl_pathc++; |
| 162 | while(FindNextFileA(hFind, &FindFileData)) { |
| 163 | if (FindFileData.cFileName[0] == '.') |
| 164 | continue; |
| 165 | if (ret->gl_pathc + 2 > nb_paths) { |
| 166 | char **tmp = realloc(ret->gl_pathv, nb_paths * 2 * sizeof(char *)); |
| 167 | if (tmp == NULL((void*)0)) |
| 168 | break; |
| 169 | ret->gl_pathv = tmp; |
| 170 | nb_paths *= 2; |
| 171 | } |
| 172 | strncpy(directory + len, FindFileData.cFileName, 499 - len); |
| 173 | ret->gl_pathv[ret->gl_pathc] = strdup(directory); |
| 174 | if (ret->gl_pathv[ret->gl_pathc] == NULL((void*)0)) |
| 175 | break; |
| 176 | ret->gl_pathc++; |
| 177 | } |
| 178 | ret->gl_pathv[ret->gl_pathc] = NULL((void*)0); |
| 179 | |
| 180 | done: |
| 181 | FindClose(hFind); |
| 182 | return(0); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | |
| 187 | static void globfree(glob_t *pglob) { |
| 188 | unsigned int i; |
| 189 | if (pglob == NULL((void*)0)) |
| 190 | return; |
| 191 | |
| 192 | for (i = 0;i < pglob->gl_pathc;i++) { |
| 193 | if (pglob->gl_pathv[i] != NULL((void*)0)) |
| 194 | free(pglob->gl_pathv[i]); |
| 195 | } |
| 196 | } |
| 197 | #define vsnprintf _vsnprintf |
| 198 | #define snprintf _snprintf |
| 199 | #else |
| 200 | #include <glob.h> |
| 201 | #endif |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | static int nb_tests = 0; |
| 210 | static int nb_errors = 0; |
| 211 | static int nb_leaks = 0; |
| 212 | static int extraMemoryFromResolver = 0; |
| 213 | |
| 214 | static int |
| 215 | fatalError(void) { |
| 216 | fprintf(stderrstderr, "Exitting tests on fatal error\n"); |
| 217 | exit(1); |
| 218 | } |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | static xmlParserInputPtr |
| 226 | testExternalEntityLoader(const char *URL, const char *ID, |
| 227 | xmlParserCtxtPtr ctxt) { |
| 228 | xmlParserInputPtr ret; |
| 229 | |
| 230 | if (checkTestFile(URL)) { |
| 231 | ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt); |
| 232 | } else { |
| 233 | int memused = xmlMemUsed(); |
| 234 | ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt); |
| 235 | extraMemoryFromResolver += xmlMemUsed() - memused; |
| 236 | } |
| 237 | |
| 238 | return(ret); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | static char testErrors[32769]; |
| 246 | static int testErrorsSize = 0; |
| 247 | |
| 248 | static void XMLCDECL |
| 249 | testErrorHandler(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const char *msg, ...) { |
| 250 | va_list args; |
| 251 | int res; |
| 252 | |
| 253 | if (testErrorsSize >= 32768) |
| 254 | return; |
| 255 | va_start(args, msg)__builtin_va_start(args, msg); |
| 256 | res = vsnprintf(&testErrors[testErrorsSize], |
| 257 | 32768 - testErrorsSize, |
| 258 | msg, args); |
| 259 | va_end(args)__builtin_va_end(args); |
| 260 | if (testErrorsSize + res >= 32768) { |
| 261 | |
| 262 | testErrorsSize = 32768; |
| 263 | testErrors[testErrorsSize] = 0; |
| 264 | } else { |
| 265 | testErrorsSize += res; |
| 266 | } |
| 267 | testErrors[testErrorsSize] = 0; |
| 268 | } |
| 269 | |
| 270 | static void XMLCDECL |
| 271 | channel(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const char *msg, ...) { |
| 272 | va_list args; |
| 273 | int res; |
| 274 | |
| 275 | if (testErrorsSize >= 32768) |
| 276 | return; |
| 277 | va_start(args, msg)__builtin_va_start(args, msg); |
| 278 | res = vsnprintf(&testErrors[testErrorsSize], |
| 279 | 32768 - testErrorsSize, |
| 280 | msg, args); |
| 281 | va_end(args)__builtin_va_end(args); |
| 282 | if (testErrorsSize + res >= 32768) { |
| 283 | |
| 284 | testErrorsSize = 32768; |
| 285 | testErrors[testErrorsSize] = 0; |
| 286 | } else { |
| 287 | testErrorsSize += res; |
| 288 | } |
| 289 | testErrors[testErrorsSize] = 0; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | static void |
| 300 | xmlParserPrintFileContextInternal(xmlParserInputPtr input , |
| 301 | xmlGenericErrorFunc chanl, void *data ) { |
| 302 | const xmlChar *cur, *base; |
| 303 | unsigned int n, col; |
| 304 | xmlChar content[81]; |
| 305 | xmlChar *ctnt; |
| 306 | |
| 307 | if (input == NULL((void*)0)) return; |
| 308 | cur = input->cur; |
| 309 | base = input->base; |
| 310 | |
| 311 | while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { |
| 312 | cur--; |
| 313 | } |
| 314 | n = 0; |
| 315 | |
| 316 | while ((n++ < (sizeof(content)-1)) && (cur > base) && |
| 317 | (*(cur) != '\n') && (*(cur) != '\r')) |
| 318 | cur--; |
| 319 | if ((*(cur) == '\n') || (*(cur) == '\r')) cur++; |
| 320 | |
| 321 | col = input->cur - cur; |
| 322 | |
| 323 | n = 0; |
| 324 | ctnt = content; |
| 325 | |
| 326 | while ((*cur != 0) && (*(cur) != '\n') && |
| 327 | (*(cur) != '\r') && (n < sizeof(content)-1)) { |
| 328 | *ctnt++ = *cur++; |
| 329 | n++; |
| 330 | } |
| 331 | *ctnt = 0; |
| 332 | |
| 333 | chanl(data ,"%s\n", content); |
| 334 | |
| 335 | n = 0; |
| 336 | ctnt = content; |
| 337 | |
| 338 | while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) { |
| 339 | if (*(ctnt) != '\t') |
| 340 | *(ctnt) = ' '; |
| 341 | ctnt++; |
| 342 | } |
| 343 | *ctnt++ = '^'; |
| 344 | *ctnt = 0; |
| 345 | chanl(data ,"%s\n", content); |
| 346 | } |
| 347 | |
| 348 | static void |
| 349 | testStructuredErrorHandler(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), xmlErrorPtr err) { |
| 350 | char *file = NULL((void*)0); |
| 351 | int line = 0; |
| 352 | int code = -1; |
| 353 | int domain; |
| 354 | void *data = NULL((void*)0); |
| 355 | const char *str; |
| 356 | const xmlChar *name = NULL((void*)0); |
| 357 | xmlNodePtr node; |
| 358 | xmlErrorLevel level; |
| 359 | xmlParserInputPtr input = NULL((void*)0); |
| 360 | xmlParserInputPtr cur = NULL((void*)0); |
| 361 | xmlParserCtxtPtr ctxt = NULL((void*)0); |
| 362 | |
| 363 | if (err == NULL((void*)0)) |
| 364 | return; |
| 365 | |
| 366 | file = err->file; |
| 367 | line = err->line; |
| 368 | code = err->code; |
| 369 | domain = err->domain; |
| 370 | level = err->level; |
| 371 | node = err->node; |
| 372 | if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || |
| 373 | (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || |
| 374 | (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { |
| 375 | ctxt = err->ctxt; |
| 376 | } |
| 377 | str = err->message; |
| 378 | |
| 379 | if (code == XML_ERR_OK) |
| 380 | return; |
| 381 | |
| 382 | if ((node != NULL((void*)0)) && (node->type == XML_ELEMENT_NODE)) |
| 383 | name = node->name; |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | if (ctxt != NULL((void*)0)) { |
| 389 | input = ctxt->input; |
| 390 | if ((input != NULL((void*)0)) && (input->filename == NULL((void*)0)) && |
| 391 | (ctxt->inputNr > 1)) { |
| 392 | cur = input; |
| 393 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 394 | } |
| 395 | if (input != NULL((void*)0)) { |
| 396 | if (input->filename) |
| 397 | channel(data, "%s:%d: ", input->filename, input->line); |
| 398 | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
| 399 | channel(data, "Entity: line %d: ", input->line); |
| 400 | } |
| 401 | } else { |
| 402 | if (file != NULL((void*)0)) |
| 403 | channel(data, "%s:%d: ", file, line); |
| 404 | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
| 405 | channel(data, "Entity: line %d: ", line); |
| 406 | } |
| 407 | if (name != NULL((void*)0)) { |
| 408 | channel(data, "element %s: ", name); |
| 409 | } |
| 410 | if (code == XML_ERR_OK) |
| 411 | return; |
| 412 | switch (domain) { |
| 413 | case XML_FROM_PARSER: |
| 414 | channel(data, "parser "); |
| 415 | break; |
| 416 | case XML_FROM_NAMESPACE: |
| 417 | channel(data, "namespace "); |
| 418 | break; |
| 419 | case XML_FROM_DTD: |
| 420 | case XML_FROM_VALID: |
| 421 | channel(data, "validity "); |
| 422 | break; |
| 423 | case XML_FROM_HTML: |
| 424 | channel(data, "HTML parser "); |
| 425 | break; |
| 426 | case XML_FROM_MEMORY: |
| 427 | channel(data, "memory "); |
| 428 | break; |
| 429 | case XML_FROM_OUTPUT: |
| 430 | channel(data, "output "); |
| 431 | break; |
| 432 | case XML_FROM_IO: |
| 433 | channel(data, "I/O "); |
| 434 | break; |
| 435 | case XML_FROM_XINCLUDE: |
| 436 | channel(data, "XInclude "); |
| 437 | break; |
| 438 | case XML_FROM_XPATH: |
| 439 | channel(data, "XPath "); |
| 440 | break; |
| 441 | case XML_FROM_XPOINTER: |
| 442 | channel(data, "parser "); |
| 443 | break; |
| 444 | case XML_FROM_REGEXP: |
| 445 | channel(data, "regexp "); |
| 446 | break; |
| 447 | case XML_FROM_MODULE: |
| 448 | channel(data, "module "); |
| 449 | break; |
| 450 | case XML_FROM_SCHEMASV: |
| 451 | channel(data, "Schemas validity "); |
| 452 | break; |
| 453 | case XML_FROM_SCHEMASP: |
| 454 | channel(data, "Schemas parser "); |
| 455 | break; |
| 456 | case XML_FROM_RELAXNGP: |
| 457 | channel(data, "Relax-NG parser "); |
| 458 | break; |
| 459 | case XML_FROM_RELAXNGV: |
| 460 | channel(data, "Relax-NG validity "); |
| 461 | break; |
| 462 | case XML_FROM_CATALOG: |
| 463 | channel(data, "Catalog "); |
| 464 | break; |
| 465 | case XML_FROM_C14N: |
| 466 | channel(data, "C14N "); |
| 467 | break; |
| 468 | case XML_FROM_XSLT: |
| 469 | channel(data, "XSLT "); |
| 470 | break; |
| 471 | default: |
| 472 | break; |
| 473 | } |
| 474 | if (code == XML_ERR_OK) |
| 475 | return; |
| 476 | switch (level) { |
| 477 | case XML_ERR_NONE: |
| 478 | channel(data, ": "); |
| 479 | break; |
| 480 | case XML_ERR_WARNING: |
| 481 | channel(data, "warning : "); |
| 482 | break; |
| 483 | case XML_ERR_ERROR: |
| 484 | channel(data, "error : "); |
| 485 | break; |
| 486 | case XML_ERR_FATAL: |
| 487 | channel(data, "error : "); |
| 488 | break; |
| 489 | } |
| 490 | if (code == XML_ERR_OK) |
| 491 | return; |
| 492 | if (str != NULL((void*)0)) { |
| 493 | int len; |
| 494 | len = xmlStrlen((const xmlChar *)str); |
| 495 | if ((len > 0) && (str[len - 1] != '\n')) |
| 496 | channel(data, "%s\n", str); |
| 497 | else |
| 498 | channel(data, "%s", str); |
| 499 | } else { |
| 500 | channel(data, "%s\n", "out of memory error"); |
| 501 | } |
| 502 | if (code == XML_ERR_OK) |
| 503 | return; |
| 504 | |
| 505 | if (ctxt != NULL((void*)0)) { |
| 506 | xmlParserPrintFileContextInternal(input, channel, data); |
| 507 | if (cur != NULL((void*)0)) { |
| 508 | if (cur->filename) |
| 509 | channel(data, "%s:%d: \n", cur->filename, cur->line); |
| 510 | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
| 511 | channel(data, "Entity: line %d: \n", cur->line); |
| 512 | xmlParserPrintFileContextInternal(cur, channel, data); |
| 513 | } |
| 514 | } |
| 515 | if ((domain == XML_FROM_XPATH) && (err->str1 != NULL((void*)0)) && |
| 516 | (err->int1 < 100) && |
| 517 | (err->int1 < xmlStrlen((const xmlChar *)err->str1))) { |
| 518 | xmlChar buf[150]; |
| 519 | int i; |
| 520 | |
| 521 | channel(data, "%s\n", err->str1); |
| 522 | for (i=0;i < err->int1;i++) |
| 523 | buf[i] = ' '; |
| 524 | buf[i++] = '^'; |
| 525 | buf[i] = 0; |
| 526 | channel(data, "%s\n", buf); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | static void |
| 531 | initializeLibxml2(void) { |
| 532 | xmlGetWarningsDefaultValue(*(__xmlGetWarningsDefaultValue())) = 0; |
| 533 | xmlPedanticParserDefault(0); |
| 534 | |
| 535 | xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup); |
| 536 | xmlInitParser(); |
| 537 | xmlSetExternalEntityLoader(testExternalEntityLoader); |
| 538 | xmlSetStructuredErrorFunc(NULL((void*)0), testStructuredErrorHandler); |
| 539 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 540 | xmlSchemaInitTypes(); |
| 541 | xmlRelaxNGInitTypes(); |
| 542 | #endif |
| 543 | } |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | static const char *baseFilename(const char *filename) { |
| 553 | const char *cur; |
| 554 | if (filename == NULL((void*)0)) |
| 555 | return(NULL((void*)0)); |
| 556 | cur = &filename[strlen(filename)]; |
| 557 | while ((cur > filename) && (*cur != '/')) |
| 558 | cur--; |
| 559 | if (*cur == '/') |
| 560 | return(cur + 1); |
| 561 | return(cur); |
| 562 | } |
| 563 | |
| 564 | static char *resultFilename(const char *filename, const char *out, |
| 565 | const char *suffix) { |
| 566 | const char *base; |
| 567 | char res[500]; |
| 568 | char suffixbuff[500]; |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | base = baseFilename(filename); |
| 578 | if (suffix == NULL((void*)0)) |
| 579 | suffix = ".tmp"; |
| 580 | if (out == NULL((void*)0)) |
| 581 | out = ""; |
| 582 | |
| 583 | strncpy(suffixbuff,suffix,499); |
| 584 | #ifdef VMS |
| 585 | if(strstr(base,".") && suffixbuff[0]=='.') |
| 586 | suffixbuff[0]='_'; |
| 587 | #endif |
| 588 | |
| 589 | snprintf(res, 499, "%s%s%s", out, base, suffixbuff); |
| 590 | res[499] = 0; |
| 591 | return(strdup(res)); |
| 592 | } |
| 593 | |
| 594 | static int checkTestFile(const char *filename) { |
| 595 | struct stat buf; |
| 596 | |
| 597 | if (stat(filename, &buf) == -1) |
| 598 | return(0); |
| 599 | |
| 600 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 601 | if (!(buf.st_mode & _S_IFREG)) |
| 602 | return(0); |
| 603 | #else |
| 604 | if (!S_ISREG(buf.st_mode)((((buf.st_mode)) & 0170000) == (0100000))) |
| 605 | return(0); |
| 606 | #endif |
| 607 | |
| 608 | return(1); |
| 609 | } |
| 610 | |
| 611 | static int compareFiles(const char *r1, const char *r2) { |
| 612 | int res1, res2; |
| 613 | int fd1, fd2; |
| 614 | char bytes1[4096]; |
| 615 | char bytes2[4096]; |
| 616 | |
| 617 | fd1 = open(r1, RD_FLAGS00); |
| 618 | if (fd1 < 0) |
| 619 | return(-1); |
| 620 | fd2 = open(r2, RD_FLAGS00); |
| 621 | if (fd2 < 0) { |
| 622 | close(fd1); |
| 623 | return(-1); |
| 624 | } |
| 625 | while (1) { |
| 626 | res1 = read(fd1, bytes1, 4096); |
| 627 | res2 = read(fd2, bytes2, 4096); |
| 628 | if ((res1 != res2) || (res1 < 0)) { |
| 629 | close(fd1); |
| 630 | close(fd2); |
| 631 | return(1); |
| 632 | } |
| 633 | if (res1 == 0) |
| 634 | break; |
| 635 | if (memcmp(bytes1, bytes2, res1) != 0) { |
| 636 | close(fd1); |
| 637 | close(fd2); |
| 638 | return(1); |
| 639 | } |
| 640 | } |
| 641 | close(fd1); |
| 642 | close(fd2); |
| 643 | return(0); |
| 644 | } |
| 645 | |
| 646 | static int compareFileMem(const char *filename, const char *mem, int size) { |
| 647 | int res; |
| 648 | int fd; |
| 649 | char bytes[4096]; |
| 650 | int idx = 0; |
| 651 | struct stat info; |
| 652 | |
| 653 | if (stat(filename, &info) < 0) |
| 654 | return(-1); |
| 655 | if (info.st_size != size) |
| 656 | return(-1); |
| 657 | fd = open(filename, RD_FLAGS00); |
| 658 | if (fd < 0) |
| 659 | return(-1); |
| 660 | while (idx < size) { |
| 661 | res = read(fd, bytes, 4096); |
| 662 | if (res <= 0) |
| 663 | break; |
| 664 | if (res + idx > size) |
| 665 | break; |
| 666 | if (memcmp(bytes, &mem[idx], res) != 0) { |
| 667 | int ix; |
| 668 | for (ix=0; ix<res; ix++) |
| 669 | if (bytes[ix] != mem[idx+ix]) |
| 670 | break; |
| 671 | fprintf(stderrstderr,"Compare error at position %d\n", idx+ix); |
| 672 | close(fd); |
| 673 | return(1); |
| 674 | } |
| 675 | idx += res; |
| 676 | } |
| 677 | close(fd); |
| 678 | return(idx != size); |
| 679 | } |
| 680 | |
| 681 | static int loadMem(const char *filename, const char **mem, int *size) { |
| 682 | int fd, res; |
| 683 | struct stat info; |
| 684 | char *base; |
| 685 | int siz = 0; |
| 686 | if (stat(filename, &info) < 0) |
| 687 | return(-1); |
| 688 | base = malloc(info.st_size + 1); |
| 689 | if (base == NULL((void*)0)) |
| 690 | return(-1); |
| 691 | if ((fd = open(filename, RD_FLAGS00)) < 0) { |
| 692 | free(base); |
| 693 | return(-1); |
| 694 | } |
| 695 | while ((res = read(fd, &base[siz], info.st_size - siz)) > 0) { |
| 696 | siz += res; |
| 697 | } |
| 698 | close(fd); |
| 699 | #if !defined(_WIN32) |
| 700 | if (siz != info.st_size) { |
| 701 | free(base); |
| 702 | return(-1); |
| 703 | } |
| 704 | #endif |
| 705 | base[siz] = 0; |
| 706 | *mem = base; |
| 707 | *size = siz; |
| 708 | return(0); |
| 709 | } |
| 710 | |
| 711 | static int unloadMem(const char *mem) { |
| 712 | free((char *)mem); |
| 713 | return(0); |
| 714 | } |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | static FILE *SAXdebug = NULL((void*)0); |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | static xmlSAXHandler emptySAXHandlerStruct = { |
| 734 | NULL((void*)0), |
| 735 | NULL((void*)0), |
| 736 | NULL((void*)0), |
| 737 | NULL((void*)0), |
| 738 | NULL((void*)0), |
| 739 | NULL((void*)0), |
| 740 | NULL((void*)0), |
| 741 | NULL((void*)0), |
| 742 | NULL((void*)0), |
| 743 | NULL((void*)0), |
| 744 | NULL((void*)0), |
| 745 | NULL((void*)0), |
| 746 | NULL((void*)0), |
| 747 | NULL((void*)0), |
| 748 | NULL((void*)0), |
| 749 | NULL((void*)0), |
| 750 | NULL((void*)0), |
| 751 | NULL((void*)0), |
| 752 | NULL((void*)0), |
| 753 | NULL((void*)0), |
| 754 | NULL((void*)0), |
| 755 | NULL((void*)0), |
| 756 | NULL((void*)0), |
| 757 | NULL((void*)0), |
| 758 | NULL((void*)0), |
| 759 | NULL((void*)0), |
| 760 | NULL((void*)0), |
| 761 | 1, |
| 762 | NULL((void*)0), |
| 763 | NULL((void*)0), |
| 764 | NULL((void*)0), |
| 765 | NULL((void*)0) |
| 766 | }; |
| 767 | |
| 768 | static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; |
| 769 | static int callbacks = 0; |
| 770 | static int quiet = 0; |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | static int |
| 781 | isStandaloneDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused))) |
| 782 | { |
| 783 | callbacks++; |
| 784 | if (quiet) |
| 785 | return(0); |
| 786 | fprintf(SAXdebug, "SAX.isStandalone()\n"); |
| 787 | return(0); |
| 788 | } |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | static int |
| 799 | hasInternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused))) |
| 800 | { |
| 801 | callbacks++; |
| 802 | if (quiet) |
| 803 | return(0); |
| 804 | fprintf(SAXdebug, "SAX.hasInternalSubset()\n"); |
| 805 | return(0); |
| 806 | } |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | static int |
| 817 | hasExternalSubsetDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused))) |
| 818 | { |
| 819 | callbacks++; |
| 820 | if (quiet) |
| 821 | return(0); |
| 822 | fprintf(SAXdebug, "SAX.hasExternalSubset()\n"); |
| 823 | return(0); |
| 824 | } |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | static void |
| 833 | internalSubsetDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, |
| 834 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 835 | { |
| 836 | callbacks++; |
| 837 | if (quiet) |
| 838 | return; |
| 839 | fprintf(SAXdebug, "SAX.internalSubset(%s,", name); |
| 840 | if (ExternalID == NULL((void*)0)) |
| 841 | fprintf(SAXdebug, " ,"); |
| 842 | else |
| 843 | fprintf(SAXdebug, " %s,", ExternalID); |
| 844 | if (SystemID == NULL((void*)0)) |
| 845 | fprintf(SAXdebug, " )\n"); |
| 846 | else |
| 847 | fprintf(SAXdebug, " %s)\n", SystemID); |
| 848 | } |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | static void |
| 857 | externalSubsetDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, |
| 858 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 859 | { |
| 860 | callbacks++; |
| 861 | if (quiet) |
| 862 | return; |
| 863 | fprintf(SAXdebug, "SAX.externalSubset(%s,", name); |
| 864 | if (ExternalID == NULL((void*)0)) |
| 865 | fprintf(SAXdebug, " ,"); |
| 866 | else |
| 867 | fprintf(SAXdebug, " %s,", ExternalID); |
| 868 | if (SystemID == NULL((void*)0)) |
| 869 | fprintf(SAXdebug, " )\n"); |
| 870 | else |
| 871 | fprintf(SAXdebug, " %s)\n", SystemID); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | static xmlParserInputPtr |
| 889 | resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *publicId, const xmlChar *systemId) |
| 890 | { |
| 891 | callbacks++; |
| 892 | if (quiet) |
| 893 | return(NULL((void*)0)); |
| 894 | |
| 895 | |
| 896 | |
| 897 | fprintf(SAXdebug, "SAX.resolveEntity("); |
| 898 | if (publicId != NULL((void*)0)) |
| 899 | fprintf(SAXdebug, "%s", (char *)publicId); |
| 900 | else |
| 901 | fprintf(SAXdebug, " "); |
| 902 | if (systemId != NULL((void*)0)) |
| 903 | fprintf(SAXdebug, ", %s)\n", (char *)systemId); |
| 904 | else |
| 905 | fprintf(SAXdebug, ", )\n"); |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | return(NULL((void*)0)); |
| 912 | } |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | static xmlEntityPtr |
| 924 | getEntityDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name) |
| 925 | { |
| 926 | callbacks++; |
| 927 | if (quiet) |
| 928 | return(NULL((void*)0)); |
| 929 | fprintf(SAXdebug, "SAX.getEntity(%s)\n", name); |
| 930 | return(NULL((void*)0)); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 942 | static xmlEntityPtr |
| 943 | getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name) |
| 944 | { |
| 945 | callbacks++; |
| 946 | if (quiet) |
| 947 | return(NULL((void*)0)); |
| 948 | fprintf(SAXdebug, "SAX.getParameterEntity(%s)\n", name); |
| 949 | return(NULL((void*)0)); |
| 950 | } |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | static void |
| 965 | entityDeclDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, int type, |
| 966 | const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
| 967 | { |
| 968 | const xmlChar *nullstr = BAD_CAST(xmlChar *) "(null)"; |
| 969 | |
| 970 | if (publicId == NULL((void*)0)) |
| 971 | publicId = nullstr; |
| 972 | if (systemId == NULL((void*)0)) |
| 973 | systemId = nullstr; |
| 974 | if (content == NULL((void*)0)) |
| 975 | content = (xmlChar *)nullstr; |
| 976 | callbacks++; |
| 977 | if (quiet) |
| 978 | return; |
| 979 | fprintf(SAXdebug, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", |
| 980 | name, type, publicId, systemId, content); |
| 981 | } |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | static void |
| 992 | attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar * elem, |
| 993 | const xmlChar * name, int type, int def, |
| 994 | const xmlChar * defaultValue, xmlEnumerationPtr tree) |
| 995 | { |
| 996 | callbacks++; |
| 997 | if (quiet) |
| 998 | return; |
| 999 | if (defaultValue == NULL((void*)0)) |
| 1000 | fprintf(SAXdebug, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n", |
| 1001 | elem, name, type, def); |
| 1002 | else |
| 1003 | fprintf(SAXdebug, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
| 1004 | elem, name, type, def, defaultValue); |
| 1005 | xmlFreeEnumeration(tree); |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | static void |
| 1018 | elementDeclDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, int type, |
| 1019 | xmlElementContentPtr content ATTRIBUTE_UNUSED__attribute__((unused))) |
| 1020 | { |
| 1021 | callbacks++; |
| 1022 | if (quiet) |
| 1023 | return; |
| 1024 | fprintf(SAXdebug, "SAX.elementDecl(%s, %d, ...)\n", |
| 1025 | name, type); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | static void |
| 1038 | notationDeclDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, |
| 1039 | const xmlChar *publicId, const xmlChar *systemId) |
| 1040 | { |
| 1041 | callbacks++; |
| 1042 | if (quiet) |
| 1043 | return; |
| 1044 | fprintf(SAXdebug, "SAX.notationDecl(%s, %s, %s)\n", |
| 1045 | (char *) name, (char *) publicId, (char *) systemId); |
| 1046 | } |
| 1047 | |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | static void |
| 1059 | unparsedEntityDeclDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, |
| 1060 | const xmlChar *publicId, const xmlChar *systemId, |
| 1061 | const xmlChar *notationName) |
| 1062 | { |
| 1063 | const xmlChar *nullstr = BAD_CAST(xmlChar *) "(null)"; |
| 1064 | |
| 1065 | if (publicId == NULL((void*)0)) |
| 1066 | publicId = nullstr; |
| 1067 | if (systemId == NULL((void*)0)) |
| 1068 | systemId = nullstr; |
| 1069 | if (notationName == NULL((void*)0)) |
| 1070 | notationName = nullstr; |
| 1071 | callbacks++; |
| 1072 | if (quiet) |
| 1073 | return; |
| 1074 | fprintf(SAXdebug, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", |
| 1075 | (char *) name, (char *) publicId, (char *) systemId, |
| 1076 | (char *) notationName); |
| 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | static void |
| 1088 | setDocumentLocatorDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), xmlSAXLocatorPtr loc ATTRIBUTE_UNUSED__attribute__((unused))) |
| 1089 | { |
| 1090 | callbacks++; |
| 1091 | if (quiet) |
| 1092 | return; |
| 1093 | fprintf(SAXdebug, "SAX.setDocumentLocator()\n"); |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | static void |
| 1103 | startDocumentDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused))) |
| 1104 | { |
| 1105 | callbacks++; |
| 1106 | if (quiet) |
| 1107 | return; |
| 1108 | fprintf(SAXdebug, "SAX.startDocument()\n"); |
| 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | static void |
| 1118 | endDocumentDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused))) |
| 1119 | { |
| 1120 | callbacks++; |
| 1121 | if (quiet) |
| 1122 | return; |
| 1123 | fprintf(SAXdebug, "SAX.endDocument()\n"); |
| 1124 | } |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | static void |
| 1134 | startElementDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, const xmlChar **atts) |
| 1135 | { |
| 1136 | int i; |
| 1137 | |
| 1138 | callbacks++; |
| 1139 | if (quiet) |
| 1140 | return; |
| 1141 | fprintf(SAXdebug, "SAX.startElement(%s", (char *) name); |
| 1142 | if (atts != NULL((void*)0)) { |
| 1143 | for (i = 0;(atts[i] != NULL((void*)0));i++) { |
| 1144 | fprintf(SAXdebug, ", %s='", atts[i++]); |
| 1145 | if (atts[i] != NULL((void*)0)) |
| 1146 | fprintf(SAXdebug, "%s'", atts[i]); |
| 1147 | } |
| 1148 | } |
| 1149 | fprintf(SAXdebug, ")\n"); |
| 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | static void |
| 1160 | endElementDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name) |
| 1161 | { |
| 1162 | callbacks++; |
| 1163 | if (quiet) |
| 1164 | return; |
| 1165 | fprintf(SAXdebug, "SAX.endElement(%s)\n", (char *) name); |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | static void |
| 1178 | charactersDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *ch, int len) |
| 1179 | { |
| 1180 | char output[40]; |
| 1181 | int i; |
| 1182 | |
| 1183 | callbacks++; |
| 1184 | if (quiet) |
| 1185 | return; |
| 1186 | for (i = 0;(i<len) && (i < 30);i++) |
| 1187 | output[i] = ch[i]; |
| 1188 | output[i] = 0; |
| 1189 | |
| 1190 | fprintf(SAXdebug, "SAX.characters(%s, %d)\n", output, len); |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | static void |
| 1201 | referenceDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name) |
| 1202 | { |
| 1203 | callbacks++; |
| 1204 | if (quiet) |
| 1205 | return; |
| 1206 | fprintf(SAXdebug, "SAX.reference(%s)\n", name); |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | static void |
| 1220 | ignorableWhitespaceDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *ch, int len) |
| 1221 | { |
| 1222 | char output[40]; |
| 1223 | int i; |
| 1224 | |
| 1225 | callbacks++; |
| 1226 | if (quiet) |
| 1227 | return; |
| 1228 | for (i = 0;(i<len) && (i < 30);i++) |
| 1229 | output[i] = ch[i]; |
| 1230 | output[i] = 0; |
| 1231 | fprintf(SAXdebug, "SAX.ignorableWhitespace(%s, %d)\n", output, len); |
| 1232 | } |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | static void |
| 1244 | processingInstructionDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *target, |
| 1245 | const xmlChar *data) |
| 1246 | { |
| 1247 | callbacks++; |
| 1248 | if (quiet) |
| 1249 | return; |
| 1250 | if (data != NULL((void*)0)) |
| 1251 | fprintf(SAXdebug, "SAX.processingInstruction(%s, %s)\n", |
| 1252 | (char *) target, (char *) data); |
| 1253 | else |
| 1254 | fprintf(SAXdebug, "SAX.processingInstruction(%s, NULL)\n", |
| 1255 | (char *) target); |
| 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | static void |
| 1267 | cdataBlockDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *value, int len) |
| 1268 | { |
| 1269 | callbacks++; |
| 1270 | if (quiet) |
| 1271 | return; |
| 1272 | fprintf(SAXdebug, "SAX.pcdata(%.20s, %d)\n", |
| 1273 | (char *) value, len); |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | static void |
| 1284 | commentDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *value) |
| 1285 | { |
| 1286 | callbacks++; |
| 1287 | if (quiet) |
| 1288 | return; |
| 1289 | fprintf(SAXdebug, "SAX.comment(%s)\n", value); |
| 1290 | } |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | static void XMLCDECL |
| 1302 | warningDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const char *msg, ...) |
| 1303 | { |
| 1304 | va_list args; |
| 1305 | |
| 1306 | callbacks++; |
| 1307 | if (quiet) |
| 1308 | return; |
| 1309 | va_start(args, msg)__builtin_va_start(args, msg); |
| 1310 | fprintf(SAXdebug, "SAX.warning: "); |
| 1311 | vfprintf(SAXdebug, msg, args); |
| 1312 | va_end(args)__builtin_va_end(args); |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | static void XMLCDECL |
| 1325 | errorDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const char *msg, ...) |
| 1326 | { |
| 1327 | va_list args; |
| 1328 | |
| 1329 | callbacks++; |
| 1330 | if (quiet) |
| 1331 | return; |
| 1332 | va_start(args, msg)__builtin_va_start(args, msg); |
| 1333 | fprintf(SAXdebug, "SAX.error: "); |
| 1334 | vfprintf(SAXdebug, msg, args); |
| 1335 | va_end(args)__builtin_va_end(args); |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | static void XMLCDECL |
| 1348 | fatalErrorDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const char *msg, ...) |
| 1349 | { |
| 1350 | va_list args; |
| 1351 | |
| 1352 | callbacks++; |
| 1353 | if (quiet) |
| 1354 | return; |
| 1355 | va_start(args, msg)__builtin_va_start(args, msg); |
| 1356 | fprintf(SAXdebug, "SAX.fatalError: "); |
| 1357 | vfprintf(SAXdebug, msg, args); |
| 1358 | va_end(args)__builtin_va_end(args); |
| 1359 | } |
| 1360 | |
| 1361 | static xmlSAXHandler debugSAXHandlerStruct = { |
| 1362 | internalSubsetDebug, |
| 1363 | isStandaloneDebug, |
| 1364 | hasInternalSubsetDebug, |
| 1365 | hasExternalSubsetDebug, |
| 1366 | resolveEntityDebug, |
| 1367 | getEntityDebug, |
| 1368 | entityDeclDebug, |
| 1369 | notationDeclDebug, |
| 1370 | attributeDeclDebug, |
| 1371 | elementDeclDebug, |
| 1372 | unparsedEntityDeclDebug, |
| 1373 | setDocumentLocatorDebug, |
| 1374 | startDocumentDebug, |
| 1375 | endDocumentDebug, |
| 1376 | startElementDebug, |
| 1377 | endElementDebug, |
| 1378 | referenceDebug, |
| 1379 | charactersDebug, |
| 1380 | ignorableWhitespaceDebug, |
| 1381 | processingInstructionDebug, |
| 1382 | commentDebug, |
| 1383 | warningDebug, |
| 1384 | errorDebug, |
| 1385 | fatalErrorDebug, |
| 1386 | getParameterEntityDebug, |
| 1387 | cdataBlockDebug, |
| 1388 | externalSubsetDebug, |
| 1389 | 1, |
| 1390 | NULL((void*)0), |
| 1391 | NULL((void*)0), |
| 1392 | NULL((void*)0), |
| 1393 | NULL((void*)0) |
| 1394 | }; |
| 1395 | |
| 1396 | static xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | static void |
| 1409 | startElementNsDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1410 | const xmlChar *localname, |
| 1411 | const xmlChar *prefix, |
| 1412 | const xmlChar *URI, |
| 1413 | int nb_namespaces, |
| 1414 | const xmlChar **namespaces, |
| 1415 | int nb_attributes, |
| 1416 | int nb_defaulted, |
| 1417 | const xmlChar **attributes) |
| 1418 | { |
| 1419 | int i; |
| 1420 | |
| 1421 | callbacks++; |
| 1422 | if (quiet) |
| 1423 | return; |
| 1424 | fprintf(SAXdebug, "SAX.startElementNs(%s", (char *) localname); |
| 1425 | if (prefix == NULL((void*)0)) |
| 1426 | fprintf(SAXdebug, ", NULL"); |
| 1427 | else |
| 1428 | fprintf(SAXdebug, ", %s", (char *) prefix); |
| 1429 | if (URI == NULL((void*)0)) |
| 1430 | fprintf(SAXdebug, ", NULL"); |
| 1431 | else |
| 1432 | fprintf(SAXdebug, ", '%s'", (char *) URI); |
| 1433 | fprintf(SAXdebug, ", %d", nb_namespaces); |
| 1434 | |
| 1435 | if (namespaces != NULL((void*)0)) { |
| 1436 | for (i = 0;i < nb_namespaces * 2;i++) { |
| 1437 | fprintf(SAXdebug, ", xmlns"); |
| 1438 | if (namespaces[i] != NULL((void*)0)) |
| 1439 | fprintf(SAXdebug, ":%s", namespaces[i]); |
| 1440 | i++; |
| 1441 | fprintf(SAXdebug, "='%s'", namespaces[i]); |
| 1442 | } |
| 1443 | } |
| 1444 | fprintf(SAXdebug, ", %d, %d", nb_attributes, nb_defaulted); |
| 1445 | if (attributes != NULL((void*)0)) { |
| 1446 | for (i = 0;i < nb_attributes * 5;i += 5) { |
| 1447 | if (attributes[i + 1] != NULL((void*)0)) |
| 1448 | fprintf(SAXdebug, ", %s:%s='", attributes[i + 1], attributes[i]); |
| 1449 | else |
| 1450 | fprintf(SAXdebug, ", %s='", attributes[i]); |
| 1451 | fprintf(SAXdebug, "%.4s...', %d", attributes[i + 3], |
| 1452 | (int)(attributes[i + 4] - attributes[i + 3])); |
| 1453 | } |
| 1454 | } |
| 1455 | fprintf(SAXdebug, ")\n"); |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | static void |
| 1466 | endElementNsDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1467 | const xmlChar *localname, |
| 1468 | const xmlChar *prefix, |
| 1469 | const xmlChar *URI) |
| 1470 | { |
| 1471 | callbacks++; |
| 1472 | if (quiet) |
| 1473 | return; |
| 1474 | fprintf(SAXdebug, "SAX.endElementNs(%s", (char *) localname); |
| 1475 | if (prefix == NULL((void*)0)) |
| 1476 | fprintf(SAXdebug, ", NULL"); |
| 1477 | else |
| 1478 | fprintf(SAXdebug, ", %s", (char *) prefix); |
| 1479 | if (URI == NULL((void*)0)) |
| 1480 | fprintf(SAXdebug, ", NULL)\n"); |
| 1481 | else |
| 1482 | fprintf(SAXdebug, ", '%s')\n", (char *) URI); |
| 1483 | } |
| 1484 | |
| 1485 | static xmlSAXHandler debugSAX2HandlerStruct = { |
| 1486 | internalSubsetDebug, |
| 1487 | isStandaloneDebug, |
| 1488 | hasInternalSubsetDebug, |
| 1489 | hasExternalSubsetDebug, |
| 1490 | resolveEntityDebug, |
| 1491 | getEntityDebug, |
| 1492 | entityDeclDebug, |
| 1493 | notationDeclDebug, |
| 1494 | attributeDeclDebug, |
| 1495 | elementDeclDebug, |
| 1496 | unparsedEntityDeclDebug, |
| 1497 | setDocumentLocatorDebug, |
| 1498 | startDocumentDebug, |
| 1499 | endDocumentDebug, |
| 1500 | NULL((void*)0), |
| 1501 | NULL((void*)0), |
| 1502 | referenceDebug, |
| 1503 | charactersDebug, |
| 1504 | ignorableWhitespaceDebug, |
| 1505 | processingInstructionDebug, |
| 1506 | commentDebug, |
| 1507 | warningDebug, |
| 1508 | errorDebug, |
| 1509 | fatalErrorDebug, |
| 1510 | getParameterEntityDebug, |
| 1511 | cdataBlockDebug, |
| 1512 | externalSubsetDebug, |
| 1513 | XML_SAX2_MAGIC0xDEEDBEAF, |
| 1514 | NULL((void*)0), |
| 1515 | startElementNsDebug, |
| 1516 | endElementNsDebug, |
| 1517 | NULL((void*)0) |
| 1518 | }; |
| 1519 | |
| 1520 | static xmlSAXHandlerPtr debugSAX2Handler = &debugSAX2HandlerStruct; |
| 1521 | |
| 1522 | #ifdef LIBXML_HTML_ENABLED |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | static void |
| 1531 | htmlstartElementDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *name, const xmlChar **atts) |
| 1532 | { |
| 1533 | int i; |
| 1534 | |
| 1535 | fprintf(SAXdebug, "SAX.startElement(%s", (char *) name); |
| 1536 | if (atts != NULL((void*)0)) { |
| 1537 | for (i = 0;(atts[i] != NULL((void*)0));i++) { |
| 1538 | fprintf(SAXdebug, ", %s", atts[i++]); |
| 1539 | if (atts[i] != NULL((void*)0)) { |
| 1540 | unsigned char output[40]; |
| 1541 | const unsigned char *att = atts[i]; |
| 1542 | int outlen, attlen; |
| 1543 | fprintf(SAXdebug, "='"); |
| 1544 | while ((attlen = strlen((char*)att)) > 0) { |
| 1545 | outlen = sizeof output - 1; |
| 1546 | htmlEncodeEntities(output, &outlen, att, &attlen, '\''); |
| 1547 | output[outlen] = 0; |
| 1548 | fprintf(SAXdebug, "%s", (char *) output); |
| 1549 | att += attlen; |
| 1550 | } |
| 1551 | fprintf(SAXdebug, "'"); |
| 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | fprintf(SAXdebug, ")\n"); |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | static void |
| 1568 | htmlcharactersDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *ch, int len) |
| 1569 | { |
| 1570 | unsigned char output[40]; |
| 1571 | int inlen = len, outlen = 30; |
| 1572 | |
| 1573 | htmlEncodeEntities(output, &outlen, ch, &inlen, 0); |
| 1574 | output[outlen] = 0; |
| 1575 | |
| 1576 | fprintf(SAXdebug, "SAX.characters(%s, %d)\n", output, len); |
| 1577 | } |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | static void |
| 1589 | htmlcdataDebug(void *ctx ATTRIBUTE_UNUSED__attribute__((unused)), const xmlChar *ch, int len) |
| 1590 | { |
| 1591 | unsigned char output[40]; |
| 1592 | int inlen = len, outlen = 30; |
| 1593 | |
| 1594 | htmlEncodeEntities(output, &outlen, ch, &inlen, 0); |
| 1595 | output[outlen] = 0; |
| 1596 | |
| 1597 | fprintf(SAXdebug, "SAX.cdata(%s, %d)\n", output, len); |
| 1598 | } |
| 1599 | |
| 1600 | static xmlSAXHandler debugHTMLSAXHandlerStruct = { |
| 1601 | internalSubsetDebug, |
| 1602 | isStandaloneDebug, |
| 1603 | hasInternalSubsetDebug, |
| 1604 | hasExternalSubsetDebug, |
| 1605 | resolveEntityDebug, |
| 1606 | getEntityDebug, |
| 1607 | entityDeclDebug, |
| 1608 | notationDeclDebug, |
| 1609 | attributeDeclDebug, |
| 1610 | elementDeclDebug, |
| 1611 | unparsedEntityDeclDebug, |
| 1612 | setDocumentLocatorDebug, |
| 1613 | startDocumentDebug, |
| 1614 | endDocumentDebug, |
| 1615 | htmlstartElementDebug, |
| 1616 | endElementDebug, |
| 1617 | referenceDebug, |
| 1618 | htmlcharactersDebug, |
| 1619 | ignorableWhitespaceDebug, |
| 1620 | processingInstructionDebug, |
| 1621 | commentDebug, |
| 1622 | warningDebug, |
| 1623 | errorDebug, |
| 1624 | fatalErrorDebug, |
| 1625 | getParameterEntityDebug, |
| 1626 | htmlcdataDebug, |
| 1627 | externalSubsetDebug, |
| 1628 | 1, |
| 1629 | NULL((void*)0), |
| 1630 | NULL((void*)0), |
| 1631 | NULL((void*)0), |
| 1632 | NULL((void*)0) |
| 1633 | }; |
| 1634 | |
| 1635 | static xmlSAXHandlerPtr debugHTMLSAXHandler = &debugHTMLSAXHandlerStruct; |
| 1636 | #endif /* LIBXML_HTML_ENABLED */ |
| 1637 | |
| 1638 | #ifdef LIBXML_SAX1_ENABLED |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | static int |
| 1650 | saxParseTest(const char *filename, const char *result, |
| 1651 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1652 | int options) { |
| 1653 | int ret; |
| 1654 | char *temp; |
| 1655 | |
| 1656 | nb_tests++; |
| 1657 | temp = resultFilename(filename, "", ".res"); |
| 1658 | if (temp == NULL((void*)0)) { |
| 1659 | fprintf(stderrstderr, "out of memory\n"); |
| 1660 | fatalError(); |
| 1661 | } |
| 1662 | SAXdebug = fopen(temp, "wb"); |
| 1663 | if (SAXdebug == NULL((void*)0)) { |
| 1664 | fprintf(stderrstderr, "Failed to write to %s\n", temp); |
| 1665 | free(temp); |
| 1666 | return(-1); |
| 1667 | } |
| 1668 | |
| 1669 | |
| 1670 | xmlSetStructuredErrorFunc(NULL((void*)0), NULL((void*)0)); |
| 1671 | xmlSetGenericErrorFunc(NULL((void*)0), testErrorHandler); |
| 1672 | |
| 1673 | #ifdef LIBXML_HTML_ENABLED |
| 1674 | if (options & XML_PARSE_HTML1 << 24) { |
| 1675 | htmlSAXParseFile(filename, NULL((void*)0), emptySAXHandler, NULL((void*)0)); |
| 1676 | ret = 0; |
| 1677 | } else |
| 1678 | #endif |
| 1679 | ret = xmlSAXUserParseFile(emptySAXHandler, NULL((void*)0), filename); |
| 1680 | if (ret == XML_WAR_UNDECLARED_ENTITY) { |
| 1681 | fprintf(SAXdebug, "xmlSAXUserParseFile returned error %d\n", ret); |
| 1682 | ret = 0; |
| 1683 | } |
| 1684 | if (ret != 0) { |
| 1685 | fprintf(stderrstderr, "Failed to parse %s\n", filename); |
| 1686 | return(1); |
| 1687 | } |
| 1688 | #ifdef LIBXML_HTML_ENABLED |
| 1689 | if (options & XML_PARSE_HTML1 << 24) { |
| 1690 | htmlSAXParseFile(filename, NULL((void*)0), debugHTMLSAXHandler, NULL((void*)0)); |
| 1691 | ret = 0; |
| 1692 | } else |
| 1693 | #endif |
| 1694 | if (options & XML_PARSE_SAX1) { |
| 1695 | ret = xmlSAXUserParseFile(debugSAXHandler, NULL((void*)0), filename); |
| 1696 | } else { |
| 1697 | ret = xmlSAXUserParseFile(debugSAX2Handler, NULL((void*)0), filename); |
| 1698 | } |
| 1699 | if (ret == XML_WAR_UNDECLARED_ENTITY) { |
| 1700 | fprintf(SAXdebug, "xmlSAXUserParseFile returned error %d\n", ret); |
| 1701 | ret = 0; |
| 1702 | } |
| 1703 | fclose(SAXdebug); |
| 1704 | if (compareFiles(temp, result)) { |
| 1705 | fprintf(stderrstderr, "Got a difference for %s\n", filename); |
| 1706 | ret = 1; |
| 1707 | } else |
| 1708 | unlink(temp); |
| 1709 | free(temp); |
| 1710 | |
| 1711 | |
| 1712 | xmlSetGenericErrorFunc(NULL((void*)0), NULL((void*)0)); |
| 1713 | xmlSetStructuredErrorFunc(NULL((void*)0), testStructuredErrorHandler); |
| 1714 | |
| 1715 | return(ret); |
| 1716 | } |
| 1717 | #endif |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | static int |
| 1737 | oldParseTest(const char *filename, const char *result, |
| 1738 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1739 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 1740 | xmlDocPtr doc; |
| 1741 | char *temp; |
| 1742 | int res = 0; |
| 1743 | |
| 1744 | nb_tests++; |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | #ifdef LIBXML_SAX1_ENABLED |
| 1749 | doc = xmlParseFile(filename); |
| 1750 | #else |
| 1751 | doc = xmlReadFile(filename, NULL((void*)0), 0); |
| 1752 | #endif |
| 1753 | if (doc == NULL((void*)0)) |
| 1754 | return(1); |
| 1755 | temp = resultFilename(filename, "", ".res"); |
| 1756 | if (temp == NULL((void*)0)) { |
| 1757 | fprintf(stderrstderr, "out of memory\n"); |
| 1758 | fatalError(); |
| 1759 | } |
| 1760 | xmlSaveFile(temp, doc); |
| 1761 | if (compareFiles(temp, result)) { |
| 1762 | res = 1; |
| 1763 | } |
| 1764 | xmlFreeDoc(doc); |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | #ifdef LIBXML_SAX1_ENABLED |
| 1770 | doc = xmlParseFile(temp); |
| 1771 | #else |
| 1772 | doc = xmlReadFile(temp, NULL((void*)0), 0); |
| 1773 | #endif |
| 1774 | if (doc == NULL((void*)0)) |
| 1775 | return(1); |
| 1776 | xmlSaveFile(temp, doc); |
| 1777 | if (compareFiles(temp, result)) { |
| 1778 | res = 1; |
| 1779 | } |
| 1780 | xmlFreeDoc(doc); |
| 1781 | |
| 1782 | unlink(temp); |
| 1783 | free(temp); |
| 1784 | return(res); |
| 1785 | } |
| 1786 | |
| 1787 | #ifdef LIBXML_PUSH_ENABLED |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | static int |
| 1800 | pushParseTest(const char *filename, const char *result, |
| 1801 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1802 | int options) { |
| 1803 | xmlParserCtxtPtr ctxt; |
| 1804 | xmlDocPtr doc; |
| 1805 | const char *base; |
| 1806 | int size, res; |
| 1807 | int cur = 0; |
| 1808 | |
| 1809 | nb_tests++; |
| 1810 | |
| 1811 | |
| 1812 | |
| 1813 | if (loadMem(filename, &base, &size) != 0) { |
| 1814 | fprintf(stderrstderr, "Failed to load %s\n", filename); |
| 1815 | return(-1); |
| 1816 | } |
| 1817 | |
| 1818 | #ifdef LIBXML_HTML_ENABLED |
| 1819 | if (options & XML_PARSE_HTML1 << 24) |
| 1820 | ctxt = htmlCreatePushParserCtxt(NULL((void*)0), NULL((void*)0), base + cur, 4, filename, |
| 1821 | XML_CHAR_ENCODING_NONE); |
| 1822 | else |
| 1823 | #endif |
| 1824 | ctxt = xmlCreatePushParserCtxt(NULL((void*)0), NULL((void*)0), base + cur, 4, filename); |
| 1825 | xmlCtxtUseOptions(ctxt, options); |
| 1826 | cur += 4; |
| 1827 | while (cur < size) { |
| 1828 | if (cur + 1024 >= size) { |
| 1829 | #ifdef LIBXML_HTML_ENABLED |
| 1830 | if (options & XML_PARSE_HTML1 << 24) |
| 1831 | htmlParseChunk(ctxt, base + cur, size - cur, 1); |
| 1832 | else |
| 1833 | #endif |
| 1834 | xmlParseChunk(ctxt, base + cur, size - cur, 1); |
| 1835 | break; |
| 1836 | } else { |
| 1837 | #ifdef LIBXML_HTML_ENABLED |
| 1838 | if (options & XML_PARSE_HTML1 << 24) |
| 1839 | htmlParseChunk(ctxt, base + cur, 1024, 0); |
| 1840 | else |
| 1841 | #endif |
| 1842 | xmlParseChunk(ctxt, base + cur, 1024, 0); |
| 1843 | cur += 1024; |
| 1844 | } |
| 1845 | } |
| 1846 | doc = ctxt->myDoc; |
| 1847 | #ifdef LIBXML_HTML_ENABLED |
| 1848 | if (options & XML_PARSE_HTML1 << 24) |
| 1849 | res = 1; |
| 1850 | else |
| 1851 | #endif |
| 1852 | res = ctxt->wellFormed; |
| 1853 | xmlFreeParserCtxt(ctxt); |
| 1854 | free((char *)base); |
| 1855 | if (!res) { |
| 1856 | xmlFreeDoc(doc); |
| 1857 | fprintf(stderrstderr, "Failed to parse %s\n", filename); |
| 1858 | return(-1); |
| 1859 | } |
| 1860 | #ifdef LIBXML_HTML_ENABLED |
| 1861 | if (options & XML_PARSE_HTML1 << 24) |
| 1862 | htmlDocDumpMemory(doc, (xmlChar **) &base, &size); |
| 1863 | else |
| 1864 | #endif |
| 1865 | xmlDocDumpMemory(doc, (xmlChar **) &base, &size); |
| 1866 | xmlFreeDoc(doc); |
| 1867 | res = compareFileMem(result, base, size); |
| 1868 | if ((base == NULL((void*)0)) || (res != 0)) { |
| 1869 | if (base != NULL((void*)0)) |
| 1870 | xmlFree((char *)base); |
| 1871 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 1872 | return(-1); |
| 1873 | } |
| 1874 | xmlFree((char *)base); |
| 1875 | if (err != NULL((void*)0)) { |
| 1876 | res = compareFileMem(err, testErrors, testErrorsSize); |
| 1877 | if (res != 0) { |
| 1878 | fprintf(stderrstderr, "Error for %s failed\n", filename); |
| 1879 | return(-1); |
| 1880 | } |
| 1881 | } |
| 1882 | return(0); |
| 1883 | } |
| 1884 | #endif |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | |
| 1889 | |
| 1890 | |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | |
| 1898 | static int |
| 1899 | memParseTest(const char *filename, const char *result, |
| 1900 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1901 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 1902 | xmlDocPtr doc; |
| 1903 | const char *base; |
| 1904 | int size, res; |
| 1905 | |
| 1906 | nb_tests++; |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | if (loadMem(filename, &base, &size) != 0) { |
| 1911 | fprintf(stderrstderr, "Failed to load %s\n", filename); |
| 1912 | return(-1); |
| 1913 | } |
| 1914 | |
| 1915 | doc = xmlReadMemory(base, size, filename, NULL((void*)0), 0); |
| 1916 | unloadMem(base); |
| 1917 | if (doc == NULL((void*)0)) { |
| 1918 | return(1); |
| 1919 | } |
| 1920 | xmlDocDumpMemory(doc, (xmlChar **) &base, &size); |
| 1921 | xmlFreeDoc(doc); |
| 1922 | res = compareFileMem(result, base, size); |
| 1923 | if ((base == NULL((void*)0)) || (res != 0)) { |
| 1924 | if (base != NULL((void*)0)) |
| 1925 | xmlFree((char *)base); |
| 1926 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 1927 | return(-1); |
| 1928 | } |
| 1929 | xmlFree((char *)base); |
| 1930 | return(0); |
| 1931 | } |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | |
| 1944 | |
| 1945 | static int |
| 1946 | noentParseTest(const char *filename, const char *result, |
| 1947 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 1948 | int options) { |
| 1949 | xmlDocPtr doc; |
| 1950 | char *temp; |
| 1951 | int res = 0; |
| 1952 | |
| 1953 | nb_tests++; |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 1958 | if (doc == NULL((void*)0)) |
| 1959 | return(1); |
| 1960 | temp = resultFilename(filename, "", ".res"); |
| 1961 | if (temp == NULL((void*)0)) { |
| 1962 | fprintf(stderrstderr, "Out of memory\n"); |
| 1963 | fatalError(); |
| 1964 | } |
| 1965 | xmlSaveFile(temp, doc); |
| 1966 | if (compareFiles(temp, result)) { |
| 1967 | res = 1; |
| 1968 | } |
| 1969 | xmlFreeDoc(doc); |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 1975 | if (doc == NULL((void*)0)) |
| 1976 | return(1); |
| 1977 | xmlSaveFile(temp, doc); |
| 1978 | if (compareFiles(temp, result)) { |
| 1979 | res = 1; |
| 1980 | } |
| 1981 | xmlFreeDoc(doc); |
| 1982 | |
| 1983 | unlink(temp); |
| 1984 | free(temp); |
| 1985 | return(res); |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | static int |
| 1999 | errParseTest(const char *filename, const char *result, const char *err, |
| 2000 | int options) { |
| 2001 | xmlDocPtr doc; |
| 2002 | const char *base = NULL((void*)0); |
| 2003 | int size, res = 0; |
| 2004 | |
| 2005 | nb_tests++; |
| 2006 | #ifdef LIBXML_HTML_ENABLED |
| 2007 | if (options & XML_PARSE_HTML1 << 24) { |
| 2008 | doc = htmlReadFile(filename, NULL((void*)0), options); |
| 2009 | } else |
| 2010 | #endif |
| 2011 | #ifdef LIBXML_XINCLUDE_ENABLED |
| 2012 | if (options & XML_PARSE_XINCLUDE) { |
| 2013 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 2014 | xmlXIncludeProcessFlags(doc, options); |
| 2015 | } else |
| 2016 | #endif |
| 2017 | { |
| 2018 | xmlGetWarningsDefaultValue(*(__xmlGetWarningsDefaultValue())) = 1; |
| 2019 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 2020 | } |
| 2021 | xmlGetWarningsDefaultValue(*(__xmlGetWarningsDefaultValue())) = 0; |
| 2022 | if (result) { |
| 2023 | if (doc == NULL((void*)0)) { |
| 2024 | base = ""; |
| 2025 | size = 0; |
| 2026 | } else { |
| 2027 | #ifdef LIBXML_HTML_ENABLED |
| 2028 | if (options & XML_PARSE_HTML1 << 24) { |
| 2029 | htmlDocDumpMemory(doc, (xmlChar **) &base, &size); |
| 2030 | } else |
| 2031 | #endif |
| 2032 | xmlDocDumpMemory(doc, (xmlChar **) &base, &size); |
| 2033 | } |
| 2034 | res = compareFileMem(result, base, size); |
| 2035 | } |
| 2036 | if (doc != NULL((void*)0)) { |
| 2037 | if (base != NULL((void*)0)) |
| 2038 | xmlFree((char *)base); |
| 2039 | xmlFreeDoc(doc); |
| 2040 | } |
| 2041 | if (res != 0) { |
| 2042 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 2043 | return(-1); |
| 2044 | } |
| 2045 | if (err != NULL((void*)0)) { |
| 2046 | res = compareFileMem(err, testErrors, testErrorsSize); |
| 2047 | if (res != 0) { |
| 2048 | fprintf(stderrstderr, "Error for %s failed\n", filename); |
| 2049 | return(-1); |
| 2050 | } |
| 2051 | } else if (options & XML_PARSE_DTDVALID) { |
| 2052 | if (testErrorsSize != 0) |
| 2053 | fprintf(stderrstderr, "Validation for %s failed\n", filename); |
| 2054 | } |
| 2055 | |
| 2056 | return(0); |
| 2057 | } |
| 2058 | |
| 2059 | #ifdef LIBXML_READER_ENABLED |
| 2060 | |
| 2061 | |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | static void processNode(FILE *out, xmlTextReaderPtr reader) { |
| 2067 | const xmlChar *name, *value; |
| 2068 | int type, empty; |
| 2069 | |
| 2070 | type = xmlTextReaderNodeType(reader); |
| 2071 | empty = xmlTextReaderIsEmptyElement(reader); |
| 2072 | |
| 2073 | name = xmlTextReaderConstName(reader); |
| 2074 | if (name == NULL((void*)0)) |
| 2075 | name = BAD_CAST(xmlChar *) "--"; |
| 2076 | |
| 2077 | value = xmlTextReaderConstValue(reader); |
| 2078 | |
| 2079 | |
| 2080 | fprintf(out, "%d %d %s %d %d", |
| 2081 | xmlTextReaderDepth(reader), |
| 2082 | type, |
| 2083 | name, |
| 2084 | empty, |
| 2085 | xmlTextReaderHasValue(reader)); |
| 2086 | if (value == NULL((void*)0)) |
| 2087 | fprintf(out, "\n"); |
| 2088 | else { |
| 2089 | fprintf(out, " %s\n", value); |
| 2090 | } |
| 2091 | } |
| 2092 | static int |
| 2093 | streamProcessTest(const char *filename, const char *result, const char *err, |
| 2094 | xmlTextReaderPtr reader, const char *rng) { |
| 2095 | int ret; |
| 2096 | char *temp = NULL((void*)0); |
| 2097 | FILE *t = NULL((void*)0); |
| 2098 | |
| 2099 | if (reader == NULL((void*)0)) |
| 2100 | return(-1); |
| 2101 | |
| 2102 | nb_tests++; |
| 2103 | if (result != NULL((void*)0)) { |
| 2104 | temp = resultFilename(filename, "", ".res"); |
| 2105 | if (temp == NULL((void*)0)) { |
| 2106 | fprintf(stderrstderr, "Out of memory\n"); |
| 2107 | fatalError(); |
| 2108 | } |
| 2109 | t = fopen(temp, "wb"); |
| 2110 | if (t == NULL((void*)0)) { |
| 2111 | fprintf(stderrstderr, "Can't open temp file %s\n", temp); |
| 2112 | free(temp); |
| 2113 | return(-1); |
| 2114 | } |
| 2115 | } |
| 2116 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 2117 | if (rng != NULL((void*)0)) { |
| 2118 | ret = xmlTextReaderRelaxNGValidate(reader, rng); |
| 2119 | if (ret < 0) { |
| 2120 | testErrorHandler(NULL((void*)0), "Relax-NG schema %s failed to compile\n", |
| 2121 | rng); |
| 2122 | fclose(t); |
| 2123 | unlink(temp); |
| 2124 | free(temp); |
| 2125 | return(0); |
| 2126 | } |
| 2127 | } |
| 2128 | #endif |
| 2129 | xmlGetWarningsDefaultValue(*(__xmlGetWarningsDefaultValue())) = 1; |
| 2130 | ret = xmlTextReaderRead(reader); |
| 2131 | while (ret == 1) { |
| 2132 | if ((t != NULL((void*)0)) && (rng == NULL((void*)0))) |
| 2133 | processNode(t, reader); |
| 2134 | ret = xmlTextReaderRead(reader); |
| 2135 | } |
| 2136 | if (ret != 0) { |
| 2137 | testErrorHandler(NULL((void*)0), "%s : failed to parse\n", filename); |
| 2138 | } |
| 2139 | if (rng != NULL((void*)0)) { |
| 2140 | if (xmlTextReaderIsValid(reader) != 1) { |
| 2141 | testErrorHandler(NULL((void*)0), "%s fails to validate\n", filename); |
| 2142 | } else { |
| 2143 | testErrorHandler(NULL((void*)0), "%s validates\n", filename); |
| 2144 | } |
| 2145 | } |
| 2146 | xmlGetWarningsDefaultValue(*(__xmlGetWarningsDefaultValue())) = 0; |
| 2147 | if (t != NULL((void*)0)) { |
| 2148 | fclose(t); |
| 2149 | ret = compareFiles(temp, result); |
| 2150 | unlink(temp); |
| 2151 | free(temp); |
| 2152 | if (ret) { |
| 2153 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 2154 | return(-1); |
| 2155 | } |
| 2156 | } |
| 2157 | if (err != NULL((void*)0)) { |
| 2158 | ret = compareFileMem(err, testErrors, testErrorsSize); |
| 2159 | if (ret != 0) { |
| 2160 | fprintf(stderrstderr, "Error for %s failed\n", filename); |
| 2161 | printf("%s", testErrors); |
| 2162 | return(-1); |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | return(0); |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | |
| 2179 | static int |
| 2180 | streamParseTest(const char *filename, const char *result, const char *err, |
| 2181 | int options) { |
| 2182 | xmlTextReaderPtr reader; |
| 2183 | int ret; |
| 2184 | |
| 2185 | reader = xmlReaderForFile(filename, NULL((void*)0), options); |
| 2186 | ret = streamProcessTest(filename, result, err, reader, NULL((void*)0)); |
| 2187 | xmlFreeTextReader(reader); |
| 2188 | return(ret); |
| 2189 | } |
| 2190 | |
| 2191 | |
| 2192 | |
| 2193 | |
| 2194 | |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | static int |
| 2202 | walkerParseTest(const char *filename, const char *result, const char *err, |
| 2203 | int options) { |
| 2204 | xmlDocPtr doc; |
| 2205 | xmlTextReaderPtr reader; |
| 2206 | int ret; |
| 2207 | |
| 2208 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 2209 | if (doc == NULL((void*)0)) { |
| 2210 | fprintf(stderrstderr, "Failed to parse %s\n", filename); |
| 2211 | return(-1); |
| 2212 | } |
| 2213 | reader = xmlReaderWalker(doc); |
| 2214 | ret = streamProcessTest(filename, result, err, reader, NULL((void*)0)); |
| 2215 | xmlFreeTextReader(reader); |
| 2216 | xmlFreeDoc(doc); |
| 2217 | return(ret); |
| 2218 | } |
| 2219 | |
| 2220 | |
| 2221 | |
| 2222 | |
| 2223 | |
| 2224 | |
| 2225 | |
| 2226 | |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | static int |
| 2231 | streamMemParseTest(const char *filename, const char *result, const char *err, |
| 2232 | int options) { |
| 2233 | xmlTextReaderPtr reader; |
| 2234 | int ret; |
| 2235 | const char *base; |
| 2236 | int size; |
| 2237 | |
| 2238 | |
| 2239 | |
| 2240 | |
| 2241 | if (loadMem(filename, &base, &size) != 0) { |
| 2242 | fprintf(stderrstderr, "Failed to load %s\n", filename); |
| 2243 | return(-1); |
| 2244 | } |
| 2245 | reader = xmlReaderForMemory(base, size, filename, NULL((void*)0), options); |
| 2246 | ret = streamProcessTest(filename, result, err, reader, NULL((void*)0)); |
| 2247 | free((char *)base); |
| 2248 | xmlFreeTextReader(reader); |
| 2249 | return(ret); |
| 2250 | } |
| 2251 | #endif |
| 2252 | |
| 2253 | #ifdef LIBXML_XPATH_ENABLED |
| 2254 | #ifdef LIBXML_DEBUG_ENABLED |
| 2255 | |
| 2256 | |
| 2257 | |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | static FILE *xpathOutput; |
| 2262 | static xmlDocPtr xpathDocument; |
| 2263 | |
| 2264 | static void |
| 2265 | testXPath(const char *str, int xptr, int expr) { |
| 2266 | xmlXPathObjectPtr res; |
| 2267 | xmlXPathContextPtr ctxt; |
| 2268 | |
| 2269 | nb_tests++; |
| 2270 | #if defined(LIBXML_XPTR_ENABLED) |
| 2271 | if (xptr) { |
| 2272 | ctxt = xmlXPtrNewContext(xpathDocument, NULL((void*)0), NULL((void*)0)); |
| 2273 | res = xmlXPtrEval(BAD_CAST(xmlChar *) str, ctxt); |
| 2274 | } else { |
| 2275 | #endif |
| 2276 | ctxt = xmlXPathNewContext(xpathDocument); |
| 2277 | ctxt->node = xmlDocGetRootElement(xpathDocument); |
| 2278 | if (expr) |
| 2279 | res = xmlXPathEvalExpression(BAD_CAST(xmlChar *) str, ctxt); |
| 2280 | else { |
| 2281 | |
| 2282 | xmlXPathCompExprPtr comp; |
| 2283 | |
| 2284 | comp = xmlXPathCompile(BAD_CAST(xmlChar *) str); |
| 2285 | if (comp != NULL((void*)0)) { |
| 2286 | res = xmlXPathCompiledEval(comp, ctxt); |
| 2287 | xmlXPathFreeCompExpr(comp); |
| 2288 | } else |
| 2289 | res = NULL((void*)0); |
| 2290 | } |
| 2291 | #if defined(LIBXML_XPTR_ENABLED) |
| 2292 | } |
| 2293 | #endif |
| 2294 | xmlXPathDebugDumpObject(xpathOutput, res, 0); |
| 2295 | xmlXPathFreeObject(res); |
| 2296 | xmlXPathFreeContext(ctxt); |
| 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | static int |
| 2310 | xpathCommonTest(const char *filename, const char *result, |
| 2311 | int xptr, int expr) { |
| 2312 | FILE *input; |
| 2313 | char expression[5000]; |
| 2314 | int len, ret = 0; |
| 2315 | char *temp; |
| 2316 | |
| 2317 | temp = resultFilename(filename, "", ".res"); |
| 2318 | if (temp == NULL((void*)0)) { |
| 2319 | fprintf(stderrstderr, "Out of memory\n"); |
| 2320 | fatalError(); |
| 2321 | } |
| 2322 | xpathOutput = fopen(temp, "wb"); |
| 2323 | if (xpathOutput == NULL((void*)0)) { |
| 2324 | fprintf(stderrstderr, "failed to open output file %s\n", temp); |
| 2325 | free(temp); |
| 2326 | return(-1); |
| 2327 | } |
| 2328 | |
| 2329 | input = fopen(filename, "rb"); |
| 2330 | if (input == NULL((void*)0)) { |
| 2331 | xmlGenericError(*(__xmlGenericError()))(xmlGenericErrorContext(*(__xmlGenericErrorContext())), |
| 2332 | "Cannot open %s for reading\n", filename); |
| 2333 | free(temp); |
| 2334 | return(-1); |
| 2335 | } |
| 2336 | while (fgets(expression, 4500, input) != NULL((void*)0)) { |
| 2337 | len = strlen(expression); |
| 2338 | len--; |
| 2339 | while ((len >= 0) && |
| 2340 | ((expression[len] == '\n') || (expression[len] == '\t') || |
| 2341 | (expression[len] == '\r') || (expression[len] == ' '))) len--; |
| 2342 | expression[len + 1] = 0; |
| 2343 | if (len >= 0) { |
| 2344 | fprintf(xpathOutput, |
| 2345 | "\n========================\nExpression: %s\n", |
| 2346 | expression) ; |
| 2347 | testXPath(expression, xptr, expr); |
| 2348 | } |
| 2349 | } |
| 2350 | |
| 2351 | fclose(input); |
| 2352 | fclose(xpathOutput); |
| 2353 | if (result != NULL((void*)0)) { |
| 2354 | ret = compareFiles(temp, result); |
| 2355 | if (ret) { |
| 2356 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | unlink(temp); |
| 2361 | free(temp); |
| 2362 | return(ret); |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | |
| 2367 | |
| 2368 | |
| 2369 | |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | |
| 2375 | static int |
| 2376 | xpathExprTest(const char *filename, const char *result, |
| 2377 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2378 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 2379 | return(xpathCommonTest(filename, result, 0, 1)); |
| 2380 | } |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 | |
| 2385 | |
| 2386 | |
| 2387 | |
| 2388 | |
| 2389 | |
| 2390 | |
| 2391 | |
| 2392 | |
| 2393 | static int |
| 2394 | xpathDocTest(const char *filename, |
| 2395 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2396 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2397 | int options) { |
| 2398 | |
| 2399 | char pattern[500]; |
| 2400 | char result[500]; |
| 2401 | glob_t globbuf; |
| 2402 | size_t i; |
| 2403 | int ret = 0, res; |
| 2404 | |
| 2405 | xpathDocument = xmlReadFile(filename, NULL((void*)0), |
| 2406 | options | XML_PARSE_DTDATTR | XML_PARSE_NOENT); |
| 2407 | if (xpathDocument == NULL((void*)0)) { |
| 2408 | fprintf(stderrstderr, "Failed to load %s\n", filename); |
| 2409 | return(-1); |
| 2410 | } |
| 2411 | |
| 2412 | snprintf(pattern, 499, "./test/XPath/tests/%s*", baseFilename(filename)); |
| 2413 | pattern[499] = 0; |
| 2414 | globbuf.gl_offs = 0; |
| 2415 | glob(pattern, GLOB_DOOFFS(1 << 3), NULL((void*)0), &globbuf); |
| 2416 | for (i = 0;i < globbuf.gl_pathc;i++) { |
| 2417 | snprintf(result, 499, "result/XPath/tests/%s", |
| 2418 | baseFilename(globbuf.gl_pathv[i])); |
| 2419 | res = xpathCommonTest(globbuf.gl_pathv[i], &result[0], 0, 0); |
| 2420 | if (res != 0) |
| 2421 | ret = res; |
| 2422 | } |
| 2423 | globfree(&globbuf); |
| 2424 | |
| 2425 | xmlFreeDoc(xpathDocument); |
| 2426 | return(ret); |
| 2427 | } |
| 2428 | |
| 2429 | #ifdef LIBXML_XPTR_ENABLED |
| 2430 | |
| 2431 | |
| 2432 | |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | static int |
| 2442 | xptrDocTest(const char *filename, |
| 2443 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2444 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2445 | int options) { |
| 2446 | |
| 2447 | char pattern[500]; |
| 2448 | char result[500]; |
| 2449 | glob_t globbuf; |
| 2450 | size_t i; |
| 2451 | int ret = 0, res; |
| 2452 | |
| 2453 | xpathDocument = xmlReadFile(filename, NULL((void*)0), |
| 2454 | options | XML_PARSE_DTDATTR | XML_PARSE_NOENT); |
| 2455 | if (xpathDocument == NULL((void*)0)) { |
| 2456 | fprintf(stderrstderr, "Failed to load %s\n", filename); |
| 2457 | return(-1); |
| 2458 | } |
| 2459 | |
| 2460 | snprintf(pattern, 499, "./test/XPath/xptr/%s*", baseFilename(filename)); |
| 2461 | pattern[499] = 0; |
| 2462 | globbuf.gl_offs = 0; |
| 2463 | glob(pattern, GLOB_DOOFFS(1 << 3), NULL((void*)0), &globbuf); |
| 2464 | for (i = 0;i < globbuf.gl_pathc;i++) { |
| 2465 | snprintf(result, 499, "result/XPath/xptr/%s", |
| 2466 | baseFilename(globbuf.gl_pathv[i])); |
| 2467 | res = xpathCommonTest(globbuf.gl_pathv[i], &result[0], 1, 0); |
| 2468 | if (res != 0) |
| 2469 | ret = res; |
| 2470 | } |
| 2471 | globfree(&globbuf); |
| 2472 | |
| 2473 | xmlFreeDoc(xpathDocument); |
| 2474 | return(ret); |
| 2475 | } |
| 2476 | #endif /* LIBXML_XPTR_ENABLED */ |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | |
| 2488 | |
| 2489 | static int |
| 2490 | xmlidDocTest(const char *filename, |
| 2491 | const char *result, |
| 2492 | const char *err, |
| 2493 | int options) { |
| 2494 | |
| 2495 | int res = 0; |
| 2496 | int ret = 0; |
| 2497 | char *temp; |
| 2498 | |
| 2499 | xpathDocument = xmlReadFile(filename, NULL((void*)0), |
| 2500 | options | XML_PARSE_DTDATTR | XML_PARSE_NOENT); |
| 2501 | if (xpathDocument == NULL((void*)0)) { |
| 2502 | fprintf(stderrstderr, "Failed to load %s\n", filename); |
| 2503 | return(-1); |
| 2504 | } |
| 2505 | |
| 2506 | temp = resultFilename(filename, "", ".res"); |
| 2507 | if (temp == NULL((void*)0)) { |
| 2508 | fprintf(stderrstderr, "Out of memory\n"); |
| 2509 | fatalError(); |
| 2510 | } |
| 2511 | xpathOutput = fopen(temp, "wb"); |
| 2512 | if (xpathOutput == NULL((void*)0)) { |
| 2513 | fprintf(stderrstderr, "failed to open output file %s\n", temp); |
| 2514 | xmlFreeDoc(xpathDocument); |
| 2515 | free(temp); |
| 2516 | return(-1); |
| 2517 | } |
| 2518 | |
| 2519 | testXPath("id('bar')", 0, 0); |
| 2520 | |
| 2521 | fclose(xpathOutput); |
| 2522 | if (result != NULL((void*)0)) { |
| 2523 | ret = compareFiles(temp, result); |
| 2524 | if (ret) { |
| 2525 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 2526 | res = 1; |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | unlink(temp); |
| 2531 | free(temp); |
| 2532 | xmlFreeDoc(xpathDocument); |
| 2533 | |
| 2534 | if (err != NULL((void*)0)) { |
| 2535 | ret = compareFileMem(err, testErrors, testErrorsSize); |
| 2536 | if (ret != 0) { |
| 2537 | fprintf(stderrstderr, "Error for %s failed\n", filename); |
| 2538 | res = 1; |
| 2539 | } |
| 2540 | } |
| 2541 | return(res); |
| 2542 | } |
| 2543 | |
| 2544 | #endif /* LIBXML_DEBUG_ENABLED */ |
| 2545 | #endif /* XPATH */ |
| 2546 | |
| 2547 | |
| 2548 | |
| 2549 | |
| 2550 | |
| 2551 | |
| 2552 | static void |
| 2553 | handleURI(const char *str, const char *base, FILE *o) { |
| 2554 | int ret; |
| 2555 | xmlURIPtr uri; |
| 2556 | xmlChar *res = NULL((void*)0); |
| 2557 | |
| 2558 | uri = xmlCreateURI(); |
| 2559 | |
| 2560 | if (base == NULL((void*)0)) { |
| 2561 | ret = xmlParseURIReference(uri, str); |
| 2562 | if (ret != 0) |
| 2563 | fprintf(o, "%s : error %d\n", str, ret); |
| 2564 | else { |
| 2565 | xmlNormalizeURIPath(uri->path); |
| 2566 | xmlPrintURI(o, uri); |
| 2567 | fprintf(o, "\n"); |
| 2568 | } |
| 2569 | } else { |
| 2570 | res = xmlBuildURI((xmlChar *)str, (xmlChar *) base); |
| 2571 | if (res != NULL((void*)0)) { |
| 2572 | fprintf(o, "%s\n", (char *) res); |
| 2573 | } |
| 2574 | else |
| 2575 | fprintf(o, "::ERROR::\n"); |
| 2576 | } |
| 2577 | if (res != NULL((void*)0)) |
| 2578 | xmlFree(res); |
| 2579 | xmlFreeURI(uri); |
| 2580 | } |
| 2581 | |
| 2582 | |
| 2583 | |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | |
| 2588 | |
| 2589 | |
| 2590 | |
| 2591 | |
| 2592 | static int |
| 2593 | uriCommonTest(const char *filename, |
| 2594 | const char *result, |
| 2595 | const char *err, |
| 2596 | const char *base) { |
| 2597 | char *temp; |
| 2598 | FILE *o, *f; |
| 2599 | char str[1024]; |
| 2600 | int res = 0, i, ret; |
| 2601 | |
| 2602 | temp = resultFilename(filename, "", ".res"); |
| 2603 | if (temp == NULL((void*)0)) { |
| 1 | Assuming pointer value is null |
|
| |
| 2604 | fprintf(stderrstderr, "Out of memory\n"); |
| 2605 | fatalError(); |
| 2606 | } |
| 2607 | o = fopen(temp, "wb"); |
| 2608 | if (o == NULL((void*)0)) { |
| |
| 2609 | fprintf(stderrstderr, "failed to open output file %s\n", temp); |
| 2610 | free(temp); |
| 2611 | return(-1); |
| 2612 | } |
| 2613 | f = fopen(filename, "rb"); |
| 2614 | if (f == NULL((void*)0)) { |
| |
| 2615 | fprintf(stderrstderr, "failed to open input file %s\n", filename); |
| 2616 | fclose(o); |
| 2617 | unlink(temp); |
| 2618 | free(temp); |
| 2619 | return(-1); |
| 2620 | } |
| 2621 | |
| 2622 | while (1) { |
| 5 | Loop condition is true. Entering loop body |
|
| 2623 | |
| 2624 | |
| 2625 | |
| 2626 | if (fgets (&str[0], sizeof (str) - 1, f) == NULL((void*)0)) |
| |
| 2627 | break; |
| 7 | Execution continues on line 2643 |
|
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | i = strlen(str); |
| 2633 | while ((i > 0) && |
| 2634 | ((str[i - 1] == '\n') || (str[i - 1] == '\r') || |
| 2635 | (str[i - 1] == ' ') || (str[i - 1] == '\t'))) { |
| 2636 | i--; |
| 2637 | str[i] = 0; |
| 2638 | } |
| 2639 | nb_tests++; |
| 2640 | handleURI(str, base, o); |
| 2641 | } |
| 2642 | |
| 2643 | fclose(f); |
| 2644 | fclose(o); |
| 2645 | |
| 2646 | if (result != NULL((void*)0)) { |
| |
| 2647 | ret = compareFiles(temp, result); |
| 2648 | if (ret) { |
| 2649 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 2650 | res = 1; |
| 2651 | } |
| 2652 | } |
| 2653 | if (err != NULL((void*)0)) { |
| |
| 2654 | ret = compareFileMem(err, testErrors, testErrorsSize); |
| 2655 | if (ret != 0) { |
| 2656 | fprintf(stderrstderr, "Error for %s failed\n", filename); |
| 2657 | res = 1; |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | unlink(temp); |
| 10 | Null pointer passed as an argument to a 'nonnull' parameter |
|
| 2662 | free(temp); |
| 2663 | return(res); |
| 2664 | } |
| 2665 | |
| 2666 | |
| 2667 | |
| 2668 | |
| 2669 | |
| 2670 | |
| 2671 | |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | static int |
| 2677 | uriParseTest(const char *filename, |
| 2678 | const char *result, |
| 2679 | const char *err, |
| 2680 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 2681 | return(uriCommonTest(filename, result, err, NULL((void*)0))); |
| 2682 | } |
| 2683 | |
| 2684 | |
| 2685 | |
| 2686 | |
| 2687 | |
| 2688 | |
| 2689 | |
| 2690 | |
| 2691 | |
| 2692 | |
| 2693 | |
| 2694 | |
| 2695 | static int |
| 2696 | uriBaseTest(const char *filename, |
| 2697 | const char *result, |
| 2698 | const char *err, |
| 2699 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 2700 | return(uriCommonTest(filename, result, err, |
| 2701 | "http://foo.com/path/to/index.html?orig#help")); |
| 2702 | } |
| 2703 | |
| 2704 | static int urip_success = 1; |
| 2705 | static int urip_current = 0; |
| 2706 | static const char *urip_testURLs[] = { |
| 2707 | "urip://example.com/a b.html", |
| 2708 | "urip://example.com/a%20b.html", |
| 2709 | "file:///path/to/a b.html", |
| 2710 | "file:///path/to/a%20b.html", |
| 2711 | "/path/to/a b.html", |
| 2712 | "/path/to/a%20b.html", |
| 2713 | "urip://example.com/résumé.html", |
| 2714 | "urip://example.com/test?a=1&b=2%263&c=4#foo", |
| 2715 | NULL((void*)0) |
| 2716 | }; |
| 2717 | static const char *urip_rcvsURLs[] = { |
| 2718 | |
| 2719 | "urip://example.com/a%20b.html", |
| 2720 | |
| 2721 | "urip://example.com/a%20b.html", |
| 2722 | |
| 2723 | "file:///path/to/a%20b.html", |
| 2724 | |
| 2725 | "file:///path/to/a%20b.html", |
| 2726 | |
| 2727 | "/path/to/a b.html", |
| 2728 | |
| 2729 | "/path/to/a%20b.html", |
| 2730 | |
| 2731 | "urip://example.com/r%E9sum%E9.html", |
| 2732 | |
| 2733 | "urip://example.com/test?a=1&b=2%263&c=4#foo", |
| 2734 | NULL((void*)0) |
| 2735 | }; |
| 2736 | static const char *urip_res = "<list/>"; |
| 2737 | static const char *urip_cur = NULL((void*)0); |
| 2738 | static int urip_rlen; |
| 2739 | |
| 2740 | |
| 2741 | |
| 2742 | |
| 2743 | |
| 2744 | |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | static int |
| 2749 | uripMatch(const char * URI) { |
| 2750 | if ((URI == NULL((void*)0)) || (!strcmp(URI, "file:///etc/xml/catalog"))) |
| 2751 | return(0); |
| 2752 | |
| 2753 | if (strcmp(urip_rcvsURLs[urip_current], URI)) |
| 2754 | urip_success = 0; |
| 2755 | return(1); |
| 2756 | } |
| 2757 | |
| 2758 | |
| 2759 | |
| 2760 | |
| 2761 | |
| 2762 | |
| 2763 | |
| 2764 | |
| 2765 | |
| 2766 | |
| 2767 | static void * |
| 2768 | uripOpen(const char * URI) { |
| 2769 | if ((URI == NULL((void*)0)) || (!strcmp(URI, "file:///etc/xml/catalog"))) |
| 2770 | return(NULL((void*)0)); |
| 2771 | |
| 2772 | if (strcmp(urip_rcvsURLs[urip_current], URI)) |
| 2773 | urip_success = 0; |
| 2774 | urip_cur = urip_res; |
| 2775 | urip_rlen = strlen(urip_res); |
| 2776 | return((void *) urip_cur); |
| 2777 | } |
| 2778 | |
| 2779 | |
| 2780 | |
| 2781 | |
| 2782 | |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | static int |
| 2788 | uripClose(void * context) { |
| 2789 | if (context == NULL((void*)0)) return(-1); |
| 2790 | urip_cur = NULL((void*)0); |
| 2791 | urip_rlen = 0; |
| 2792 | return(0); |
| 2793 | } |
| 2794 | |
| 2795 | |
| 2796 | |
| 2797 | |
| 2798 | |
| 2799 | |
| 2800 | |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | |
| 2805 | static int |
| 2806 | uripRead(void * context, char * buffer, int len) { |
| 2807 | const char *ptr = (const char *) context; |
| 2808 | |
| 2809 | if ((context == NULL((void*)0)) || (buffer == NULL((void*)0)) || (len < 0)) |
| 2810 | return(-1); |
| 2811 | |
| 2812 | if (len > urip_rlen) len = urip_rlen; |
| 2813 | memcpy(buffer, ptr, len); |
| 2814 | urip_rlen -= len; |
| 2815 | return(len); |
| 2816 | } |
| 2817 | |
| 2818 | static int |
| 2819 | urip_checkURL(const char *URL) { |
| 2820 | xmlDocPtr doc; |
| 2821 | |
| 2822 | doc = xmlReadFile(URL, NULL((void*)0), 0); |
| 2823 | if (doc == NULL((void*)0)) |
| 2824 | return(-1); |
| 2825 | xmlFreeDoc(doc); |
| 2826 | return(1); |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | |
| 2831 | |
| 2832 | |
| 2833 | |
| 2834 | |
| 2835 | |
| 2836 | |
| 2837 | |
| 2838 | |
| 2839 | |
| 2840 | static int |
| 2841 | uriPathTest(const char *filename ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2842 | const char *result ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2843 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2844 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 2845 | int parsed; |
| 2846 | int failures = 0; |
| 2847 | |
| 2848 | |
| 2849 | |
| 2850 | |
| 2851 | if (xmlRegisterInputCallbacks(uripMatch, uripOpen, uripRead, uripClose) < 0) |
| 2852 | { |
| 2853 | fprintf(stderrstderr, "failed to register HTTP handler\n"); |
| 2854 | return(-1); |
| 2855 | } |
| 2856 | |
| 2857 | for (urip_current = 0;urip_testURLs[urip_current] != NULL((void*)0);urip_current++) { |
| 2858 | urip_success = 1; |
| 2859 | parsed = urip_checkURL(urip_testURLs[urip_current]); |
| 2860 | if (urip_success != 1) { |
| 2861 | fprintf(stderrstderr, "failed the URL passing test for %s", |
| 2862 | urip_testURLs[urip_current]); |
| 2863 | failures++; |
| 2864 | } else if (parsed != 1) { |
| 2865 | fprintf(stderrstderr, "failed the parsing test for %s", |
| 2866 | urip_testURLs[urip_current]); |
| 2867 | failures++; |
| 2868 | } |
| 2869 | nb_tests++; |
| 2870 | } |
| 2871 | |
| 2872 | xmlPopInputCallbacks(); |
| 2873 | return(failures); |
| 2874 | } |
| 2875 | |
| 2876 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 2877 | |
| 2878 | |
| 2879 | |
| 2880 | |
| 2881 | |
| 2882 | static int |
| 2883 | schemasOneTest(const char *sch, |
| 2884 | const char *filename, |
| 2885 | const char *result, |
| 2886 | const char *err, |
| 2887 | int options, |
| 2888 | xmlSchemaPtr schemas) { |
| 2889 | xmlDocPtr doc; |
| 2890 | xmlSchemaValidCtxtPtr ctxt; |
| 2891 | int ret = 0; |
| 2892 | int validResult = 0; |
| 2893 | char *temp; |
| 2894 | FILE *schemasOutput; |
| 2895 | |
| 2896 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 2897 | if (doc == NULL((void*)0)) { |
| 2898 | fprintf(stderrstderr, "failed to parse instance %s for %s\n", filename, sch); |
| 2899 | return(-1); |
| 2900 | } |
| 2901 | |
| 2902 | temp = resultFilename(result, "", ".res"); |
| 2903 | if (temp == NULL((void*)0)) { |
| 2904 | fprintf(stderrstderr, "Out of memory\n"); |
| 2905 | fatalError(); |
| 2906 | } |
| 2907 | schemasOutput = fopen(temp, "wb"); |
| 2908 | if (schemasOutput == NULL((void*)0)) { |
| 2909 | fprintf(stderrstderr, "failed to open output file %s\n", temp); |
| 2910 | xmlFreeDoc(doc); |
| 2911 | free(temp); |
| 2912 | return(-1); |
| 2913 | } |
| 2914 | |
| 2915 | ctxt = xmlSchemaNewValidCtxt(schemas); |
| 2916 | xmlSchemaSetValidErrors(ctxt, |
| 2917 | (xmlSchemaValidityErrorFunc) testErrorHandler, |
| 2918 | (xmlSchemaValidityWarningFunc) testErrorHandler, |
| 2919 | ctxt); |
| 2920 | validResult = xmlSchemaValidateDoc(ctxt, doc); |
| 2921 | if (validResult == 0) { |
| 2922 | fprintf(schemasOutput, "%s validates\n", filename); |
| 2923 | } else if (validResult > 0) { |
| 2924 | fprintf(schemasOutput, "%s fails to validate\n", filename); |
| 2925 | } else { |
| 2926 | fprintf(schemasOutput, "%s validation generated an internal error\n", |
| 2927 | filename); |
| 2928 | } |
| 2929 | fclose(schemasOutput); |
| 2930 | if (result) { |
| 2931 | if (compareFiles(temp, result)) { |
| 2932 | fprintf(stderrstderr, "Result for %s on %s failed\n", filename, sch); |
| 2933 | ret = 1; |
| 2934 | } |
| 2935 | } |
| 2936 | unlink(temp); |
| 2937 | free(temp); |
| 2938 | |
| 2939 | if ((validResult != 0) && (err != NULL((void*)0))) { |
| 2940 | if (compareFileMem(err, testErrors, testErrorsSize)) { |
| 2941 | fprintf(stderrstderr, "Error for %s on %s failed\n", filename, sch); |
| 2942 | ret = 1; |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | xmlSchemaFreeValidCtxt(ctxt); |
| 2947 | xmlFreeDoc(doc); |
| 2948 | return(ret); |
| 2949 | } |
| 2950 | |
| 2951 | |
| 2952 | |
| 2953 | |
| 2954 | |
| 2955 | |
| 2956 | |
| 2957 | |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | static int |
| 2962 | schemasTest(const char *filename, |
| 2963 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2964 | const char *errr ATTRIBUTE_UNUSED__attribute__((unused)), |
| 2965 | int options) { |
| 2966 | const char *base = baseFilename(filename); |
| 2967 | const char *base2; |
| 2968 | const char *instance; |
| 2969 | xmlSchemaParserCtxtPtr ctxt; |
| 2970 | xmlSchemaPtr schemas; |
| 2971 | int res = 0, len, ret; |
| 2972 | char pattern[500]; |
| 2973 | char prefix[500]; |
| 2974 | char result[500]; |
| 2975 | char err[500]; |
| 2976 | glob_t globbuf; |
| 2977 | size_t i; |
| 2978 | char count = 0; |
| 2979 | |
| 2980 | |
| 2981 | ctxt = xmlSchemaNewParserCtxt(filename); |
| 2982 | xmlSchemaSetParserErrors(ctxt, |
| 2983 | (xmlSchemaValidityErrorFunc) testErrorHandler, |
| 2984 | (xmlSchemaValidityWarningFunc) testErrorHandler, |
| 2985 | ctxt); |
| 2986 | schemas = xmlSchemaParse(ctxt); |
| 2987 | xmlSchemaFreeParserCtxt(ctxt); |
| 2988 | |
| 2989 | |
| 2990 | |
| 2991 | |
| 2992 | len = strlen(base); |
| 2993 | if ((len > 499) || (len < 5)) { |
| 2994 | xmlSchemaFree(schemas); |
| 2995 | return(-1); |
| 2996 | } |
| 2997 | len -= 4; |
| 2998 | if (base[len - 2] == '_') { |
| 2999 | len -= 2; |
| 3000 | } |
| 3001 | if (base[len - 2] == '_') { |
| 3002 | len -= 2; |
| 3003 | } |
| 3004 | memcpy(prefix, base, len); |
| 3005 | prefix[len] = 0; |
| 3006 | |
| 3007 | snprintf(pattern, 499, "./test/schemas/%s_?.xml", prefix); |
| 3008 | pattern[499] = 0; |
| 3009 | |
| 3010 | if (base[len] == '_') { |
| 3011 | len += 2; |
| 3012 | memcpy(prefix, base, len); |
| 3013 | prefix[len] = 0; |
| 3014 | } |
| 3015 | |
| 3016 | globbuf.gl_offs = 0; |
| 3017 | glob(pattern, GLOB_DOOFFS(1 << 3), NULL((void*)0), &globbuf); |
| 3018 | for (i = 0;i < globbuf.gl_pathc;i++) { |
| 3019 | testErrorsSize = 0; |
| 3020 | testErrors[0] = 0; |
| 3021 | instance = globbuf.gl_pathv[i]; |
| 3022 | base2 = baseFilename(instance); |
| 3023 | len = strlen(base2); |
| 3024 | if ((len > 6) && (base2[len - 6] == '_')) { |
| 3025 | count = base2[len - 5]; |
| 3026 | snprintf(result, 499, "result/schemas/%s_%c", |
| 3027 | prefix, count); |
| 3028 | result[499] = 0; |
| 3029 | snprintf(err, 499, "result/schemas/%s_%c.err", |
| 3030 | prefix, count); |
| 3031 | err[499] = 0; |
| 3032 | } else { |
| 3033 | fprintf(stderrstderr, "don't know how to process %s\n", instance); |
| 3034 | continue; |
| 3035 | } |
| 3036 | if (schemas == NULL((void*)0)) { |
| 3037 | } else { |
| 3038 | nb_tests++; |
| 3039 | ret = schemasOneTest(filename, instance, result, err, |
| 3040 | options, schemas); |
| 3041 | if (ret != 0) |
| 3042 | res = ret; |
| 3043 | } |
| 3044 | } |
| 3045 | globfree(&globbuf); |
| 3046 | xmlSchemaFree(schemas); |
| 3047 | |
| 3048 | return(res); |
| 3049 | } |
| 3050 | |
| 3051 | |
| 3052 | |
| 3053 | |
| 3054 | |
| 3055 | |
| 3056 | static int |
| 3057 | rngOneTest(const char *sch, |
| 3058 | const char *filename, |
| 3059 | const char *result, |
| 3060 | const char *err, |
| 3061 | int options, |
| 3062 | xmlRelaxNGPtr schemas) { |
| 3063 | xmlDocPtr doc; |
| 3064 | xmlRelaxNGValidCtxtPtr ctxt; |
| 3065 | int ret = 0; |
| 3066 | char *temp; |
| 3067 | FILE *schemasOutput; |
| 3068 | |
| 3069 | doc = xmlReadFile(filename, NULL((void*)0), options); |
| 3070 | if (doc == NULL((void*)0)) { |
| 3071 | fprintf(stderrstderr, "failed to parse instance %s for %s\n", filename, sch); |
| 3072 | return(-1); |
| 3073 | } |
| 3074 | |
| 3075 | temp = resultFilename(result, "", ".res"); |
| 3076 | if (temp == NULL((void*)0)) { |
| 3077 | fprintf(stderrstderr, "Out of memory\n"); |
| 3078 | fatalError(); |
| 3079 | } |
| 3080 | schemasOutput = fopen(temp, "wb"); |
| 3081 | if (schemasOutput == NULL((void*)0)) { |
| 3082 | fprintf(stderrstderr, "failed to open output file %s\n", temp); |
| 3083 | xmlFreeDoc(doc); |
| 3084 | free(temp); |
| 3085 | return(-1); |
| 3086 | } |
| 3087 | |
| 3088 | ctxt = xmlRelaxNGNewValidCtxt(schemas); |
| 3089 | xmlRelaxNGSetValidErrors(ctxt, |
| 3090 | (xmlRelaxNGValidityErrorFunc) testErrorHandler, |
| 3091 | (xmlRelaxNGValidityWarningFunc) testErrorHandler, |
| 3092 | ctxt); |
| 3093 | ret = xmlRelaxNGValidateDoc(ctxt, doc); |
| 3094 | if (ret == 0) { |
| 3095 | testErrorHandler(NULL((void*)0), "%s validates\n", filename); |
| 3096 | } else if (ret > 0) { |
| 3097 | testErrorHandler(NULL((void*)0), "%s fails to validate\n", filename); |
| 3098 | } else { |
| 3099 | testErrorHandler(NULL((void*)0), "%s validation generated an internal error\n", |
| 3100 | filename); |
| 3101 | } |
| 3102 | fclose(schemasOutput); |
| 3103 | if (result) { |
| 3104 | if (compareFiles(temp, result)) { |
| 3105 | fprintf(stderrstderr, "Result for %s on %s failed\n", filename, sch); |
| 3106 | ret = 1; |
| 3107 | } |
| 3108 | } |
| 3109 | unlink(temp); |
| 3110 | free(temp); |
| 3111 | |
| 3112 | if (err != NULL((void*)0)) { |
| 3113 | if (compareFileMem(err, testErrors, testErrorsSize)) { |
| 3114 | fprintf(stderrstderr, "Error for %s on %s failed\n", filename, sch); |
| 3115 | ret = 1; |
| 3116 | printf("%s", testErrors); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | |
| 3121 | xmlRelaxNGFreeValidCtxt(ctxt); |
| 3122 | xmlFreeDoc(doc); |
| 3123 | return(ret); |
| 3124 | } |
| 3125 | |
| 3126 | |
| 3127 | |
| 3128 | |
| 3129 | |
| 3130 | |
| 3131 | |
| 3132 | |
| 3133 | |
| 3134 | |
| 3135 | static int |
| 3136 | rngTest(const char *filename, |
| 3137 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3138 | const char *errr ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3139 | int options) { |
| 3140 | const char *base = baseFilename(filename); |
| 3141 | const char *base2; |
| 3142 | const char *instance; |
| 3143 | xmlRelaxNGParserCtxtPtr ctxt; |
| 3144 | xmlRelaxNGPtr schemas; |
| 3145 | int res = 0, len, ret; |
| 3146 | char pattern[500]; |
| 3147 | char prefix[500]; |
| 3148 | char result[500]; |
| 3149 | char err[500]; |
| 3150 | glob_t globbuf; |
| 3151 | size_t i; |
| 3152 | char count = 0; |
| 3153 | |
| 3154 | |
| 3155 | ctxt = xmlRelaxNGNewParserCtxt(filename); |
| 3156 | xmlRelaxNGSetParserErrors(ctxt, |
| 3157 | (xmlRelaxNGValidityErrorFunc) testErrorHandler, |
| 3158 | (xmlRelaxNGValidityWarningFunc) testErrorHandler, |
| 3159 | ctxt); |
| 3160 | schemas = xmlRelaxNGParse(ctxt); |
| 3161 | xmlRelaxNGFreeParserCtxt(ctxt); |
| 3162 | |
| 3163 | |
| 3164 | |
| 3165 | |
| 3166 | len = strlen(base); |
| 3167 | if ((len > 499) || (len < 5)) { |
| 3168 | xmlRelaxNGFree(schemas); |
| 3169 | return(-1); |
| 3170 | } |
| 3171 | len -= 4; |
| 3172 | memcpy(prefix, base, len); |
| 3173 | prefix[len] = 0; |
| 3174 | |
| 3175 | snprintf(pattern, 499, "./test/relaxng/%s_?.xml", prefix); |
| 3176 | pattern[499] = 0; |
| 3177 | |
| 3178 | globbuf.gl_offs = 0; |
| 3179 | glob(pattern, GLOB_DOOFFS(1 << 3), NULL((void*)0), &globbuf); |
| 3180 | for (i = 0;i < globbuf.gl_pathc;i++) { |
| 3181 | testErrorsSize = 0; |
| 3182 | testErrors[0] = 0; |
| 3183 | instance = globbuf.gl_pathv[i]; |
| 3184 | base2 = baseFilename(instance); |
| 3185 | len = strlen(base2); |
| 3186 | if ((len > 6) && (base2[len - 6] == '_')) { |
| 3187 | count = base2[len - 5]; |
| 3188 | snprintf(result, 499, "result/relaxng/%s_%c", |
| 3189 | prefix, count); |
| 3190 | result[499] = 0; |
| 3191 | snprintf(err, 499, "result/relaxng/%s_%c.err", |
| 3192 | prefix, count); |
| 3193 | err[499] = 0; |
| 3194 | } else { |
| 3195 | fprintf(stderrstderr, "don't know how to process %s\n", instance); |
| 3196 | continue; |
| 3197 | } |
| 3198 | if (schemas == NULL((void*)0)) { |
| 3199 | } else { |
| 3200 | nb_tests++; |
| 3201 | ret = rngOneTest(filename, instance, result, err, |
| 3202 | options, schemas); |
| 3203 | if (res != 0) |
| 3204 | ret = res; |
| 3205 | } |
| 3206 | } |
| 3207 | globfree(&globbuf); |
| 3208 | xmlRelaxNGFree(schemas); |
| 3209 | |
| 3210 | return(res); |
| 3211 | } |
| 3212 | |
| 3213 | #ifdef LIBXML_READER_ENABLED |
| 3214 | |
| 3215 | |
| 3216 | |
| 3217 | |
| 3218 | |
| 3219 | |
| 3220 | |
| 3221 | |
| 3222 | |
| 3223 | |
| 3224 | static int |
| 3225 | rngStreamTest(const char *filename, |
| 3226 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3227 | const char *errr ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3228 | int options) { |
| 3229 | const char *base = baseFilename(filename); |
| 3230 | const char *base2; |
| 3231 | const char *instance; |
| 3232 | int res = 0, len, ret; |
| 3233 | char pattern[500]; |
| 3234 | char prefix[500]; |
| 3235 | char result[500]; |
| 3236 | char err[500]; |
| 3237 | glob_t globbuf; |
| 3238 | size_t i; |
| 3239 | char count = 0; |
| 3240 | xmlTextReaderPtr reader; |
| 3241 | int disable_err = 0; |
| 3242 | |
| 3243 | |
| 3244 | |
| 3245 | |
| 3246 | len = strlen(base); |
| 3247 | if ((len > 499) || (len < 5)) { |
| 3248 | fprintf(stderrstderr, "len(base) == %d !\n", len); |
| 3249 | return(-1); |
| 3250 | } |
| 3251 | len -= 4; |
| 3252 | memcpy(prefix, base, len); |
| 3253 | prefix[len] = 0; |
| 3254 | |
| 3255 | |
| 3256 | |
| 3257 | |
| 3258 | |
| 3259 | if ((!strcmp(prefix, "tutor10_1")) || (!strcmp(prefix, "tutor10_2")) || |
| 3260 | (!strcmp(prefix, "tutor3_2")) || (!strcmp(prefix, "307377")) || |
| 3261 | (!strcmp(prefix, "tutor8_2"))) |
| 3262 | disable_err = 1; |
| 3263 | |
| 3264 | snprintf(pattern, 499, "./test/relaxng/%s_?.xml", prefix); |
| 3265 | pattern[499] = 0; |
| 3266 | |
| 3267 | globbuf.gl_offs = 0; |
| 3268 | glob(pattern, GLOB_DOOFFS(1 << 3), NULL((void*)0), &globbuf); |
| 3269 | for (i = 0;i < globbuf.gl_pathc;i++) { |
| 3270 | testErrorsSize = 0; |
| 3271 | testErrors[0] = 0; |
| 3272 | instance = globbuf.gl_pathv[i]; |
| 3273 | base2 = baseFilename(instance); |
| 3274 | len = strlen(base2); |
| 3275 | if ((len > 6) && (base2[len - 6] == '_')) { |
| 3276 | count = base2[len - 5]; |
| 3277 | snprintf(result, 499, "result/relaxng/%s_%c", |
| 3278 | prefix, count); |
| 3279 | result[499] = 0; |
| 3280 | snprintf(err, 499, "result/relaxng/%s_%c.err", |
| 3281 | prefix, count); |
| 3282 | err[499] = 0; |
| 3283 | } else { |
| 3284 | fprintf(stderrstderr, "don't know how to process %s\n", instance); |
| 3285 | continue; |
| 3286 | } |
| 3287 | reader = xmlReaderForFile(instance, NULL((void*)0), options); |
| 3288 | if (reader == NULL((void*)0)) { |
| 3289 | fprintf(stderrstderr, "Failed to build reder for %s\n", instance); |
| 3290 | } |
| 3291 | if (disable_err == 1) |
| 3292 | ret = streamProcessTest(instance, result, NULL((void*)0), reader, filename); |
| 3293 | else |
| 3294 | ret = streamProcessTest(instance, result, err, reader, filename); |
| 3295 | xmlFreeTextReader(reader); |
| 3296 | if (ret != 0) { |
| 3297 | fprintf(stderrstderr, "instance %s failed\n", instance); |
| 3298 | res = ret; |
| 3299 | } |
| 3300 | } |
| 3301 | globfree(&globbuf); |
| 3302 | |
| 3303 | return(res); |
| 3304 | } |
| 3305 | #endif /* READER */ |
| 3306 | |
| 3307 | #endif |
| 3308 | |
| 3309 | #ifdef LIBXML_PATTERN_ENABLED |
| 3310 | #ifdef LIBXML_READER_ENABLED |
| 3311 | |
| 3312 | |
| 3313 | |
| 3314 | |
| 3315 | |
| 3316 | static void patternNode(FILE *out, xmlTextReaderPtr reader, |
| 3317 | const char *pattern, xmlPatternPtr patternc, |
| 3318 | xmlStreamCtxtPtr patstream) { |
| 3319 | xmlChar *path = NULL((void*)0); |
| 3320 | int match = -1; |
| 3321 | int type, empty; |
| 3322 | |
| 3323 | type = xmlTextReaderNodeType(reader); |
| 3324 | empty = xmlTextReaderIsEmptyElement(reader); |
| 3325 | |
| 3326 | if (type == XML_READER_TYPE_ELEMENT) { |
| 3327 | |
| 3328 | match = xmlPatternMatch(patternc, xmlTextReaderCurrentNode(reader)); |
| 3329 | |
| 3330 | if (match) { |
| 3331 | path = xmlGetNodePath(xmlTextReaderCurrentNode(reader)); |
| 3332 | fprintf(out, "Node %s matches pattern %s\n", path, pattern); |
| 3333 | } |
| 3334 | } |
| 3335 | if (patstream != NULL((void*)0)) { |
| 3336 | int ret; |
| 3337 | |
| 3338 | if (type == XML_READER_TYPE_ELEMENT) { |
| 3339 | ret = xmlStreamPush(patstream, |
| 3340 | xmlTextReaderConstLocalName(reader), |
| 3341 | xmlTextReaderConstNamespaceUri(reader)); |
| 3342 | if (ret < 0) { |
| 3343 | fprintf(out, "xmlStreamPush() failure\n"); |
| 3344 | xmlFreeStreamCtxt(patstream); |
| 3345 | patstream = NULL((void*)0); |
| 3346 | } else if (ret != match) { |
| 3347 | if (path == NULL((void*)0)) { |
| 3348 | path = xmlGetNodePath( |
| 3349 | xmlTextReaderCurrentNode(reader)); |
| 3350 | } |
| 3351 | fprintf(out, |
| 3352 | "xmlPatternMatch and xmlStreamPush disagree\n"); |
| 3353 | fprintf(out, |
| 3354 | " pattern %s node %s\n", |
| 3355 | pattern, path); |
| 3356 | } |
| 3357 | |
| 3358 | |
| 3359 | } |
| 3360 | if ((type == XML_READER_TYPE_END_ELEMENT) || |
| 3361 | ((type == XML_READER_TYPE_ELEMENT) && (empty))) { |
| 3362 | ret = xmlStreamPop(patstream); |
| 3363 | if (ret < 0) { |
| 3364 | fprintf(out, "xmlStreamPop() failure\n"); |
| 3365 | xmlFreeStreamCtxt(patstream); |
| 3366 | patstream = NULL((void*)0); |
| 3367 | } |
| 3368 | } |
| 3369 | } |
| 3370 | if (path != NULL((void*)0)) |
| 3371 | xmlFree(path); |
| 3372 | } |
| 3373 | |
| 3374 | |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | |
| 3379 | |
| 3380 | |
| 3381 | |
| 3382 | |
| 3383 | |
| 3384 | static int |
| 3385 | patternTest(const char *filename, |
| 3386 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3387 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3388 | int options) { |
| 3389 | xmlPatternPtr patternc = NULL((void*)0); |
| 3390 | xmlStreamCtxtPtr patstream = NULL((void*)0); |
| 3391 | FILE *o, *f; |
| 3392 | char str[1024]; |
| 3393 | char xml[500]; |
| 3394 | char result[500]; |
| 3395 | int len, i; |
| 3396 | int ret = 0, res; |
| 3397 | char *temp; |
| 3398 | xmlTextReaderPtr reader; |
| 3399 | xmlDocPtr doc; |
| 3400 | |
| 3401 | len = strlen(filename); |
| 3402 | len -= 4; |
| 3403 | memcpy(xml, filename, len); |
| 3404 | xml[len] = 0; |
| 3405 | snprintf(result, 499, "result/pattern/%s", baseFilename(xml)); |
| 3406 | result[499] = 0; |
| 3407 | memcpy(xml + len, ".xml", 5); |
| 3408 | |
| 3409 | if (!checkTestFile(xml)) { |
| 3410 | fprintf(stderrstderr, "Missing xml file %s\n", xml); |
| 3411 | return(-1); |
| 3412 | } |
| 3413 | if (!checkTestFile(result)) { |
| 3414 | fprintf(stderrstderr, "Missing result file %s\n", result); |
| 3415 | return(-1); |
| 3416 | } |
| 3417 | f = fopen(filename, "rb"); |
| 3418 | if (f == NULL((void*)0)) { |
| 3419 | fprintf(stderrstderr, "Failed to open %s\n", filename); |
| 3420 | return(-1); |
| 3421 | } |
| 3422 | temp = resultFilename(filename, "", ".res"); |
| 3423 | if (temp == NULL((void*)0)) { |
| 3424 | fprintf(stderrstderr, "Out of memory\n"); |
| 3425 | fatalError(); |
| 3426 | } |
| 3427 | o = fopen(temp, "wb"); |
| 3428 | if (o == NULL((void*)0)) { |
| 3429 | fprintf(stderrstderr, "failed to open output file %s\n", temp); |
| 3430 | fclose(f); |
| 3431 | free(temp); |
| 3432 | return(-1); |
| 3433 | } |
| 3434 | while (1) { |
| 3435 | |
| 3436 | |
| 3437 | |
| 3438 | if (fgets (&str[0], sizeof (str) - 1, f) == NULL((void*)0)) |
| 3439 | break; |
| 3440 | |
| 3441 | |
| 3442 | |
| 3443 | |
| 3444 | i = strlen(str); |
| 3445 | while ((i > 0) && |
| 3446 | ((str[i - 1] == '\n') || (str[i - 1] == '\r') || |
| 3447 | (str[i - 1] == ' ') || (str[i - 1] == '\t'))) { |
| 3448 | i--; |
| 3449 | str[i] = 0; |
| 3450 | } |
| 3451 | doc = xmlReadFile(xml, NULL((void*)0), options); |
| 3452 | if (doc == NULL((void*)0)) { |
| 3453 | fprintf(stderrstderr, "Failed to parse %s\n", xml); |
| 3454 | ret = 1; |
| 3455 | } else { |
| 3456 | xmlNodePtr root; |
| 3457 | const xmlChar *namespaces[22]; |
| 3458 | int j; |
| 3459 | xmlNsPtr ns; |
| 3460 | |
| 3461 | root = xmlDocGetRootElement(doc); |
| 3462 | for (ns = root->nsDef, j = 0;ns != NULL((void*)0) && j < 20;ns=ns->next) { |
| 3463 | namespaces[j++] = ns->href; |
| 3464 | namespaces[j++] = ns->prefix; |
| 3465 | } |
| 3466 | namespaces[j++] = NULL((void*)0); |
| 3467 | namespaces[j++] = NULL((void*)0); |
| 3468 | |
| 3469 | patternc = xmlPatterncompile((const xmlChar *) str, doc->dict, |
| 3470 | 0, &namespaces[0]); |
| 3471 | if (patternc == NULL((void*)0)) { |
| 3472 | testErrorHandler(NULL((void*)0), |
| 3473 | "Pattern %s failed to compile\n", str); |
| 3474 | xmlFreeDoc(doc); |
| 3475 | ret = 1; |
| 3476 | continue; |
| 3477 | } |
| 3478 | patstream = xmlPatternGetStreamCtxt(patternc); |
| 3479 | if (patstream != NULL((void*)0)) { |
| 3480 | ret = xmlStreamPush(patstream, NULL((void*)0), NULL((void*)0)); |
| 3481 | if (ret < 0) { |
| 3482 | fprintf(stderrstderr, "xmlStreamPush() failure\n"); |
| 3483 | xmlFreeStreamCtxt(patstream); |
| 3484 | patstream = NULL((void*)0); |
| 3485 | } |
| 3486 | } |
| 3487 | nb_tests++; |
| 3488 | |
| 3489 | reader = xmlReaderWalker(doc); |
| 3490 | res = xmlTextReaderRead(reader); |
| 3491 | while (res == 1) { |
| 3492 | patternNode(o, reader, str, patternc, patstream); |
| 3493 | res = xmlTextReaderRead(reader); |
| 3494 | } |
| 3495 | if (res != 0) { |
| 3496 | fprintf(o, "%s : failed to parse\n", filename); |
| 3497 | } |
| 3498 | xmlFreeTextReader(reader); |
| 3499 | xmlFreeDoc(doc); |
| 3500 | xmlFreeStreamCtxt(patstream); |
| 3501 | patstream = NULL((void*)0); |
| 3502 | xmlFreePattern(patternc); |
| 3503 | |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | fclose(f); |
| 3508 | fclose(o); |
| 3509 | |
| 3510 | ret = compareFiles(temp, result); |
| 3511 | if (ret) { |
| 3512 | fprintf(stderrstderr, "Result for %s failed\n", filename); |
| 3513 | ret = 1; |
| 3514 | } |
| 3515 | unlink(temp); |
| 3516 | free(temp); |
| 3517 | return(ret); |
| 3518 | } |
| 3519 | #endif /* READER */ |
| 3520 | #endif /* PATTERN */ |
| 3521 | #ifdef LIBXML_C14N_ENABLED |
| 3522 | |
| 3523 | |
| 3524 | |
| 3525 | |
| 3526 | |
| 3527 | static xmlXPathObjectPtr |
| 3528 | load_xpath_expr (xmlDocPtr parent_doc, const char* filename) { |
| 3529 | xmlXPathObjectPtr xpath; |
| 3530 | xmlDocPtr doc; |
| 3531 | xmlChar *expr; |
| 3532 | xmlXPathContextPtr ctx; |
| 3533 | xmlNodePtr node; |
| 3534 | xmlNsPtr ns; |
| 3535 | |
| 3536 | |
| 3537 | |
| 3538 | |
| 3539 | xmlLoadExtDtdDefaultValue(*(__xmlLoadExtDtdDefaultValue())) = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4; |
| 3540 | xmlSubstituteEntitiesDefault(1); |
| 3541 | |
| 3542 | doc = xmlReadFile(filename, NULL((void*)0), XML_PARSE_DTDATTR | XML_PARSE_NOENT); |
| 3543 | if (doc == NULL((void*)0)) { |
| 3544 | fprintf(stderrstderr, "Error: unable to parse file \"%s\"\n", filename); |
| 3545 | return(NULL((void*)0)); |
| 3546 | } |
| 3547 | |
| 3548 | |
| 3549 | |
| 3550 | |
| 3551 | if(xmlDocGetRootElement(doc) == NULL((void*)0)) { |
| 3552 | fprintf(stderrstderr,"Error: empty document for file \"%s\"\n", filename); |
| 3553 | xmlFreeDoc(doc); |
| 3554 | return(NULL((void*)0)); |
| 3555 | } |
| 3556 | |
| 3557 | node = doc->children; |
| 3558 | while(node != NULL((void*)0) && !xmlStrEqual(node->name, (const xmlChar *)"XPath")) { |
| 3559 | node = node->next; |
| 3560 | } |
| 3561 | |
| 3562 | if(node == NULL((void*)0)) { |
| 3563 | fprintf(stderrstderr,"Error: XPath element expected in the file \"%s\"\n", filename); |
| 3564 | xmlFreeDoc(doc); |
| 3565 | return(NULL((void*)0)); |
| 3566 | } |
| 3567 | |
| 3568 | expr = xmlNodeGetContent(node); |
| 3569 | if(expr == NULL((void*)0)) { |
| 3570 | fprintf(stderrstderr,"Error: XPath content element is NULL \"%s\"\n", filename); |
| 3571 | xmlFreeDoc(doc); |
| 3572 | return(NULL((void*)0)); |
| 3573 | } |
| 3574 | |
| 3575 | ctx = xmlXPathNewContext(parent_doc); |
| 3576 | if(ctx == NULL((void*)0)) { |
| 3577 | fprintf(stderrstderr,"Error: unable to create new context\n"); |
| 3578 | xmlFree(expr); |
| 3579 | xmlFreeDoc(doc); |
| 3580 | return(NULL((void*)0)); |
| 3581 | } |
| 3582 | |
| 3583 | |
| 3584 | |
| 3585 | |
| 3586 | ns = node->nsDef; |
| 3587 | while(ns != NULL((void*)0)) { |
| 3588 | if(xmlXPathRegisterNs(ctx, ns->prefix, ns->href) != 0) { |
| 3589 | fprintf(stderrstderr,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", ns->prefix, ns->href); |
| 3590 | xmlFree(expr); |
| 3591 | xmlXPathFreeContext(ctx); |
| 3592 | xmlFreeDoc(doc); |
| 3593 | return(NULL((void*)0)); |
| 3594 | } |
| 3595 | ns = ns->next; |
| 3596 | } |
| 3597 | |
| 3598 | |
| 3599 | |
| 3600 | |
| 3601 | xpath = xmlXPathEvalExpression(expr, ctx); |
| 3602 | if(xpath == NULL((void*)0)) { |
| 3603 | fprintf(stderrstderr,"Error: unable to evaluate xpath expression\n"); |
| 3604 | xmlFree(expr); |
| 3605 | xmlXPathFreeContext(ctx); |
| 3606 | xmlFreeDoc(doc); |
| 3607 | return(NULL((void*)0)); |
| 3608 | } |
| 3609 | |
| 3610 | |
| 3611 | |
| 3612 | xmlFree(expr); |
| 3613 | xmlXPathFreeContext(ctx); |
| 3614 | xmlFreeDoc(doc); |
| 3615 | return(xpath); |
| 3616 | } |
| 3617 | |
| 3618 | |
| 3619 | |
| 3620 | |
| 3621 | #define xxx_growBufferReentrant(){ buffer_size *= 2; buffer = (xmlChar **) xmlRealloc(buffer, buffer_size * sizeof(xmlChar*)); if (buffer == ((void*)0)) { perror("realloc failed" ); return(((void*)0)); } } { \ |
| 3622 | buffer_size *= 2; \ |
| 3623 | buffer = (xmlChar **) \ |
| 3624 | xmlRealloc(buffer, buffer_size * sizeof(xmlChar*)); \ |
| 3625 | if (buffer == NULL((void*)0)) { \ |
| 3626 | perror("realloc failed"); \ |
| 3627 | return(NULL((void*)0)); \ |
| 3628 | } \ |
| 3629 | } |
| 3630 | |
| 3631 | static xmlChar ** |
| 3632 | parse_list(xmlChar *str) { |
| 3633 | xmlChar **buffer; |
| 3634 | xmlChar **out = NULL((void*)0); |
| 3635 | int buffer_size = 0; |
| 3636 | int len; |
| 3637 | |
| 3638 | if(str == NULL((void*)0)) { |
| 3639 | return(NULL((void*)0)); |
| 3640 | } |
| 3641 | |
| 3642 | len = xmlStrlen(str); |
| 3643 | if((str[0] == '\'') && (str[len - 1] == '\'')) { |
| 3644 | str[len - 1] = '\0'; |
| 3645 | str++; |
| 3646 | len -= 2; |
| 3647 | } |
| 3648 | |
| 3649 | |
| 3650 | |
| 3651 | buffer_size = 1000; |
| 3652 | buffer = (xmlChar **) xmlMalloc(buffer_size * sizeof(xmlChar*)); |
| 3653 | if (buffer == NULL((void*)0)) { |
| 3654 | perror("malloc failed"); |
| 3655 | return(NULL((void*)0)); |
| 3656 | } |
| 3657 | out = buffer; |
| 3658 | |
| 3659 | while(*str != '\0') { |
| 3660 | if (out - buffer > buffer_size - 10) { |
| 3661 | int indx = out - buffer; |
| 3662 | |
| 3663 | xxx_growBufferReentrant(){ buffer_size *= 2; buffer = (xmlChar **) xmlRealloc(buffer, buffer_size * sizeof(xmlChar*)); if (buffer == ((void*)0)) { perror("realloc failed" ); return(((void*)0)); } }; |
| 3664 | out = &buffer[indx]; |
| 3665 | } |
| 3666 | (*out++) = str; |
| 3667 | while(*str != ',' && *str != '\0') ++str; |
| 3668 | if(*str == ',') *(str++) = '\0'; |
| 3669 | } |
| 3670 | (*out) = NULL((void*)0); |
| 3671 | return buffer; |
| 3672 | } |
| 3673 | |
| 3674 | static int |
| 3675 | c14nRunTest(const char* xml_filename, int with_comments, int mode, |
| 3676 | const char* xpath_filename, const char *ns_filename, |
| 3677 | const char* result_file) { |
| 3678 | xmlDocPtr doc; |
| 3679 | xmlXPathObjectPtr xpath = NULL((void*)0); |
| 3680 | xmlChar *result = NULL((void*)0); |
| 3681 | int ret; |
| 3682 | xmlChar **inclusive_namespaces = NULL((void*)0); |
| 3683 | const char *nslist = NULL((void*)0); |
| 3684 | int nssize; |
| 3685 | |
| 3686 | |
| 3687 | |
| 3688 | |
| 3689 | |
| 3690 | |
| 3691 | xmlLoadExtDtdDefaultValue(*(__xmlLoadExtDtdDefaultValue())) = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4; |
| 3692 | xmlSubstituteEntitiesDefault(1); |
| 3693 | |
| 3694 | doc = xmlReadFile(xml_filename, NULL((void*)0), XML_PARSE_DTDATTR | XML_PARSE_NOENT); |
| 3695 | if (doc == NULL((void*)0)) { |
| 3696 | fprintf(stderrstderr, "Error: unable to parse file \"%s\"\n", xml_filename); |
| 3697 | return(-1); |
| 3698 | } |
| 3699 | |
| 3700 | |
| 3701 | |
| 3702 | |
| 3703 | if(xmlDocGetRootElement(doc) == NULL((void*)0)) { |
| 3704 | fprintf(stderrstderr,"Error: empty document for file \"%s\"\n", xml_filename); |
| 3705 | xmlFreeDoc(doc); |
| 3706 | return(-1); |
| 3707 | } |
| 3708 | |
| 3709 | |
| 3710 | |
| 3711 | |
| 3712 | if(xpath_filename) { |
| 3713 | xpath = load_xpath_expr(doc, xpath_filename); |
| 3714 | if(xpath == NULL((void*)0)) { |
| 3715 | fprintf(stderrstderr,"Error: unable to evaluate xpath expression\n"); |
| 3716 | xmlFreeDoc(doc); |
| 3717 | return(-1); |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | if (ns_filename != NULL((void*)0)) { |
| 3722 | if (loadMem(ns_filename, &nslist, &nssize)) { |
| 3723 | fprintf(stderrstderr,"Error: unable to evaluate xpath expression\n"); |
| 3724 | if(xpath != NULL((void*)0)) xmlXPathFreeObject(xpath); |
| 3725 | xmlFreeDoc(doc); |
| 3726 | return(-1); |
| 3727 | } |
| 3728 | inclusive_namespaces = parse_list((xmlChar *) nslist); |
| 3729 | } |
| 3730 | |
| 3731 | |
| 3732 | |
| 3733 | |
| 3734 | |
| 3735 | ret = xmlC14NDocDumpMemory(doc, |
| 3736 | (xpath) ? xpath->nodesetval : NULL((void*)0), |
| 3737 | mode, inclusive_namespaces, |
| 3738 | with_comments, &result); |
| 3739 | if (ret >= 0) { |
| 3740 | if(result != NULL((void*)0)) { |
| 3741 | if (compareFileMem(result_file, (const char *) result, ret)) { |
| 3742 | fprintf(stderrstderr, "Result mismatch for %s\n", xml_filename); |
| 3743 | fprintf(stderrstderr, "RESULT:\n%s\n", (const char*)result); |
| 3744 | ret = -1; |
| 3745 | } |
| 3746 | } |
| 3747 | } else { |
| 3748 | fprintf(stderrstderr,"Error: failed to canonicalize XML file \"%s\" (ret=%d)\n", xml_filename, ret); |
| 3749 | ret = -1; |
| 3750 | } |
| 3751 | |
| 3752 | |
| 3753 | |
| 3754 | |
| 3755 | if (result != NULL((void*)0)) xmlFree(result); |
| 3756 | if(xpath != NULL((void*)0)) xmlXPathFreeObject(xpath); |
| 3757 | if (inclusive_namespaces != NULL((void*)0)) xmlFree(inclusive_namespaces); |
| 3758 | if (nslist != NULL((void*)0)) free((char *) nslist); |
| 3759 | xmlFreeDoc(doc); |
| 3760 | |
| 3761 | return(ret); |
| 3762 | } |
| 3763 | |
| 3764 | static int |
| 3765 | c14nCommonTest(const char *filename, int with_comments, int mode, |
| 3766 | const char *subdir) { |
| 3767 | char buf[500]; |
| 3768 | char prefix[500]; |
| 3769 | const char *base; |
| 3770 | int len; |
| 3771 | char *result = NULL((void*)0); |
| 3772 | char *xpath = NULL((void*)0); |
| 3773 | char *ns = NULL((void*)0); |
| 3774 | int ret = 0; |
| 3775 | |
| 3776 | base = baseFilename(filename); |
| 3777 | len = strlen(base); |
| 3778 | len -= 4; |
| 3779 | memcpy(prefix, base, len); |
| 3780 | prefix[len] = 0; |
| 3781 | |
| 3782 | snprintf(buf, 499, "result/c14n/%s/%s", subdir,prefix); |
| 3783 | if (!checkTestFile(buf)) { |
| 3784 | fprintf(stderrstderr, "Missing result file %s", buf); |
| 3785 | return(-1); |
| 3786 | } |
| 3787 | result = strdup(buf); |
| 3788 | snprintf(buf, 499, "test/c14n/%s/%s.xpath", subdir,prefix); |
| 3789 | if (checkTestFile(buf)) { |
| 3790 | xpath = strdup(buf); |
| 3791 | } |
| 3792 | snprintf(buf, 499, "test/c14n/%s/%s.ns", subdir,prefix); |
| 3793 | if (checkTestFile(buf)) { |
| 3794 | ns = strdup(buf); |
| 3795 | } |
| 3796 | |
| 3797 | nb_tests++; |
| 3798 | if (c14nRunTest(filename, with_comments, mode, |
| 3799 | xpath, ns, result) < 0) |
| 3800 | ret = 1; |
| 3801 | |
| 3802 | if (result != NULL((void*)0)) free(result); |
| 3803 | if (xpath != NULL((void*)0)) free(xpath); |
| 3804 | if (ns != NULL((void*)0)) free(ns); |
| 3805 | return(ret); |
| 3806 | } |
| 3807 | |
| 3808 | static int |
| 3809 | c14nWithCommentTest(const char *filename, |
| 3810 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3811 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3812 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 3813 | return(c14nCommonTest(filename, 1, XML_C14N_1_0, "with-comments")); |
| 3814 | } |
| 3815 | static int |
| 3816 | c14nWithoutCommentTest(const char *filename, |
| 3817 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3818 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3819 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 3820 | return(c14nCommonTest(filename, 0, XML_C14N_1_0, "without-comments")); |
| 3821 | } |
| 3822 | static int |
| 3823 | c14nExcWithoutCommentTest(const char *filename, |
| 3824 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3825 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3826 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 3827 | return(c14nCommonTest(filename, 0, XML_C14N_EXCLUSIVE_1_0, "exc-without-comments")); |
| 3828 | } |
| 3829 | static int |
| 3830 | c14n11WithoutCommentTest(const char *filename, |
| 3831 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3832 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 3833 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 3834 | return(c14nCommonTest(filename, 0, XML_C14N_1_1, "1-1-without-comments")); |
| 3835 | } |
| 3836 | #endif |
| 3837 | #if defined(LIBXML_THREAD_ENABLED) && defined(LIBXML_CATALOG_ENABLED) && defined (LIBXML_SAX1_ENABLED) |
| 3838 | |
| 3839 | |
| 3840 | |
| 3841 | |
| 3842 | |
| 3843 | |
| 3844 | |
| 3845 | |
| 3846 | |
| 3847 | #define MAX_ARGC20 20 |
| 3848 | |
| 3849 | static const char *catalog = "test/threads/complex.xml"; |
| 3850 | static const char *testfiles[] = { |
| 3851 | "test/threads/abc.xml", |
| 3852 | "test/threads/acb.xml", |
| 3853 | "test/threads/bac.xml", |
| 3854 | "test/threads/bca.xml", |
| 3855 | "test/threads/cab.xml", |
| 3856 | "test/threads/cba.xml", |
| 3857 | "test/threads/invalid.xml", |
| 3858 | }; |
| 3859 | |
| 3860 | static const char *Okay = "OK"; |
| 3861 | static const char *Failed = "Failed"; |
| 3862 | |
| 3863 | #ifndef xmlDoValidityCheckingDefaultValue(*(__xmlDoValidityCheckingDefaultValue())) |
| 3864 | #error xmlDoValidityCheckingDefaultValue(*(__xmlDoValidityCheckingDefaultValue())) is not a macro |
| 3865 | #endif |
| 3866 | #ifndef xmlGenericErrorContext(*(__xmlGenericErrorContext())) |
| 3867 | #error xmlGenericErrorContext(*(__xmlGenericErrorContext())) is not a macro |
| 3868 | #endif |
| 3869 | |
| 3870 | static void * |
| 3871 | thread_specific_data(void *private_data) |
| 3872 | { |
| 3873 | xmlDocPtr myDoc; |
| 3874 | const char *filename = (const char *) private_data; |
| 3875 | int okay = 1; |
| 3876 | |
| 3877 | if (!strcmp(filename, "test/threads/invalid.xml")) { |
| 3878 | xmlDoValidityCheckingDefaultValue(*(__xmlDoValidityCheckingDefaultValue())) = 0; |
| 3879 | xmlGenericErrorContext(*(__xmlGenericErrorContext())) = stdoutstdout; |
| 3880 | } else { |
| 3881 | xmlDoValidityCheckingDefaultValue(*(__xmlDoValidityCheckingDefaultValue())) = 1; |
| 3882 | xmlGenericErrorContext(*(__xmlGenericErrorContext())) = stderrstderr; |
| 3883 | } |
| 3884 | myDoc = xmlParseFile(filename); |
| 3885 | if (myDoc) { |
| 3886 | xmlFreeDoc(myDoc); |
| 3887 | } else { |
| 3888 | printf("parse failed\n"); |
| 3889 | okay = 0; |
| 3890 | } |
| 3891 | if (!strcmp(filename, "test/threads/invalid.xml")) { |
| 3892 | if (xmlDoValidityCheckingDefaultValue(*(__xmlDoValidityCheckingDefaultValue())) != 0) { |
| 3893 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 3894 | okay = 0; |
| 3895 | } |
| 3896 | if (xmlGenericErrorContext(*(__xmlGenericErrorContext())) != stdoutstdout) { |
| 3897 | printf("xmlGenericErrorContext override failed\n"); |
| 3898 | okay = 0; |
| 3899 | } |
| 3900 | } else { |
| 3901 | if (xmlDoValidityCheckingDefaultValue(*(__xmlDoValidityCheckingDefaultValue())) != 1) { |
| 3902 | printf("ValidityCheckingDefaultValue override failed\n"); |
| 3903 | okay = 0; |
| 3904 | } |
| 3905 | if (xmlGenericErrorContext(*(__xmlGenericErrorContext())) != stderrstderr) { |
| 3906 | printf("xmlGenericErrorContext override failed\n"); |
| 3907 | okay = 0; |
| 3908 | } |
| 3909 | } |
| 3910 | if (okay == 0) |
| 3911 | return ((void *) Failed); |
| 3912 | return ((void *) Okay); |
| 3913 | } |
| 3914 | |
| 3915 | #if defined(linux1) || defined(__sun) || defined(__APPLE_CC__) |
| 3916 | |
| 3917 | #include <pthread.h> |
| 3918 | |
| 3919 | static pthread_t tid[MAX_ARGC20]; |
| 3920 | |
| 3921 | static int |
| 3922 | testThread(void) |
| 3923 | { |
| 3924 | unsigned int i, repeat; |
| 3925 | unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); |
| 3926 | void *results[MAX_ARGC20]; |
| 3927 | int ret; |
| 3928 | int res = 0; |
| 3929 | |
| 3930 | xmlInitParser(); |
| 3931 | |
| 3932 | for (repeat = 0; repeat < 500; repeat++) { |
| 3933 | xmlLoadCatalog(catalog); |
| 3934 | nb_tests++; |
| 3935 | |
| 3936 | for (i = 0; i < num_threads; i++) { |
| 3937 | results[i] = NULL((void*)0); |
| 3938 | tid[i] = (pthread_t) - 1; |
| 3939 | } |
| 3940 | |
| 3941 | for (i = 0; i < num_threads; i++) { |
| 3942 | ret = pthread_create(&tid[i], 0, thread_specific_data, |
| 3943 | (void *) testfiles[i]); |
| 3944 | if (ret != 0) { |
| 3945 | fprintf(stderrstderr, "pthread_create failed\n"); |
| 3946 | return (1); |
| 3947 | } |
| 3948 | } |
| 3949 | for (i = 0; i < num_threads; i++) { |
| 3950 | ret = pthread_join(tid[i], &results[i]); |
| 3951 | if (ret != 0) { |
| 3952 | fprintf(stderrstderr, "pthread_join failed\n"); |
| 3953 | return (1); |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | xmlCatalogCleanup(); |
| 3958 | for (i = 0; i < num_threads; i++) |
| 3959 | if (results[i] != (void *) Okay) { |
| 3960 | fprintf(stderrstderr, "Thread %d handling %s failed\n", |
| 3961 | i, testfiles[i]); |
| 3962 | res = 1; |
| 3963 | } |
| 3964 | } |
| 3965 | return (res); |
| 3966 | } |
| 3967 | |
| 3968 | #elif defined WIN32 |
| 3969 | #include <windows.h> |
| 3970 | #include <string.h> |
| 3971 | |
| 3972 | #define TEST_REPEAT_COUNT 500 |
| 3973 | |
| 3974 | static HANDLE tid[MAX_ARGC20]; |
| 3975 | |
| 3976 | static DWORD WINAPI |
| 3977 | win32_thread_specific_data(void *private_data) |
| 3978 | { |
| 3979 | return((DWORD) thread_specific_data(private_data)); |
| 3980 | } |
| 3981 | |
| 3982 | static int |
| 3983 | testThread(void) |
| 3984 | { |
| 3985 | unsigned int i, repeat; |
| 3986 | unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); |
| 3987 | DWORD results[MAX_ARGC20]; |
| 3988 | BOOL ret; |
| 3989 | int res = 0; |
| 3990 | |
| 3991 | xmlInitParser(); |
| 3992 | for (repeat = 0; repeat < TEST_REPEAT_COUNT; repeat++) { |
| 3993 | xmlLoadCatalog(catalog); |
| 3994 | nb_tests++; |
| 3995 | |
| 3996 | for (i = 0; i < num_threads; i++) { |
| 3997 | results[i] = 0; |
| 3998 | tid[i] = (HANDLE) - 1; |
| 3999 | } |
| 4000 | |
| 4001 | for (i = 0; i < num_threads; i++) { |
| 4002 | DWORD useless; |
| 4003 | |
| 4004 | tid[i] = CreateThread(NULL((void*)0), 0, |
| 4005 | win32_thread_specific_data, |
| 4006 | (void *) testfiles[i], 0, |
| 4007 | &useless); |
| 4008 | if (tid[i] == NULL((void*)0)) { |
| 4009 | fprintf(stderrstderr, "CreateThread failed\n"); |
| 4010 | return(1); |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | if (WaitForMultipleObjects(num_threads, tid, TRUE, INFINITE) == |
| 4015 | WAIT_FAILED) { |
| 4016 | fprintf(stderrstderr, "WaitForMultipleObjects failed\n"); |
| 4017 | return(1); |
| 4018 | } |
| 4019 | |
| 4020 | for (i = 0; i < num_threads; i++) { |
| 4021 | ret = GetExitCodeThread(tid[i], &results[i]); |
| 4022 | if (ret == 0) { |
| 4023 | fprintf(stderrstderr, "GetExitCodeThread failed\n"); |
| 4024 | return(1); |
| 4025 | } |
| 4026 | CloseHandle(tid[i]); |
| 4027 | } |
| 4028 | |
| 4029 | xmlCatalogCleanup(); |
| 4030 | for (i = 0; i < num_threads; i++) { |
| 4031 | if (results[i] != (DWORD) Okay) { |
| 4032 | fprintf(stderrstderr, "Thread %d handling %s failed\n", |
| 4033 | i, testfiles[i]); |
| 4034 | res = 1; |
| 4035 | } |
| 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | return (res); |
| 4040 | } |
| 4041 | |
| 4042 | #elif defined __BEOS__ |
| 4043 | #include <OS.h> |
| 4044 | |
| 4045 | static thread_id tid[MAX_ARGC20]; |
| 4046 | |
| 4047 | static int |
| 4048 | testThread(void) |
| 4049 | { |
| 4050 | unsigned int i, repeat; |
| 4051 | unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]); |
| 4052 | void *results[MAX_ARGC20]; |
| 4053 | status_t ret; |
| 4054 | int res = 0; |
| 4055 | |
| 4056 | xmlInitParser(); |
| 4057 | for (repeat = 0; repeat < 500; repeat++) { |
| 4058 | xmlLoadCatalog(catalog); |
| 4059 | for (i = 0; i < num_threads; i++) { |
| 4060 | results[i] = NULL((void*)0); |
| 4061 | tid[i] = (thread_id) - 1; |
| 4062 | } |
| 4063 | for (i = 0; i < num_threads; i++) { |
| 4064 | tid[i] = |
| 4065 | spawn_thread(thread_specific_data, "xmlTestThread", |
| 4066 | B_NORMAL_PRIORITY, (void *) testfiles[i]); |
| 4067 | if (tid[i] < B_OK) { |
| 4068 | fprintf(stderrstderr, "beos_thread_create failed\n"); |
| 4069 | return (1); |
| 4070 | } |
| 4071 | printf("beos_thread_create %d -> %d\n", i, tid[i]); |
| 4072 | } |
| 4073 | for (i = 0; i < num_threads; i++) { |
| 4074 | ret = wait_for_thread(tid[i], &results[i]); |
| 4075 | printf("beos_thread_wait %d -> %d\n", i, ret); |
| 4076 | if (ret != B_OK) { |
| 4077 | fprintf(stderrstderr, "beos_thread_wait failed\n"); |
| 4078 | return (1); |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | xmlCatalogCleanup(); |
| 4083 | ret = B_OK; |
| 4084 | for (i = 0; i < num_threads; i++) |
| 4085 | if (results[i] != (void *) Okay) { |
| 4086 | printf("Thread %d handling %s failed\n", i, testfiles[i]); |
| 4087 | ret = B_ERROR; |
| 4088 | } |
| 4089 | } |
| 4090 | if (ret != B_OK) |
| 4091 | return(1); |
| 4092 | return (0); |
| 4093 | } |
| 4094 | #else |
| 4095 | static int |
| 4096 | testThread(void) |
| 4097 | { |
| 4098 | fprintf(stderrstderr, |
| 4099 | "Specific platform thread support not detected\n"); |
| 4100 | return (-1); |
| 4101 | } |
| 4102 | #endif |
| 4103 | static int |
| 4104 | threadsTest(const char *filename ATTRIBUTE_UNUSED__attribute__((unused)), |
| 4105 | const char *resul ATTRIBUTE_UNUSED__attribute__((unused)), |
| 4106 | const char *err ATTRIBUTE_UNUSED__attribute__((unused)), |
| 4107 | int options ATTRIBUTE_UNUSED__attribute__((unused))) { |
| 4108 | return(testThread()); |
| 4109 | } |
| 4110 | #endif |
| 4111 | |
| 4112 | |
| 4113 | |
| 4114 | |
| 4115 | |
| 4116 | |
| 4117 | static |
| 4118 | testDesc testDescriptions[] = { |
| 4119 | { "XML regression tests" , |
| 4120 | oldParseTest, "./test/*", "result/", "", NULL((void*)0), |
| 4121 | 0 }, |
| 4122 | { "XML regression tests on memory" , |
| 4123 | memParseTest, "./test/*", "result/", "", NULL((void*)0), |
| 4124 | 0 }, |
| 4125 | { "XML entity subst regression tests" , |
| 4126 | noentParseTest, "./test/*", "result/noent/", "", NULL((void*)0), |
| 4127 | XML_PARSE_NOENT }, |
| 4128 | { "XML Namespaces regression tests", |
| 4129 | errParseTest, "./test/namespaces/*", "result/namespaces/", "", ".err", |
| 4130 | 0 }, |
| 4131 | { "Error cases regression tests", |
| 4132 | errParseTest, "./test/errors/*.xml", "result/errors/", "", ".err", |
| 4133 | 0 }, |
| 4134 | #ifdef LIBXML_READER_ENABLED |
| 4135 | { "Error cases stream regression tests", |
| 4136 | streamParseTest, "./test/errors/*.xml", "result/errors/", NULL((void*)0), ".str", |
| 4137 | 0 }, |
| 4138 | { "Reader regression tests", |
| 4139 | streamParseTest, "./test/*", "result/", ".rdr", NULL((void*)0), |
| 4140 | 0 }, |
| 4141 | { "Reader entities substitution regression tests", |
| 4142 | streamParseTest, "./test/*", "result/", ".rde", NULL((void*)0), |
| 4143 | XML_PARSE_NOENT }, |
| 4144 | { "Reader on memory regression tests", |
| 4145 | streamMemParseTest, |