source: branches/samba-3.0/source/lib/replace/test/testsuite.c

Last change on this file was 39, checked in by Paul Smedley, 18 years ago

Upgrade source to 3.0.25a

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