8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / test.c
blob46b3b2bdd1750c328665c0ce49842f571a2f19be
1 /*
2 * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include <sm/gen.h>
13 SM_IDSTR(Id, "@(#)$Id: test.c,v 1.16 2002/01/08 17:54:40 ca Exp $")
16 ** Abstractions for writing libsm test programs.
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <sm/debug.h>
23 #include <sm/test.h>
25 extern char *optarg;
26 extern int optind;
27 extern int optopt;
28 extern int opterr;
30 int SmTestIndex;
31 int SmTestNumErrors;
32 bool SmTestVerbose;
34 static char Help[] = "\
35 %s [-h] [-d debugging] [-v]\n\
36 \n\
37 %s\n\
38 \n\
39 -h Display this help information.\n\
40 -d debugging Set debug activation levels.\n\
41 -v Verbose output.\n\
44 static char Usage[] = "\
45 Usage: %s [-h] [-v]\n\
46 Use %s -h for help.\n\
50 ** SM_TEST_BEGIN -- initialize test system.
52 ** Parameters:
53 ** argc -- argument counter.
54 ** argv -- argument vector.
55 ** testname -- description of tests.
57 ** Results:
58 ** none.
61 void
62 sm_test_begin(argc, argv, testname)
63 int argc;
64 char **argv;
65 char *testname;
67 int c;
69 SmTestIndex = 0;
70 SmTestNumErrors = 0;
71 SmTestVerbose = false;
72 opterr = 0;
74 while ((c = getopt(argc, argv, "vhd:")) != -1)
76 switch (c)
78 case 'v':
79 SmTestVerbose = true;
80 break;
81 case 'd':
82 sm_debug_addsettings_x(optarg);
83 break;
84 case 'h':
85 (void) fprintf(stdout, Help, argv[0], testname);
86 exit(0);
87 default:
88 (void) fprintf(stderr,
89 "Unknown command line option -%c\n",
90 optopt);
91 (void) fprintf(stderr, Usage, argv[0], argv[0]);
92 exit(1);
98 ** SM_TEST -- single test.
100 ** Parameters:
101 ** success -- did test succeeed?
102 ** expr -- expression that has been evaluated.
103 ** filename -- guess...
104 ** lineno -- line number.
106 ** Results:
107 ** value of success.
110 bool
111 sm_test(success, expr, filename, lineno)
112 bool success;
113 char *expr;
114 char *filename;
115 int lineno;
117 ++SmTestIndex;
118 if (SmTestVerbose)
119 (void) fprintf(stderr, "%d..", SmTestIndex);
120 if (!success)
122 ++SmTestNumErrors;
123 if (!SmTestVerbose)
124 (void) fprintf(stderr, "%d..", SmTestIndex);
125 (void) fprintf(stderr, "bad! %s:%d %s\n", filename, lineno,
126 expr);
128 else
130 if (SmTestVerbose)
131 (void) fprintf(stderr, "ok\n");
133 return success;
137 ** SM_TEST_END -- end of test system.
139 ** Parameters:
140 ** none.
142 ** Results:
143 ** number of errors.
147 sm_test_end()
149 (void) fprintf(stderr, "%d of %d tests completed successfully\n",
150 SmTestIndex - SmTestNumErrors, SmTestIndex);
151 if (SmTestNumErrors != 0)
152 (void) fprintf(stderr, "*** %d error%s in test! ***\n",
153 SmTestNumErrors,
154 SmTestNumErrors > 1 ? "s" : "");
156 return SmTestNumErrors;