MCPcopy Create free account
hub / github.com/creatale/node-dv / regTestCheckFile

Function regTestCheckFile

deps/leptonica/src/regutils.c:503–589  ·  view source on GitHub ↗

! * \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. * *

Source from the content-addressed store, hash-verified

501 * </pre>
502 */
503l_int32
504regTestCheckFile(L_REGPARAMS *rp,
505 const char *localname)
506{
507char *ext;
508char namebuf[256];
509l_int32 ret, same, format;
510PIX *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

Callers 2

regTestWritePixAndCheckFunction · 0.85
regTestWriteDataAndCheckFunction · 0.85

Calls 8

splitPathAtExtensionFunction · 0.85
fileCopyFunction · 0.85
genPathnameFunction · 0.85
findFileFormatFunction · 0.85
pixReadFunction · 0.85
pixEqualFunction · 0.85
pixDestroyFunction · 0.85
filesAreIdenticalFunction · 0.85

Tested by

no test coverage detected