Leptonica 1.68
C Image Processing Library

regutils.h

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 #ifndef  LEPTONICA_REGUTILS_H
00017 #define  LEPTONICA_REGUTILS_H
00018 
00019 /*
00020  *   regutils.h
00021  *
00022  *   Contains this regression test parameter packaging struct
00023  *       struct L_RegParams
00024  *
00025  *
00026  *   The regression test utility allows you to write regression tests
00027  *   that compare results with existing "golden files".
00028  *
00029  *   Such regression tests can be called in three ways.
00030  *   For example, for distance_reg:
00031  *
00032  *       Case 1: distance_reg generate
00033  *           This generates golden files in /tmp for the reg test.
00034  *
00035  *       Case 2: distance_reg compare
00036  *           This runs the test against the set of golden files.  It
00037  *           appends to 'outfile.txt' either "SUCCESS" or "FAILURE",
00038  *           as well as the details of any parts of the test that failed.
00039  *           It writes to a temporary file stream (fp)
00040  *
00041  *       Case 3: distance_reg [display]
00042  *           This runs the test but makes no comparison of the output
00043  *           against the set of golden files.  In addition, this displays
00044  *           images and plots that are specified in the test under
00045  *           control of the display variable.  Display is enabled only
00046  *           for this case.  Using 'display' on the command line is optional.
00047  *
00048  *   Regression tests follow the pattern given below.  In an actual
00049  *   case, comparisons of pix and of files can occur in any order.
00050  *   We give a specific order here for clarity.
00051  *
00052  *       L_REGPARAMS  *rp;  // holds data required by the test functions
00053  *
00054  *       // Setup variables; optionally open stream
00055  *       if (regTestSetup(argc, argv, &rp))
00056  *           return 1;
00057  *
00058  *       // Test pairs of generated pix for identity.  This compares
00059  *       // two pix; no golden file is generated.
00060  *       regTestComparePix(rp, pix1, pix2);
00061  *
00062  *       // Test pairs of generated pix for similarity.  This compares
00063  *       // two pix; no golden file is generated.  The last arg determines
00064  *       // if stats are to be written to stderr.
00065  *       regTestCompareSimilarPix(rp, pix1, pix2, 15, 0.001, 0);
00066  *
00067  *       // Generation of <newfile*> outputs and testing for identity
00068  *       // These files can be anything, of course.
00069  *       regTestCheckFile(rp, <newfile0>);
00070  *       regTestCheckFile(rp, <newfile1>);
00071  *
00072  *       // Test pairs of output golden files for identity.  Here we
00073  *       // are comparing golden files 4 and 5.
00074  *       regTestCompareFiles(rp, 4, 5);
00075  *
00076  *       // "Write and check".  This writes a pix using a canonical
00077  *       // formulation for the local filename and either:
00078  *       //     case 1: generates a golden file
00079  *       //     case 2: compares the local file with a golden file
00080  *       //     case 3: generates local files and displays
00081  *       // Here we write the pix compressed with png and jpeg, respectively;
00082  *       // Then check against the golden file.  The internal @index
00083  *       // is incremented; it is embedded in the local filename and,
00084  *       // if generating, in the golden file as well.
00085  *       regTestWritePixAndCheck(rp, pix1, IFF_PNG);
00086  *       regTestWritePixAndCheck(rp, pix2, IFF_JFIF_JPEG);
00087  *
00088  *       // Display if reg test was called in 'display' mode
00089  *       pixDisplayWithTitle(pix1, 100, 100, NULL, rp->display);
00090  *
00091  *       // Clean up and output result
00092  *       regTestCleanup(rp);
00093  */
00094 
00095 
00096 /*-------------------------------------------------------------------------*
00097  *                     Regression test parameter packer                    *
00098  *-------------------------------------------------------------------------*/
00099 struct L_RegParams
00100 {
00101     FILE    *fp;        /* stream to temporary output file for compare mode */
00102     char    *testname;  /* name of test, without '_reg'                     */
00103     char    *tempfile;  /* name of temp file for compare mode output        */
00104     l_int32  mode;      /* generate, compare or display                     */
00105     l_int32  index;     /* index into saved files for this test; 0-based    */
00106     l_int32  success;   /* overall result of the test                       */
00107     l_int32  display;   /* 1 if in display mode; 0 otherwise                */
00108     L_TIMER  tstart;    /* marks beginning of the reg test                  */
00109 };
00110 typedef struct L_RegParams  L_REGPARAMS;
00111 
00112 
00113     /* Running modes for the test */
00114 enum {
00115     L_REG_GENERATE = 0,
00116     L_REG_COMPARE = 1,
00117     L_REG_DISPLAY = 2
00118 };
00119 
00120 
00121 #endif  /* LEPTONICA_REGUTILS_H */
00122 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines