Sync usage with man page.
[netbsd-mini2440.git] / regress / lib / libc / rpc / xdr / xdrtest.c
blob9b3e67cf365a475a38e68e85934c721c16d45849
1 /* $NetBSD: xdrtest.c,v 1.4 2002/03/09 01:34:18 pk Exp $ */
3 /*-
4 * Copyright (c) 2001 Ben Harris
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <err.h>
31 #include <stdio.h>
33 #include <rpc/types.h>
34 #include <rpc/xdr.h>
35 #include <stdlib.h>
37 #include "testbits.h"
39 char xdrdata[] = {
40 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* double 1.0 */
41 0x00, 0x00, 0x00, 0x01, /* enum smallenum SE_ONE */
42 0xff, 0xff, 0xfb, 0x2e, /* enum medenum ME_NEG */
43 0x00, 0x12, 0xd6, 0x87, /* enum bigenum BE_LOTS */
46 int
47 main(int argc, char **argv)
49 XDR x;
50 double d;
51 smallenum s;
52 medenum m;
53 bigenum b;
54 char newdata[sizeof(xdrdata)];
56 xdrmem_create(&x, xdrdata, sizeof(xdrdata), XDR_DECODE);
57 if (!xdr_double(&x, &d))
58 errx(1, "xdr_double DECODE failed.");
59 if (d != 1.0)
60 errx(1, "double 1.0 decoded as %g.", d);
61 if (!xdr_smallenum(&x, &s))
62 errx(1, "xdr_smallenum DECODE failed.");
63 if (s != SE_ONE)
64 errx(1, "SE_ONE decoded as %d.", s);
65 if (!xdr_medenum(&x, &m))
66 errx(1, "xdr_medenum DECODE failed.");
67 if (m != ME_NEG)
68 errx(1, "ME_NEG decoded as %d.", m);
69 if (!xdr_bigenum(&x, &b))
70 errx(1, "xdr_bigenum DECODE failed.");
71 if (b != BE_LOTS)
72 errx(1, "BE_LOTS decoded as %d.", b);
73 xdr_destroy(&x);
75 xdrmem_create(&x, newdata, sizeof(newdata), XDR_ENCODE);
76 if (!xdr_double(&x, &d))
77 errx(1, "xdr_double ENCODE failed.");
78 if (!xdr_smallenum(&x, &s))
79 errx(1, "xdr_smallenum ENCODE failed.");
80 if (!xdr_medenum(&x, &m))
81 errx(1, "xdr_medenum ENCODE failed.");
82 if (!xdr_bigenum(&x, &b))
83 errx(1, "xdr_bigenum ENCODE failed.");
84 if (memcmp(newdata, xdrdata, sizeof(xdrdata)) != 0)
85 errx(1, "xdr ENCODE result differs.");
86 xdr_destroy(&x);
88 exit(0);