From dadc1afb3dc0f28230673f457e69806ce02ba978 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Fri, 10 Dec 1999 23:42:12 +0000 Subject: [PATCH] Support for different sizes and types of integers. Organization: Straylight/Edgeware From: mdw --- man/testrig.3 | 23 +++++++++++++++++++++ testrig.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++---- testrig.h | 13 +++++++++--- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/man/testrig.3 b/man/testrig.3 index 9138b88..ae19d79 100644 --- a/man/testrig.3 +++ b/man/testrig.3 @@ -160,6 +160,29 @@ with the expression *(int *)d.buf .VE which isn't pretty but does the job. +.TP +.B "type_long" +As for +.B type_int +but reads and stores a +.B long +instead. +.TP +.B "type_ulong" +As for +.B type_long +but reads and stores an +.B "unsigned long" +instead. +.TP +.B "type_uint32" +As for +.B type_int +but reads and stores a +.B uint32 +(see +.BR bits (3)) +instead. .SH "SEE ALSO" .BR mLib (3). .SH "AUTHOR" diff --git a/testrig.c b/testrig.c index df7a031..220e3f3 100644 --- a/testrig.c +++ b/testrig.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: testrig.c,v 1.7 1999/11/21 13:01:39 mdw Exp $ + * $Id: testrig.c,v 1.8 1999/12/10 23:41:37 mdw Exp $ * * Generic test driver * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: testrig.c,v $ + * Revision 1.8 1999/12/10 23:41:37 mdw + * Support for different sizes and types of integers. + * * Revision 1.7 1999/11/21 13:01:39 mdw * Allow more characters to start words in test vector files. * @@ -255,17 +258,62 @@ const test_type type_string = { cvt_string, dump_string }; static void cvt_int(const char *s, dstr *d) { - DENSURE(d, sizeof(long)); - sscanf(s, "%i", (int *)d->buf + d->len); + DENSURE(d, sizeof(int)); + sscanf(s, "%i", (int *)d->buf); } static void dump_int(dstr *d, FILE *fp) { - fprintf(fp, "%i", *(int *)(d->buf)); + fprintf(fp, "%i", *(int *)d->buf); } const test_type type_int = { cvt_int, dump_int }; +/* --- @type_long@ --- */ + +static void cvt_long(const char *s, dstr *d) +{ + DENSURE(d, sizeof(long)); + *(long *)d->buf = strtol(s, 0, 0); +} + +static void dump_long(dstr *d, FILE *fp) +{ + fprintf(fp, "%li", *(long *)d->buf); +} + +const test_type type_long = { cvt_long, dump_long }; + +/* --- @type_ulong@ --- */ + +static void cvt_ulong(const char *s, dstr *d) +{ + DENSURE(d, sizeof(unsigned long)); + *(unsigned long *)d->buf = strtoul(s, 0, 0); +} + +static void dump_ulong(dstr *d, FILE *fp) +{ + fprintf(fp, "%lu", *(unsigned long *)d->buf); +} + +const test_type type_ulong = { cvt_ulong, dump_ulong }; + +/* --- @type_uint32@ --- */ + +static void cvt_uint32(const char *buf, dstr *d) +{ + DENSURE(d, sizeof(uint32)); + *(uint32 *)d->buf = strtoul(buf, 0, 0); +} + +static void dump_uint32(dstr *d, FILE *fp) +{ + fprintf(fp, "%lu\n", (unsigned long)*(uint32 *)d->buf); +} + +const test_type type_uint32 = { cvt_uint32, dump_uint32 }; + /* --- @test_run@ --- * * * Arguments: @int argc@ = number of command line arguments diff --git a/testrig.h b/testrig.h index cf6afa8..e0e471c 100644 --- a/testrig.h +++ b/testrig.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: testrig.h,v 1.5 1999/11/16 15:03:31 mdw Exp $ + * $Id: testrig.h,v 1.6 1999/12/10 23:41:37 mdw Exp $ * * Generic test driver * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: testrig.h,v $ + * Revision 1.6 1999/12/10 23:41:37 mdw + * Support for different sizes and types of integers. + * * Revision 1.5 1999/11/16 15:03:31 mdw * Mark test types as constant. * @@ -47,8 +50,8 @@ * */ -#ifndef TESTER_H -#define TESTER_H +#ifndef MLIB_TESTER_H +#define MLIB_TESTER_H #ifdef __cplusplus extern "C" { @@ -58,6 +61,7 @@ #include +#include "bits.h" #include "dstr.h" /*----- Magical numbers ---------------------------------------------------*/ @@ -86,6 +90,9 @@ typedef struct test_chunk { extern const test_type type_hex; extern const test_type type_string; extern const test_type type_int; +extern const test_type type_long; +extern const test_type type_ulong; +extern const test_type type_uint32; /*----- Functions provided ------------------------------------------------*/ -- [mdw]