Leptonica 1.68
C Image Processing Library

regutils.c File Reference

Regression test utilities. More...

#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static char * getRootNameFromArgv0 (const char *argv0)
l_int32 regTestSetup (l_int32 argc, char **argv, L_REGPARAMS **prp)
l_int32 regTestCleanup (L_REGPARAMS *rp)
l_int32 regTestComparePix (L_REGPARAMS *rp, PIX *pix1, PIX *pix2)
l_int32 regTestCompareSimilarPix (L_REGPARAMS *rp, PIX *pix1, PIX *pix2, l_int32 mindiff, l_float32 maxfract, l_int32 printstats)
l_int32 regTestCheckFile (L_REGPARAMS *rp, const char *localname)
l_int32 regTestCompareFiles (L_REGPARAMS *rp, l_int32 index1, l_int32 index2)
l_int32 regTestWritePixAndCheck (L_REGPARAMS *rp, PIX *pix, l_int32 format)

Variables

l_int32 NumImageFileFormatExtensions
const char * ImageFileFormatExtensions []

Detailed Description


Function Documentation

static char * getRootNameFromArgv0 ( const char *  argv0) [static]

getRootNameFromArgv0()

Input: argv0 Return: root name (without the '_reg'), or null on error

Notes: (1) For example, from psioseg_reg, we want to extract just 'psioseg' as the root. (2) In unix with autotools, the executable is not X, but ./.libs/lt-X. So in addition to stripping out the last 4 characters of the tail, we have to check for the '-' and strip out the "lt-" prefix if we find it.

Definition at line 545 of file regutils.c.

References ERROR_PTR, FREE, NULL, PROCNAME, splitPathAtDirectory(), stringFindSubstr(), and stringNew().

Referenced by regTestSetup().

l_int32 regTestSetup ( l_int32  argc,
char **  argv,
L_REGPARAMS **  prp 
)

regTestSetup()

Input: argc (from invocation; can be either 1 or 2) argv (to regtest: [1] is one of these: "generate", "compare", "display") &rp (<return> all regression params) Return: 0 if OK, 1 on error

Notes: (1) Call this function with the args to the reg test. There are three cases: Case 1: The second arg is "generate". This will cause generation of new golden files for the reg test. The results of the reg test are not recorded, and the display field is set to FALSE, preventing image display. Case 2: The second arg is "compare". This is the mode in which you run a regression test (or a set of them), looking for failures and logging the results to a file. The output, which includes logging of all reg test failures plus a SUCCESS or FAILURE summary for each test, is appended to the file "/tmp/reg_results.txt. For this case, as in Case 1, the display field in rp is set to FALSE. Case 3: There is either only arg, or the second arg is "display". The test will run and files will be written. Comparisons with golden files will not be carried out, so the only notion of success or failure is with tests that do not involve golden files. The display field in rp is TRUE, and this is used by pixDisplayWithTitle(). (2) See regutils.h for examples of usage.

Definition at line 81 of file regutils.c.

References CALLOC, L_RegParams::display, ERROR_INT, FALSE, fopenWriteStream(), L_RegParams::fp, FREE, genTempFilename(), getImagelibVersions(), getLeptonicaVersion(), getRootNameFromArgv0(), L_RegParams::index, L_REG_COMPARE, L_REG_DISPLAY, L_REG_GENERATE, lept_mkdir(), L_RegParams::mode, NULL, PROCNAME, startTimerNested(), L_RegParams::success, L_RegParams::tempfile, L_RegParams::testname, TRUE, and L_RegParams::tstart.

Referenced by main().

l_int32 regTestCleanup ( L_REGPARAMS rp)

regTestCleanup()

Input: rp (regression test parameters) Return: 0 if OK, 1 on error

Notes: (1) This copies anything written to the temporary file to the output file /tmp/reg_results.txt.

Definition at line 162 of file regutils.c.

References ERROR_INT, FALSE, fileAppendString(), L_RegParams::fp, FREE, genPathname(), l_binaryRead(), PROCNAME, stopTimerNested(), stringJoin(), L_RegParams::success, L_RegParams::tempfile, L_RegParams::testname, and L_RegParams::tstart.

Referenced by main().

l_int32 regTestComparePix ( L_REGPARAMS rp,
PIX pix1,
PIX pix2 
)

regTestComparePix()

Input: rp (regtest parameters) pix1, pix2 (to be tested for equality) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This function compares two pix for equality. If not in compare mode, on failure it writes to stderr.

Definition at line 225 of file regutils.c.

References ERROR_INT, FALSE, L_RegParams::fp, L_RegParams::index, pixEqual(), PROCNAME, L_RegParams::success, and L_RegParams::testname.

Referenced by main(), PixTest3(), and RotateOrthTest().

l_int32 regTestCompareSimilarPix ( L_REGPARAMS rp,
PIX pix1,
PIX pix2,
l_int32  mindiff,
l_float32  maxfract,
l_int32  printstats 
)

regTestCompareSimilarPix()

Input: rp (regtest parameters) pix1, pix2 (to be tested for equality) mindiff (minimum pixel difference to be counted; > 0) maxfract (maximum fraction of pixels allowed to have diff greater than or equal to mindiff) printstats (use 1 to print normalized histogram to stderr) Return: 0 if OK, 1 on error (a failure in similarity comparison is not an error)

Notes: (1) This function compares two pix for equality. If not in compare mode, on failure it writes to stderr. (2) To identify two images as 'similar', select to be the upper bound for what you expect. Typical values might be = 15 and = 0.01. (3) Normally, use = 0. In debugging mode, to see the relation between and the minimum value of for success, set this to 1.

Definition at line 280 of file regutils.c.

References ERROR_INT, FALSE, L_RegParams::fp, L_RegParams::index, L_MAX, L_MIN, NULL, pixGetDimensions(), pixTestForSimilarity(), PROCNAME, L_RegParams::success, and L_RegParams::testname.

Referenced by main().

l_int32 regTestCheckFile ( L_REGPARAMS rp,
const char *  localname 
)

regTestCheckFile()

Input: rp (regtest parameters) 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 . * "compare": compares contents with the golden file * "display": makes the file but does no comparison (2) The canonical format of the golden filenames is: /tmp/golden/<root of="" main="" name>="">_golden.<index>.<ext of="" localname>=""> e.g., /tmp/golden/maze_golden.0.png It is important to add an extension to the local name, because the extension is added to the name of the golden file.

Definition at line 340 of file regutils.c.

References ERROR_INT, FALSE, fileCopy(), filesAreIdentical(), L_RegParams::fp, FREE, L_RegParams::index, L_REG_COMPARE, L_REG_DISPLAY, L_REG_GENERATE, L_RegParams::mode, NULL, PROCNAME, splitPathAtExtension(), L_RegParams::success, and L_RegParams::testname.

Referenced by main(), and regTestWritePixAndCheck().

l_int32 regTestCompareFiles ( L_REGPARAMS rp,
l_int32  index1,
l_int32  index2 
)

regTestCompareFiles()

Input: rp (regtest parameters) index1 (of one output file from reg test) index2 (of another output file from reg test) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This only does something in "compare" mode. (2) The canonical format of the golden filenames is: /tmp/golden/<root of="" main="" name>="">_golden.<index>.<ext of="" localname>=""> e.g., /tmp/golden/maze_golden.0.png

Definition at line 409 of file regutils.c.

References ERROR_INT, FALSE, filesAreIdentical(), L_RegParams::fp, FREE, getSortedPathnamesInDirectory(), L_RegParams::index, L_COPY, L_ERROR_STRING, L_REG_COMPARE, L_RegParams::mode, PROCNAME, sarrayDestroy(), sarrayGetCount(), sarrayGetString(), L_RegParams::success, and L_RegParams::testname.

Referenced by main(), and TestProjection().

l_int32 regTestWritePixAndCheck ( L_REGPARAMS rp,
PIX pix,
l_int32  format 
)

regTestWritePixAndCheck()

Input: rp (regtest parameters) pix (to be written) format (of output pix) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This function makes it easy to write the pix in a numbered sequence of files, and either to: (a) write the golden file ("generate" arg to regression test) (b) make a local file and "compare" with the golden file (c) make a local file and "display" the results (3) The canonical format of the local filename is: /tmp/<root of="" main="" name>="">.<count>.<format extension="" string>=""> e.g., for scale_reg, /tmp/scale.0.png

Definition at line 496 of file regutils.c.

References ERROR_INT, FALSE, ImageFileFormatExtensions, L_RegParams::index, NumImageFileFormatExtensions, pixWrite(), PROCNAME, regTestCheckFile(), L_RegParams::success, and L_RegParams::testname.

Referenced by GeneratePattern(), main(), PixaSaveDisplay(), PixSave32(), PixTest1(), PixTest2(), RotateTest(), test_gif(), TestDistance(), TestHardlight(), and TestProjection().


Variable Documentation

Definition at line 79 of file writefile.c.

Definition at line 80 of file writefile.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines