Move gcc-wrapper out of glibc into nacl-build
[glibc/nacl-glibc.git] / sunrpc / tst-xdrmem.c
blob0c9929c6ede850873c7edfc25abccf076eb2fa0c
1 /* Copyright (C) 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <limits.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <rpc/rpc.h>
25 static int
26 do_test (void)
28 XDR xdrs;
29 unsigned char buf[8192];
30 int v_int;
31 u_int v_u_int;
32 long v_long;
33 u_long v_u_long;
34 quad_t v_hyper;
35 u_quad_t v_u_hyper;
36 quad_t v_longlong_t;
37 u_quad_t v_u_longlong_t;
38 short v_short;
39 u_short v_u_short;
40 char v_char;
41 u_char v_u_char;
42 bool_t v_bool;
43 enum_t v_enum;
44 char *v_wrapstring;
46 xdrmem_create (&xdrs, (char *) buf, sizeof (buf), XDR_ENCODE);
48 #define TESTS \
49 T(int, 0) \
50 T(int, CHAR_MAX) \
51 T(int, CHAR_MIN) \
52 T(int, SHRT_MAX) \
53 T(int, SHRT_MIN) \
54 T(int, INT_MAX) \
55 T(int, INT_MIN) \
56 T(int, 0x123) \
57 T(u_int, 0) \
58 T(u_int, UCHAR_MAX) \
59 T(u_int, USHRT_MAX) \
60 T(u_int, UINT_MAX) \
61 T(u_int, 0xdeadbeef) \
62 T(u_int, 0x12345678) \
63 T(long, 0) \
64 T(long, 2147483647L) \
65 T(long, -2147483648L) \
66 T(long, -305419896L) \
67 T(long, -305419896L) \
68 T(u_long, 0) \
69 T(u_long, 0xffffffffUL) \
70 T(u_long, 0xdeadbeefUL) \
71 T(u_long, 0x12345678UL) \
72 T(hyper, 0) \
73 T(hyper, CHAR_MAX) \
74 T(hyper, CHAR_MIN) \
75 T(hyper, SHRT_MAX) \
76 T(hyper, SHRT_MIN) \
77 T(hyper, INT_MAX) \
78 T(hyper, INT_MIN) \
79 T(hyper, LONG_MAX) \
80 T(hyper, LONG_MIN) \
81 T(hyper, LONG_LONG_MAX) \
82 T(hyper, LONG_LONG_MIN) \
83 T(hyper, 0x12312345678LL) \
84 T(hyper, 0x12387654321LL) \
85 T(u_hyper, 0) \
86 T(u_hyper, UCHAR_MAX) \
87 T(u_hyper, USHRT_MAX) \
88 T(u_hyper, UINT_MAX) \
89 T(u_hyper, ULONG_MAX) \
90 T(u_hyper, ULONG_LONG_MAX) \
91 T(u_hyper, 0xdeadbeefdeadbeefULL) \
92 T(u_hyper, 0x12312345678ULL) \
93 T(u_hyper, 0x12387654321ULL) \
94 T(longlong_t, 0) \
95 T(longlong_t, CHAR_MAX) \
96 T(longlong_t, CHAR_MIN) \
97 T(longlong_t, SHRT_MAX) \
98 T(longlong_t, SHRT_MIN) \
99 T(longlong_t, INT_MAX) \
100 T(longlong_t, INT_MIN) \
101 T(longlong_t, LONG_MAX) \
102 T(longlong_t, LONG_MIN) \
103 T(longlong_t, LONG_LONG_MAX) \
104 T(longlong_t, LONG_LONG_MIN) \
105 T(longlong_t, 0x12312345678LL) \
106 T(longlong_t, 0x12387654321LL) \
107 T(u_longlong_t, 0) \
108 T(u_longlong_t, UCHAR_MAX) \
109 T(u_longlong_t, USHRT_MAX) \
110 T(u_longlong_t, UINT_MAX) \
111 T(u_longlong_t, ULONG_MAX) \
112 T(u_longlong_t, ULONG_LONG_MAX) \
113 T(u_longlong_t, 0xdeadbeefdeadbeefULL)\
114 T(u_longlong_t, 0x12312345678ULL) \
115 T(u_longlong_t, 0x12387654321ULL) \
116 T(short, CHAR_MAX) \
117 T(short, CHAR_MIN) \
118 T(short, SHRT_MAX) \
119 T(short, SHRT_MIN) \
120 T(short, 0x123) \
121 T(u_short, 0) \
122 T(u_short, UCHAR_MAX) \
123 T(u_short, USHRT_MAX) \
124 T(u_short, 0xbeef) \
125 T(u_short, 0x5678) \
126 T(char, CHAR_MAX) \
127 T(char, CHAR_MIN) \
128 T(char, 0x23) \
129 T(u_char, 0) \
130 T(u_char, UCHAR_MAX) \
131 T(u_char, 0xef) \
132 T(u_char, 0x78) \
133 T(bool, 0) \
134 T(bool, 1) \
135 T(enum, 0) \
136 T(enum, CHAR_MAX) \
137 T(enum, CHAR_MIN) \
138 T(enum, SHRT_MAX) \
139 T(enum, SHRT_MIN) \
140 T(enum, INT_MAX) \
141 T(enum, INT_MIN) \
142 T(enum, 0x123) \
143 S(wrapstring, (char *) "") \
144 S(wrapstring, (char *) "hello, world")
146 #define T(type, val) \
147 v_##type = val; \
148 if (! xdr_##type (&xdrs, &v_##type)) \
150 puts ("encoding of " #type \
151 " " #val " failed"); \
152 return 1; \
154 #define S(type, val) T(type, val)
156 TESTS
157 #undef T
158 #undef S
160 xdr_destroy (&xdrs);
162 xdrmem_create (&xdrs, (char *) buf, sizeof (buf), XDR_DECODE);
164 #define T(type, val) \
165 v_##type = 0x15; \
166 if (! xdr_##type (&xdrs, &v_##type)) \
168 puts ("decoding of " #type \
169 " " #val " failed"); \
170 return 1; \
172 if (v_##type != val) \
174 puts ("decoded value differs, " \
175 "type " #type " " #val); \
176 return 1; \
178 #define S(type, val) \
179 v_##type = NULL; \
180 if (! xdr_##type (&xdrs, &v_##type)) \
182 puts ("decoding of " #type \
183 " " #val " failed"); \
184 return 1; \
186 if (strcmp (v_##type, val)) \
188 puts ("decoded value differs, " \
189 "type " #type " " #val); \
190 return 1; \
192 free (v_##type); \
193 v_##type = NULL;
195 TESTS
196 #undef T
197 #undef S
199 xdr_destroy (&xdrs);
201 return 0;
204 #define TEST_FUNCTION do_test ()
205 #include "../test-skeleton.c"