Infrastructure: Strip away crufty CVS $Id$ tags.
[mLib] / testrig.h
1 /* -*-c-*-
2 *
3 * Generic test driver
4 *
5 * (c) 1998 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of the mLib utilities library.
11 *
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28 #ifndef MLIB_TESTER_H
29 #define MLIB_TESTER_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include <stddef.h>
38
39 #include "bits.h"
40 #include "dstr.h"
41
42 /*----- Magical numbers ---------------------------------------------------*/
43
44 #define TEST_FIELDMAX 16 /* Maximum fields in a line */
45
46 /*----- Data structures ---------------------------------------------------*/
47
48 typedef struct test_results {
49 unsigned tests, failed;
50 } test_results;
51
52 /* --- Test field definition --- */
53
54 typedef struct test_type {
55 void (*cvt)(const char *buf, dstr *d); /* Conversion function */
56 void (*dump)(dstr *d, FILE *fp); /* Dump function */
57 } test_type;
58
59 /* --- Test chunk definition --- */
60
61 typedef struct test_chunk {
62 const char *name; /* Name of this chunk */
63 int (*test)(dstr /*dv*/[]); /* Test verification function */
64 const test_type *f[TEST_FIELDMAX]; /* Field definitions */
65 } test_chunk;
66
67 typedef struct test_suite {
68 const char *name; /* Name of this suite */
69 const test_chunk *chunks; /* Chunks contained in this suite */
70 } test_suite;
71
72 /*----- Predefined data types ---------------------------------------------*/
73
74 extern const test_type type_hex;
75 extern const test_type type_string;
76 extern const test_type type_int;
77 extern const test_type type_long;
78 extern const test_type type_ulong;
79 extern const test_type type_uint32;
80
81 /*----- Functions provided ------------------------------------------------*/
82
83 /* --- @test_do@ --- *
84 *
85 * Arguments: @const test_suite suites[]@ = pointer to suite definitions
86 * @FILE *fp@ = test vector file, ready opened
87 * @test_results *results@ = where to put results
88 *
89 * Returns: Negative if something bad happened, or the number of
90 * failures.
91 *
92 * Use: Runs a collection of tests against a file of test vectors and
93 * reports the results.
94 */
95
96 extern int test_do(const test_suite /*suite*/[],
97 FILE */*fp*/,
98 test_results */*results*/);
99
100 /* --- @test_run@ --- *
101 *
102 * Arguments: @int argc@ = number of command line arguments
103 * @char *argv[]@ = pointer to command line arguments
104 * @const test_chunk chunk[]@ = pointer to chunk definitions
105 * @const char *def@ = name of default test vector file
106 *
107 * Returns: Doesn't.
108 *
109 * Use: Runs a set of test vectors to ensure that a component is
110 * working properly.
111 */
112
113 extern void test_run(int /*argc*/, char */*argv*/[],
114 const test_chunk /*chunk*/[],
115 const char */*def*/);
116
117 /*----- That's all, folks -------------------------------------------------*/
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif