From d7d7374e0c62e4c77272ff42edf07608a8565c1e Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 18 Nov 2012 04:11:09 +0000 Subject: Add a regress test for strtol, which currently fails. ok otto@ --- src/regress/lib/libc/Makefile | 5 +- src/regress/lib/libc/strtol/Makefile | 5 ++ src/regress/lib/libc/strtol/strtoltest.c | 78 ++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/regress/lib/libc/strtol/Makefile create mode 100644 src/regress/lib/libc/strtol/strtoltest.c (limited to 'src') diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile index a0b950033e..b3a7fe0b2a 100644 --- a/src/regress/lib/libc/Makefile +++ b/src/regress/lib/libc/Makefile @@ -1,10 +1,11 @@ -# $OpenBSD: Makefile,v 1.34 2012/07/11 10:46:23 naddy Exp $ +# $OpenBSD: Makefile,v 1.35 2012/11/18 04:11:09 jsing Exp $ SUBDIR+= _setjmp alloca atexit basename cephes cxa-atexit db dirname env SUBDIR+= fnmatch fpclassify getaddrinfo getcap getopt_long glob hsearch SUBDIR+= longjmp locale malloc mkstemp netdb orientation popen printf SUBDIR+= regex setjmp setjmp-signal sigreturn sigsetjmp sprintf -SUBDIR+= stdio_threading stpncpy strerror strtod strtonum telldir time vis +SUBDIR+= stdio_threading stpncpy strerror strtod strtol strtonum +SUBDIR+= telldir time vis .if (${MACHINE_ARCH} != "vax") SUBDIR+= ieeefp diff --git a/src/regress/lib/libc/strtol/Makefile b/src/regress/lib/libc/strtol/Makefile new file mode 100644 index 0000000000..3e2f4c746d --- /dev/null +++ b/src/regress/lib/libc/strtol/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2012/11/18 04:11:09 jsing Exp $ + +PROG= strtoltest + +.include diff --git a/src/regress/lib/libc/strtol/strtoltest.c b/src/regress/lib/libc/strtol/strtoltest.c new file mode 100644 index 0000000000..f7a8e0ab72 --- /dev/null +++ b/src/regress/lib/libc/strtol/strtoltest.c @@ -0,0 +1,78 @@ +/* $OpenBSD: strtoltest.c,v 1.1 2012/11/18 04:11:09 jsing Exp $ */ +/* + * Copyright (c) 2012 Joel Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +struct strtol_test { + char *input; + long output; + char end; + int base; + int err; +}; + +struct strtol_test strtol_tests[] = { + {"1234567890", 1234567890L, '\0', 0, 0}, + {"0755", 493L, '\0', 0, 0}, + {"0xdeadbeef", 3735928559L, '\0', 0, 0}, + {"1234567890", 0L, '1', 1, EINVAL}, + {"10101010", 170L, '\0', 2, 0}, + {"755", 493L, '\0', 8, 0}, + {"1234567890", 1234567890L, '\0', 10, 0}, + {"abc", 0L, 'a', 10, 0}, + {"123xyz", 123L, 'x', 10, 0}, + {"deadbeef", 3735928559L, '\0', 16, 0}, + {"DEADBEEF", 3735928559L, '\0', 16, 0}, + {"deadzbeef", 57005L, 'z', 16, 0}, + {"zzz", 46655L, '\0', 36, 0}, + {"1234567890", 0L, '1', 37, EINVAL}, + {"1234567890", 0L, '1', 123, EINVAL}, +}; + +int +main(int argc, char **argv) +{ + struct strtol_test *test; + int failure = 0; + char *end; + u_int i; + long n; + + for (i = 0; i < (sizeof(strtol_tests) / sizeof(strtol_tests[0])); i++) { + test = &strtol_tests[i]; + errno = 0; + n = strtol(test->input, &end, test->base); + if (n != test->output) { + fprintf(stderr, "TEST %i FAILED: %s base %i: %li\n", + i, test->input, test->base, n); + failure = 1; + } else if (*end != test->end) { + fprintf(stderr, "TEST %i FAILED: end is not %c: %c\n", + i, test->end, *end); + failure = 1; + } else if (errno != test->err) { + fprintf(stderr, "TEST %i FAILED: errno is not %i: %i\n", + i, test->err, errno); + failure = 1; + } + } + + return failure; +} -- cgit v1.2.3-55-g6feb