src/regutils.c
l_int32
regTestSetup(l_int32        argc,
             char         **argv,
             L_REGPARAMS  **prp)
{
char         *testname, *vers;
char          errormsg[64];
L_REGPARAMS  *rp;

    PROCNAME("regTestSetup");

    if (argc != 1 && argc != 2) {
        snprintf(errormsg, sizeof(errormsg),
            "Syntax: %s [generate | compare | [display]]", argv[0]);
        return ERROR_INT(errormsg, procName, 1);
    }

    if ((testname = getRootNameFromArgv0(argv[0])) == NULL)
        return ERROR_INT("invalid root", procName, 1);

    if ((rp = (L_REGPARAMS *)CALLOC(1, sizeof(L_REGPARAMS))) == NULL)
        return ERROR_INT("rp not made", procName, 1);
    *prp = rp;
    rp->testname = testname;
    rp->index = -1;  /* increment before each test */

        /* Initialize to true.  A failure in any test is registered
         * as a failure of the regression test. */
    rp->success = TRUE;

        /* Only open a stream to a temp file for the 'compare' case */
    if (argc == 1 || !strcmp(argv[1], "display")) {
        rp->mode = L_REG_DISPLAY;
        rp->display = TRUE;
    }
    else if (!strcmp(argv[1], "compare")) {
        rp->mode = L_REG_COMPARE;
        rp->tempfile = genTempFilename("/tmp", "regtest_output.txt", 0, 1);
        rp->fp = fopenWriteStream(rp->tempfile, "wb");
        if (rp->fp == NULL) {
            rp->success = FALSE;
            return ERROR_INT("stream not opened for tempfile", procName, 1);
        }
    }
    else if (!strcmp(argv[1], "generate")) {
        rp->mode = L_REG_GENERATE;
        lept_mkdir("golden");
    }
    else {
        FREE(rp);
        snprintf(errormsg, sizeof(errormsg),
            "Syntax: %s [generate | compare | [display]]", argv[0]);
        return ERROR_INT(errormsg, procName, 1);
    }

        /* Print out test name and both the leptonica and
         * image libarary versions */
    fprintf(stderr, "\n################   %s_reg   ###############\n",
            rp->testname);
    vers = getLeptonicaVersion();
    fprintf(stderr, "%s\n", vers);
    FREE(vers);
    vers = getImagelibVersions();
    fprintf(stderr, "%s\n", vers);
    FREE(vers);

    rp->tstart = startTimerNested();
    return 0;
}
/*!
 *  regTestSetup()
 *
 *      Input:  argc (from invocation; can be either 1 or 2)
 *              argv (to regtest: @argv[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.
 */


(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.
( 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 .
l_int32
regTestSetup(l_int32        argc,
             char         **argv,
             L_REGPARAMS  **prp)
{
char         *testname, *vers;
char          errormsg[64];
L_REGPARAMS  *rp;
    PROCNAME("regTestSetup");
    if (argc != 1 && argc != 2) {
        snprintf(errormsg, sizeof(errormsg),
            "Syntax: %s [generate | compare | [display]]", argv[0]);
        return ERROR_INT(errormsg, procName, 1);
    }
    if ((testname = getRootNameFromArgv0(argv[0])) == NULL)
        return ERROR_INT("invalid root", procName, 1);
    if ((rp = (L_REGPARAMS *)CALLOC(1, sizeof(L_REGPARAMS))) == NULL)
        return ERROR_INT("rp not made", procName, 1);
    *prp = rp;
    rp->testname = testname;
    rp->index = -1;  
    rp->success = TRUE;
    if (argc == 1 || !strcmp(argv[1], "display")) {
        rp->mode = L_REG_DISPLAY;
        rp->display = TRUE;
    }
    else if (!strcmp(argv[1], "compare")) {
        rp->mode = L_REG_COMPARE;
        rp->tempfile = genTempFilename("/tmp", "regtest_output.txt", 0, 1);
        rp->fp = fopenWriteStream(rp->tempfile, "wb");
        if (rp->fp == NULL) {
            rp->success = FALSE;
            return ERROR_INT("stream not opened for tempfile", procName, 1);
        }
    }
    else if (!strcmp(argv[1], "generate")) {
        rp->mode = L_REG_GENERATE;
        lept_mkdir("golden");
    }
    else {
        FREE(rp);
        snprintf(errormsg, sizeof(errormsg),
            "Syntax: %s [generate | compare | [display]]", argv[0]);
        return ERROR_INT(errormsg, procName, 1);
    }
    fprintf(stderr, "\n################   %s_reg   ###############\n",
            rp->testname);
    vers = getLeptonicaVersion();
    fprintf(stderr, "%s\n", vers);
    FREE(vers);
    vers = getImagelibVersions();
    fprintf(stderr, "%s\n", vers);
    FREE(vers);
    rp->tstart = startTimerNested();
    return 0;
}
l_int32 regTestSetup ( l_int32 argc , char * * argv , L_REGPARAMS * * prp ) { char * testname , * vers ; char errormsg [ 64 ] ; L_REGPARAMS * rp ; PROCNAME ( " " ) ; if ( argc != 1 && argc != 2 ) { snprintf ( errormsg , sizeof ( errormsg ) , " " , argv [ 0 ] ) ; return ERROR_INT ( errormsg , procName , 1 ) ; } if ( ( testname = getRootNameFromArgv0 ( argv [ 0 ] ) ) == NULL ) return ERROR_INT ( " " , procName , 1 ) ; if ( ( rp = ( L_REGPARAMS * ) CALLOC ( 1 , sizeof ( L_REGPARAMS ) ) ) == NULL ) return ERROR_INT ( " " , procName , 1 ) ; * prp = rp ; rp -> testname = testname ; rp -> index = -1 ; rp -> success = TRUE ; if ( argc == 1 || ! strcmp ( argv [ 1 ] , " " ) ) { rp -> mode = L_REG_DISPLAY ; rp -> display = TRUE ; } else if ( ! strcmp ( argv [ 1 ] , " " ) ) { rp -> mode = L_REG_COMPARE ; rp -> tempfile = genTempFilename ( " " , " " , 0 , 1 ) ; rp -> fp = fopenWriteStream ( rp -> tempfile , " " ) ; if ( rp -> fp == NULL ) { rp -> success = FALSE ; return ERROR_INT ( " " , procName , 1 ) ; } } else if ( ! strcmp ( argv [ 1 ] , " " ) ) { rp -> mode = L_REG_GENERATE ; lept_mkdir ( " " ) ; } else { FREE ( rp ) ; snprintf ( errormsg , sizeof ( errormsg ) , " " , argv [ 0 ] ) ; return ERROR_INT ( errormsg , procName , 1 ) ; } fprintf ( stderr , " \n \n " , rp -> testname ) ; vers = getLeptonicaVersion ( ) ; fprintf ( stderr , " \n " , vers ) ; FREE ( vers ) ; vers = getImagelibVersions ( ) ; fprintf ( stderr , " \n " , vers ) ; FREE ( vers ) ; rp -> tstart = startTimerNested ( ) ; return 0 ; }
regTestSetup()
      Input:  argc (from invocation; can be either 1 or 2)
              argv (to regtest: @argv[1] is one of these:
                    "generate", "compare", "display")
              &rp (<return> all regression params)
      Return: 0 if OK, 1 on error
regTestSetup () Input : argc ( from invocation ; can be either 1 or 2 ) argv ( to regtest : @argv [ 1 ] is one of these : " generate " " compare " " display " ) &rp ( <return > all regression params ) Return : 0 if OK 1 on error
/* increment before each test */ /* Initialize to true.  A failure in any test is registered
         * as a failure of the regression test. */ /* Only open a stream to a temp file for the 'compare' case */ /* Print out test name and both the leptonica and
         * image libarary versions */