diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2002-02-17 21:56:45 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2002-02-17 21:56:45 +0000 |
commit | 8449595fe97f4474b9b9a7e4edee1ef35dcff393 (patch) | |
tree | e7a33b132264d449a512ddf4a8685df097669c1d /contrib/sendmail/libsm/test.c | |
parent | 289b381b31415647269c7520d881017e2dcb27f1 (diff) | |
download | FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.zip FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.tar.gz |
Import sendmail 8.12.2
Diffstat (limited to 'contrib/sendmail/libsm/test.c')
-rw-r--r-- | contrib/sendmail/libsm/test.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/contrib/sendmail/libsm/test.c b/contrib/sendmail/libsm/test.c new file mode 100644 index 0000000..361cc45 --- /dev/null +++ b/contrib/sendmail/libsm/test.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. + * All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + */ + +#include <sm/gen.h> +SM_IDSTR(Id, "@(#)$Id: test.c,v 1.16 2002/01/08 17:54:40 ca Exp $") + +/* +** Abstractions for writing libsm test programs. +*/ + +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <sm/debug.h> +#include <sm/test.h> + +extern char *optarg; +extern int optind; +extern int optopt; +extern int opterr; + +int SmTestIndex; +int SmTestNumErrors; +bool SmTestVerbose; + +static char Help[] = "\ +%s [-h] [-d debugging] [-v]\n\ +\n\ +%s\n\ +\n\ +-h Display this help information.\n\ +-d debugging Set debug activation levels.\n\ +-v Verbose output.\n\ +"; + +static char Usage[] = "\ +Usage: %s [-h] [-v]\n\ +Use %s -h for help.\n\ +"; + +/* +** SM_TEST_BEGIN -- initialize test system. +** +** Parameters: +** argc -- argument counter. +** argv -- argument vector. +** testname -- description of tests. +** +** Results: +** none. +*/ + +void +sm_test_begin(argc, argv, testname) + int argc; + char **argv; + char *testname; +{ + int c; + + SmTestIndex = 0; + SmTestNumErrors = 0; + SmTestVerbose = false; + opterr = 0; + + while ((c = getopt(argc, argv, "vhd:")) != -1) + { + switch (c) + { + case 'v': + SmTestVerbose = true; + break; + case 'd': + sm_debug_addsettings_x(optarg); + break; + case 'h': + (void) fprintf(stdout, Help, argv[0], testname); + exit(0); + default: + (void) fprintf(stderr, + "Unknown command line option -%c\n", + optopt); + (void) fprintf(stderr, Usage, argv[0], argv[0]); + exit(1); + } + } +} + +/* +** SM_TEST -- single test. +** +** Parameters: +** success -- did test succeeed? +** expr -- expression that has been evaluated. +** filename -- guess... +** lineno -- line number. +** +** Results: +** value of success. +*/ + +bool +sm_test(success, expr, filename, lineno) + bool success; + char *expr; + char *filename; + int lineno; +{ + ++SmTestIndex; + if (SmTestVerbose) + (void) fprintf(stderr, "%d..", SmTestIndex); + if (!success) + { + ++SmTestNumErrors; + if (!SmTestVerbose) + (void) fprintf(stderr, "%d..", SmTestIndex); + (void) fprintf(stderr, "bad! %s:%d %s\n", filename, lineno, + expr); + } + else + { + if (SmTestVerbose) + (void) fprintf(stderr, "ok\n"); + } + return success; +} + +/* +** SM_TEST_END -- end of test system. +** +** Parameters: +** none. +** +** Results: +** number of errors. +*/ + +int +sm_test_end() +{ + (void) fprintf(stderr, "%d of %d tests completed successfully\n", + SmTestIndex - SmTestNumErrors, SmTestIndex); + if (SmTestNumErrors != 0) + (void) fprintf(stderr, "*** %d error%s in test! ***\n", + SmTestNumErrors, + SmTestNumErrors > 1 ? "s" : ""); + + return SmTestNumErrors; +} |