* xpathExprTest: * @filename: the file to parse * @result: the file with expected result * @err: the file with error messages * * Parse a file containing XPath standalone expressions and evaluate them * * Returns 0 in case of success, an error code otherwise */
| 2586 | * Returns 0 in case of success, an error code otherwise |
| 2587 | */ |
| 2588 | static int |
| 2589 | xpathCommonTest(const char *filename, const char *result, |
| 2590 | int xptr, int expr) { |
| 2591 | FILE *input; |
| 2592 | char expression[5000]; |
| 2593 | int len, ret = 0; |
| 2594 | char *temp; |
| 2595 | |
| 2596 | temp = resultFilename(filename, temp_directory, ".res"); |
| 2597 | if (temp == NULL) { |
| 2598 | fprintf(stderr, "Out of memory\n"); |
| 2599 | fatalError(); |
| 2600 | } |
| 2601 | xpathOutput = fopen(temp, "wb"); |
| 2602 | if (xpathOutput == NULL) { |
| 2603 | fprintf(stderr, "failed to open output file %s\n", temp); |
| 2604 | free(temp); |
| 2605 | return(-1); |
| 2606 | } |
| 2607 | |
| 2608 | input = fopen(filename, "rb"); |
| 2609 | if (input == NULL) { |
| 2610 | fprintf(stderr, |
| 2611 | "Cannot open %s for reading\n", filename); |
| 2612 | free(temp); |
| 2613 | return(-1); |
| 2614 | } |
| 2615 | while (fgets(expression, 4500, input) != NULL) { |
| 2616 | len = strlen(expression); |
| 2617 | len--; |
| 2618 | while ((len >= 0) && |
| 2619 | ((expression[len] == '\n') || (expression[len] == '\t') || |
| 2620 | (expression[len] == '\r') || (expression[len] == ' '))) len--; |
| 2621 | expression[len + 1] = 0; |
| 2622 | if (len >= 0) { |
| 2623 | fprintf(xpathOutput, |
| 2624 | "\n========================\nExpression: %s\n", |
| 2625 | expression) ; |
| 2626 | testXPath(expression, xptr, expr); |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | fclose(input); |
| 2631 | fclose(xpathOutput); |
| 2632 | if (result != NULL) { |
| 2633 | ret = compareFiles(temp, result); |
| 2634 | if (ret) { |
| 2635 | fprintf(stderr, "Result for %s failed in %s\n", filename, result); |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | if (temp != NULL) { |
| 2640 | unlink(temp); |
| 2641 | free(temp); |
| 2642 | } |
| 2643 | return(ret); |
| 2644 | } |
| 2645 |
no test coverage detected