r20819: - include system/aio.h
[Samba.git] / source / lib / replace / test / testsuite.c
blobeffbdb13ef0f0214600ce3b1ef5160e05c03541b
1 /*
2 Unix SMB/CIFS implementation.
4 libreplace tests
6 Copyright (C) Jelmer Vernooij 2006
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
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.
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.
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
27 #include "replace.h"
30 we include all the system/ include files here so that libreplace tests
31 them in the build farm
33 #include "system/capability.h"
34 #include "system/dir.h"
35 #include "system/filesys.h"
36 #include "system/glob.h"
37 #include "system/iconv.h"
38 #include "system/locale.h"
39 #include "system/network.h"
40 #include "system/passwd.h"
41 #include "system/printing.h"
42 #include "system/readline.h"
43 #include "system/select.h"
44 #include "system/shmem.h"
45 #include "system/syslog.h"
46 #include "system/terminal.h"
47 #include "system/time.h"
48 #include "system/wait.h"
49 #include "system/aio.h"
51 #define TESTFILE "testfile.dat"
54 test ftruncate() function
56 static int test_ftruncate(void)
58 struct stat st;
59 int fd;
60 const int size = 1234;
61 printf("test: ftruncate\n");
62 unlink(TESTFILE);
63 fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
64 if (fd == -1) {
65 printf("failure: ftruncate [\n"
66 "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
67 return false;
69 if (ftruncate(fd, size) != 0) {
70 printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
71 return false;
73 if (fstat(fd, &st) != 0) {
74 printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
75 return false;
77 if (st.st_size != size) {
78 printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
79 (int)st.st_size, size);
80 return false;
82 unlink(TESTFILE);
83 printf("success: ftruncate\n");
84 return true;
88 test strlcpy() function.
89 see http://www.gratisoft.us/todd/papers/strlcpy.html
91 static int test_strlcpy(void)
93 char buf[4];
94 const struct {
95 const char *src;
96 size_t result;
97 } tests[] = {
98 { "abc", 3 },
99 { "abcdef", 6 },
100 { "abcd", 4 },
101 { "", 0 },
102 { NULL, 0 }
104 int i;
105 printf("test: strlcpy\n");
106 for (i=0;tests[i].src;i++) {
107 if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
108 printf("failure: strlcpy [\ntest %d failed\n]\n", i);
109 return false;
112 printf("success: strlcpy\n");
113 return true;
116 static int test_strlcat(void)
118 /* FIXME */
119 return true;
122 static int test_mktime(void)
124 /* FIXME */
125 return true;
128 static int test_innetgr(void)
130 /* FIXME */
131 return true;
134 static int test_initgroups(void)
136 /* FIXME */
137 return true;
140 static int test_memmove(void)
142 /* FIXME */
143 return true;
146 static int test_strdup(void)
148 /* FIXME */
149 return true;
152 static int test_setlinebuf(void)
154 printf("test: setlinebuf\n");
155 setlinebuf(stdout);
156 printf("success: setlinebuf\n");
157 return true;
160 static int test_vsyslog(void)
162 /* FIXME */
163 return true;
166 static int test_timegm(void)
168 /* FIXME */
169 return true;
172 static int test_setenv(void)
174 /* FIXME */
175 return true;
178 static int test_strndup(void)
180 /* FIXME */
181 return true;
184 static int test_strnlen(void)
186 /* FIXME */
187 return true;
190 static int test_waitpid(void)
192 /* FIXME */
193 return true;
196 static int test_seteuid(void)
198 /* FIXME */
199 return true;
202 static int test_setegid(void)
204 /* FIXME */
205 return true;
208 static int test_asprintf(void)
210 /* FIXME */
211 return true;
214 static int test_snprintf(void)
216 /* FIXME */
217 return true;
220 static int test_vasprintf(void)
222 /* FIXME */
223 return true;
226 static int test_vsnprintf(void)
228 /* FIXME */
229 return true;
232 static int test_opendir(void)
234 /* FIXME */
235 return true;
238 extern int test_readdir_os2_delete(void);
240 static int test_readdir(void)
242 printf("test: readdir\n");
243 if (test_readdir_os2_delete() != 0) {
244 return false;
246 printf("success: readdir\n");
247 return true;
250 static int test_telldir(void)
252 /* FIXME */
253 return true;
256 static int test_seekdir(void)
258 /* FIXME */
259 return true;
262 static int test_dlopen(void)
264 /* FIXME: test dlopen, dlsym, dlclose, dlerror */
265 return true;
269 static int test_chroot(void)
271 /* FIXME: chroot() */
272 return true;
275 static int test_bzero(void)
277 /* FIXME: bzero */
278 return true;
281 static int test_strerror(void)
283 /* FIXME */
284 return true;
287 static int test_errno(void)
289 /* FIXME */
290 return true;
293 static int test_mkdtemp(void)
295 /* FIXME */
296 return true;
299 static int test_mkstemp(void)
301 /* FIXME */
302 return true;
305 static int test_pread(void)
307 /* FIXME */
308 return true;
311 static int test_pwrite(void)
313 /* FIXME */
314 return true;
317 static int test_getpass(void)
319 /* FIXME */
320 return true;
323 static int test_inet_ntoa(void)
325 /* FIXME */
326 return true;
329 static int test_strtoll(void)
331 /* FIXME */
332 return true;
335 static int test_strtoull(void)
337 /* FIXME */
338 return true;
342 FIXME:
343 Types:
344 bool
345 socklen_t
346 uint_t
347 uint{8,16,32,64}_t
348 int{8,16,32,64}_t
349 intptr_t
351 Constants:
352 PATH_NAME_MAX
353 UINT{16,32,64}_MAX
354 INT32_MAX
357 static int test_va_copy(void)
359 /* FIXME */
360 return true;
363 static int test_FUNCTION(void)
365 /* FIXME: test __FUNCTION__ macro */
366 return true;
369 static int test_MIN(void)
371 /* FIXME */
372 return true;
375 static int test_MAX(void)
377 /* FIXME */
378 return true;
381 static int test_socketpair(void)
383 int sock[2];
384 char buf[20];
386 printf("test: socketpair\n");
388 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
389 printf("failure: socketpair [\n"
390 "socketpair() failed\n"
391 "]\n");
392 return false;
395 if (write(sock[1], "automatisch", 12) == -1) {
396 printf("failure: socketpair [\n"
397 "write() failed: %s\n"
398 "]\n", strerror(errno));
399 return false;
402 if (read(sock[0], buf, 12) == -1) {
403 printf("failure: socketpair [\n"
404 "read() failed: %s\n"
405 "]\n", strerror(errno));
406 return false;
409 if (strcmp(buf, "automatisch") != 0) {
410 printf("failure: socketpair [\n"
411 "expected: automatisch, got: %s\n"
412 "]\n", buf);
413 return false;
416 printf("success: socketpair\n");
418 return true;
421 struct torture_context;
422 bool torture_local_replace(struct torture_context *ctx)
424 bool ret = true;
425 ret &= test_ftruncate();
426 ret &= test_strlcpy();
427 ret &= test_strlcat();
428 ret &= test_mktime();
429 ret &= test_innetgr();
430 ret &= test_initgroups();
431 ret &= test_memmove();
432 ret &= test_strdup();
433 ret &= test_setlinebuf();
434 ret &= test_vsyslog();
435 ret &= test_timegm();
436 ret &= test_setenv();
437 ret &= test_strndup();
438 ret &= test_strnlen();
439 ret &= test_waitpid();
440 ret &= test_seteuid();
441 ret &= test_setegid();
442 ret &= test_asprintf();
443 ret &= test_snprintf();
444 ret &= test_vasprintf();
445 ret &= test_vsnprintf();
446 ret &= test_opendir();
447 ret &= test_readdir();
448 ret &= test_telldir();
449 ret &= test_seekdir();
450 ret &= test_dlopen();
451 ret &= test_chroot();
452 ret &= test_bzero();
453 ret &= test_strerror();
454 ret &= test_errno();
455 ret &= test_mkdtemp();
456 ret &= test_mkstemp();
457 ret &= test_pread();
458 ret &= test_pwrite();
459 ret &= test_getpass();
460 ret &= test_inet_ntoa();
461 ret &= test_strtoll();
462 ret &= test_strtoll();
463 ret &= test_strtoull();
464 ret &= test_va_copy();
465 ret &= test_FUNCTION();
466 ret &= test_MIN();
467 ret &= test_MAX();
468 ret &= test_socketpair();
470 return ret;
473 #if _SAMBA_BUILD_<4
474 int main(void)
476 bool ret = torture_local_replace(NULL);
477 if (ret)
478 return 0;
479 return -1;
481 #endif