/* reportframe.c - Routines to handle housekeeping for tests.
* © Copyright 1999 by John Halleck
* All rights reserved.
*/
/* Version of August 16th, 1999 */
#include <stdio.h>
/* We need to put out messages */
#include "errors.h"
/* We return package standard error codes. */
#include "reportframe.h"
/* We need the routines we are testing also */
/* Local variables */
static int initialized = 0;
/* Has the package been initialized? */
int progerrors = 0; /* No program errors yet */
int secterrors = 0; /* No errors in section yet */
int testerrors = 0; /* No errors in test yet */
static char * prgname; /* Place to store name strings */
static char * secname;
static char * tstname;
static int secopen = 0; /* Not in a section */
static int tstopen = 0; /* Nor test */
static int waiting = 0; /* Are we waiting for a new line? */
/* This just returns the error given so that it can be
* used as return internalerror ("message", ERRtoreturn)
*/
static error internalerror (char *text, error given) {
printf ("*** REPORTFRAME error: ");
if (text && *text) printf ("%s", text);
printf ("\n");
progerrors ++; /* This counts an a test error */
secterrors ++;
testerrors ++;
waiting = 0;
return given;
}
/* Initialize package */
error inittests (char * packagename) {
prgname = packagename;
if (!prgname || !*prgname) prgname = "[NO PROGRAM NAME]";
secopen = 0; secname = "[NO SECTION NAME]";
tstopen = 0; tstname = "[NO TEST NAME]";
if (initialized)
return internalerror("Package already initialized", ERRreinitialized);
initialized = 1;
if (!packagename) return internalerror
("Package name not given for initialize", ERRnil);
if (!*packagename) return internalerror
("Package name nil in initialize", ERRempty);
printf ("=================== %s package tests ===============\n", prgname);
progerrors = 0;
secterrors = 0;
testerrors = 0;
waiting = 0;
return NoError;
}
/* Optional initialize section */
error newsection (char * sectionname) {
secname = sectionname;
if (secopen) return internalerror
("Section already open for newsection call", ERRreinitialized);
secopen = 1;
if (!initialized) return internalerror
("newsection called before initialize", ERRuninitialized);
if (!sectionname) return internalerror
("newsection called without section name", ERRnil);
if (!*sectionname) return internalerror
("newsection called with nil Section name", ERRempty);
printf ("------- %s tests\n", sectionname);
testerrors = 0;
secterrors = 0;
waiting = 0;
return NoError;
}
/* Start test */
error newtest (char * testname) {
tstname = "[BAD NAME GIVEN]";
if (tstname && *tstname) tstname = testname;
if (tstopen) return internalerror
("newtest called without closing old test", ERRreinitialized);
tstopen = 1;
if (!initialized) return internalerror
("newtest called before package initialize", ERRuninitialized);
if (!testname) return internalerror
("newtest called without test name", ERRnil);
if (!*testname) return internalerror
("newtest called with nil name", ERRempty);
printf ("testing %s ... ", testname); waiting = 1;
testerrors = 0;
return NoError;
}
/* goterror */
error goterror (char *message) {
if (waiting) { waiting = 0; printf ("\n"); }
testerrors = 1;
if (!tstname) tstname = "[??? No name given ???]";
if (message) printf ("*** %s: %s\n", tstname, message);
if (!initialized) return internalerror
("goterror called before initialize", ERRuninitialized);
if (!tstopen) return internalerror
("goterror called with no test open", ERRnesting);
if (!message) return internalerror ("goterror called with NIL", ERRnil);
if (!*message) return internalerror ("goterror called without text", ERRnil);
return NoError;
}
/* Got error and status */
error goterrorstat (char *message, error problem) {
error dumperror;
dumperror = goterror (message);
if (problem != NoError) printerror (problem);
if (dumperror != NoError) {
printf ("Error dumping error message: ");
printerror (dumperror);
}
return dumperror;
}
error remark (char *text) {
if (!text) return ERRnil;
if (!*text) return ERRempty;
if (waiting) { waiting = 0; printf ("\n"); }
printf ("%s\n", text);
return NoError;
}
/* End test */
error endtest() {
waiting = 0;
if (!tstname) tstname = "[NO TEST NAME GIVEN]";
if (testerrors) printf ("*** %s FAILED\n", tstname);
else printf ("%s PASSED\n", tstname);
tstname = "[NONE]";
progerrors += testerrors;
secterrors += testerrors;
testerrors = 0;
if (!initialized) return internalerror
("endtest called before package initialize", ERRuninitialized);
if (!tstopen) {
printf ("*** ??? End test called when no test open?");
secterrors ++;
progerrors ++;
return internalerror
("endtest called with no test open",ERRuninitialized);
}
tstopen = 0;
return NoError;
}
/* End optional section */
error endsection () {
if (!secname) secname = "[NO NAME SPECIFIED]";
if (secterrors) printf ("******* %s tests FAILED\n", secname);
else printf ("------- %s tests OK\n", secname);
progerrors += secterrors;
secterrors = 0;
secname = "[NONE]";
if (!initialized) return internalerror
("endsection called before package initialize", ERRuninitialized);
if (!secopen) return internalerror
("endsection called with no section open", ERRnesting);
secopen = 0;
if (tstopen) return internalerror
("endsection called while test still open", ERRnesting);
tstopen = 0;
return NoError;
}
/* Terminate package. */
error finalizetests () {
if (secopen) return internalerror
("finalizetests called with section still open", ERRnesting);
secopen = 0;
if (tstopen) return internalerror
("finalize tests called with test still open", ERRnesting);
tstopen = 0;
if (!initialized) return internalerror
("finalizetests called before REPORTFRAME package initialized",
ERRuninitialized);
initialized = 0;
if (!prgname) prgname = "[NO NAME SPECIFIED]";
if (progerrors) printf ("*******\a =========== %s package FAILED\n", prgname);
else printf ("============== %s package PASSED ======\n", prgname);
progerrors = 0;
secterrors = 0;
testerrors = 0;
return NoError;
}
/* ========================================================================== */
This page is http://www.cc.utah.edu/~nahaj/cave/survey/code/c/reportframe.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 11th, 2000