! * \brief regTestCheckFile() * * \param[in] rp regtest parameters * \param[in] localname name of output file from reg test * \return 0 if OK, 1 on error a failure in comparison is not an error * * * Notes: * (1) This function does one of three things, depending on the mode: * * "generate": makes a "golden" file as a copy %localname. * *
| 501 | * </pre> |
| 502 | */ |
| 503 | l_int32 |
| 504 | regTestCheckFile(L_REGPARAMS *rp, |
| 505 | const char *localname) |
| 506 | { |
| 507 | char *ext; |
| 508 | char namebuf[256]; |
| 509 | l_int32 ret, same, format; |
| 510 | PIX *pix1, *pix2; |
| 511 | |
| 512 | PROCNAME("regTestCheckFile"); |
| 513 | |
| 514 | if (!rp) |
| 515 | return ERROR_INT("rp not defined", procName, 1); |
| 516 | if (!localname) { |
| 517 | rp->success = FALSE; |
| 518 | return ERROR_INT("local name not defined", procName, 1); |
| 519 | } |
| 520 | if (rp->mode != L_REG_GENERATE && rp->mode != L_REG_COMPARE && |
| 521 | rp->mode != L_REG_DISPLAY) { |
| 522 | rp->success = FALSE; |
| 523 | return ERROR_INT("invalid mode", procName, 1); |
| 524 | } |
| 525 | rp->index++; |
| 526 | |
| 527 | /* If display mode, no generation and no testing */ |
| 528 | if (rp->mode == L_REG_DISPLAY) return 0; |
| 529 | |
| 530 | /* Generate the golden file name; used in 'generate' and 'compare' */ |
| 531 | splitPathAtExtension(localname, NULL, &ext); |
| 532 | snprintf(namebuf, sizeof(namebuf), "/tmp/lept/golden/%s_golden.%02d%s", |
| 533 | rp->testname, rp->index, ext); |
| 534 | LEPT_FREE(ext); |
| 535 | |
| 536 | /* Generate mode. No testing. */ |
| 537 | if (rp->mode == L_REG_GENERATE) { |
| 538 | /* Save the file as a golden file */ |
| 539 | ret = fileCopy(localname, namebuf); |
| 540 | #if 0 /* Enable for details on writing of golden files */ |
| 541 | if (!ret) { |
| 542 | char *local = genPathname(localname, NULL); |
| 543 | char *golden = genPathname(namebuf, NULL); |
| 544 | L_INFO("Copy: %s to %s\n", procName, local, golden); |
| 545 | LEPT_FREE(local); |
| 546 | LEPT_FREE(golden); |
| 547 | } |
| 548 | #endif |
| 549 | return ret; |
| 550 | } |
| 551 | |
| 552 | /* Compare mode: test and record on failure. This can be used |
| 553 | * for all image formats, as well as for all files of serialized |
| 554 | * data, such as boxa, pta, etc. In all cases except for |
| 555 | * GIF compressed images, we compare the files to see if they |
| 556 | * are identical. GIF doesn't support RGB images; to write |
| 557 | * a 32 bpp RGB image in GIF, we do a lossy quantization to |
| 558 | * 256 colors, so the cycle read-RGB/write-GIF is not idempotent. |
| 559 | * And although the read/write cycle for GIF images with bpp <= 8 |
| 560 | * is idempotent in the image pixels, it is not idempotent in the |
no test coverage detected