r18059: another cpp error
[jelmer/samba4-debian.git] / source / lib / replace / test / testsuite.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    libreplace tests
5
6    Copyright (C) Jelmer Vernooij 2006
7
8      ** NOTE! The following LGPL license applies to the talloc
9      ** library. This does NOT imply that all of Samba is released
10      ** under the LGPL
11    
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 */
26
27 #include "../replace.h"
28 #include <stdio.h>
29
30 #if HAVE_STDLIB_H
31 #include <stdlib.h>
32 #endif
33
34 #if HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
37
38 #if HAVE_SYS_STAT_H
39 #include <sys/stat.h>
40 #endif
41
42 #if HAVE_UNISTD_H
43 #include <unistd.h>
44 #endif
45
46 #if HAVE_STRING_H
47 #include <string.h>
48 #endif
49
50 #include <fcntl.h>
51 #include <errno.h>
52
53 #define TESTFILE "testfile.dat"
54
55 /*
56   test ftruncate() function
57  */
58 static int test_ftruncate(void)
59 {
60         struct stat st;
61         int fd;
62         const int size = 1234;
63         printf("testing ftruncate\n");
64         unlink(TESTFILE);
65         fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
66         if (fd == -1) {
67                 printf("creating '%s' failed - %s\n", TESTFILE, strerror(errno));
68                 return false;
69         }
70         if (ftruncate(fd, size) != 0) {
71                 printf("ftruncate failed - %s\n", strerror(errno));
72                 return false;
73         }
74         if (fstat(fd, &st) != 0) {
75                 printf("fstat failed - %s\n", strerror(errno));
76                 return false;
77         }
78         if (st.st_size != size) {
79                 printf("ftruncate gave wrong size %d - expected %d\n",
80                        (int)st.st_size, size);
81                 return false;
82         }
83         return true;
84 }
85
86 /*
87   test strlcpy() function.
88   see http://www.gratisoft.us/todd/papers/strlcpy.html
89  */
90 static int test_strlcpy(void)
91 {
92         char buf[4];
93         const struct {
94                 const char *src;
95                 int result;
96         } tests[] = {
97                 { "abc", 3 },
98                 { "abcdef", 6 },
99                 { "abcd", 4 },
100                 { "", 0 },
101                 { NULL, 0 }
102         };
103         int i;
104         printf("testing strlcpy\n");
105         for (i=0;tests[i].src;i++) {
106                 if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
107                         printf("strlcpy test %d failed\n", i);
108                         return false;
109                 }
110         }
111         return true;
112 }
113
114 static int test_strlcat(void)
115 {
116         /* FIXME */
117         return true;
118 }
119
120 static int test_mktime(void)
121 {
122         /* FIXME */
123         return true;
124 }
125
126 static int test_rename(void)
127 {
128         /* FIXME */
129         return true;
130 }
131
132 static int test_innetgr(void)
133 {
134         /* FIXME */
135         return true;
136 }
137
138 static int test_initgroups(void)
139 {
140         /* FIXME */
141         return true;
142 }
143
144 static int test_memmove(void)
145 {
146         /* FIXME */
147         return true;
148 }
149
150 static int test_strdup(void)
151 {
152         /* FIXME */
153         return true;
154 }       
155
156 static int test_setlinebuf(void)
157 {
158         /* FIXME */
159         return true;
160 }
161
162 static int test_vsyslog(void)
163 {
164         /* FIXME */
165         return true;
166 }
167
168 static int test_timegm(void)
169 {
170         /* FIXME */
171         return true;
172 }
173
174 static int test_setenv(void)
175 {
176         /* FIXME */
177         return true;
178 }
179
180 static int test_strndup(void)
181 {
182         /* FIXME */
183         return true;
184 }
185
186 static int test_strnlen(void)
187 {
188         /* FIXME */
189         return true;
190 }
191
192 static int test_waitpid(void)
193 {
194         /* FIXME */
195         return true;
196 }
197
198 static int test_seteuid(void)
199 {
200         /* FIXME */
201         return true;
202 }
203
204 static int test_setegid(void)
205 {
206         /* FIXME */
207         return true;
208 }
209
210 static int test_asprintf(void)
211 {
212         /* FIXME */
213         return true;
214 }
215
216 static int test_snprintf(void)
217 {
218         /* FIXME */
219         return true;
220 }
221
222 static int test_vasprintf(void)
223 {
224         /* FIXME */
225         return true;
226 }
227
228 static int test_vsnprintf(void)
229 {
230         /* FIXME */
231         return true;
232 }
233
234 static int test_opendir(void)
235 {
236         /* FIXME */
237         return true;
238 }
239
240 static int test_readdir(void)
241 {
242         /* FIXME */
243         return true;
244 }
245
246 static int test_telldir(void)
247 {
248         /* FIXME */
249         return true;
250 }
251
252 static int test_seekdir(void)
253 {
254         /* FIXME */
255         return true;
256 }
257
258 static int test_dlopen(void)
259 {
260         /* FIXME: test dlopen, dlsym, dlclose, dlerror */
261         return true;
262 }
263
264
265 static int test_chroot(void)
266 {
267         /* FIXME: chroot() */
268         return true;
269 }
270
271 static int test_bzero(void)
272 {
273         /* FIXME: bzero */
274         return true;
275 }
276
277 static int test_strerror(void)
278 {
279         /* FIXME */
280         return true;
281 }
282
283 static int test_errno(void)
284 {
285         /* FIXME */
286         return true;
287 }
288
289 static int test_mkdtemp(void)
290 {
291         /* FIXME */
292         return true;
293 }
294
295 static int test_mkstemp(void)
296 {
297         /* FIXME */
298         return true;
299 }
300
301 static int test_pread(void)
302 {
303         /* FIXME */
304         return true;
305 }
306
307 static int test_pwrite(void)
308 {
309         /* FIXME */
310         return true;
311 }
312
313 static int test_getpass(void)
314 {
315         /* FIXME */
316         return true;
317 }
318
319 static int test_inet_ntoa(void)
320 {
321         /* FIXME */
322         return true;
323 }
324
325 static int test_strtoll(void)
326 {
327         /* FIXME */
328         return true;
329 }
330
331 static int test_strtoull(void)
332 {
333         /* FIXME */
334         return true;
335 }
336
337 /* 
338 FIXME:
339 Types:
340 bool
341 socklen_t
342 uint_t
343 uint{8,16,32,64}_t
344 int{8,16,32,64}_t
345 intptr_t
346
347 Constants:
348 PATH_NAME_MAX
349 UINT{16,32,64}_MAX
350 INT32_MAX
351 */
352
353 static int test_va_copy(void)
354 {
355         /* FIXME */
356         return true;
357 }
358
359 static int test_FUNCTION(void)
360 {
361         /* FIXME: test __FUNCTION__ macro */
362         return true;
363 }
364
365 static int test_MIN(void)
366 {
367         /* FIXME */
368         return true;
369 }
370
371 static int test_MAX(void)
372 {
373         /* FIXME */
374         return true;
375 }
376
377 int torture_local_replace(void *ctx)
378 {
379         int ret = true;
380         ret &= test_ftruncate();
381         ret &= test_strlcpy();
382         ret &= test_strlcat();
383         ret &= test_mktime();
384         ret &= test_rename();
385         ret &= test_innetgr();
386         ret &= test_initgroups();
387         ret &= test_memmove();
388         ret &= test_strdup();
389         ret &= test_setlinebuf();
390         ret &= test_vsyslog();
391         ret &= test_timegm();
392         ret &= test_setenv();
393         ret &= test_strndup();
394         ret &= test_strnlen();
395         ret &= test_waitpid();
396         ret &= test_seteuid();
397         ret &= test_setegid();
398         ret &= test_asprintf();
399         ret &= test_snprintf();
400         ret &= test_vasprintf();
401         ret &= test_vsnprintf();
402         ret &= test_opendir();
403         ret &= test_readdir() ;
404         ret &= test_telldir();
405         ret &= test_seekdir();
406         ret &= test_dlopen();
407         ret &= test_chroot();
408         ret &= test_bzero();
409         ret &= test_strerror();
410         ret &= test_errno();
411         ret &= test_mkdtemp();
412         ret &= test_mkstemp();
413         ret &= test_pread();
414         ret &= test_pwrite();
415         ret &= test_getpass();
416         ret &= test_inet_ntoa();
417         ret &= test_strtoll();
418         ret &= test_strtoll();
419         ret &= test_strtoull();
420         ret &= test_va_copy();
421         ret &= test_FUNCTION();
422         ret &= test_MIN();
423         ret &= test_MAX();
424
425         return ret;
426 }
427
428 #if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9))
429 int main(void)
430 {
431         if (!torture_local_replace(NULL)) {
432                 printf("ERROR: TESTSUITE FAILED\n");
433                 return -1;
434         }
435         return 0;
436 }
437 #endif