r23798: updated old Temple Place FSF addresses to new URL
[bbaumbach/samba-autobuild/.git] / source3 / 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 3 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, see <http://www.gnu.org/licenses/>.
24 */
25
26 #include "replace.h"
27
28 /*
29   we include all the system/ include files here so that libreplace tests
30   them in the build farm
31 */
32 #include "system/capability.h"
33 #include "system/dir.h"
34 #include "system/filesys.h"
35 #include "system/glob.h"
36 #include "system/iconv.h"
37 #include "system/locale.h"
38 #include "system/network.h"
39 #include "system/passwd.h"
40 #include "system/printing.h"
41 #include "system/readline.h"
42 #include "system/select.h"
43 #include "system/shmem.h"
44 #include "system/syslog.h"
45 #include "system/terminal.h"
46 #include "system/time.h"
47 #include "system/wait.h"
48 #include "system/aio.h"
49
50 #define TESTFILE "testfile.dat"
51
52 /*
53   test ftruncate() function
54  */
55 static int test_ftruncate(void)
56 {
57         struct stat st;
58         int fd;
59         const int size = 1234;
60         printf("test: ftruncate\n");
61         unlink(TESTFILE);
62         fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
63         if (fd == -1) {
64                 printf("failure: ftruncate [\n"
65                            "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
66                 return false;
67         }
68         if (ftruncate(fd, size) != 0) {
69                 printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
70                 return false;
71         }
72         if (fstat(fd, &st) != 0) {
73                 printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
74                 return false;
75         }
76         if (st.st_size != size) {
77                 printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
78                        (int)st.st_size, size);
79                 return false;
80         }
81         unlink(TESTFILE);
82         printf("success: ftruncate\n");
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                 size_t result;
96         } tests[] = {
97                 { "abc", 3 },
98                 { "abcdef", 6 },
99                 { "abcd", 4 },
100                 { "", 0 },
101                 { NULL, 0 }
102         };
103         int i;
104         printf("test: strlcpy\n");
105         for (i=0;tests[i].src;i++) {
106                 if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
107                         printf("failure: strlcpy [\ntest %d failed\n]\n", i);
108                         return false;
109                 }
110         }
111         printf("success: strlcpy\n");
112         return true;
113 }
114
115 static int test_strlcat(void)
116 {
117         char tmp[10];
118         printf("test: strlcat\n");
119         strlcpy(tmp, "", sizeof(tmp));
120         if (strlcat(tmp, "bla", 3) != 3) {
121                 printf("failure: strlcat [\ninvalid return code\n]\n");
122                 return false;
123         }
124         if (strcmp(tmp, "bl") != 0) {
125                 printf("failure: strlcat [\nexpected \"bl\", got \"%s\"\n]\n", 
126                            tmp);
127                 return false;
128         }
129
130         strlcpy(tmp, "da", sizeof(tmp));
131         if (strlcat(tmp, "me", 4) != 4) {
132                 printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n",
133                            tmp);
134                 return false;
135         }
136
137         printf("success: strlcat\n");
138         return true;
139 }
140
141 static int test_mktime(void)
142 {
143         /* FIXME */
144         return true;
145 }
146
147 static int test_initgroups(void)
148 {
149         /* FIXME */
150         return true;
151 }
152
153 static int test_memmove(void)
154 {
155         /* FIXME */
156         return true;
157 }
158
159 static int test_strdup(void)
160 {
161         char *x;
162         printf("test: strdup\n");
163         x = strdup("bla");
164         if (strcmp("bla", x) != 0) {
165                 printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n",
166                            x);
167                 return false;
168         }
169         free(x);
170         printf("success: strdup\n");
171         return true;
172 }       
173
174 static int test_setlinebuf(void)
175 {
176         printf("test: setlinebuf\n");
177         setlinebuf(stdout);
178         printf("success: setlinebuf\n");
179         return true;
180 }
181
182 static int test_vsyslog(void)
183 {
184         /* FIXME */
185         return true;
186 }
187
188 static int test_timegm(void)
189 {
190         /* FIXME */
191         return true;
192 }
193
194 static int test_setenv(void)
195 {
196 #define TEST_SETENV(key, value, overwrite, result) do { \
197         int _ret; \
198         char *_v; \
199         _ret = setenv(key, value, overwrite); \
200         if (_ret != 0) { \
201                 printf("failure: setenv [\n" \
202                         "setenv(%s, %s, %d) failed\n" \
203                         "]\n", \
204                         key, value, overwrite); \
205                 return false; \
206         } \
207         _v=getenv(key); \
208         if (!_v) { \
209                 printf("failure: setenv [\n" \
210                         "getenv(%s) returned NULL\n" \
211                         "]\n", \
212                         key); \
213                 return false; \
214         } \
215         if (strcmp(result, _v) != 0) { \
216                 printf("failure: setenv [\n" \
217                         "getenv(%s): '%s' != '%s'\n" \
218                         "]\n", \
219                         key, result, _v); \
220                 return false; \
221         } \
222 } while(0)
223
224 #define TEST_UNSETENV(key) do { \
225         char *_v; \
226         unsetenv(key); \
227         _v=getenv(key); \
228         if (_v) { \
229                 printf("failure: setenv [\n" \
230                         "getenv(%s): NULL != '%s'\n" \
231                         "]\n", \
232                         SETENVTEST_KEY, _v); \
233                 return false; \
234         } \
235 } while (0)
236
237 #define SETENVTEST_KEY "SETENVTESTKEY"
238 #define SETENVTEST_VAL "SETENVTESTVAL"
239
240         printf("test: setenv\n");
241         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1");
242         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1");
243         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3");
244         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4");
245         TEST_UNSETENV(SETENVTEST_KEY);
246         TEST_UNSETENV(SETENVTEST_KEY);
247         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5");
248         TEST_UNSETENV(SETENVTEST_KEY);
249         TEST_UNSETENV(SETENVTEST_KEY);
250         printf("success: setenv\n");
251         return true;
252 }
253
254 static int test_strndup(void)
255 {
256         char *x;
257         printf("test: strndup\n");
258         x = strndup("bla", 0);
259         if (strcmp(x, "") != 0) {
260                 printf("failure: strndup [\ninvalid\n]\n");
261                 return false;
262         }
263         free(x);
264         x = strndup("bla", 2);
265         if (strcmp(x, "bl") != 0) {
266                 printf("failure: strndup [\ninvalid\n]\n");
267                 return false;
268         }
269         free(x);
270         x = strndup("bla", 10);
271         if (strcmp(x, "bla") != 0) {
272                 printf("failure: strndup [\ninvalid\n]\n");
273                 return false;
274         }
275         free(x);
276         printf("success: strndup\n");
277         return true;
278 }
279
280 static int test_strnlen(void)
281 {
282         printf("test: strnlen\n");
283         if (strnlen("bla", 2) != 2) {
284                 printf("failure: strnlen [\nunexpected length\n]\n");
285                 return false;
286         }
287
288         if (strnlen("some text\n", 0) != 0) {
289                 printf("failure: strnlen [\nunexpected length\n]\n");
290                 return false;
291         }
292
293         if (strnlen("some text", 20) != 9) {
294                 printf("failure: strnlen [\nunexpected length\n]\n");
295                 return false;
296         }
297
298         printf("success: strnlen\n");
299         return true;
300 }
301
302 static int test_waitpid(void)
303 {
304         /* FIXME */
305         return true;
306 }
307
308 static int test_seteuid(void)
309 {
310         /* FIXME */
311         return true;
312 }
313
314 static int test_setegid(void)
315 {
316         /* FIXME */
317         return true;
318 }
319
320 static int test_asprintf(void)
321 {
322         char *x;
323         printf("test: asprintf\n");
324         if (asprintf(&x, "%d", 9) != 1) {
325                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
326                 return false;
327         }
328         if (strcmp(x, "9") != 0) {
329                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
330                 return false;
331         }
332         if (asprintf(&x, "dat%s", "a") != 4) {
333                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
334                 return false;
335         }
336         if (strcmp(x, "data") != 0) {
337                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
338                 return false;
339         }
340         printf("success: asprintf\n");
341         return true;
342 }
343
344 static int test_snprintf(void)
345 {
346         char tmp[10];
347         printf("test: snprintf\n");
348         if (snprintf(tmp, 3, "foo%d", 9) != 4) {
349                 printf("failure: snprintf [\nsnprintf return code failed\n]\n");
350                 return false;
351         }
352
353         if (strcmp(tmp, "fo") != 0) {
354                 printf("failure: snprintf [\nsnprintf failed\n]\n");
355                 return false;
356         }
357
358         printf("success: snprintf\n");
359         return true;
360 }
361
362 static int test_vasprintf(void)
363 {
364         /* FIXME */
365         return true;
366 }
367
368 static int test_vsnprintf(void)
369 {
370         /* FIXME */
371         return true;
372 }
373
374 static int test_opendir(void)
375 {
376         /* FIXME */
377         return true;
378 }
379
380 extern int test_readdir_os2_delete(void);
381
382 static int test_readdir(void)
383 {
384         printf("test: readdir\n");
385         if (test_readdir_os2_delete() != 0) {
386                 return false;
387         }
388         printf("success: readdir\n");
389         return true;
390 }
391
392 static int test_telldir(void)
393 {
394         /* FIXME */
395         return true;
396 }
397
398 static int test_seekdir(void)
399 {
400         /* FIXME */
401         return true;
402 }
403
404 static int test_dlopen(void)
405 {
406         /* FIXME: test dlopen, dlsym, dlclose, dlerror */
407         return true;
408 }
409
410
411 static int test_chroot(void)
412 {
413         /* FIXME: chroot() */
414         return true;
415 }
416
417 static int test_bzero(void)
418 {
419         /* FIXME: bzero */
420         return true;
421 }
422
423 static int test_strerror(void)
424 {
425         /* FIXME */
426         return true;
427 }
428
429 static int test_errno(void)
430 {
431         printf("test: errno\n");
432         errno = 3;
433         if (errno != 3) {
434                 printf("failure: errno [\nerrno failed\n]\n");
435                 return false;
436         }
437
438         printf("success: errno\n");
439         return true;
440 }
441
442 static int test_mkdtemp(void)
443 {
444         /* FIXME */
445         return true;
446 }
447
448 static int test_mkstemp(void)
449 {
450         /* FIXME */
451         return true;
452 }
453
454 static int test_pread(void)
455 {
456         /* FIXME */
457         return true;
458 }
459
460 static int test_pwrite(void)
461 {
462         /* FIXME */
463         return true;
464 }
465
466 static int test_getpass(void)
467 {
468         /* FIXME */
469         return true;
470 }
471
472 static int test_inet_ntoa(void)
473 {
474         /* FIXME */
475         return true;
476 }
477
478 #define TEST_STRTO_X(type,fmt,func,str,base,res,diff,rrnoo) do {\
479         type _v; \
480         char _s[64]; \
481         char *_p = NULL;\
482         char *_ep = NULL; \
483         strlcpy(_s, str, sizeof(_s));\
484         if (diff >= 0) { \
485                 _ep = &_s[diff]; \
486         } \
487         errno = 0; \
488         _v = func(_s, &_p, base); \
489         if (errno != rrnoo) { \
490                 printf("failure: %s [\n" \
491                        "\t%s\n" \
492                        "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
493                        "\terrno: %d != %d\n" \
494                        "]\n", \
495                         __STRING(func), __location__, __STRING(func), \
496                        str, diff, base, res, _v, rrnoo, errno); \
497                 return false; \
498         } else if (_v != res) { \
499                 printf("failure: %s [\n" \
500                        "\t%s\n" \
501                        "\t%s(\"%s\",%d,%d): " fmt " != " fmt "\n" \
502                        "]\n", \
503                        __STRING(func), __location__, __STRING(func), \
504                        str, diff, base, res, _v); \
505                 return false; \
506         } else if (_p != _ep) { \
507                 printf("failure: %s [\n" \
508                        "\t%s\n" \
509                        "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
510                        "\tptr: %p - %p = %d != %d\n" \
511                        "]\n", \
512                        __STRING(func), __location__, __STRING(func), \
513                        str, diff, base, res, _v, _ep, _p, (int)(diff - (_ep - _p)), diff); \
514                 return false; \
515         } \
516 } while (0)
517
518 static int test_strtoll(void)
519 {
520         printf("test: strtoll\n");
521
522 #define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(int64_t, "%lld", strtoll,str,base,res,diff,errnoo)
523
524         TEST_STRTOLL("15",      10,     15LL,   2, 0);
525         TEST_STRTOLL("  15",    10,     15LL,   4, 0);
526         TEST_STRTOLL("15",      0,      15LL,   2, 0);
527         TEST_STRTOLL(" 15 ",    0,      15LL,   3, 0);
528         TEST_STRTOLL("+15",     10,     15LL,   3, 0);
529         TEST_STRTOLL("  +15",   10,     15LL,   5, 0);
530         TEST_STRTOLL("+15",     0,      15LL,   3, 0);
531         TEST_STRTOLL(" +15 ",   0,      15LL,   4, 0);
532         TEST_STRTOLL("-15",     10,     -15LL,  3, 0);
533         TEST_STRTOLL("  -15",   10,     -15LL,  5, 0);
534         TEST_STRTOLL("-15",     0,      -15LL,  3, 0);
535         TEST_STRTOLL(" -15 ",   0,      -15LL,  4, 0);
536         TEST_STRTOLL("015",     10,     15LL,   3, 0);
537         TEST_STRTOLL("  015",   10,     15LL,   5, 0);
538         TEST_STRTOLL("015",     0,      13LL,   3, 0);
539         TEST_STRTOLL("  015",   0,      13LL,   5, 0);
540         TEST_STRTOLL("0x15",    10,     0LL,    1, 0);
541         TEST_STRTOLL("  0x15",  10,     0LL,    3, 0);
542         TEST_STRTOLL("0x15",    0,      21LL,   4, 0);
543         TEST_STRTOLL("  0x15",  0,      21LL,   6, 0);
544
545         TEST_STRTOLL("10",      16,     16LL,   2, 0);
546         TEST_STRTOLL("  10 ",   16,     16LL,   4, 0);
547         TEST_STRTOLL("0x10",    16,     16LL,   4, 0);
548         TEST_STRTOLL("0x10",    0,      16LL,   4, 0);
549         TEST_STRTOLL(" 0x10 ",  0,      16LL,   5, 0);
550         TEST_STRTOLL("+10",     16,     16LL,   3, 0);
551         TEST_STRTOLL("  +10 ",  16,     16LL,   5, 0);
552         TEST_STRTOLL("+0x10",   16,     16LL,   5, 0);
553         TEST_STRTOLL("+0x10",   0,      16LL,   5, 0);
554         TEST_STRTOLL(" +0x10 ", 0,      16LL,   6, 0);
555         TEST_STRTOLL("-10",     16,     -16LL,  3, 0);
556         TEST_STRTOLL("  -10 ",  16,     -16LL,  5, 0);
557         TEST_STRTOLL("-0x10",   16,     -16LL,  5, 0);
558         TEST_STRTOLL("-0x10",   0,      -16LL,  5, 0);
559         TEST_STRTOLL(" -0x10 ", 0,      -16LL,  6, 0);
560         TEST_STRTOLL("010",     16,     16LL,   3, 0);
561         TEST_STRTOLL("  010 ",  16,     16LL,   5, 0);
562         TEST_STRTOLL("-010",    16,     -16LL,  4, 0);
563
564         TEST_STRTOLL("11",      8,      9LL,    2, 0);
565         TEST_STRTOLL("011",     8,      9LL,    3, 0);
566         TEST_STRTOLL("011",     0,      9LL,    3, 0);
567         TEST_STRTOLL("-11",     8,      -9LL,   3, 0);
568         TEST_STRTOLL("-011",    8,      -9LL,   4, 0);
569         TEST_STRTOLL("-011",    0,      -9LL,   4, 0);
570
571         TEST_STRTOLL("011",     8,      9LL,    3, 0);
572         TEST_STRTOLL("011",     0,      9LL,    3, 0);
573         TEST_STRTOLL("-11",     8,      -9LL,   3, 0);
574         TEST_STRTOLL("-011",    8,      -9LL,   4, 0);
575         TEST_STRTOLL("-011",    0,      -9LL,   4, 0);
576
577         TEST_STRTOLL("Text",    0,      0LL,    0, 0);
578
579         TEST_STRTOLL("9223372036854775807",     10,     9223372036854775807LL,  19, 0);
580         TEST_STRTOLL("9223372036854775807",     0,      9223372036854775807LL,  19, 0);
581         TEST_STRTOLL("9223372036854775808",     0,      9223372036854775807LL,  19, ERANGE);
582         TEST_STRTOLL("9223372036854775808",     10,     9223372036854775807LL,  19, ERANGE);
583         TEST_STRTOLL("0x7FFFFFFFFFFFFFFF",      0,      9223372036854775807LL,  18, 0);
584         TEST_STRTOLL("0x7FFFFFFFFFFFFFFF",      16,     9223372036854775807LL,  18, 0);
585         TEST_STRTOLL("7FFFFFFFFFFFFFFF",        16,     9223372036854775807LL,  16, 0);
586         TEST_STRTOLL("0x8000000000000000",      0,      9223372036854775807LL,  18, ERANGE);
587         TEST_STRTOLL("0x8000000000000000",      16,     9223372036854775807LL,  18, ERANGE);
588         TEST_STRTOLL("80000000000000000",       16,     9223372036854775807LL,  17, ERANGE);
589         TEST_STRTOLL("0777777777777777777777",  0,      9223372036854775807LL,  22, 0);
590         TEST_STRTOLL("0777777777777777777777",  8,      9223372036854775807LL,  22, 0);
591         TEST_STRTOLL("777777777777777777777",   8,      9223372036854775807LL,  21, 0);
592         TEST_STRTOLL("01000000000000000000000", 0,      9223372036854775807LL,  23, ERANGE);
593         TEST_STRTOLL("01000000000000000000000", 8,      9223372036854775807LL,  23, ERANGE);
594         TEST_STRTOLL("1000000000000000000000",  8,      9223372036854775807LL,  22, ERANGE);
595
596         TEST_STRTOLL("-9223372036854775808",    10,     -9223372036854775807LL -1,      20, 0);
597         TEST_STRTOLL("-9223372036854775808",    0,      -9223372036854775807LL -1,      20, 0);
598         TEST_STRTOLL("-9223372036854775809",    0,      -9223372036854775807LL -1,      20, ERANGE);
599         TEST_STRTOLL("-9223372036854775809",    10,     -9223372036854775807LL -1,      20, ERANGE);
600         TEST_STRTOLL("-0x8000000000000000",     0,      -9223372036854775807LL -1,      19, 0);
601         TEST_STRTOLL("-0x8000000000000000",     16,     -9223372036854775807LL -1,      19, 0);
602         TEST_STRTOLL("-8000000000000000",       16,     -9223372036854775807LL -1,      17, 0);
603         TEST_STRTOLL("-0x8000000000000001",     0,      -9223372036854775807LL -1,      19, ERANGE);
604         TEST_STRTOLL("-0x8000000000000001",     16,     -9223372036854775807LL -1,      19, ERANGE);
605         TEST_STRTOLL("-80000000000000001",      16,     -9223372036854775807LL -1,      18, ERANGE);
606         TEST_STRTOLL("-01000000000000000000000",0,      -9223372036854775807LL -1,      24, 0);
607         TEST_STRTOLL("-01000000000000000000000",8,      -9223372036854775807LL -1,      24, 0);
608         TEST_STRTOLL("-1000000000000000000000", 8,      -9223372036854775807LL -1,      23, 0);
609         TEST_STRTOLL("-01000000000000000000001",0,      -9223372036854775807LL -1,      24, ERANGE);
610         TEST_STRTOLL("-01000000000000000000001",8,      -9223372036854775807LL -1,      24, ERANGE);
611         TEST_STRTOLL("-1000000000000000000001", 8,      -9223372036854775807LL -1,      23, ERANGE);
612
613         printf("success: strtoll\n");
614         return true;
615 }
616
617 static int test_strtoull(void)
618 {
619         printf("test: strtoull\n");
620
621 #define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(uint64_t,"%llu",strtoull,str,base,res,diff,errnoo)
622
623         TEST_STRTOULL("15",     10,     15LLU,  2, 0);
624         TEST_STRTOULL("  15",   10,     15LLU,  4, 0);
625         TEST_STRTOULL("15",     0,      15LLU,  2, 0);
626         TEST_STRTOULL(" 15 ",   0,      15LLU,  3, 0);
627         TEST_STRTOULL("+15",    10,     15LLU,  3, 0);
628         TEST_STRTOULL("  +15",  10,     15LLU,  5, 0);
629         TEST_STRTOULL("+15",    0,      15LLU,  3, 0);
630         TEST_STRTOULL(" +15 ",  0,      15LLU,  4, 0);
631         TEST_STRTOULL("-15",    10,     18446744073709551601LLU,        3, 0);
632         TEST_STRTOULL("  -15",  10,     18446744073709551601LLU,        5, 0);
633         TEST_STRTOULL("-15",    0,      18446744073709551601LLU,        3, 0);
634         TEST_STRTOULL(" -15 ",  0,      18446744073709551601LLU,        4, 0);
635         TEST_STRTOULL("015",    10,     15LLU,  3, 0);
636         TEST_STRTOULL("  015",  10,     15LLU,  5, 0);
637         TEST_STRTOULL("015",    0,      13LLU,  3, 0);
638         TEST_STRTOULL("  015",  0,      13LLU,  5, 0);
639         TEST_STRTOULL("0x15",   10,     0LLU,   1, 0);
640         TEST_STRTOULL("  0x15", 10,     0LLU,   3, 0);
641         TEST_STRTOULL("0x15",   0,      21LLU,  4, 0);
642         TEST_STRTOULL("  0x15", 0,      21LLU,  6, 0);
643
644         TEST_STRTOULL("10",     16,     16LLU,  2, 0);
645         TEST_STRTOULL("  10 ",  16,     16LLU,  4, 0);
646         TEST_STRTOULL("0x10",   16,     16LLU,  4, 0);
647         TEST_STRTOULL("0x10",   0,      16LLU,  4, 0);
648         TEST_STRTOULL(" 0x10 ", 0,      16LLU,  5, 0);
649         TEST_STRTOULL("+10",    16,     16LLU,  3, 0);
650         TEST_STRTOULL("  +10 ", 16,     16LLU,  5, 0);
651         TEST_STRTOULL("+0x10",  16,     16LLU,  5, 0);
652         TEST_STRTOULL("+0x10",  0,      16LLU,  5, 0);
653         TEST_STRTOULL(" +0x10 ",        0,      16LLU,  6, 0);
654         TEST_STRTOULL("-10",    16,     -16LLU, 3, 0);
655         TEST_STRTOULL("  -10 ", 16,     -16LLU, 5, 0);
656         TEST_STRTOULL("-0x10",  16,     -16LLU, 5, 0);
657         TEST_STRTOULL("-0x10",  0,      -16LLU, 5, 0);
658         TEST_STRTOULL(" -0x10 ",        0,      -16LLU, 6, 0);
659         TEST_STRTOULL("010",    16,     16LLU,  3, 0);
660         TEST_STRTOULL("  010 ", 16,     16LLU,  5, 0);
661         TEST_STRTOULL("-010",   16,     -16LLU, 4, 0);
662
663         TEST_STRTOULL("11",     8,      9LLU,   2, 0);
664         TEST_STRTOULL("011",    8,      9LLU,   3, 0);
665         TEST_STRTOULL("011",    0,      9LLU,   3, 0);
666         TEST_STRTOULL("-11",    8,      -9LLU,  3, 0);
667         TEST_STRTOULL("-011",   8,      -9LLU,  4, 0);
668         TEST_STRTOULL("-011",   0,      -9LLU,  4, 0);
669
670         TEST_STRTOULL("011",    8,      9LLU,   3, 0);
671         TEST_STRTOULL("011",    0,      9LLU,   3, 0);
672         TEST_STRTOULL("-11",    8,      -9LLU,  3, 0);
673         TEST_STRTOULL("-011",   8,      -9LLU,  4, 0);
674         TEST_STRTOULL("-011",   0,      -9LLU,  4, 0);
675
676         TEST_STRTOULL("Text",   0,      0LLU,   0, 0);
677
678         TEST_STRTOULL("9223372036854775807",    10,     9223372036854775807LLU, 19, 0);
679         TEST_STRTOULL("9223372036854775807",    0,      9223372036854775807LLU, 19, 0);
680         TEST_STRTOULL("9223372036854775808",    0,      9223372036854775808LLU, 19, 0);
681         TEST_STRTOULL("9223372036854775808",    10,     9223372036854775808LLU, 19, 0);
682         TEST_STRTOULL("0x7FFFFFFFFFFFFFFF",     0,      9223372036854775807LLU, 18, 0);
683         TEST_STRTOULL("0x7FFFFFFFFFFFFFFF",     16,     9223372036854775807LLU, 18, 0);
684         TEST_STRTOULL("7FFFFFFFFFFFFFFF",       16,     9223372036854775807LLU, 16, 0);
685         TEST_STRTOULL("0x8000000000000000",     0,      9223372036854775808LLU, 18, 0);
686         TEST_STRTOULL("0x8000000000000000",     16,     9223372036854775808LLU, 18, 0);
687         TEST_STRTOULL("8000000000000000",       16,     9223372036854775808LLU, 16, 0);
688         TEST_STRTOULL("0777777777777777777777", 0,      9223372036854775807LLU, 22, 0);
689         TEST_STRTOULL("0777777777777777777777", 8,      9223372036854775807LLU, 22, 0);
690         TEST_STRTOULL("777777777777777777777",  8,      9223372036854775807LLU, 21, 0);
691         TEST_STRTOULL("01000000000000000000000",0,      9223372036854775808LLU, 23, 0);
692         TEST_STRTOULL("01000000000000000000000",8,      9223372036854775808LLU, 23, 0);
693         TEST_STRTOULL("1000000000000000000000", 8,      9223372036854775808LLU, 22, 0);
694
695         TEST_STRTOULL("-9223372036854775808",   10,     9223372036854775808LLU, 20, 0);
696         TEST_STRTOULL("-9223372036854775808",   0,      9223372036854775808LLU, 20, 0);
697         TEST_STRTOULL("-9223372036854775809",   0,      9223372036854775807LLU, 20, 0);
698         TEST_STRTOULL("-9223372036854775809",   10,     9223372036854775807LLU, 20, 0);
699         TEST_STRTOULL("-0x8000000000000000",    0,      9223372036854775808LLU, 19, 0);
700         TEST_STRTOULL("-0x8000000000000000",    16,     9223372036854775808LLU, 19, 0);
701         TEST_STRTOULL("-8000000000000000",      16,     9223372036854775808LLU, 17, 0);
702         TEST_STRTOULL("-0x8000000000000001",    0,      9223372036854775807LLU, 19, 0);
703         TEST_STRTOULL("-0x8000000000000001",    16,     9223372036854775807LLU, 19, 0);
704         TEST_STRTOULL("-8000000000000001",      16,     9223372036854775807LLU, 17, 0);
705         TEST_STRTOULL("-01000000000000000000000",0,     9223372036854775808LLU, 24, 0);
706         TEST_STRTOULL("-01000000000000000000000",8,     9223372036854775808LLU, 24, 0);
707         TEST_STRTOULL("-1000000000000000000000",8,      9223372036854775808LLU, 23, 0);
708         TEST_STRTOULL("-01000000000000000000001",0,     9223372036854775807LLU, 24, 0);
709         TEST_STRTOULL("-01000000000000000000001",8,     9223372036854775807LLU, 24, 0);
710         TEST_STRTOULL("-1000000000000000000001",8,      9223372036854775807LLU, 23, 0);
711
712         TEST_STRTOULL("18446744073709551615",   0,      18446744073709551615LLU,        20, 0);
713         TEST_STRTOULL("18446744073709551615",   10,     18446744073709551615LLU,        20, 0);
714         TEST_STRTOULL("18446744073709551616",   0,      18446744073709551615LLU,        20, ERANGE);
715         TEST_STRTOULL("18446744073709551616",   10,     18446744073709551615LLU,        20, ERANGE);
716         TEST_STRTOULL("0xFFFFFFFFFFFFFFFF",     0,      18446744073709551615LLU,        18, 0);
717         TEST_STRTOULL("0xFFFFFFFFFFFFFFFF",     16,     18446744073709551615LLU,        18, 0);
718         TEST_STRTOULL("FFFFFFFFFFFFFFFF",       16,     18446744073709551615LLU,        16, 0);
719         TEST_STRTOULL("0x10000000000000000",    0,      18446744073709551615LLU,        19, ERANGE);
720         TEST_STRTOULL("0x10000000000000000",    16,     18446744073709551615LLU,        19, ERANGE);
721         TEST_STRTOULL("10000000000000000",      16,     18446744073709551615LLU,        17, ERANGE);
722         TEST_STRTOULL("01777777777777777777777",0,      18446744073709551615LLU,        23, 0);
723         TEST_STRTOULL("01777777777777777777777",8,      18446744073709551615LLU,        23, 0);
724         TEST_STRTOULL("1777777777777777777777", 8,      18446744073709551615LLU,        22, 0);
725         TEST_STRTOULL("02000000000000000000000",0,      18446744073709551615LLU,        23, ERANGE);
726         TEST_STRTOULL("02000000000000000000000",8,      18446744073709551615LLU,        23, ERANGE);
727         TEST_STRTOULL("2000000000000000000000", 8,      18446744073709551615LLU,        22, ERANGE);
728
729         TEST_STRTOULL("-18446744073709551615",  0,      1LLU,                           21, 0);
730         TEST_STRTOULL("-18446744073709551615",  10,     1LLU,                           21, 0);
731         TEST_STRTOULL("-18446744073709551616",  0,      18446744073709551615LLU,        21, ERANGE);
732         TEST_STRTOULL("-18446744073709551616",  10,     18446744073709551615LLU,        21, ERANGE);
733         TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF",    0,      1LLU,                           19, 0);
734         TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF",    16,     1LLU,                           19, 0);
735         TEST_STRTOULL("-FFFFFFFFFFFFFFFF",      16,     1LLU,                           17, 0);
736         TEST_STRTOULL("-0x10000000000000000",   0,      18446744073709551615LLU,        20, ERANGE);
737         TEST_STRTOULL("-0x10000000000000000",   16,     18446744073709551615LLU,        20, ERANGE);
738         TEST_STRTOULL("-10000000000000000",     16,     18446744073709551615LLU,        18, ERANGE);
739         TEST_STRTOULL("-01777777777777777777777",0,     1LLU,                           24, 0);
740         TEST_STRTOULL("-01777777777777777777777",8,     1LLU,                           24, 0);
741         TEST_STRTOULL("-1777777777777777777777",8,      1LLU,                           23, 0);
742         TEST_STRTOULL("-02000000000000000000000",0,     18446744073709551615LLU,        24, ERANGE);
743         TEST_STRTOULL("-02000000000000000000000",8,     18446744073709551615LLU,        24, ERANGE);
744         TEST_STRTOULL("-2000000000000000000000",8,      18446744073709551615LLU,        23, ERANGE);
745
746         printf("success: strtuoll\n");
747         return true;
748 }
749
750 /* 
751 FIXME:
752 Types:
753 bool
754 socklen_t
755 uint_t
756 uint{8,16,32,64}_t
757 int{8,16,32,64}_t
758 intptr_t
759
760 Constants:
761 PATH_NAME_MAX
762 UINT{16,32,64}_MAX
763 INT32_MAX
764 */
765
766 static int test_va_copy(void)
767 {
768         /* FIXME */
769         return true;
770 }
771
772 static int test_FUNCTION(void)
773 {
774         printf("test: FUNCTION\n");
775         if (strcmp(__FUNCTION__, "test_FUNCTION") != 0) {
776                 printf("failure: FAILURE [\nFAILURE invalid\n]\n");
777                 return false;
778         }
779         printf("success: FUNCTION\n");
780         return true;
781 }
782
783 static int test_MIN(void)
784 {
785         printf("test: MIN\n");
786         if (MIN(20, 1) != 1) {
787                 printf("failure: MIN [\nMIN invalid\n]\n");
788                 return false;
789         }
790         if (MIN(1, 20) != 1) {
791                 printf("failure: MIN [\nMIN invalid\n]\n");
792                 return false;
793         }
794         printf("success: MIN\n");
795         return true;
796 }
797
798 static int test_MAX(void)
799 {
800         printf("test: MAX\n");
801         if (MAX(20, 1) != 20) {
802                 printf("failure: MAX [\nMAX invalid\n]\n");
803                 return false;
804         }
805         if (MAX(1, 20) != 20) {
806                 printf("failure: MAX [\nMAX invalid\n]\n");
807                 return false;
808         }
809         printf("success: MAX\n");
810         return true;
811 }
812
813 static int test_socketpair(void)
814 {
815         int sock[2];
816         char buf[20];
817
818         printf("test: socketpair\n");
819
820         if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
821                 printf("failure: socketpair [\n"
822                            "socketpair() failed\n"
823                            "]\n");
824                 return false;
825         }
826
827         if (write(sock[1], "automatisch", 12) == -1) {
828                 printf("failure: socketpair [\n"
829                            "write() failed: %s\n"
830                            "]\n", strerror(errno));
831                 return false;
832         }
833
834         if (read(sock[0], buf, 12) == -1) {
835                 printf("failure: socketpair [\n"
836                            "read() failed: %s\n"
837                            "]\n", strerror(errno));
838                 return false;
839         }
840
841         if (strcmp(buf, "automatisch") != 0) {
842                 printf("failure: socketpair [\n"
843                            "expected: automatisch, got: %s\n"
844                            "]\n", buf);
845                 return false;
846         }
847
848         printf("success: socketpair\n");
849
850         return true;
851 }
852
853 extern int libreplace_test_strptime(void);
854
855 static int test_strptime(void)
856 {
857         return libreplace_test_strptime();
858 }
859
860 struct torture_context;
861 bool torture_local_replace(struct torture_context *ctx)
862 {
863         bool ret = true;
864         ret &= test_ftruncate();
865         ret &= test_strlcpy();
866         ret &= test_strlcat();
867         ret &= test_mktime();
868         ret &= test_initgroups();
869         ret &= test_memmove();
870         ret &= test_strdup();
871         ret &= test_setlinebuf();
872         ret &= test_vsyslog();
873         ret &= test_timegm();
874         ret &= test_setenv();
875         ret &= test_strndup();
876         ret &= test_strnlen();
877         ret &= test_waitpid();
878         ret &= test_seteuid();
879         ret &= test_setegid();
880         ret &= test_asprintf();
881         ret &= test_snprintf();
882         ret &= test_vasprintf();
883         ret &= test_vsnprintf();
884         ret &= test_opendir();
885         ret &= test_readdir();
886         ret &= test_telldir();
887         ret &= test_seekdir();
888         ret &= test_dlopen();
889         ret &= test_chroot();
890         ret &= test_bzero();
891         ret &= test_strerror();
892         ret &= test_errno();
893         ret &= test_mkdtemp();
894         ret &= test_mkstemp();
895         ret &= test_pread();
896         ret &= test_pwrite();
897         ret &= test_getpass();
898         ret &= test_inet_ntoa();
899         ret &= test_strtoll();
900         ret &= test_strtoull();
901         ret &= test_va_copy();
902         ret &= test_FUNCTION();
903         ret &= test_MIN();
904         ret &= test_MAX();
905         ret &= test_socketpair();
906         ret &= test_strptime();
907
908         return ret;
909 }
910
911 #if _SAMBA_BUILD_<4
912 int main(void)
913 {
914         bool ret = torture_local_replace(NULL);
915         if (ret) 
916                 return 0;
917         return -1;
918 }
919 #endif