00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "replace.h"
00028
00029
00030
00031
00032
00033 #include "system/capability.h"
00034 #include "system/dir.h"
00035 #include "system/filesys.h"
00036 #include "system/glob.h"
00037 #include "system/iconv.h"
00038 #include "system/locale.h"
00039 #include "system/network.h"
00040 #include "system/passwd.h"
00041 #include "system/printing.h"
00042 #include "system/readline.h"
00043 #include "system/select.h"
00044 #include "system/shmem.h"
00045 #include "system/syslog.h"
00046 #include "system/terminal.h"
00047 #include "system/time.h"
00048 #include "system/wait.h"
00049 #include "system/aio.h"
00050
00051 #define TESTFILE "testfile.dat"
00052
00053
00054
00055
00056 static int test_ftruncate(void)
00057 {
00058 struct stat st;
00059 int fd;
00060 const int size = 1234;
00061 printf("test: ftruncate\n");
00062 unlink(TESTFILE);
00063 fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
00064 if (fd == -1) {
00065 printf("failure: ftruncate [\n"
00066 "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
00067 return false;
00068 }
00069 if (ftruncate(fd, size) != 0) {
00070 printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
00071 return false;
00072 }
00073 if (fstat(fd, &st) != 0) {
00074 printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
00075 return false;
00076 }
00077 if (st.st_size != size) {
00078 printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
00079 (int)st.st_size, size);
00080 return false;
00081 }
00082 unlink(TESTFILE);
00083 printf("success: ftruncate\n");
00084 return true;
00085 }
00086
00087
00088
00089
00090
00091 static int test_strlcpy(void)
00092 {
00093 char buf[4];
00094 const struct {
00095 const char *src;
00096 size_t result;
00097 } tests[] = {
00098 { "abc", 3 },
00099 { "abcdef", 6 },
00100 { "abcd", 4 },
00101 { "", 0 },
00102 { NULL, 0 }
00103 };
00104 int i;
00105 printf("test: strlcpy\n");
00106 for (i=0;tests[i].src;i++) {
00107 if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
00108 printf("failure: strlcpy [\ntest %d failed\n]\n", i);
00109 return false;
00110 }
00111 }
00112 printf("success: strlcpy\n");
00113 return true;
00114 }
00115
00116 static int test_strlcat(void)
00117 {
00118 char tmp[10];
00119 printf("test: strlcat\n");
00120 strlcpy(tmp, "", sizeof(tmp));
00121 if (strlcat(tmp, "bla", 3) != 3) {
00122 printf("failure: strlcat [\ninvalid return code\n]\n");
00123 return false;
00124 }
00125 if (strcmp(tmp, "bl") != 0) {
00126 printf("failure: strlcat [\nexpected \"bl\", got \"%s\"\n]\n",
00127 tmp);
00128 return false;
00129 }
00130
00131 strlcpy(tmp, "da", sizeof(tmp));
00132 if (strlcat(tmp, "me", 4) != 4) {
00133 printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n",
00134 tmp);
00135 return false;
00136 }
00137
00138 printf("success: strlcat\n");
00139 return true;
00140 }
00141
00142 static int test_mktime(void)
00143 {
00144
00145 return true;
00146 }
00147
00148 static int test_initgroups(void)
00149 {
00150
00151 return true;
00152 }
00153
00154 static int test_memmove(void)
00155 {
00156
00157 return true;
00158 }
00159
00160 static int test_strdup(void)
00161 {
00162 char *x;
00163 printf("test: strdup\n");
00164 x = strdup("bla");
00165 if (strcmp("bla", x) != 0) {
00166 printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n",
00167 x);
00168 return false;
00169 }
00170 free(x);
00171 printf("success: strdup\n");
00172 return true;
00173 }
00174
00175 static int test_setlinebuf(void)
00176 {
00177 printf("test: setlinebuf\n");
00178 setlinebuf(stdout);
00179 printf("success: setlinebuf\n");
00180 return true;
00181 }
00182
00183 static int test_vsyslog(void)
00184 {
00185
00186 return true;
00187 }
00188
00189 static int test_timegm(void)
00190 {
00191
00192 return true;
00193 }
00194
00195 static int test_setenv(void)
00196 {
00197 #define TEST_SETENV(key, value, overwrite, result) do { \
00198 int _ret; \
00199 char *_v; \
00200 _ret = setenv(key, value, overwrite); \
00201 if (_ret != 0) { \
00202 printf("failure: setenv [\n" \
00203 "setenv(%s, %s, %d) failed\n" \
00204 "]\n", \
00205 key, value, overwrite); \
00206 return false; \
00207 } \
00208 _v=getenv(key); \
00209 if (!_v) { \
00210 printf("failure: setenv [\n" \
00211 "getenv(%s) returned NULL\n" \
00212 "]\n", \
00213 key); \
00214 return false; \
00215 } \
00216 if (strcmp(result, _v) != 0) { \
00217 printf("failure: setenv [\n" \
00218 "getenv(%s): '%s' != '%s'\n" \
00219 "]\n", \
00220 key, result, _v); \
00221 return false; \
00222 } \
00223 } while(0)
00224
00225 #define TEST_UNSETENV(key) do { \
00226 char *_v; \
00227 unsetenv(key); \
00228 _v=getenv(key); \
00229 if (_v) { \
00230 printf("failure: setenv [\n" \
00231 "getenv(%s): NULL != '%s'\n" \
00232 "]\n", \
00233 SETENVTEST_KEY, _v); \
00234 return false; \
00235 } \
00236 } while (0)
00237
00238 #define SETENVTEST_KEY "SETENVTESTKEY"
00239 #define SETENVTEST_VAL "SETENVTESTVAL"
00240
00241 printf("test: setenv\n");
00242 TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1");
00243 TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1");
00244 TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3");
00245 TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4");
00246 TEST_UNSETENV(SETENVTEST_KEY);
00247 TEST_UNSETENV(SETENVTEST_KEY);
00248 TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5");
00249 TEST_UNSETENV(SETENVTEST_KEY);
00250 TEST_UNSETENV(SETENVTEST_KEY);
00251 printf("success: setenv\n");
00252 return true;
00253 }
00254
00255 static int test_strndup(void)
00256 {
00257 char *x;
00258 printf("test: strndup\n");
00259 x = strndup("bla", 0);
00260 if (strcmp(x, "") != 0) {
00261 printf("failure: strndup [\ninvalid\n]\n");
00262 return false;
00263 }
00264 free(x);
00265 x = strndup("bla", 2);
00266 if (strcmp(x, "bl") != 0) {
00267 printf("failure: strndup [\ninvalid\n]\n");
00268 return false;
00269 }
00270 free(x);
00271 x = strndup("bla", 10);
00272 if (strcmp(x, "bla") != 0) {
00273 printf("failure: strndup [\ninvalid\n]\n");
00274 return false;
00275 }
00276 free(x);
00277 printf("success: strndup\n");
00278 return true;
00279 }
00280
00281 static int test_strnlen(void)
00282 {
00283 printf("test: strnlen\n");
00284 if (strnlen("bla", 2) != 2) {
00285 printf("failure: strnlen [\nunexpected length\n]\n");
00286 return false;
00287 }
00288
00289 if (strnlen("some text\n", 0) != 0) {
00290 printf("failure: strnlen [\nunexpected length\n]\n");
00291 return false;
00292 }
00293
00294 if (strnlen("some text", 20) != 9) {
00295 printf("failure: strnlen [\nunexpected length\n]\n");
00296 return false;
00297 }
00298
00299 printf("success: strnlen\n");
00300 return true;
00301 }
00302
00303 static int test_waitpid(void)
00304 {
00305
00306 return true;
00307 }
00308
00309 static int test_seteuid(void)
00310 {
00311
00312 return true;
00313 }
00314
00315 static int test_setegid(void)
00316 {
00317
00318 return true;
00319 }
00320
00321 static int test_asprintf(void)
00322 {
00323 char *x;
00324 printf("test: asprintf\n");
00325 if (asprintf(&x, "%d", 9) != 1) {
00326 printf("failure: asprintf [\ngenerate asprintf\n]\n");
00327 return false;
00328 }
00329 if (strcmp(x, "9") != 0) {
00330 printf("failure: asprintf [\ngenerate asprintf\n]\n");
00331 return false;
00332 }
00333 if (asprintf(&x, "dat%s", "a") != 4) {
00334 printf("failure: asprintf [\ngenerate asprintf\n]\n");
00335 return false;
00336 }
00337 if (strcmp(x, "data") != 0) {
00338 printf("failure: asprintf [\ngenerate asprintf\n]\n");
00339 return false;
00340 }
00341 printf("success: asprintf\n");
00342 return true;
00343 }
00344
00345 static int test_snprintf(void)
00346 {
00347 char tmp[10];
00348 printf("test: snprintf\n");
00349 if (snprintf(tmp, 3, "foo%d", 9) != 4) {
00350 printf("failure: snprintf [\nsnprintf return code failed\n]\n");
00351 return false;
00352 }
00353
00354 if (strcmp(tmp, "fo") != 0) {
00355 printf("failure: snprintf [\nsnprintf failed\n]\n");
00356 return false;
00357 }
00358
00359 printf("success: snprintf\n");
00360 return true;
00361 }
00362
00363 static int test_vasprintf(void)
00364 {
00365
00366 return true;
00367 }
00368
00369 static int test_vsnprintf(void)
00370 {
00371
00372 return true;
00373 }
00374
00375 static int test_opendir(void)
00376 {
00377
00378 return true;
00379 }
00380
00381 extern int test_readdir_os2_delete(void);
00382
00383 static int test_readdir(void)
00384 {
00385 printf("test: readdir\n");
00386 if (test_readdir_os2_delete() != 0) {
00387 return false;
00388 }
00389 printf("success: readdir\n");
00390 return true;
00391 }
00392
00393 static int test_telldir(void)
00394 {
00395
00396 return true;
00397 }
00398
00399 static int test_seekdir(void)
00400 {
00401
00402 return true;
00403 }
00404
00405 static int test_dlopen(void)
00406 {
00407
00408 return true;
00409 }
00410
00411
00412 static int test_chroot(void)
00413 {
00414
00415 return true;
00416 }
00417
00418 static int test_bzero(void)
00419 {
00420
00421 return true;
00422 }
00423
00424 static int test_strerror(void)
00425 {
00426
00427 return true;
00428 }
00429
00430 static int test_errno(void)
00431 {
00432 printf("test: errno\n");
00433 errno = 3;
00434 if (errno != 3) {
00435 printf("failure: errno [\nerrno failed\n]\n");
00436 return false;
00437 }
00438
00439 printf("success: errno\n");
00440 return true;
00441 }
00442
00443 static int test_mkdtemp(void)
00444 {
00445
00446 return true;
00447 }
00448
00449 static int test_mkstemp(void)
00450 {
00451
00452 return true;
00453 }
00454
00455 static int test_pread(void)
00456 {
00457
00458 return true;
00459 }
00460
00461 static int test_pwrite(void)
00462 {
00463
00464 return true;
00465 }
00466
00467 static int test_getpass(void)
00468 {
00469
00470 return true;
00471 }
00472
00473 static int test_inet_ntoa(void)
00474 {
00475
00476 return true;
00477 }
00478
00479 #define TEST_STRTO_X(type,fmt,func,str,base,res,diff,rrnoo) do {\
00480 type _v; \
00481 char _s[64]; \
00482 char *_p = NULL;\
00483 char *_ep = NULL; \
00484 strlcpy(_s, str, sizeof(_s));\
00485 if (diff >= 0) { \
00486 _ep = &_s[diff]; \
00487 } \
00488 errno = 0; \
00489 _v = func(_s, &_p, base); \
00490 if (errno != rrnoo) { \
00491 printf("failure: %s [\n" \
00492 "\t%s\n" \
00493 "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
00494 "\terrno: %d != %d\n" \
00495 "]\n", \
00496 __STRING(func), __location__, __STRING(func), \
00497 str, diff, base, res, _v, rrnoo, errno); \
00498 return false; \
00499 } else if (_v != res) { \
00500 printf("failure: %s [\n" \
00501 "\t%s\n" \
00502 "\t%s(\"%s\",%d,%d): " fmt " != " fmt "\n" \
00503 "]\n", \
00504 __STRING(func), __location__, __STRING(func), \
00505 str, diff, base, res, _v); \
00506 return false; \
00507 } else if (_p != _ep) { \
00508 printf("failure: %s [\n" \
00509 "\t%s\n" \
00510 "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
00511 "\tptr: %p - %p = %d != %d\n" \
00512 "]\n", \
00513 __STRING(func), __location__, __STRING(func), \
00514 str, diff, base, res, _v, _ep, _p, (int)(diff - (_ep - _p)), diff); \
00515 return false; \
00516 } \
00517 } while (0)
00518
00519 static int test_strtoll(void)
00520 {
00521 printf("test: strtoll\n");
00522
00523 #define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(int64_t, "%lld", strtoll,str,base,res,diff,errnoo)
00524
00525 TEST_STRTOLL("15", 10, 15LL, 2, 0);
00526 TEST_STRTOLL(" 15", 10, 15LL, 4, 0);
00527 TEST_STRTOLL("15", 0, 15LL, 2, 0);
00528 TEST_STRTOLL(" 15 ", 0, 15LL, 3, 0);
00529 TEST_STRTOLL("+15", 10, 15LL, 3, 0);
00530 TEST_STRTOLL(" +15", 10, 15LL, 5, 0);
00531 TEST_STRTOLL("+15", 0, 15LL, 3, 0);
00532 TEST_STRTOLL(" +15 ", 0, 15LL, 4, 0);
00533 TEST_STRTOLL("-15", 10, -15LL, 3, 0);
00534 TEST_STRTOLL(" -15", 10, -15LL, 5, 0);
00535 TEST_STRTOLL("-15", 0, -15LL, 3, 0);
00536 TEST_STRTOLL(" -15 ", 0, -15LL, 4, 0);
00537 TEST_STRTOLL("015", 10, 15LL, 3, 0);
00538 TEST_STRTOLL(" 015", 10, 15LL, 5, 0);
00539 TEST_STRTOLL("015", 0, 13LL, 3, 0);
00540 TEST_STRTOLL(" 015", 0, 13LL, 5, 0);
00541 TEST_STRTOLL("0x15", 10, 0LL, 1, 0);
00542 TEST_STRTOLL(" 0x15", 10, 0LL, 3, 0);
00543 TEST_STRTOLL("0x15", 0, 21LL, 4, 0);
00544 TEST_STRTOLL(" 0x15", 0, 21LL, 6, 0);
00545
00546 TEST_STRTOLL("10", 16, 16LL, 2, 0);
00547 TEST_STRTOLL(" 10 ", 16, 16LL, 4, 0);
00548 TEST_STRTOLL("0x10", 16, 16LL, 4, 0);
00549 TEST_STRTOLL("0x10", 0, 16LL, 4, 0);
00550 TEST_STRTOLL(" 0x10 ", 0, 16LL, 5, 0);
00551 TEST_STRTOLL("+10", 16, 16LL, 3, 0);
00552 TEST_STRTOLL(" +10 ", 16, 16LL, 5, 0);
00553 TEST_STRTOLL("+0x10", 16, 16LL, 5, 0);
00554 TEST_STRTOLL("+0x10", 0, 16LL, 5, 0);
00555 TEST_STRTOLL(" +0x10 ", 0, 16LL, 6, 0);
00556 TEST_STRTOLL("-10", 16, -16LL, 3, 0);
00557 TEST_STRTOLL(" -10 ", 16, -16LL, 5, 0);
00558 TEST_STRTOLL("-0x10", 16, -16LL, 5, 0);
00559 TEST_STRTOLL("-0x10", 0, -16LL, 5, 0);
00560 TEST_STRTOLL(" -0x10 ", 0, -16LL, 6, 0);
00561 TEST_STRTOLL("010", 16, 16LL, 3, 0);
00562 TEST_STRTOLL(" 010 ", 16, 16LL, 5, 0);
00563 TEST_STRTOLL("-010", 16, -16LL, 4, 0);
00564
00565 TEST_STRTOLL("11", 8, 9LL, 2, 0);
00566 TEST_STRTOLL("011", 8, 9LL, 3, 0);
00567 TEST_STRTOLL("011", 0, 9LL, 3, 0);
00568 TEST_STRTOLL("-11", 8, -9LL, 3, 0);
00569 TEST_STRTOLL("-011", 8, -9LL, 4, 0);
00570 TEST_STRTOLL("-011", 0, -9LL, 4, 0);
00571
00572 TEST_STRTOLL("011", 8, 9LL, 3, 0);
00573 TEST_STRTOLL("011", 0, 9LL, 3, 0);
00574 TEST_STRTOLL("-11", 8, -9LL, 3, 0);
00575 TEST_STRTOLL("-011", 8, -9LL, 4, 0);
00576 TEST_STRTOLL("-011", 0, -9LL, 4, 0);
00577
00578 TEST_STRTOLL("Text", 0, 0LL, 0, 0);
00579
00580 TEST_STRTOLL("9223372036854775807", 10, 9223372036854775807LL, 19, 0);
00581 TEST_STRTOLL("9223372036854775807", 0, 9223372036854775807LL, 19, 0);
00582 TEST_STRTOLL("9223372036854775808", 0, 9223372036854775807LL, 19, ERANGE);
00583 TEST_STRTOLL("9223372036854775808", 10, 9223372036854775807LL, 19, ERANGE);
00584 TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LL, 18, 0);
00585 TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 18, 0);
00586 TEST_STRTOLL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 16, 0);
00587 TEST_STRTOLL("0x8000000000000000", 0, 9223372036854775807LL, 18, ERANGE);
00588 TEST_STRTOLL("0x8000000000000000", 16, 9223372036854775807LL, 18, ERANGE);
00589 TEST_STRTOLL("80000000000000000", 16, 9223372036854775807LL, 17, ERANGE);
00590 TEST_STRTOLL("0777777777777777777777", 0, 9223372036854775807LL, 22, 0);
00591 TEST_STRTOLL("0777777777777777777777", 8, 9223372036854775807LL, 22, 0);
00592 TEST_STRTOLL("777777777777777777777", 8, 9223372036854775807LL, 21, 0);
00593 TEST_STRTOLL("01000000000000000000000", 0, 9223372036854775807LL, 23, ERANGE);
00594 TEST_STRTOLL("01000000000000000000000", 8, 9223372036854775807LL, 23, ERANGE);
00595 TEST_STRTOLL("1000000000000000000000", 8, 9223372036854775807LL, 22, ERANGE);
00596
00597 TEST_STRTOLL("-9223372036854775808", 10, -9223372036854775807LL -1, 20, 0);
00598 TEST_STRTOLL("-9223372036854775808", 0, -9223372036854775807LL -1, 20, 0);
00599 TEST_STRTOLL("-9223372036854775809", 0, -9223372036854775807LL -1, 20, ERANGE);
00600 TEST_STRTOLL("-9223372036854775809", 10, -9223372036854775807LL -1, 20, ERANGE);
00601 TEST_STRTOLL("-0x8000000000000000", 0, -9223372036854775807LL -1, 19, 0);
00602 TEST_STRTOLL("-0x8000000000000000", 16, -9223372036854775807LL -1, 19, 0);
00603 TEST_STRTOLL("-8000000000000000", 16, -9223372036854775807LL -1, 17, 0);
00604 TEST_STRTOLL("-0x8000000000000001", 0, -9223372036854775807LL -1, 19, ERANGE);
00605 TEST_STRTOLL("-0x8000000000000001", 16, -9223372036854775807LL -1, 19, ERANGE);
00606 TEST_STRTOLL("-80000000000000001", 16, -9223372036854775807LL -1, 18, ERANGE);
00607 TEST_STRTOLL("-01000000000000000000000",0, -9223372036854775807LL -1, 24, 0);
00608 TEST_STRTOLL("-01000000000000000000000",8, -9223372036854775807LL -1, 24, 0);
00609 TEST_STRTOLL("-1000000000000000000000", 8, -9223372036854775807LL -1, 23, 0);
00610 TEST_STRTOLL("-01000000000000000000001",0, -9223372036854775807LL -1, 24, ERANGE);
00611 TEST_STRTOLL("-01000000000000000000001",8, -9223372036854775807LL -1, 24, ERANGE);
00612 TEST_STRTOLL("-1000000000000000000001", 8, -9223372036854775807LL -1, 23, ERANGE);
00613
00614 printf("success: strtoll\n");
00615 return true;
00616 }
00617
00618 static int test_strtoull(void)
00619 {
00620 printf("test: strtoull\n");
00621
00622 #define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(uint64_t,"%llu",strtoull,str,base,res,diff,errnoo)
00623
00624 TEST_STRTOULL("15", 10, 15LLU, 2, 0);
00625 TEST_STRTOULL(" 15", 10, 15LLU, 4, 0);
00626 TEST_STRTOULL("15", 0, 15LLU, 2, 0);
00627 TEST_STRTOULL(" 15 ", 0, 15LLU, 3, 0);
00628 TEST_STRTOULL("+15", 10, 15LLU, 3, 0);
00629 TEST_STRTOULL(" +15", 10, 15LLU, 5, 0);
00630 TEST_STRTOULL("+15", 0, 15LLU, 3, 0);
00631 TEST_STRTOULL(" +15 ", 0, 15LLU, 4, 0);
00632 TEST_STRTOULL("-15", 10, 18446744073709551601LLU, 3, 0);
00633 TEST_STRTOULL(" -15", 10, 18446744073709551601LLU, 5, 0);
00634 TEST_STRTOULL("-15", 0, 18446744073709551601LLU, 3, 0);
00635 TEST_STRTOULL(" -15 ", 0, 18446744073709551601LLU, 4, 0);
00636 TEST_STRTOULL("015", 10, 15LLU, 3, 0);
00637 TEST_STRTOULL(" 015", 10, 15LLU, 5, 0);
00638 TEST_STRTOULL("015", 0, 13LLU, 3, 0);
00639 TEST_STRTOULL(" 015", 0, 13LLU, 5, 0);
00640 TEST_STRTOULL("0x15", 10, 0LLU, 1, 0);
00641 TEST_STRTOULL(" 0x15", 10, 0LLU, 3, 0);
00642 TEST_STRTOULL("0x15", 0, 21LLU, 4, 0);
00643 TEST_STRTOULL(" 0x15", 0, 21LLU, 6, 0);
00644
00645 TEST_STRTOULL("10", 16, 16LLU, 2, 0);
00646 TEST_STRTOULL(" 10 ", 16, 16LLU, 4, 0);
00647 TEST_STRTOULL("0x10", 16, 16LLU, 4, 0);
00648 TEST_STRTOULL("0x10", 0, 16LLU, 4, 0);
00649 TEST_STRTOULL(" 0x10 ", 0, 16LLU, 5, 0);
00650 TEST_STRTOULL("+10", 16, 16LLU, 3, 0);
00651 TEST_STRTOULL(" +10 ", 16, 16LLU, 5, 0);
00652 TEST_STRTOULL("+0x10", 16, 16LLU, 5, 0);
00653 TEST_STRTOULL("+0x10", 0, 16LLU, 5, 0);
00654 TEST_STRTOULL(" +0x10 ", 0, 16LLU, 6, 0);
00655 TEST_STRTOULL("-10", 16, -16LLU, 3, 0);
00656 TEST_STRTOULL(" -10 ", 16, -16LLU, 5, 0);
00657 TEST_STRTOULL("-0x10", 16, -16LLU, 5, 0);
00658 TEST_STRTOULL("-0x10", 0, -16LLU, 5, 0);
00659 TEST_STRTOULL(" -0x10 ", 0, -16LLU, 6, 0);
00660 TEST_STRTOULL("010", 16, 16LLU, 3, 0);
00661 TEST_STRTOULL(" 010 ", 16, 16LLU, 5, 0);
00662 TEST_STRTOULL("-010", 16, -16LLU, 4, 0);
00663
00664 TEST_STRTOULL("11", 8, 9LLU, 2, 0);
00665 TEST_STRTOULL("011", 8, 9LLU, 3, 0);
00666 TEST_STRTOULL("011", 0, 9LLU, 3, 0);
00667 TEST_STRTOULL("-11", 8, -9LLU, 3, 0);
00668 TEST_STRTOULL("-011", 8, -9LLU, 4, 0);
00669 TEST_STRTOULL("-011", 0, -9LLU, 4, 0);
00670
00671 TEST_STRTOULL("011", 8, 9LLU, 3, 0);
00672 TEST_STRTOULL("011", 0, 9LLU, 3, 0);
00673 TEST_STRTOULL("-11", 8, -9LLU, 3, 0);
00674 TEST_STRTOULL("-011", 8, -9LLU, 4, 0);
00675 TEST_STRTOULL("-011", 0, -9LLU, 4, 0);
00676
00677 TEST_STRTOULL("Text", 0, 0LLU, 0, 0);
00678
00679 TEST_STRTOULL("9223372036854775807", 10, 9223372036854775807LLU, 19, 0);
00680 TEST_STRTOULL("9223372036854775807", 0, 9223372036854775807LLU, 19, 0);
00681 TEST_STRTOULL("9223372036854775808", 0, 9223372036854775808LLU, 19, 0);
00682 TEST_STRTOULL("9223372036854775808", 10, 9223372036854775808LLU, 19, 0);
00683 TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LLU, 18, 0);
00684 TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 18, 0);
00685 TEST_STRTOULL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 16, 0);
00686 TEST_STRTOULL("0x8000000000000000", 0, 9223372036854775808LLU, 18, 0);
00687 TEST_STRTOULL("0x8000000000000000", 16, 9223372036854775808LLU, 18, 0);
00688 TEST_STRTOULL("8000000000000000", 16, 9223372036854775808LLU, 16, 0);
00689 TEST_STRTOULL("0777777777777777777777", 0, 9223372036854775807LLU, 22, 0);
00690 TEST_STRTOULL("0777777777777777777777", 8, 9223372036854775807LLU, 22, 0);
00691 TEST_STRTOULL("777777777777777777777", 8, 9223372036854775807LLU, 21, 0);
00692 TEST_STRTOULL("01000000000000000000000",0, 9223372036854775808LLU, 23, 0);
00693 TEST_STRTOULL("01000000000000000000000",8, 9223372036854775808LLU, 23, 0);
00694 TEST_STRTOULL("1000000000000000000000", 8, 9223372036854775808LLU, 22, 0);
00695
00696 TEST_STRTOULL("-9223372036854775808", 10, 9223372036854775808LLU, 20, 0);
00697 TEST_STRTOULL("-9223372036854775808", 0, 9223372036854775808LLU, 20, 0);
00698 TEST_STRTOULL("-9223372036854775809", 0, 9223372036854775807LLU, 20, 0);
00699 TEST_STRTOULL("-9223372036854775809", 10, 9223372036854775807LLU, 20, 0);
00700 TEST_STRTOULL("-0x8000000000000000", 0, 9223372036854775808LLU, 19, 0);
00701 TEST_STRTOULL("-0x8000000000000000", 16, 9223372036854775808LLU, 19, 0);
00702 TEST_STRTOULL("-8000000000000000", 16, 9223372036854775808LLU, 17, 0);
00703 TEST_STRTOULL("-0x8000000000000001", 0, 9223372036854775807LLU, 19, 0);
00704 TEST_STRTOULL("-0x8000000000000001", 16, 9223372036854775807LLU, 19, 0);
00705 TEST_STRTOULL("-8000000000000001", 16, 9223372036854775807LLU, 17, 0);
00706 TEST_STRTOULL("-01000000000000000000000",0, 9223372036854775808LLU, 24, 0);
00707 TEST_STRTOULL("-01000000000000000000000",8, 9223372036854775808LLU, 24, 0);
00708 TEST_STRTOULL("-1000000000000000000000",8, 9223372036854775808LLU, 23, 0);
00709 TEST_STRTOULL("-01000000000000000000001",0, 9223372036854775807LLU, 24, 0);
00710 TEST_STRTOULL("-01000000000000000000001",8, 9223372036854775807LLU, 24, 0);
00711 TEST_STRTOULL("-1000000000000000000001",8, 9223372036854775807LLU, 23, 0);
00712
00713 TEST_STRTOULL("18446744073709551615", 0, 18446744073709551615LLU, 20, 0);
00714 TEST_STRTOULL("18446744073709551615", 10, 18446744073709551615LLU, 20, 0);
00715 TEST_STRTOULL("18446744073709551616", 0, 18446744073709551615LLU, 20, ERANGE);
00716 TEST_STRTOULL("18446744073709551616", 10, 18446744073709551615LLU, 20, ERANGE);
00717 TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 0, 18446744073709551615LLU, 18, 0);
00718 TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 18, 0);
00719 TEST_STRTOULL("FFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 16, 0);
00720 TEST_STRTOULL("0x10000000000000000", 0, 18446744073709551615LLU, 19, ERANGE);
00721 TEST_STRTOULL("0x10000000000000000", 16, 18446744073709551615LLU, 19, ERANGE);
00722 TEST_STRTOULL("10000000000000000", 16, 18446744073709551615LLU, 17, ERANGE);
00723 TEST_STRTOULL("01777777777777777777777",0, 18446744073709551615LLU, 23, 0);
00724 TEST_STRTOULL("01777777777777777777777",8, 18446744073709551615LLU, 23, 0);
00725 TEST_STRTOULL("1777777777777777777777", 8, 18446744073709551615LLU, 22, 0);
00726 TEST_STRTOULL("02000000000000000000000",0, 18446744073709551615LLU, 23, ERANGE);
00727 TEST_STRTOULL("02000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE);
00728 TEST_STRTOULL("2000000000000000000000", 8, 18446744073709551615LLU, 22, ERANGE);
00729
00730 TEST_STRTOULL("-18446744073709551615", 0, 1LLU, 21, 0);
00731 TEST_STRTOULL("-18446744073709551615", 10, 1LLU, 21, 0);
00732 TEST_STRTOULL("-18446744073709551616", 0, 18446744073709551615LLU, 21, ERANGE);
00733 TEST_STRTOULL("-18446744073709551616", 10, 18446744073709551615LLU, 21, ERANGE);
00734 TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 0, 1LLU, 19, 0);
00735 TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 16, 1LLU, 19, 0);
00736 TEST_STRTOULL("-FFFFFFFFFFFFFFFF", 16, 1LLU, 17, 0);
00737 TEST_STRTOULL("-0x10000000000000000", 0, 18446744073709551615LLU, 20, ERANGE);
00738 TEST_STRTOULL("-0x10000000000000000", 16, 18446744073709551615LLU, 20, ERANGE);
00739 TEST_STRTOULL("-10000000000000000", 16, 18446744073709551615LLU, 18, ERANGE);
00740 TEST_STRTOULL("-01777777777777777777777",0, 1LLU, 24, 0);
00741 TEST_STRTOULL("-01777777777777777777777",8, 1LLU, 24, 0);
00742 TEST_STRTOULL("-1777777777777777777777",8, 1LLU, 23, 0);
00743 TEST_STRTOULL("-02000000000000000000000",0, 18446744073709551615LLU, 24, ERANGE);
00744 TEST_STRTOULL("-02000000000000000000000",8, 18446744073709551615LLU, 24, ERANGE);
00745 TEST_STRTOULL("-2000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE);
00746
00747 printf("success: strtuoll\n");
00748 return true;
00749 }
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767 static int test_va_copy(void)
00768 {
00769
00770 return true;
00771 }
00772
00773 static int test_FUNCTION(void)
00774 {
00775 printf("test: FUNCTION\n");
00776 if (strcmp(__FUNCTION__, "test_FUNCTION") != 0) {
00777 printf("failure: FAILURE [\nFAILURE invalid\n]\n");
00778 return false;
00779 }
00780 printf("success: FUNCTION\n");
00781 return true;
00782 }
00783
00784 static int test_MIN(void)
00785 {
00786 printf("test: MIN\n");
00787 if (MIN(20, 1) != 1) {
00788 printf("failure: MIN [\nMIN invalid\n]\n");
00789 return false;
00790 }
00791 if (MIN(1, 20) != 1) {
00792 printf("failure: MIN [\nMIN invalid\n]\n");
00793 return false;
00794 }
00795 printf("success: MIN\n");
00796 return true;
00797 }
00798
00799 static int test_MAX(void)
00800 {
00801 printf("test: MAX\n");
00802 if (MAX(20, 1) != 20) {
00803 printf("failure: MAX [\nMAX invalid\n]\n");
00804 return false;
00805 }
00806 if (MAX(1, 20) != 20) {
00807 printf("failure: MAX [\nMAX invalid\n]\n");
00808 return false;
00809 }
00810 printf("success: MAX\n");
00811 return true;
00812 }
00813
00814 static int test_socketpair(void)
00815 {
00816 int sock[2];
00817 char buf[20];
00818
00819 printf("test: socketpair\n");
00820
00821 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
00822 printf("failure: socketpair [\n"
00823 "socketpair() failed\n"
00824 "]\n");
00825 return false;
00826 }
00827
00828 if (write(sock[1], "automatisch", 12) == -1) {
00829 printf("failure: socketpair [\n"
00830 "write() failed: %s\n"
00831 "]\n", strerror(errno));
00832 return false;
00833 }
00834
00835 if (read(sock[0], buf, 12) == -1) {
00836 printf("failure: socketpair [\n"
00837 "read() failed: %s\n"
00838 "]\n", strerror(errno));
00839 return false;
00840 }
00841
00842 if (strcmp(buf, "automatisch") != 0) {
00843 printf("failure: socketpair [\n"
00844 "expected: automatisch, got: %s\n"
00845 "]\n", buf);
00846 return false;
00847 }
00848
00849 printf("success: socketpair\n");
00850
00851 return true;
00852 }
00853
00854 extern int libreplace_test_strptime(void);
00855
00856 static int test_strptime(void)
00857 {
00858 return libreplace_test_strptime();
00859 }
00860
00861 struct torture_context;
00862 bool torture_local_replace(struct torture_context *ctx)
00863 {
00864 bool ret = true;
00865 ret &= test_ftruncate();
00866 ret &= test_strlcpy();
00867 ret &= test_strlcat();
00868 ret &= test_mktime();
00869 ret &= test_initgroups();
00870 ret &= test_memmove();
00871 ret &= test_strdup();
00872 ret &= test_setlinebuf();
00873 ret &= test_vsyslog();
00874 ret &= test_timegm();
00875 ret &= test_setenv();
00876 ret &= test_strndup();
00877 ret &= test_strnlen();
00878 ret &= test_waitpid();
00879 ret &= test_seteuid();
00880 ret &= test_setegid();
00881 ret &= test_asprintf();
00882 ret &= test_snprintf();
00883 ret &= test_vasprintf();
00884 ret &= test_vsnprintf();
00885 ret &= test_opendir();
00886 ret &= test_readdir();
00887 ret &= test_telldir();
00888 ret &= test_seekdir();
00889 ret &= test_dlopen();
00890 ret &= test_chroot();
00891 ret &= test_bzero();
00892 ret &= test_strerror();
00893 ret &= test_errno();
00894 ret &= test_mkdtemp();
00895 ret &= test_mkstemp();
00896 ret &= test_pread();
00897 ret &= test_pwrite();
00898 ret &= test_getpass();
00899 ret &= test_inet_ntoa();
00900 ret &= test_strtoll();
00901 ret &= test_strtoull();
00902 ret &= test_va_copy();
00903 ret &= test_FUNCTION();
00904 ret &= test_MIN();
00905 ret &= test_MAX();
00906 ret &= test_socketpair();
00907 ret &= test_strptime();
00908
00909 return ret;
00910 }
00911
00912 #if _SAMBA_BUILD_<4
00913 int main(void)
00914 {
00915 bool ret = torture_local_replace(NULL);
00916 if (ret)
00917 return 0;
00918 return -1;
00919 }
00920 #endif