| 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/readline.h"
|
|---|
| 41 | #include "system/select.h"
|
|---|
| 42 | #include "system/shmem.h"
|
|---|
| 43 | #include "system/syslog.h"
|
|---|
| 44 | #include "system/terminal.h"
|
|---|
| 45 | #include "system/time.h"
|
|---|
| 46 | #include "system/wait.h"
|
|---|
| 47 | #include "system/aio.h"
|
|---|
| 48 |
|
|---|
| 49 | #define TESTFILE "testfile.dat"
|
|---|
| 50 |
|
|---|
| 51 | /*
|
|---|
| 52 | test ftruncate() function
|
|---|
| 53 | */
|
|---|
| 54 | static int test_ftruncate(void)
|
|---|
| 55 | {
|
|---|
| 56 | struct stat st;
|
|---|
| 57 | int fd;
|
|---|
| 58 | const int size = 1234;
|
|---|
| 59 | printf("test: ftruncate\n");
|
|---|
| 60 | unlink(TESTFILE);
|
|---|
| 61 | fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
|
|---|
| 62 | if (fd == -1) {
|
|---|
| 63 | printf("failure: ftruncate [\n"
|
|---|
| 64 | "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
|
|---|
| 65 | return false;
|
|---|
| 66 | }
|
|---|
| 67 | if (ftruncate(fd, size) != 0) {
|
|---|
| 68 | printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
|
|---|
| 69 | return false;
|
|---|
| 70 | }
|
|---|
| 71 | if (fstat(fd, &st) != 0) {
|
|---|
| 72 | printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
|
|---|
| 73 | return false;
|
|---|
| 74 | }
|
|---|
| 75 | if (st.st_size != size) {
|
|---|
| 76 | printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
|
|---|
| 77 | (int)st.st_size, size);
|
|---|
| 78 | return false;
|
|---|
| 79 | }
|
|---|
| 80 | unlink(TESTFILE);
|
|---|
| 81 | printf("success: ftruncate\n");
|
|---|
| 82 | return true;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | /*
|
|---|
| 86 | test strlcpy() function.
|
|---|
| 87 | see http://www.gratisoft.us/todd/papers/strlcpy.html
|
|---|
| 88 | */
|
|---|
| 89 | static int test_strlcpy(void)
|
|---|
| 90 | {
|
|---|
| 91 | char buf[4];
|
|---|
| 92 | const struct {
|
|---|
| 93 | const char *src;
|
|---|
| 94 | size_t result;
|
|---|
| 95 | } tests[] = {
|
|---|
| 96 | { "abc", 3 },
|
|---|
| 97 | { "abcdef", 6 },
|
|---|
| 98 | { "abcd", 4 },
|
|---|
| 99 | { "", 0 },
|
|---|
| 100 | { NULL, 0 }
|
|---|
| 101 | };
|
|---|
| 102 | int i;
|
|---|
| 103 | printf("test: strlcpy\n");
|
|---|
| 104 | for (i=0;tests[i].src;i++) {
|
|---|
| 105 | if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
|
|---|
| 106 | printf("failure: strlcpy [\ntest %d failed\n]\n", i);
|
|---|
| 107 | return false;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | printf("success: strlcpy\n");
|
|---|
| 111 | return true;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | static int test_strlcat(void)
|
|---|
| 115 | {
|
|---|
| 116 | char tmp[10];
|
|---|
| 117 | printf("test: strlcat\n");
|
|---|
| 118 | strlcpy(tmp, "", sizeof(tmp));
|
|---|
| 119 | if (strlcat(tmp, "bla", 3) != 3) {
|
|---|
| 120 | printf("failure: strlcat [\ninvalid return code\n]\n");
|
|---|
| 121 | return false;
|
|---|
| 122 | }
|
|---|
| 123 | if (strcmp(tmp, "bl") != 0) {
|
|---|
| 124 | printf("failure: strlcat [\nexpected \"bl\", got \"%s\"\n]\n",
|
|---|
| 125 | tmp);
|
|---|
| 126 | return false;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | strlcpy(tmp, "da", sizeof(tmp));
|
|---|
| 130 | if (strlcat(tmp, "me", 4) != 4) {
|
|---|
| 131 | printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n",
|
|---|
| 132 | tmp);
|
|---|
| 133 | return false;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | printf("success: strlcat\n");
|
|---|
| 137 | return true;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | static int test_mktime(void)
|
|---|
| 141 | {
|
|---|
| 142 | /* FIXME */
|
|---|
| 143 | return true;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | static int test_initgroups(void)
|
|---|
| 147 | {
|
|---|
| 148 | /* FIXME */
|
|---|
| 149 | return true;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | static int test_memmove(void)
|
|---|
| 153 | {
|
|---|
| 154 | /* FIXME */
|
|---|
| 155 | return true;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | static int test_strdup(void)
|
|---|
| 159 | {
|
|---|
| 160 | char *x;
|
|---|
| 161 | printf("test: strdup\n");
|
|---|
| 162 | x = strdup("bla");
|
|---|
| 163 | if (strcmp("bla", x) != 0) {
|
|---|
| 164 | printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n",
|
|---|
| 165 | x);
|
|---|
| 166 | return false;
|
|---|
| 167 | }
|
|---|
| 168 | free(x);
|
|---|
| 169 | printf("success: strdup\n");
|
|---|
| 170 | return true;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | static int test_setlinebuf(void)
|
|---|
| 174 | {
|
|---|
| 175 | printf("test: setlinebuf\n");
|
|---|
| 176 | setlinebuf(stdout);
|
|---|
| 177 | printf("success: setlinebuf\n");
|
|---|
| 178 | return true;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | static int test_vsyslog(void)
|
|---|
| 182 | {
|
|---|
| 183 | /* FIXME */
|
|---|
| 184 | return true;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | static int test_timegm(void)
|
|---|
| 188 | {
|
|---|
| 189 | /* FIXME */
|
|---|
| 190 | return true;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | static int test_setenv(void)
|
|---|
| 194 | {
|
|---|
| 195 | #define TEST_SETENV(key, value, overwrite, result) do { \
|
|---|
| 196 | int _ret; \
|
|---|
| 197 | char *_v; \
|
|---|
| 198 | _ret = setenv(key, value, overwrite); \
|
|---|
| 199 | if (_ret != 0) { \
|
|---|
| 200 | printf("failure: setenv [\n" \
|
|---|
| 201 | "setenv(%s, %s, %d) failed\n" \
|
|---|
| 202 | "]\n", \
|
|---|
| 203 | key, value, overwrite); \
|
|---|
| 204 | return false; \
|
|---|
| 205 | } \
|
|---|
| 206 | _v=getenv(key); \
|
|---|
| 207 | if (!_v) { \
|
|---|
| 208 | printf("failure: setenv [\n" \
|
|---|
| 209 | "getenv(%s) returned NULL\n" \
|
|---|
| 210 | "]\n", \
|
|---|
| 211 | key); \
|
|---|
| 212 | return false; \
|
|---|
| 213 | } \
|
|---|
| 214 | if (strcmp(result, _v) != 0) { \
|
|---|
| 215 | printf("failure: setenv [\n" \
|
|---|
| 216 | "getenv(%s): '%s' != '%s'\n" \
|
|---|
| 217 | "]\n", \
|
|---|
| 218 | key, result, _v); \
|
|---|
| 219 | return false; \
|
|---|
| 220 | } \
|
|---|
| 221 | } while(0)
|
|---|
| 222 |
|
|---|
| 223 | #define TEST_UNSETENV(key) do { \
|
|---|
| 224 | char *_v; \
|
|---|
| 225 | unsetenv(key); \
|
|---|
| 226 | _v=getenv(key); \
|
|---|
| 227 | if (_v) { \
|
|---|
| 228 | printf("failure: setenv [\n" \
|
|---|
| 229 | "getenv(%s): NULL != '%s'\n" \
|
|---|
| 230 | "]\n", \
|
|---|
| 231 | SETENVTEST_KEY, _v); \
|
|---|
| 232 | return false; \
|
|---|
| 233 | } \
|
|---|
| 234 | } while (0)
|
|---|
| 235 |
|
|---|
| 236 | #define SETENVTEST_KEY "SETENVTESTKEY"
|
|---|
| 237 | #define SETENVTEST_VAL "SETENVTESTVAL"
|
|---|
| 238 |
|
|---|
| 239 | printf("test: setenv\n");
|
|---|
| 240 | TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1");
|
|---|
| 241 | TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1");
|
|---|
| 242 | TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3");
|
|---|
| 243 | TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4");
|
|---|
| 244 | TEST_UNSETENV(SETENVTEST_KEY);
|
|---|
| 245 | TEST_UNSETENV(SETENVTEST_KEY);
|
|---|
| 246 | TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5");
|
|---|
| 247 | TEST_UNSETENV(SETENVTEST_KEY);
|
|---|
| 248 | TEST_UNSETENV(SETENVTEST_KEY);
|
|---|
| 249 | printf("success: setenv\n");
|
|---|
| 250 | return true;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | static int test_strndup(void)
|
|---|
| 254 | {
|
|---|
| 255 | char *x;
|
|---|
| 256 | printf("test: strndup\n");
|
|---|
| 257 | x = strndup("bla", 0);
|
|---|
| 258 | if (strcmp(x, "") != 0) {
|
|---|
| 259 | printf("failure: strndup [\ninvalid\n]\n");
|
|---|
| 260 | return false;
|
|---|
| 261 | }
|
|---|
| 262 | free(x);
|
|---|
| 263 | x = strndup("bla", 2);
|
|---|
| 264 | if (strcmp(x, "bl") != 0) {
|
|---|
| 265 | printf("failure: strndup [\ninvalid\n]\n");
|
|---|
| 266 | return false;
|
|---|
| 267 | }
|
|---|
| 268 | free(x);
|
|---|
| 269 | x = strndup("bla", 10);
|
|---|
| 270 | if (strcmp(x, "bla") != 0) {
|
|---|
| 271 | printf("failure: strndup [\ninvalid\n]\n");
|
|---|
| 272 | return false;
|
|---|
| 273 | }
|
|---|
| 274 | free(x);
|
|---|
| 275 | printf("success: strndup\n");
|
|---|
| 276 | return true;
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | static int test_strnlen(void)
|
|---|
| 280 | {
|
|---|
| 281 | printf("test: strnlen\n");
|
|---|
| 282 | if (strnlen("bla", 2) != 2) {
|
|---|
| 283 | printf("failure: strnlen [\nunexpected length\n]\n");
|
|---|
| 284 | return false;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | if (strnlen("some text\n", 0) != 0) {
|
|---|
| 288 | printf("failure: strnlen [\nunexpected length\n]\n");
|
|---|
| 289 | return false;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | if (strnlen("some text", 20) != 9) {
|
|---|
| 293 | printf("failure: strnlen [\nunexpected length\n]\n");
|
|---|
| 294 | return false;
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | printf("success: strnlen\n");
|
|---|
| 298 | return true;
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | static int test_waitpid(void)
|
|---|
| 302 | {
|
|---|
| 303 | /* FIXME */
|
|---|
| 304 | return true;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | static int test_seteuid(void)
|
|---|
| 308 | {
|
|---|
| 309 | /* FIXME */
|
|---|
| 310 | return true;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | static int test_setegid(void)
|
|---|
| 314 | {
|
|---|
| 315 | /* FIXME */
|
|---|
| 316 | return true;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | static int test_asprintf(void)
|
|---|
| 320 | {
|
|---|
| 321 | char *x;
|
|---|
| 322 | printf("test: asprintf\n");
|
|---|
| 323 | if (asprintf(&x, "%d", 9) != 1) {
|
|---|
| 324 | printf("failure: asprintf [\ngenerate asprintf\n]\n");
|
|---|
| 325 | return false;
|
|---|
| 326 | }
|
|---|
| 327 | if (strcmp(x, "9") != 0) {
|
|---|
| 328 | printf("failure: asprintf [\ngenerate asprintf\n]\n");
|
|---|
| 329 | return false;
|
|---|
| 330 | }
|
|---|
| 331 | if (asprintf(&x, "dat%s", "a") != 4) {
|
|---|
| 332 | printf("failure: asprintf [\ngenerate asprintf\n]\n");
|
|---|
| 333 | return false;
|
|---|
| 334 | }
|
|---|
| 335 | if (strcmp(x, "data") != 0) {
|
|---|
| 336 | printf("failure: asprintf [\ngenerate asprintf\n]\n");
|
|---|
| 337 | return false;
|
|---|
| 338 | }
|
|---|
| 339 | printf("success: asprintf\n");
|
|---|
| 340 | return true;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | static int test_snprintf(void)
|
|---|
| 344 | {
|
|---|
| 345 | char tmp[10];
|
|---|
| 346 | printf("test: snprintf\n");
|
|---|
| 347 | if (snprintf(tmp, 3, "foo%d", 9) != 4) {
|
|---|
| 348 | printf("failure: snprintf [\nsnprintf return code failed\n]\n");
|
|---|
| 349 | return false;
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | if (strcmp(tmp, "fo") != 0) {
|
|---|
| 353 | printf("failure: snprintf [\nsnprintf failed\n]\n");
|
|---|
| 354 | return false;
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | printf("success: snprintf\n");
|
|---|
| 358 | return true;
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | static int test_vasprintf(void)
|
|---|
| 362 | {
|
|---|
| 363 | /* FIXME */
|
|---|
| 364 | return true;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | static int test_vsnprintf(void)
|
|---|
| 368 | {
|
|---|
| 369 | /* FIXME */
|
|---|
| 370 | return true;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | static int test_opendir(void)
|
|---|
| 374 | {
|
|---|
| 375 | /* FIXME */
|
|---|
| 376 | return true;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | extern int test_readdir_os2_delete(void);
|
|---|
| 380 |
|
|---|
| 381 | static int test_readdir(void)
|
|---|
| 382 | {
|
|---|
| 383 | printf("test: readdir\n");
|
|---|
| 384 | if (test_readdir_os2_delete() != 0) {
|
|---|
| 385 | return false;
|
|---|
| 386 | }
|
|---|
| 387 | printf("success: readdir\n");
|
|---|
| 388 | return true;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | static int test_telldir(void)
|
|---|
| 392 | {
|
|---|
| 393 | /* FIXME */
|
|---|
| 394 | return true;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | static int test_seekdir(void)
|
|---|
| 398 | {
|
|---|
| 399 | /* FIXME */
|
|---|
| 400 | return true;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | static int test_dlopen(void)
|
|---|
| 404 | {
|
|---|
| 405 | /* FIXME: test dlopen, dlsym, dlclose, dlerror */
|
|---|
| 406 | return true;
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 | static int test_chroot(void)
|
|---|
| 411 | {
|
|---|
| 412 | /* FIXME: chroot() */
|
|---|
| 413 | return true;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | static int test_bzero(void)
|
|---|
| 417 | {
|
|---|
| 418 | /* FIXME: bzero */
|
|---|
| 419 | return true;
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | static int test_strerror(void)
|
|---|
| 423 | {
|
|---|
| 424 | /* FIXME */
|
|---|
| 425 | return true;
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | static int test_errno(void)
|
|---|
| 429 | {
|
|---|
| 430 | printf("test: errno\n");
|
|---|
| 431 | errno = 3;
|
|---|
| 432 | if (errno != 3) {
|
|---|
| 433 | printf("failure: errno [\nerrno failed\n]\n");
|
|---|
| 434 | return false;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | printf("success: errno\n");
|
|---|
| 438 | return true;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | static int test_mkdtemp(void)
|
|---|
| 442 | {
|
|---|
| 443 | /* FIXME */
|
|---|
| 444 | return true;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | static int test_mkstemp(void)
|
|---|
| 448 | {
|
|---|
| 449 | /* FIXME */
|
|---|
| 450 | return true;
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | static int test_pread(void)
|
|---|
| 454 | {
|
|---|
| 455 | /* FIXME */
|
|---|
| 456 | return true;
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | static int test_pwrite(void)
|
|---|
| 460 | {
|
|---|
| 461 | /* FIXME */
|
|---|
| 462 | return true;
|
|---|
| 463 | }
|
|---|
| 464 |
|
|---|
| 465 | static int test_getpass(void)
|
|---|
| 466 | {
|
|---|
| 467 | /* FIXME */
|
|---|
| 468 | return true;
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | static int test_inet_ntoa(void)
|
|---|
| 472 | {
|
|---|
| 473 | /* FIXME */
|
|---|
| 474 | return true;
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | #define TEST_STRTO_X(type,fmt,func,str,base,res,diff,rrnoo) do {\
|
|---|
| 478 | type _v; \
|
|---|
| 479 | char _s[64]; \
|
|---|
| 480 | char *_p = NULL;\
|
|---|
| 481 | char *_ep = NULL; \
|
|---|
| 482 | strlcpy(_s, str, sizeof(_s));\
|
|---|
| 483 | if (diff >= 0) { \
|
|---|
| 484 | _ep = &_s[diff]; \
|
|---|
| 485 | } \
|
|---|
| 486 | errno = 0; \
|
|---|
| 487 | _v = func(_s, &_p, base); \
|
|---|
| 488 | if (errno != rrnoo) { \
|
|---|
| 489 | printf("failure: %s [\n" \
|
|---|
| 490 | "\t%s\n" \
|
|---|
| 491 | "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
|
|---|
| 492 | "\terrno: %d != %d\n" \
|
|---|
| 493 | "]\n", \
|
|---|
| 494 | __STRING(func), __location__, __STRING(func), \
|
|---|
| 495 | str, diff, base, res, _v, rrnoo, errno); \
|
|---|
| 496 | return false; \
|
|---|
| 497 | } else if (_v != res) { \
|
|---|
| 498 | printf("failure: %s [\n" \
|
|---|
| 499 | "\t%s\n" \
|
|---|
| 500 | "\t%s(\"%s\",%d,%d): " fmt " != " fmt "\n" \
|
|---|
| 501 | "]\n", \
|
|---|
| 502 | __STRING(func), __location__, __STRING(func), \
|
|---|
| 503 | str, diff, base, res, _v); \
|
|---|
| 504 | return false; \
|
|---|
| 505 | } else if (_p != _ep) { \
|
|---|
| 506 | printf("failure: %s [\n" \
|
|---|
| 507 | "\t%s\n" \
|
|---|
| 508 | "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
|
|---|
| 509 | "\tptr: %p - %p = %d != %d\n" \
|
|---|
| 510 | "]\n", \
|
|---|
| 511 | __STRING(func), __location__, __STRING(func), \
|
|---|
| 512 | str, diff, base, res, _v, _ep, _p, (int)(diff - (_ep - _p)), diff); \
|
|---|
| 513 | return false; \
|
|---|
| 514 | } \
|
|---|
| 515 | } while (0)
|
|---|
| 516 |
|
|---|
| 517 | static int test_strtoll(void)
|
|---|
| 518 | {
|
|---|
| 519 | printf("test: strtoll\n");
|
|---|
| 520 |
|
|---|
| 521 | #define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(long long int, "%lld", strtoll,str,base,res,diff,errnoo)
|
|---|
| 522 |
|
|---|
| 523 | TEST_STRTOLL("15", 10, 15LL, 2, 0);
|
|---|
| 524 | TEST_STRTOLL(" 15", 10, 15LL, 4, 0);
|
|---|
| 525 | TEST_STRTOLL("15", 0, 15LL, 2, 0);
|
|---|
| 526 | TEST_STRTOLL(" 15 ", 0, 15LL, 3, 0);
|
|---|
| 527 | TEST_STRTOLL("+15", 10, 15LL, 3, 0);
|
|---|
| 528 | TEST_STRTOLL(" +15", 10, 15LL, 5, 0);
|
|---|
| 529 | TEST_STRTOLL("+15", 0, 15LL, 3, 0);
|
|---|
| 530 | TEST_STRTOLL(" +15 ", 0, 15LL, 4, 0);
|
|---|
| 531 | TEST_STRTOLL("-15", 10, -15LL, 3, 0);
|
|---|
| 532 | TEST_STRTOLL(" -15", 10, -15LL, 5, 0);
|
|---|
| 533 | TEST_STRTOLL("-15", 0, -15LL, 3, 0);
|
|---|
| 534 | TEST_STRTOLL(" -15 ", 0, -15LL, 4, 0);
|
|---|
| 535 | TEST_STRTOLL("015", 10, 15LL, 3, 0);
|
|---|
| 536 | TEST_STRTOLL(" 015", 10, 15LL, 5, 0);
|
|---|
| 537 | TEST_STRTOLL("015", 0, 13LL, 3, 0);
|
|---|
| 538 | TEST_STRTOLL(" 015", 0, 13LL, 5, 0);
|
|---|
| 539 | TEST_STRTOLL("0x15", 10, 0LL, 1, 0);
|
|---|
| 540 | TEST_STRTOLL(" 0x15", 10, 0LL, 3, 0);
|
|---|
| 541 | TEST_STRTOLL("0x15", 0, 21LL, 4, 0);
|
|---|
| 542 | TEST_STRTOLL(" 0x15", 0, 21LL, 6, 0);
|
|---|
| 543 |
|
|---|
| 544 | TEST_STRTOLL("10", 16, 16LL, 2, 0);
|
|---|
| 545 | TEST_STRTOLL(" 10 ", 16, 16LL, 4, 0);
|
|---|
| 546 | TEST_STRTOLL("0x10", 16, 16LL, 4, 0);
|
|---|
| 547 | TEST_STRTOLL("0x10", 0, 16LL, 4, 0);
|
|---|
| 548 | TEST_STRTOLL(" 0x10 ", 0, 16LL, 5, 0);
|
|---|
| 549 | TEST_STRTOLL("+10", 16, 16LL, 3, 0);
|
|---|
| 550 | TEST_STRTOLL(" +10 ", 16, 16LL, 5, 0);
|
|---|
| 551 | TEST_STRTOLL("+0x10", 16, 16LL, 5, 0);
|
|---|
| 552 | TEST_STRTOLL("+0x10", 0, 16LL, 5, 0);
|
|---|
| 553 | TEST_STRTOLL(" +0x10 ", 0, 16LL, 6, 0);
|
|---|
| 554 | TEST_STRTOLL("-10", 16, -16LL, 3, 0);
|
|---|
| 555 | TEST_STRTOLL(" -10 ", 16, -16LL, 5, 0);
|
|---|
| 556 | TEST_STRTOLL("-0x10", 16, -16LL, 5, 0);
|
|---|
| 557 | TEST_STRTOLL("-0x10", 0, -16LL, 5, 0);
|
|---|
| 558 | TEST_STRTOLL(" -0x10 ", 0, -16LL, 6, 0);
|
|---|
| 559 | TEST_STRTOLL("010", 16, 16LL, 3, 0);
|
|---|
| 560 | TEST_STRTOLL(" 010 ", 16, 16LL, 5, 0);
|
|---|
| 561 | TEST_STRTOLL("-010", 16, -16LL, 4, 0);
|
|---|
| 562 |
|
|---|
| 563 | TEST_STRTOLL("11", 8, 9LL, 2, 0);
|
|---|
| 564 | TEST_STRTOLL("011", 8, 9LL, 3, 0);
|
|---|
| 565 | TEST_STRTOLL("011", 0, 9LL, 3, 0);
|
|---|
| 566 | TEST_STRTOLL("-11", 8, -9LL, 3, 0);
|
|---|
| 567 | TEST_STRTOLL("-011", 8, -9LL, 4, 0);
|
|---|
| 568 | TEST_STRTOLL("-011", 0, -9LL, 4, 0);
|
|---|
| 569 |
|
|---|
| 570 | TEST_STRTOLL("011", 8, 9LL, 3, 0);
|
|---|
| 571 | TEST_STRTOLL("011", 0, 9LL, 3, 0);
|
|---|
| 572 | TEST_STRTOLL("-11", 8, -9LL, 3, 0);
|
|---|
| 573 | TEST_STRTOLL("-011", 8, -9LL, 4, 0);
|
|---|
| 574 | TEST_STRTOLL("-011", 0, -9LL, 4, 0);
|
|---|
| 575 |
|
|---|
| 576 | TEST_STRTOLL("Text", 0, 0LL, 0, 0);
|
|---|
| 577 |
|
|---|
| 578 | TEST_STRTOLL("9223372036854775807", 10, 9223372036854775807LL, 19, 0);
|
|---|
| 579 | TEST_STRTOLL("9223372036854775807", 0, 9223372036854775807LL, 19, 0);
|
|---|
| 580 | TEST_STRTOLL("9223372036854775808", 0, 9223372036854775807LL, 19, ERANGE);
|
|---|
| 581 | TEST_STRTOLL("9223372036854775808", 10, 9223372036854775807LL, 19, ERANGE);
|
|---|
| 582 | TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LL, 18, 0);
|
|---|
| 583 | TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 18, 0);
|
|---|
| 584 | TEST_STRTOLL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 16, 0);
|
|---|
| 585 | TEST_STRTOLL("0x8000000000000000", 0, 9223372036854775807LL, 18, ERANGE);
|
|---|
| 586 | TEST_STRTOLL("0x8000000000000000", 16, 9223372036854775807LL, 18, ERANGE);
|
|---|
| 587 | TEST_STRTOLL("80000000000000000", 16, 9223372036854775807LL, 17, ERANGE);
|
|---|
| 588 | TEST_STRTOLL("0777777777777777777777", 0, 9223372036854775807LL, 22, 0);
|
|---|
| 589 | TEST_STRTOLL("0777777777777777777777", 8, 9223372036854775807LL, 22, 0);
|
|---|
| 590 | TEST_STRTOLL("777777777777777777777", 8, 9223372036854775807LL, 21, 0);
|
|---|
| 591 | TEST_STRTOLL("01000000000000000000000", 0, 9223372036854775807LL, 23, ERANGE);
|
|---|
| 592 | TEST_STRTOLL("01000000000000000000000", 8, 9223372036854775807LL, 23, ERANGE);
|
|---|
| 593 | TEST_STRTOLL("1000000000000000000000", 8, 9223372036854775807LL, 22, ERANGE);
|
|---|
| 594 |
|
|---|
| 595 | TEST_STRTOLL("-9223372036854775808", 10, -9223372036854775807LL -1, 20, 0);
|
|---|
| 596 | TEST_STRTOLL("-9223372036854775808", 0, -9223372036854775807LL -1, 20, 0);
|
|---|
| 597 | TEST_STRTOLL("-9223372036854775809", 0, -9223372036854775807LL -1, 20, ERANGE);
|
|---|
| 598 | TEST_STRTOLL("-9223372036854775809", 10, -9223372036854775807LL -1, 20, ERANGE);
|
|---|
| 599 | TEST_STRTOLL("-0x8000000000000000", 0, -9223372036854775807LL -1, 19, 0);
|
|---|
| 600 | TEST_STRTOLL("-0x8000000000000000", 16, -9223372036854775807LL -1, 19, 0);
|
|---|
| 601 | TEST_STRTOLL("-8000000000000000", 16, -9223372036854775807LL -1, 17, 0);
|
|---|
| 602 | TEST_STRTOLL("-0x8000000000000001", 0, -9223372036854775807LL -1, 19, ERANGE);
|
|---|
| 603 | TEST_STRTOLL("-0x8000000000000001", 16, -9223372036854775807LL -1, 19, ERANGE);
|
|---|
| 604 | TEST_STRTOLL("-80000000000000001", 16, -9223372036854775807LL -1, 18, ERANGE);
|
|---|
| 605 | TEST_STRTOLL("-01000000000000000000000",0, -9223372036854775807LL -1, 24, 0);
|
|---|
| 606 | TEST_STRTOLL("-01000000000000000000000",8, -9223372036854775807LL -1, 24, 0);
|
|---|
| 607 | TEST_STRTOLL("-1000000000000000000000", 8, -9223372036854775807LL -1, 23, 0);
|
|---|
| 608 | TEST_STRTOLL("-01000000000000000000001",0, -9223372036854775807LL -1, 24, ERANGE);
|
|---|
| 609 | TEST_STRTOLL("-01000000000000000000001",8, -9223372036854775807LL -1, 24, ERANGE);
|
|---|
| 610 | TEST_STRTOLL("-1000000000000000000001", 8, -9223372036854775807LL -1, 23, ERANGE);
|
|---|
| 611 |
|
|---|
| 612 | printf("success: strtoll\n");
|
|---|
| 613 | return true;
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | static int test_strtoull(void)
|
|---|
| 617 | {
|
|---|
| 618 | printf("test: strtoull\n");
|
|---|
| 619 |
|
|---|
| 620 | #define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(long long unsigned int,"%llu",strtoull,str,base,res,diff,errnoo)
|
|---|
| 621 |
|
|---|
| 622 | TEST_STRTOULL("15", 10, 15LLU, 2, 0);
|
|---|
| 623 | TEST_STRTOULL(" 15", 10, 15LLU, 4, 0);
|
|---|
| 624 | TEST_STRTOULL("15", 0, 15LLU, 2, 0);
|
|---|
| 625 | TEST_STRTOULL(" 15 ", 0, 15LLU, 3, 0);
|
|---|
| 626 | TEST_STRTOULL("+15", 10, 15LLU, 3, 0);
|
|---|
| 627 | TEST_STRTOULL(" +15", 10, 15LLU, 5, 0);
|
|---|
| 628 | TEST_STRTOULL("+15", 0, 15LLU, 3, 0);
|
|---|
| 629 | TEST_STRTOULL(" +15 ", 0, 15LLU, 4, 0);
|
|---|
| 630 | TEST_STRTOULL("-15", 10, 18446744073709551601LLU, 3, 0);
|
|---|
| 631 | TEST_STRTOULL(" -15", 10, 18446744073709551601LLU, 5, 0);
|
|---|
| 632 | TEST_STRTOULL("-15", 0, 18446744073709551601LLU, 3, 0);
|
|---|
| 633 | TEST_STRTOULL(" -15 ", 0, 18446744073709551601LLU, 4, 0);
|
|---|
| 634 | TEST_STRTOULL("015", 10, 15LLU, 3, 0);
|
|---|
| 635 | TEST_STRTOULL(" 015", 10, 15LLU, 5, 0);
|
|---|
| 636 | TEST_STRTOULL("015", 0, 13LLU, 3, 0);
|
|---|
| 637 | TEST_STRTOULL(" 015", 0, 13LLU, 5, 0);
|
|---|
| 638 | TEST_STRTOULL("0x15", 10, 0LLU, 1, 0);
|
|---|
| 639 | TEST_STRTOULL(" 0x15", 10, 0LLU, 3, 0);
|
|---|
| 640 | TEST_STRTOULL("0x15", 0, 21LLU, 4, 0);
|
|---|
| 641 | TEST_STRTOULL(" 0x15", 0, 21LLU, 6, 0);
|
|---|
| 642 |
|
|---|
| 643 | TEST_STRTOULL("10", 16, 16LLU, 2, 0);
|
|---|
| 644 | TEST_STRTOULL(" 10 ", 16, 16LLU, 4, 0);
|
|---|
| 645 | TEST_STRTOULL("0x10", 16, 16LLU, 4, 0);
|
|---|
| 646 | TEST_STRTOULL("0x10", 0, 16LLU, 4, 0);
|
|---|
| 647 | TEST_STRTOULL(" 0x10 ", 0, 16LLU, 5, 0);
|
|---|
| 648 | TEST_STRTOULL("+10", 16, 16LLU, 3, 0);
|
|---|
| 649 | TEST_STRTOULL(" +10 ", 16, 16LLU, 5, 0);
|
|---|
| 650 | TEST_STRTOULL("+0x10", 16, 16LLU, 5, 0);
|
|---|
| 651 | TEST_STRTOULL("+0x10", 0, 16LLU, 5, 0);
|
|---|
| 652 | TEST_STRTOULL(" +0x10 ", 0, 16LLU, 6, 0);
|
|---|
| 653 | TEST_STRTOULL("-10", 16, -16LLU, 3, 0);
|
|---|
| 654 | TEST_STRTOULL(" -10 ", 16, -16LLU, 5, 0);
|
|---|
| 655 | TEST_STRTOULL("-0x10", 16, -16LLU, 5, 0);
|
|---|
| 656 | TEST_STRTOULL("-0x10", 0, -16LLU, 5, 0);
|
|---|
| 657 | TEST_STRTOULL(" -0x10 ", 0, -16LLU, 6, 0);
|
|---|
| 658 | TEST_STRTOULL("010", 16, 16LLU, 3, 0);
|
|---|
| 659 | TEST_STRTOULL(" 010 ", 16, 16LLU, 5, 0);
|
|---|
| 660 | TEST_STRTOULL("-010", 16, -16LLU, 4, 0);
|
|---|
| 661 |
|
|---|
| 662 | TEST_STRTOULL("11", 8, 9LLU, 2, 0);
|
|---|
| 663 | TEST_STRTOULL("011", 8, 9LLU, 3, 0);
|
|---|
| 664 | TEST_STRTOULL("011", 0, 9LLU, 3, 0);
|
|---|
| 665 | TEST_STRTOULL("-11", 8, -9LLU, 3, 0);
|
|---|
| 666 | TEST_STRTOULL("-011", 8, -9LLU, 4, 0);
|
|---|
| 667 | TEST_STRTOULL("-011", 0, -9LLU, 4, 0);
|
|---|
| 668 |
|
|---|
| 669 | TEST_STRTOULL("011", 8, 9LLU, 3, 0);
|
|---|
| 670 | TEST_STRTOULL("011", 0, 9LLU, 3, 0);
|
|---|
| 671 | TEST_STRTOULL("-11", 8, -9LLU, 3, 0);
|
|---|
| 672 | TEST_STRTOULL("-011", 8, -9LLU, 4, 0);
|
|---|
| 673 | TEST_STRTOULL("-011", 0, -9LLU, 4, 0);
|
|---|
| 674 |
|
|---|
| 675 | TEST_STRTOULL("Text", 0, 0LLU, 0, 0);
|
|---|
| 676 |
|
|---|
| 677 | TEST_STRTOULL("9223372036854775807", 10, 9223372036854775807LLU, 19, 0);
|
|---|
| 678 | TEST_STRTOULL("9223372036854775807", 0, 9223372036854775807LLU, 19, 0);
|
|---|
| 679 | TEST_STRTOULL("9223372036854775808", 0, 9223372036854775808LLU, 19, 0);
|
|---|
| 680 | TEST_STRTOULL("9223372036854775808", 10, 9223372036854775808LLU, 19, 0);
|
|---|
| 681 | TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LLU, 18, 0);
|
|---|
| 682 | TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 18, 0);
|
|---|
| 683 | TEST_STRTOULL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 16, 0);
|
|---|
| 684 | TEST_STRTOULL("0x8000000000000000", 0, 9223372036854775808LLU, 18, 0);
|
|---|
| 685 | TEST_STRTOULL("0x8000000000000000", 16, 9223372036854775808LLU, 18, 0);
|
|---|
| 686 | TEST_STRTOULL("8000000000000000", 16, 9223372036854775808LLU, 16, 0);
|
|---|
| 687 | TEST_STRTOULL("0777777777777777777777", 0, 9223372036854775807LLU, 22, 0);
|
|---|
| 688 | TEST_STRTOULL("0777777777777777777777", 8, 9223372036854775807LLU, 22, 0);
|
|---|
| 689 | TEST_STRTOULL("777777777777777777777", 8, 9223372036854775807LLU, 21, 0);
|
|---|
| 690 | TEST_STRTOULL("01000000000000000000000",0, 9223372036854775808LLU, 23, 0);
|
|---|
| 691 | TEST_STRTOULL("01000000000000000000000",8, 9223372036854775808LLU, 23, 0);
|
|---|
| 692 | TEST_STRTOULL("1000000000000000000000", 8, 9223372036854775808LLU, 22, 0);
|
|---|
| 693 |
|
|---|
| 694 | TEST_STRTOULL("-9223372036854775808", 10, 9223372036854775808LLU, 20, 0);
|
|---|
| 695 | TEST_STRTOULL("-9223372036854775808", 0, 9223372036854775808LLU, 20, 0);
|
|---|
| 696 | TEST_STRTOULL("-9223372036854775809", 0, 9223372036854775807LLU, 20, 0);
|
|---|
| 697 | TEST_STRTOULL("-9223372036854775809", 10, 9223372036854775807LLU, 20, 0);
|
|---|
| 698 | TEST_STRTOULL("-0x8000000000000000", 0, 9223372036854775808LLU, 19, 0);
|
|---|
| 699 | TEST_STRTOULL("-0x8000000000000000", 16, 9223372036854775808LLU, 19, 0);
|
|---|
| 700 | TEST_STRTOULL("-8000000000000000", 16, 9223372036854775808LLU, 17, 0);
|
|---|
| 701 | TEST_STRTOULL("-0x8000000000000001", 0, 9223372036854775807LLU, 19, 0);
|
|---|
| 702 | TEST_STRTOULL("-0x8000000000000001", 16, 9223372036854775807LLU, 19, 0);
|
|---|
| 703 | TEST_STRTOULL("-8000000000000001", 16, 9223372036854775807LLU, 17, 0);
|
|---|
| 704 | TEST_STRTOULL("-01000000000000000000000",0, 9223372036854775808LLU, 24, 0);
|
|---|
| 705 | TEST_STRTOULL("-01000000000000000000000",8, 9223372036854775808LLU, 24, 0);
|
|---|
| 706 | TEST_STRTOULL("-1000000000000000000000",8, 9223372036854775808LLU, 23, 0);
|
|---|
| 707 | TEST_STRTOULL("-01000000000000000000001",0, 9223372036854775807LLU, 24, 0);
|
|---|
| 708 | TEST_STRTOULL("-01000000000000000000001",8, 9223372036854775807LLU, 24, 0);
|
|---|
| 709 | TEST_STRTOULL("-1000000000000000000001",8, 9223372036854775807LLU, 23, 0);
|
|---|
| 710 |
|
|---|
| 711 | TEST_STRTOULL("18446744073709551615", 0, 18446744073709551615LLU, 20, 0);
|
|---|
| 712 | TEST_STRTOULL("18446744073709551615", 10, 18446744073709551615LLU, 20, 0);
|
|---|
| 713 | TEST_STRTOULL("18446744073709551616", 0, 18446744073709551615LLU, 20, ERANGE);
|
|---|
| 714 | TEST_STRTOULL("18446744073709551616", 10, 18446744073709551615LLU, 20, ERANGE);
|
|---|
| 715 | TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 0, 18446744073709551615LLU, 18, 0);
|
|---|
| 716 | TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 18, 0);
|
|---|
| 717 | TEST_STRTOULL("FFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 16, 0);
|
|---|
| 718 | TEST_STRTOULL("0x10000000000000000", 0, 18446744073709551615LLU, 19, ERANGE);
|
|---|
| 719 | TEST_STRTOULL("0x10000000000000000", 16, 18446744073709551615LLU, 19, ERANGE);
|
|---|
| 720 | TEST_STRTOULL("10000000000000000", 16, 18446744073709551615LLU, 17, ERANGE);
|
|---|
| 721 | TEST_STRTOULL("01777777777777777777777",0, 18446744073709551615LLU, 23, 0);
|
|---|
| 722 | TEST_STRTOULL("01777777777777777777777",8, 18446744073709551615LLU, 23, 0);
|
|---|
| 723 | TEST_STRTOULL("1777777777777777777777", 8, 18446744073709551615LLU, 22, 0);
|
|---|
| 724 | TEST_STRTOULL("02000000000000000000000",0, 18446744073709551615LLU, 23, ERANGE);
|
|---|
| 725 | TEST_STRTOULL("02000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE);
|
|---|
| 726 | TEST_STRTOULL("2000000000000000000000", 8, 18446744073709551615LLU, 22, ERANGE);
|
|---|
| 727 |
|
|---|
| 728 | TEST_STRTOULL("-18446744073709551615", 0, 1LLU, 21, 0);
|
|---|
| 729 | TEST_STRTOULL("-18446744073709551615", 10, 1LLU, 21, 0);
|
|---|
| 730 | TEST_STRTOULL("-18446744073709551616", 0, 18446744073709551615LLU, 21, ERANGE);
|
|---|
| 731 | TEST_STRTOULL("-18446744073709551616", 10, 18446744073709551615LLU, 21, ERANGE);
|
|---|
| 732 | TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 0, 1LLU, 19, 0);
|
|---|
| 733 | TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 16, 1LLU, 19, 0);
|
|---|
| 734 | TEST_STRTOULL("-FFFFFFFFFFFFFFFF", 16, 1LLU, 17, 0);
|
|---|
| 735 | TEST_STRTOULL("-0x10000000000000000", 0, 18446744073709551615LLU, 20, ERANGE);
|
|---|
| 736 | TEST_STRTOULL("-0x10000000000000000", 16, 18446744073709551615LLU, 20, ERANGE);
|
|---|
| 737 | TEST_STRTOULL("-10000000000000000", 16, 18446744073709551615LLU, 18, ERANGE);
|
|---|
| 738 | TEST_STRTOULL("-01777777777777777777777",0, 1LLU, 24, 0);
|
|---|
| 739 | TEST_STRTOULL("-01777777777777777777777",8, 1LLU, 24, 0);
|
|---|
| 740 | TEST_STRTOULL("-1777777777777777777777",8, 1LLU, 23, 0);
|
|---|
| 741 | TEST_STRTOULL("-02000000000000000000000",0, 18446744073709551615LLU, 24, ERANGE);
|
|---|
| 742 | TEST_STRTOULL("-02000000000000000000000",8, 18446744073709551615LLU, 24, ERANGE);
|
|---|
| 743 | TEST_STRTOULL("-2000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE);
|
|---|
| 744 |
|
|---|
| 745 | printf("success: strtoull\n");
|
|---|
| 746 | return true;
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 | /*
|
|---|
| 750 | FIXME:
|
|---|
| 751 | Types:
|
|---|
| 752 | bool
|
|---|
| 753 | socklen_t
|
|---|
| 754 | uint{8,16,32,64}_t
|
|---|
| 755 | int{8,16,32,64}_t
|
|---|
| 756 | intptr_t
|
|---|
| 757 |
|
|---|
| 758 | Constants:
|
|---|
| 759 | PATH_NAME_MAX
|
|---|
| 760 | UINT{16,32,64}_MAX
|
|---|
| 761 | INT32_MAX
|
|---|
| 762 | */
|
|---|
| 763 |
|
|---|
| 764 | static int test_va_copy(void)
|
|---|
| 765 | {
|
|---|
| 766 | /* FIXME */
|
|---|
| 767 | return true;
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | static int test_FUNCTION(void)
|
|---|
| 771 | {
|
|---|
| 772 | printf("test: FUNCTION\n");
|
|---|
| 773 | if (strcmp(__FUNCTION__, "test_FUNCTION") != 0) {
|
|---|
| 774 | printf("failure: FUNCTION [\nFUNCTION invalid\n]\n");
|
|---|
| 775 | return false;
|
|---|
| 776 | }
|
|---|
| 777 | printf("success: FUNCTION\n");
|
|---|
| 778 | return true;
|
|---|
| 779 | }
|
|---|
| 780 |
|
|---|
| 781 | static int test_MIN(void)
|
|---|
| 782 | {
|
|---|
| 783 | printf("test: MIN\n");
|
|---|
| 784 | if (MIN(20, 1) != 1) {
|
|---|
| 785 | printf("failure: MIN [\nMIN invalid\n]\n");
|
|---|
| 786 | return false;
|
|---|
| 787 | }
|
|---|
| 788 | if (MIN(1, 20) != 1) {
|
|---|
| 789 | printf("failure: MIN [\nMIN invalid\n]\n");
|
|---|
| 790 | return false;
|
|---|
| 791 | }
|
|---|
| 792 | printf("success: MIN\n");
|
|---|
| 793 | return true;
|
|---|
| 794 | }
|
|---|
| 795 |
|
|---|
| 796 | static int test_MAX(void)
|
|---|
| 797 | {
|
|---|
| 798 | printf("test: MAX\n");
|
|---|
| 799 | if (MAX(20, 1) != 20) {
|
|---|
| 800 | printf("failure: MAX [\nMAX invalid\n]\n");
|
|---|
| 801 | return false;
|
|---|
| 802 | }
|
|---|
| 803 | if (MAX(1, 20) != 20) {
|
|---|
| 804 | printf("failure: MAX [\nMAX invalid\n]\n");
|
|---|
| 805 | return false;
|
|---|
| 806 | }
|
|---|
| 807 | printf("success: MAX\n");
|
|---|
| 808 | return true;
|
|---|
| 809 | }
|
|---|
| 810 |
|
|---|
| 811 | static int test_socketpair(void)
|
|---|
| 812 | {
|
|---|
| 813 | int sock[2];
|
|---|
| 814 | char buf[20];
|
|---|
| 815 |
|
|---|
| 816 | printf("test: socketpair\n");
|
|---|
| 817 |
|
|---|
| 818 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
|
|---|
| 819 | printf("failure: socketpair [\n"
|
|---|
| 820 | "socketpair() failed\n"
|
|---|
| 821 | "]\n");
|
|---|
| 822 | return false;
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 | if (write(sock[1], "automatisch", 12) == -1) {
|
|---|
| 826 | printf("failure: socketpair [\n"
|
|---|
| 827 | "write() failed: %s\n"
|
|---|
| 828 | "]\n", strerror(errno));
|
|---|
| 829 | return false;
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 | if (read(sock[0], buf, 12) == -1) {
|
|---|
| 833 | printf("failure: socketpair [\n"
|
|---|
| 834 | "read() failed: %s\n"
|
|---|
| 835 | "]\n", strerror(errno));
|
|---|
| 836 | return false;
|
|---|
| 837 | }
|
|---|
| 838 |
|
|---|
| 839 | if (strcmp(buf, "automatisch") != 0) {
|
|---|
| 840 | printf("failure: socketpair [\n"
|
|---|
| 841 | "expected: automatisch, got: %s\n"
|
|---|
| 842 | "]\n", buf);
|
|---|
| 843 | return false;
|
|---|
| 844 | }
|
|---|
| 845 |
|
|---|
| 846 | printf("success: socketpair\n");
|
|---|
| 847 |
|
|---|
| 848 | return true;
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | extern int libreplace_test_strptime(void);
|
|---|
| 852 |
|
|---|
| 853 | static int test_strptime(void)
|
|---|
| 854 | {
|
|---|
| 855 | return libreplace_test_strptime();
|
|---|
| 856 | }
|
|---|
| 857 |
|
|---|
| 858 | extern int getifaddrs_test(void);
|
|---|
| 859 |
|
|---|
| 860 | static int test_getifaddrs(void)
|
|---|
| 861 | {
|
|---|
| 862 |
|
|---|
| 863 | printf("test: getifaddrs\n");
|
|---|
| 864 |
|
|---|
| 865 | if (getifaddrs_test() != 0) {
|
|---|
| 866 | printf("failure: getifaddrs\n");
|
|---|
| 867 | return false;
|
|---|
| 868 | }
|
|---|
| 869 |
|
|---|
| 870 | printf("success: getifaddrs\n");
|
|---|
| 871 | return true;
|
|---|
| 872 | }
|
|---|
| 873 |
|
|---|
| 874 | static int test_utime(void)
|
|---|
| 875 | {
|
|---|
| 876 | struct utimbuf u;
|
|---|
| 877 | struct stat st1, st2, st3;
|
|---|
| 878 | int fd;
|
|---|
| 879 |
|
|---|
| 880 | printf("test: utime\n");
|
|---|
| 881 | unlink(TESTFILE);
|
|---|
| 882 |
|
|---|
| 883 | fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
|
|---|
| 884 | if (fd == -1) {
|
|---|
| 885 | printf("failure: utime [\n"
|
|---|
| 886 | "creating '%s' failed - %s\n]\n",
|
|---|
| 887 | TESTFILE, strerror(errno));
|
|---|
| 888 | return false;
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 | if (fstat(fd, &st1) != 0) {
|
|---|
| 892 | printf("failure: utime [\n"
|
|---|
| 893 | "fstat (1) failed - %s\n]\n",
|
|---|
| 894 | strerror(errno));
|
|---|
| 895 | return false;
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | u.actime = st1.st_atime + 300;
|
|---|
| 899 | u.modtime = st1.st_mtime - 300;
|
|---|
| 900 | if (utime(TESTFILE, &u) != 0) {
|
|---|
| 901 | printf("failure: utime [\n"
|
|---|
| 902 | "utime(&u) failed - %s\n]\n",
|
|---|
| 903 | strerror(errno));
|
|---|
| 904 | return false;
|
|---|
| 905 | }
|
|---|
| 906 |
|
|---|
| 907 | if (fstat(fd, &st2) != 0) {
|
|---|
| 908 | printf("failure: utime [\n"
|
|---|
| 909 | "fstat (2) failed - %s\n]\n",
|
|---|
| 910 | strerror(errno));
|
|---|
| 911 | return false;
|
|---|
| 912 | }
|
|---|
| 913 |
|
|---|
| 914 | if (utime(TESTFILE, NULL) != 0) {
|
|---|
| 915 | printf("failure: utime [\n"
|
|---|
| 916 | "utime(NULL) failed - %s\n]\n",
|
|---|
| 917 | strerror(errno));
|
|---|
| 918 | return false;
|
|---|
| 919 | }
|
|---|
| 920 |
|
|---|
| 921 | if (fstat(fd, &st3) != 0) {
|
|---|
| 922 | printf("failure: utime [\n"
|
|---|
| 923 | "fstat (3) failed - %s\n]\n",
|
|---|
| 924 | strerror(errno));
|
|---|
| 925 | return false;
|
|---|
| 926 | }
|
|---|
| 927 |
|
|---|
| 928 | #define CMP_VAL(a,c,b) do { \
|
|---|
| 929 | if (a c b) { \
|
|---|
| 930 | printf("failure: utime [\n" \
|
|---|
| 931 | "%s: %s(%d) %s %s(%d)\n]\n", \
|
|---|
| 932 | __location__, \
|
|---|
| 933 | #a, (int)a, #c, #b, (int)b); \
|
|---|
| 934 | return false; \
|
|---|
| 935 | } \
|
|---|
| 936 | } while(0)
|
|---|
| 937 | #define EQUAL_VAL(a,b) CMP_VAL(a,!=,b)
|
|---|
| 938 | #define GREATER_VAL(a,b) CMP_VAL(a,<=,b)
|
|---|
| 939 | #define LESSER_VAL(a,b) CMP_VAL(a,>=,b)
|
|---|
| 940 |
|
|---|
| 941 | EQUAL_VAL(st2.st_atime, st1.st_atime + 300);
|
|---|
| 942 | EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300);
|
|---|
| 943 | LESSER_VAL(st3.st_atime, st2.st_atime);
|
|---|
| 944 | GREATER_VAL(st3.st_mtime, st2.st_mtime);
|
|---|
| 945 |
|
|---|
| 946 | #undef CMP_VAL
|
|---|
| 947 | #undef EQUAL_VAL
|
|---|
| 948 | #undef GREATER_VAL
|
|---|
| 949 | #undef LESSER_VAL
|
|---|
| 950 |
|
|---|
| 951 | unlink(TESTFILE);
|
|---|
| 952 | printf("success: utime\n");
|
|---|
| 953 | return true;
|
|---|
| 954 | }
|
|---|
| 955 |
|
|---|
| 956 | static int test_utimes(void)
|
|---|
| 957 | {
|
|---|
| 958 | struct timeval tv[2];
|
|---|
| 959 | struct stat st1, st2;
|
|---|
| 960 | int fd;
|
|---|
| 961 |
|
|---|
| 962 | printf("test: utimes\n");
|
|---|
| 963 | unlink(TESTFILE);
|
|---|
| 964 |
|
|---|
| 965 | fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
|
|---|
| 966 | if (fd == -1) {
|
|---|
| 967 | printf("failure: utimes [\n"
|
|---|
| 968 | "creating '%s' failed - %s\n]\n",
|
|---|
| 969 | TESTFILE, strerror(errno));
|
|---|
| 970 | return false;
|
|---|
| 971 | }
|
|---|
| 972 |
|
|---|
| 973 | if (fstat(fd, &st1) != 0) {
|
|---|
| 974 | printf("failure: utimes [\n"
|
|---|
| 975 | "fstat (1) failed - %s\n]\n",
|
|---|
| 976 | strerror(errno));
|
|---|
| 977 | return false;
|
|---|
| 978 | }
|
|---|
| 979 |
|
|---|
| 980 | ZERO_STRUCT(tv);
|
|---|
| 981 | tv[0].tv_sec = st1.st_atime + 300;
|
|---|
| 982 | tv[1].tv_sec = st1.st_mtime - 300;
|
|---|
| 983 | if (utimes(TESTFILE, tv) != 0) {
|
|---|
| 984 | printf("failure: utimes [\n"
|
|---|
| 985 | "utimes(tv) failed - %s\n]\n",
|
|---|
| 986 | strerror(errno));
|
|---|
| 987 | return false;
|
|---|
| 988 | }
|
|---|
| 989 |
|
|---|
| 990 | if (fstat(fd, &st2) != 0) {
|
|---|
| 991 | printf("failure: utimes [\n"
|
|---|
| 992 | "fstat (2) failed - %s\n]\n",
|
|---|
| 993 | strerror(errno));
|
|---|
| 994 | return false;
|
|---|
| 995 | }
|
|---|
| 996 |
|
|---|
| 997 | #define EQUAL_VAL(a,b) do { \
|
|---|
| 998 | if (a != b) { \
|
|---|
| 999 | printf("failure: utimes [\n" \
|
|---|
| 1000 | "%s: %s(%d) != %s(%d)\n]\n", \
|
|---|
| 1001 | __location__, \
|
|---|
| 1002 | #a, (int)a, #b, (int)b); \
|
|---|
| 1003 | return false; \
|
|---|
| 1004 | } \
|
|---|
| 1005 | } while(0)
|
|---|
| 1006 |
|
|---|
| 1007 | EQUAL_VAL(st2.st_atime, st1.st_atime + 300);
|
|---|
| 1008 | EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300);
|
|---|
| 1009 |
|
|---|
| 1010 | #undef EQUAL_VAL
|
|---|
| 1011 |
|
|---|
| 1012 | unlink(TESTFILE);
|
|---|
| 1013 | printf("success: utimes\n");
|
|---|
| 1014 | return true;
|
|---|
| 1015 | }
|
|---|
| 1016 |
|
|---|
| 1017 | static int test_memmem(void)
|
|---|
| 1018 | {
|
|---|
| 1019 | char *s;
|
|---|
| 1020 |
|
|---|
| 1021 | printf("test: memmem\n");
|
|---|
| 1022 |
|
|---|
| 1023 | s = (char *)memmem("foo", 3, "fo", 2);
|
|---|
| 1024 | if (strcmp(s, "foo") != 0) {
|
|---|
| 1025 | printf(__location__ ": Failed memmem\n");
|
|---|
| 1026 | return false;
|
|---|
| 1027 | }
|
|---|
| 1028 |
|
|---|
| 1029 | s = (char *)memmem("foo", 3, "", 0);
|
|---|
| 1030 | /* it is allowable for this to return NULL (as happens on
|
|---|
| 1031 | FreeBSD) */
|
|---|
| 1032 | if (s && strcmp(s, "foo") != 0) {
|
|---|
| 1033 | printf(__location__ ": Failed memmem\n");
|
|---|
| 1034 | return false;
|
|---|
| 1035 | }
|
|---|
| 1036 |
|
|---|
| 1037 | s = (char *)memmem("foo", 4, "o", 1);
|
|---|
| 1038 | if (strcmp(s, "oo") != 0) {
|
|---|
| 1039 | printf(__location__ ": Failed memmem\n");
|
|---|
| 1040 | return false;
|
|---|
| 1041 | }
|
|---|
| 1042 |
|
|---|
| 1043 | s = (char *)memmem("foobarfodx", 11, "fod", 3);
|
|---|
| 1044 | if (strcmp(s, "fodx") != 0) {
|
|---|
| 1045 | printf(__location__ ": Failed memmem\n");
|
|---|
| 1046 | return false;
|
|---|
| 1047 | }
|
|---|
| 1048 |
|
|---|
| 1049 | printf("success: memmem\n");
|
|---|
| 1050 |
|
|---|
| 1051 | return true;
|
|---|
| 1052 | }
|
|---|
| 1053 |
|
|---|
| 1054 |
|
|---|
| 1055 | struct torture_context;
|
|---|
| 1056 | bool torture_local_replace(struct torture_context *ctx)
|
|---|
| 1057 | {
|
|---|
| 1058 | bool ret = true;
|
|---|
| 1059 | ret &= test_ftruncate();
|
|---|
| 1060 | ret &= test_strlcpy();
|
|---|
| 1061 | ret &= test_strlcat();
|
|---|
| 1062 | ret &= test_mktime();
|
|---|
| 1063 | ret &= test_initgroups();
|
|---|
| 1064 | ret &= test_memmove();
|
|---|
| 1065 | ret &= test_strdup();
|
|---|
| 1066 | ret &= test_setlinebuf();
|
|---|
| 1067 | ret &= test_vsyslog();
|
|---|
| 1068 | ret &= test_timegm();
|
|---|
| 1069 | ret &= test_setenv();
|
|---|
| 1070 | ret &= test_strndup();
|
|---|
| 1071 | ret &= test_strnlen();
|
|---|
| 1072 | ret &= test_waitpid();
|
|---|
| 1073 | ret &= test_seteuid();
|
|---|
| 1074 | ret &= test_setegid();
|
|---|
| 1075 | ret &= test_asprintf();
|
|---|
| 1076 | ret &= test_snprintf();
|
|---|
| 1077 | ret &= test_vasprintf();
|
|---|
| 1078 | ret &= test_vsnprintf();
|
|---|
| 1079 | ret &= test_opendir();
|
|---|
| 1080 | ret &= test_readdir();
|
|---|
| 1081 | ret &= test_telldir();
|
|---|
| 1082 | ret &= test_seekdir();
|
|---|
| 1083 | ret &= test_dlopen();
|
|---|
| 1084 | ret &= test_chroot();
|
|---|
| 1085 | ret &= test_bzero();
|
|---|
| 1086 | ret &= test_strerror();
|
|---|
| 1087 | ret &= test_errno();
|
|---|
| 1088 | ret &= test_mkdtemp();
|
|---|
| 1089 | ret &= test_mkstemp();
|
|---|
| 1090 | ret &= test_pread();
|
|---|
| 1091 | ret &= test_pwrite();
|
|---|
| 1092 | ret &= test_getpass();
|
|---|
| 1093 | ret &= test_inet_ntoa();
|
|---|
| 1094 | ret &= test_strtoll();
|
|---|
| 1095 | ret &= test_strtoull();
|
|---|
| 1096 | ret &= test_va_copy();
|
|---|
| 1097 | ret &= test_FUNCTION();
|
|---|
| 1098 | ret &= test_MIN();
|
|---|
| 1099 | ret &= test_MAX();
|
|---|
| 1100 | ret &= test_socketpair();
|
|---|
| 1101 | ret &= test_strptime();
|
|---|
| 1102 | ret &= test_getifaddrs();
|
|---|
| 1103 | ret &= test_utime();
|
|---|
| 1104 | ret &= test_utimes();
|
|---|
| 1105 | ret &= test_memmem();
|
|---|
| 1106 |
|
|---|
| 1107 | return ret;
|
|---|
| 1108 | }
|
|---|