chiark / gitweb /
Support for different sizes and types of integers.
authormdw <mdw>
Fri, 10 Dec 1999 23:42:12 +0000 (23:42 +0000)
committermdw <mdw>
Fri, 10 Dec 1999 23:42:12 +0000 (23:42 +0000)
man/testrig.3
testrig.c
testrig.h

index 9138b8801ccc1c4a638d1f05ad141c7a5dd03fb2..ae19d79e67a323081b147f5b5c8e73ed23e58258 100644 (file)
@@ -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"
index df7a0313496e3492af3b6c5071a102492b4dffef..220e3f3d7e624291689aee6df870d44050f86a20 100644 (file)
--- 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
index cf6afa872b4a755be842669bdb570954c72f8989..e0e471c644cb9643711019ae80f42a6f12f93f2b 100644 (file)
--- 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 <stddef.h>
 
+#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 ------------------------------------------------*/