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