Commit | Line | Data |
---|---|---|
0875b58f | 1 | /* -*-c-*- |
2 | * | |
0875b58f | 3 | * Generic test driver |
4 | * | |
5 | * (c) 1998 Straylight/Edgeware | |
6 | */ | |
7 | ||
d4efbcd9 | 8 | /*----- Licensing notice --------------------------------------------------* |
0875b58f | 9 | * |
10 | * This file is part of the mLib utilities library. | |
11 | * | |
12 | * mLib is free software; you can redistribute it and/or modify | |
c846879c | 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. | |
d4efbcd9 | 16 | * |
0875b58f | 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 | |
c846879c | 20 | * GNU Library General Public License for more details. |
d4efbcd9 | 21 | * |
c846879c | 22 | * You should have received a copy of the GNU Library General Public |
0bd98442 | 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. | |
0875b58f | 26 | */ |
27 | ||
dadc1afb | 28 | #ifndef MLIB_TESTER_H |
29 | #define MLIB_TESTER_H | |
0875b58f | 30 | |
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
35 | /*----- Header files ------------------------------------------------------*/ | |
36 | ||
37 | #include <stddef.h> | |
38 | ||
dd3c57bc MW |
39 | #ifndef MLIB_BITS_H |
40 | # include "bits.h" | |
41 | #endif | |
42 | ||
43 | #ifndef MLIB_DSTR_H | |
44 | # include "dstr.h" | |
45 | #endif | |
0875b58f | 46 | |
3832000d MW |
47 | #ifndef MLIB_MACROS_H |
48 | # include "macros.h" | |
49 | #endif | |
50 | ||
0875b58f | 51 | /*----- Magical numbers ---------------------------------------------------*/ |
52 | ||
53 | #define TEST_FIELDMAX 16 /* Maximum fields in a line */ | |
54 | ||
55 | /*----- Data structures ---------------------------------------------------*/ | |
56 | ||
9fcce036 MW |
57 | typedef struct test_results { |
58 | unsigned tests, failed; | |
59 | } test_results; | |
60 | ||
0875b58f | 61 | /* --- Test field definition --- */ |
62 | ||
63 | typedef struct test_type { | |
64 | void (*cvt)(const char *buf, dstr *d); /* Conversion function */ | |
65 | void (*dump)(dstr *d, FILE *fp); /* Dump function */ | |
66 | } test_type; | |
67 | ||
68 | /* --- Test chunk definition --- */ | |
69 | ||
70 | typedef struct test_chunk { | |
71 | const char *name; /* Name of this chunk */ | |
0319f58d | 72 | int (*test)(dstr /*dv*/[]); /* Test verification function */ |
d66299dc | 73 | const test_type *f[TEST_FIELDMAX]; /* Field definitions */ |
0875b58f | 74 | } test_chunk; |
75 | ||
9fcce036 MW |
76 | typedef struct test_suite { |
77 | const char *name; /* Name of this suite */ | |
78 | const test_chunk *chunks; /* Chunks contained in this suite */ | |
79 | } test_suite; | |
80 | ||
0875b58f | 81 | /*----- Predefined data types ---------------------------------------------*/ |
82 | ||
d66299dc | 83 | extern const test_type type_hex; |
84 | extern const test_type type_string; | |
85 | extern const test_type type_int; | |
dadc1afb | 86 | extern const test_type type_long; |
87 | extern const test_type type_ulong; | |
88 | extern const test_type type_uint32; | |
0875b58f | 89 | |
90 | /*----- Functions provided ------------------------------------------------*/ | |
91 | ||
9fcce036 MW |
92 | /* --- @test_do@ --- * |
93 | * | |
94 | * Arguments: @const test_suite suites[]@ = pointer to suite definitions | |
95 | * @FILE *fp@ = test vector file, ready opened | |
96 | * @test_results *results@ = where to put results | |
97 | * | |
98 | * Returns: Negative if something bad happened, or the number of | |
99 | * failures. | |
100 | * | |
101 | * Use: Runs a collection of tests against a file of test vectors and | |
102 | * reports the results. | |
103 | */ | |
104 | ||
105 | extern int test_do(const test_suite /*suite*/[], | |
106 | FILE */*fp*/, | |
107 | test_results */*results*/); | |
108 | ||
0875b58f | 109 | /* --- @test_run@ --- * |
110 | * | |
111 | * Arguments: @int argc@ = number of command line arguments | |
112 | * @char *argv[]@ = pointer to command line arguments | |
113 | * @const test_chunk chunk[]@ = pointer to chunk definitions | |
114 | * @const char *def@ = name of default test vector file | |
115 | * | |
116 | * Returns: Doesn't. | |
117 | * | |
118 | * Use: Runs a set of test vectors to ensure that a component is | |
119 | * working properly. | |
120 | */ | |
121 | ||
3832000d MW |
122 | extern void NORETURN |
123 | test_run(int /*argc*/, char */*argv*/[], | |
124 | const test_chunk /*chunk*/[], | |
125 | const char */*def*/); | |
0875b58f | 126 | |
127 | /*----- That's all, folks -------------------------------------------------*/ | |
128 | ||
129 | #ifdef __cplusplus | |
130 | } | |
131 | #endif | |
132 | ||
133 | #endif |