1N/A/*
1N/A * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_IDSTR(Id, "@(#)$Id: test.c,v 1.16 2002/01/08 17:54:40 ca Exp $")
1N/A
1N/A/*
1N/A** Abstractions for writing libsm test programs.
1N/A*/
1N/A
1N/A#include <stdlib.h>
1N/A#include <unistd.h>
1N/A#include <stdio.h>
1N/A#include <sm/debug.h>
1N/A#include <sm/test.h>
1N/A
1N/Aextern char *optarg;
1N/Aextern int optind;
1N/Aextern int optopt;
1N/Aextern int opterr;
1N/A
1N/Aint SmTestIndex;
1N/Aint SmTestNumErrors;
1N/Abool SmTestVerbose;
1N/A
1N/Astatic char Help[] = "\
1N/A%s [-h] [-d debugging] [-v]\n\
1N/A\n\
1N/A%s\n\
1N/A\n\
1N/A-h Display this help information.\n\
1N/A-d debugging Set debug activation levels.\n\
1N/A-v Verbose output.\n\
1N/A";
1N/A
1N/Astatic char Usage[] = "\
1N/AUsage: %s [-h] [-v]\n\
1N/AUse %s -h for help.\n\
1N/A";
1N/A
1N/A/*
1N/A** SM_TEST_BEGIN -- initialize test system.
1N/A**
1N/A** Parameters:
1N/A** argc -- argument counter.
1N/A** argv -- argument vector.
1N/A** testname -- description of tests.
1N/A**
1N/A** Results:
1N/A** none.
1N/A*/
1N/A
1N/Avoid
1N/Asm_test_begin(argc, argv, testname)
1N/A int argc;
1N/A char **argv;
1N/A char *testname;
1N/A{
1N/A int c;
1N/A
1N/A SmTestIndex = 0;
1N/A SmTestNumErrors = 0;
1N/A SmTestVerbose = false;
1N/A opterr = 0;
1N/A
1N/A while ((c = getopt(argc, argv, "vhd:")) != -1)
1N/A {
1N/A switch (c)
1N/A {
1N/A case 'v':
1N/A SmTestVerbose = true;
1N/A break;
1N/A case 'd':
1N/A sm_debug_addsettings_x(optarg);
1N/A break;
1N/A case 'h':
1N/A (void) fprintf(stdout, Help, argv[0], testname);
1N/A exit(0);
1N/A default:
1N/A (void) fprintf(stderr,
1N/A "Unknown command line option -%c\n",
1N/A optopt);
1N/A (void) fprintf(stderr, Usage, argv[0], argv[0]);
1N/A exit(1);
1N/A }
1N/A }
1N/A}
1N/A
1N/A/*
1N/A** SM_TEST -- single test.
1N/A**
1N/A** Parameters:
1N/A** success -- did test succeeed?
1N/A** expr -- expression that has been evaluated.
1N/A** filename -- guess...
1N/A** lineno -- line number.
1N/A**
1N/A** Results:
1N/A** value of success.
1N/A*/
1N/A
1N/Abool
1N/Asm_test(success, expr, filename, lineno)
1N/A bool success;
1N/A char *expr;
1N/A char *filename;
1N/A int lineno;
1N/A{
1N/A ++SmTestIndex;
1N/A if (SmTestVerbose)
1N/A (void) fprintf(stderr, "%d..", SmTestIndex);
1N/A if (!success)
1N/A {
1N/A ++SmTestNumErrors;
1N/A if (!SmTestVerbose)
1N/A (void) fprintf(stderr, "%d..", SmTestIndex);
1N/A (void) fprintf(stderr, "bad! %s:%d %s\n", filename, lineno,
1N/A expr);
1N/A }
1N/A else
1N/A {
1N/A if (SmTestVerbose)
1N/A (void) fprintf(stderr, "ok\n");
1N/A }
1N/A return success;
1N/A}
1N/A
1N/A/*
1N/A** SM_TEST_END -- end of test system.
1N/A**
1N/A** Parameters:
1N/A** none.
1N/A**
1N/A** Results:
1N/A** number of errors.
1N/A*/
1N/A
1N/Aint
1N/Asm_test_end()
1N/A{
1N/A (void) fprintf(stderr, "%d of %d tests completed successfully\n",
1N/A SmTestIndex - SmTestNumErrors, SmTestIndex);
1N/A if (SmTestNumErrors != 0)
1N/A (void) fprintf(stderr, "*** %d error%s in test! ***\n",
1N/A SmTestNumErrors,
1N/A SmTestNumErrors > 1 ? "s" : "");
1N/A
1N/A return SmTestNumErrors;
1N/A}