69 #include <config_auto.h>
73 #include "allheaders.h"
75 extern l_int32 NumImageFileFormatExtensions;
76 extern const char *ImageFileFormatExtensions[];
127 char *testname, *vers;
131 if (argc != 1 && argc != 2) {
132 snprintf(errormsg,
sizeof(errormsg),
133 "Syntax: %s [ [compare] | generate | display ]", argv[0]);
134 return ERROR_INT(errormsg, __func__, 1);
138 return ERROR_INT(
"invalid root", __func__, 1);
155 if (argc == 1 || !strcmp(argv[1],
"compare")) {
156 rp->
mode = L_REG_COMPARE;
159 if (rp->
fp == NULL) {
161 return ERROR_INT(
"stream not opened for tempfile", __func__, 1);
163 }
else if (!strcmp(argv[1],
"generate")) {
164 rp->
mode = L_REG_GENERATE;
166 }
else if (!strcmp(argv[1],
"display")) {
167 rp->
mode = L_REG_DISPLAY;
171 snprintf(errormsg,
sizeof(errormsg),
172 "Syntax: %s [ [generate] | compare | display ]", argv[0]);
173 return ERROR_INT(errormsg, __func__, 1);
178 lept_stderr(
"\n////////////////////////////////////////////////\n"
179 "//////////////// %s_reg ///////////////\n"
180 "////////////////////////////////////////////////\n",
211 char *text, *message;
216 return ERROR_INT(
"rp not defined", __func__, 1);
236 return ERROR_INT(
"text not returned", __func__, 1);
241 snprintf(result,
sizeof(result),
"SUCCESS: %s_reg\n", rp->
testname);
243 snprintf(result,
sizeof(result),
"FAILURE: %s_reg\n", rp->
testname);
246 results_file =
stringNew(
"/tmp/lept/reg_results.txt");
248 retval = (rp->
success) ? 0 : 1;
249 LEPT_FREE(results_file);
277 return ERROR_INT(
"rp not defined", __func__, 1);
280 diff = L_ABS(val2 - val1);
286 "Failure in %s_reg: value comparison for index %d\n"
287 "difference = %f but allowed delta = %f\n",
290 lept_stderr(
"Failure in %s_reg: value comparison for index %d\n"
291 "difference = %f but allowed delta = %f\n",
321 return ERROR_INT(
"rp not defined", __func__, 1);
329 snprintf(buf,
sizeof(buf),
"/tmp/lept/regout/string1_%d_%zu",
332 snprintf(buf,
sizeof(buf),
"/tmp/lept/regout/string2_%d_%zu",
337 snprintf(buf,
sizeof(buf),
"/tmp/lept/regout/string*_%d_*", rp->
index);
340 "Failure in %s_reg: string comp for index %d; "
343 lept_stderr(
"Failure in %s_reg: string comp for index %d; "
373 return ERROR_INT(
"rp not defined", __func__, 1);
374 if (!pix1 || !pix2) {
376 return ERROR_INT(
"pix1 and pix2 not both defined", __func__, 1);
385 fprintf(rp->
fp,
"Failure in %s_reg: pix comparison for index %d\n",
388 lept_stderr(
"Failure in %s_reg: pix comparison for index %d\n",
431 l_int32 w, h, factor, similar;
434 return ERROR_INT(
"rp not defined", __func__, 1);
435 if (!pix1 || !pix2) {
437 return ERROR_INT(
"pix1 and pix2 not both defined", __func__, 1);
442 factor = L_MAX(w, h) / 400;
443 factor = L_MAX(1, L_MIN(factor, 4));
445 &similar, printstats);
451 "Failure in %s_reg: pix similarity comp for index %d\n",
454 lept_stderr(
"Failure in %s_reg: pix similarity comp for index %d\n",
490 const char *localname)
494 l_int32 ret, same, format;
498 return ERROR_INT(
"rp not defined", __func__, 1);
501 return ERROR_INT(
"local name not defined", __func__, 1);
503 if (rp->
mode != L_REG_GENERATE && rp->
mode != L_REG_COMPARE &&
504 rp->
mode != L_REG_DISPLAY) {
506 return ERROR_INT(
"invalid mode", __func__, 1);
511 if (rp->
mode == L_REG_DISPLAY)
return 0;
515 snprintf(namebuf,
sizeof(namebuf),
"/tmp/lept/golden/%s_golden.%02d%s",
520 if (rp->
mode == L_REG_GENERATE) {
527 L_INFO(
"Copy: %s to %s\n", __func__, local, golden);
553 if (format == IFF_GIF) {
564 fprintf(rp->
fp,
"Failure in %s_reg, index %d: comparing %s with %s\n",
566 lept_stderr(
"Failure in %s_reg, index %d: comparing %s with %s\n",
605 return ERROR_INT(
"rp not defined", __func__, 1);
606 if (index1 < 0 || index2 < 0) {
608 return ERROR_INT(
"index1 and/or index2 is negative", __func__, 1);
610 if (index1 == index2) {
612 return ERROR_INT(
"index1 must differ from index2", __func__, 1);
616 if (rp->
mode != L_REG_COMPARE)
return 0;
619 snprintf(namebuf,
sizeof(namebuf),
"%s_golden.%02d", rp->
testname, index1);
624 L_ERROR(
"golden file %s not found\n", __func__, namebuf);
630 snprintf(namebuf,
sizeof(namebuf),
"%s_golden.%02d", rp->
testname, index2);
636 L_ERROR(
"golden file %s not found\n", __func__, namebuf);
646 "Failure in %s_reg, index %d: comparing %s with %s\n",
648 lept_stderr(
"Failure in %s_reg, index %d: comparing %s with %s\n",
693 return ERROR_INT(
"rp not defined", __func__, 1);
696 return ERROR_INT(
"pix not defined", __func__, 1);
698 if (format < 0 || format >= NumImageFileFormatExtensions) {
700 return ERROR_INT(
"invalid format", __func__, 1);
705 changeFormatForMissingLib(&format);
708 snprintf(namebuf,
sizeof(namebuf),
"/tmp/lept/regout/%s.%02d.%s",
709 rp->
testname, rp->
index + 1, ImageFileFormatExtensions[format]);
712 if (pixGetDepth(pix) < 8)
714 pixWrite(namebuf, pix, format);
763 return ERROR_INT(
"rp not defined", __func__, 1);
764 if (!data || nbytes == 0) {
766 return ERROR_INT(
"data not defined or size == 0", __func__, 1);
770 snprintf(namebuf,
sizeof(namebuf),
"/tmp/lept/regout/%s.%02d.%s",
812 return (
char *)ERROR_PTR(
"rp not defined", __func__, NULL);
814 ind = (index >= 0) ? index : rp->
index;
815 snprintf(buf,
sizeof(buf),
"/tmp/lept/regout/%s.%02d.%s",
816 rp->
testname, ind, ImageFileFormatExtensions[format]);
844 if ((len = strlen(root)) <= 4) {
846 return (
char *)ERROR_PTR(
"invalid argv0; too small", __func__, NULL);
862 if (strstr(root,
".exe") != NULL)
864 if (strstr(root,
"_reg") == root + len - 4)
l_ok pixEqual(PIX *pix1, PIX *pix2, l_int32 *psame)
pixEqual()
l_ok pixTestForSimilarity(PIX *pix1, PIX *pix2, l_int32 factor, l_int32 mindiff, l_float32 maxfract, l_float32 maxave, l_int32 *psimilar, l_int32 details)
pixTestForSimilarity()
char * getImagelibVersions(void)
getImagelibVersions()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
l_ok pixSetPadBits(PIX *pix, l_int32 val)
pixSetPadBits()
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
PIX * pixRead(const char *filename)
pixRead()
l_ok regTestSetup(l_int32 argc, char **argv, L_REGPARAMS **prp)
regTestSetup()
l_ok regTestCompareSimilarPix(L_REGPARAMS *rp, PIX *pix1, PIX *pix2, l_int32 mindiff, l_float32 maxfract, l_int32 printstats)
regTestCompareSimilarPix()
l_ok regTestCompareFiles(L_REGPARAMS *rp, l_int32 index1, l_int32 index2)
regTestCompareFiles()
l_ok regTestCompareStrings(L_REGPARAMS *rp, l_uint8 *string1, size_t bytes1, l_uint8 *string2, size_t bytes2)
regTestCompareStrings()
l_ok regTestWritePixAndCheck(L_REGPARAMS *rp, PIX *pix, l_int32 format)
regTestWritePixAndCheck()
static char * getRootNameFromArgv0(const char *argv0)
getRootNameFromArgv0()
l_ok regTestCheckFile(L_REGPARAMS *rp, const char *localname)
regTestCheckFile()
l_ok regTestComparePix(L_REGPARAMS *rp, PIX *pix1, PIX *pix2)
regTestComparePix()
char * regTestGenLocalFilename(L_REGPARAMS *rp, l_int32 index, l_int32 format)
regTestGenLocalFilename()
l_ok regTestCompareValues(L_REGPARAMS *rp, l_float32 val1, l_float32 val2, l_float32 delta)
regTestCompareValues()
l_ok regTestCleanup(L_REGPARAMS *rp)
regTestCleanup()
l_ok regTestWriteDataAndCheck(L_REGPARAMS *rp, void *data, size_t nbytes, const char *ext)
regTestWriteDataAndCheck()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * getSortedPathnamesInDirectory(const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
getSortedPathnamesInDirectory()
l_ok filesAreIdentical(const char *fname1, const char *fname2, l_int32 *psame)
filesAreIdentical()
void lept_stderr(const char *fmt,...)
lept_stderr()
L_TIMER startTimerNested(void)
startTimerNested(), stopTimerNested()
char * getLeptonicaVersion(void)
getLeptonicaVersion()
char * stringNew(const char *src)
stringNew()
l_ok fileAppendString(const char *filename, const char *str)
fileAppendString()
l_ok splitPathAtExtension(const char *pathname, char **pbasename, char **pextension)
splitPathAtExtension()
l_ok l_binaryCompare(const l_uint8 *data1, size_t size1, const l_uint8 *data2, size_t size2, l_int32 *psame)
l_binaryCompare()
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
l_int32 stringFindSubstr(const char *src, const char *sub, l_int32 *ploc)
stringFindSubstr()
char * genPathname(const char *dir, const char *fname)
genPathname()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
char * stringJoin(const char *src1, const char *src2)
stringJoin()
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
l_ok fileCopy(const char *srcfile, const char *newfile)
fileCopy()