Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/regress/lib/libc/rpc/xdr Add some minimal testing of enumera...
details: https://anonhg.NetBSD.org/src/rev/b38aaa6c0627
branches: trunk
changeset: 522011:b38aaa6c0627
user: bjh21 <bjh21%NetBSD.org@localhost>
date: Sun Feb 10 13:22:58 2002 +0000
description:
Add some minimal testing of enumerations.
diffstat:
regress/lib/libc/rpc/xdr/Makefile | 18 +++++++++++++-
regress/lib/libc/rpc/xdr/testbits.x | 20 ++++++++++++++++
regress/lib/libc/rpc/xdr/xdrtest.c | 45 ++++++++++++++++++++++++++++++++++--
3 files changed, 79 insertions(+), 4 deletions(-)
diffs (122 lines):
diff -r 68fee66749db -r b38aaa6c0627 regress/lib/libc/rpc/xdr/Makefile
--- a/regress/lib/libc/rpc/xdr/Makefile Sun Feb 10 13:20:26 2002 +0000
+++ b/regress/lib/libc/rpc/xdr/Makefile Sun Feb 10 13:22:58 2002 +0000
@@ -1,9 +1,25 @@
-# $NetBSD: Makefile,v 1.3 2001/12/12 01:24:03 tv Exp $
+# $NetBSD: Makefile,v 1.4 2002/02/10 13:22:58 bjh21 Exp $
PROG= xdrtest
+RPCSRCS= testbits.x
+SRCS= ${RPCSRCS:.x=.c} ${RPCSRCS:.x=.h} xdrtest.c
NOMAN= # defined
+CPPFLAGS+= -I.
regress: ${PROG}
./${PROG}
.include <bsd.prog.mk>
+
+# Resolve rpcgen's path, to allow it to be a dependency.
+_RPCGEN:= ${RPCGEN:M*rpcgen}
+.if ${_RPCGEN:M/*} == ""
+_RPCGEN!= type ${RPCGEN} | awk '{print $$NF}'
+.endif
+
+.SUFFIXES: .x
+
+.x.c: ${_RPCGEN}
+ ${RPCGEN} -C -c ${.IMPSRC} -o ${.TARGET}
+.x.h: ${_RPCGEN}
+ ${RPCGEN} -C -h ${.IMPSRC} -o ${.TARGET}
diff -r 68fee66749db -r b38aaa6c0627 regress/lib/libc/rpc/xdr/testbits.x
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/rpc/xdr/testbits.x Sun Feb 10 13:22:58 2002 +0000
@@ -0,0 +1,20 @@
+/* $NetBSD: testbits.x,v 1.1 2002/02/10 13:22:58 bjh21 Exp $ */
+
+enum smallenum {
+ SE_ONE = 1,
+ SE_TWO = 2
+};
+
+enum medenum {
+ ME_NEG = -1234,
+ ME_ONE = 1,
+ ME_TWO = 2,
+ ME_MANY = 1234
+};
+
+enum bigenum {
+ BE_ONE = 1,
+ BE_TWO = 2,
+ BE_MANY = 1234,
+ BE_LOTS = 1234567
+};
diff -r 68fee66749db -r b38aaa6c0627 regress/lib/libc/rpc/xdr/xdrtest.c
--- a/regress/lib/libc/rpc/xdr/xdrtest.c Sun Feb 10 13:20:26 2002 +0000
+++ b/regress/lib/libc/rpc/xdr/xdrtest.c Sun Feb 10 13:22:58 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xdrtest.c,v 1.2 2001/07/24 15:32:02 bjh21 Exp $ */
+/* $NetBSD: xdrtest.c,v 1.3 2002/02/10 13:22:58 bjh21 Exp $ */
/*-
* Copyright (c) 2001 Ben Harris
@@ -33,17 +33,56 @@
#include <rpc/types.h>
#include <rpc/xdr.h>
-char xdrdata[] = { 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+#include <testbits.h>
+
+char xdrdata[] = {
+ 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* double 1.0 */
+ 0x00, 0x00, 0x00, 0x01, /* enum smallenum SE_ONE */
+ 0xff, 0xff, 0xfb, 0x2e, /* enum medenum ME_NEG */
+ 0x00, 0x12, 0xd6, 0x87, /* enum bigenum BE_LOTS */
+};
int
main(int argc, char **argv)
{
XDR x;
double d;
+ smallenum s;
+ medenum m;
+ bigenum b;
+ char newdata[sizeof(xdrdata)];
xdrmem_create(&x, xdrdata, sizeof(xdrdata), XDR_DECODE);
- xdr_double(&x, &d);
+ if (!xdr_double(&x, &d))
+ errx(1, "xdr_double DECODE failed.");
if (d != 1.0)
errx(1, "double 1.0 decoded as %g.", d);
+ if (!xdr_smallenum(&x, &s))
+ errx(1, "xdr_smallenum DECODE failed.");
+ if (s != SE_ONE)
+ errx(1, "SE_ONE decoded as %d.", s);
+ if (!xdr_medenum(&x, &m))
+ errx(1, "xdr_medenum DECODE failed.");
+ if (m != ME_NEG)
+ errx(1, "ME_NEG decoded as %d.", m);
+ if (!xdr_bigenum(&x, &b))
+ errx(1, "xdr_bigenum DECODE failed.");
+ if (b != BE_LOTS)
+ errx(1, "BE_LOTS decoded as %d.", b);
+ xdr_destroy(&x);
+
+ xdrmem_create(&x, newdata, sizeof(newdata), XDR_ENCODE);
+ if (!xdr_double(&x, &d))
+ errx(1, "xdr_double ENCODE failed.");
+ if (!xdr_smallenum(&x, &s))
+ errx(1, "xdr_smallenum ENCODE failed.");
+ if (!xdr_medenum(&x, &m))
+ errx(1, "xdr_medenum ENCODE failed.");
+ if (!xdr_bigenum(&x, &b))
+ errx(1, "xdr_bigenum ENCODE failed.");
+ if (memcmp(newdata, xdrdata, sizeof(xdrdata)) != 0)
+ errx(1, "xdr ENCODE result differs.");
+ xdr_destroy(&x);
+
exit(0);
}
Home |
Main Index |
Thread Index |
Old Index