summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2012-11-18 04:11:09 +0000
committerjsing <>2012-11-18 04:11:09 +0000
commitd7d7374e0c62e4c77272ff42edf07608a8565c1e (patch)
tree10da8b9471abc4fb8e002435a7c53fffbd6a7924
parent09f7cf44d9e90e3122800af8160365f64d33dd83 (diff)
downloadopenbsd-d7d7374e0c62e4c77272ff42edf07608a8565c1e.tar.gz
openbsd-d7d7374e0c62e4c77272ff42edf07608a8565c1e.tar.bz2
openbsd-d7d7374e0c62e4c77272ff42edf07608a8565c1e.zip
Add a regress test for strtol, which currently fails.
ok otto@
-rw-r--r--src/regress/lib/libc/Makefile5
-rw-r--r--src/regress/lib/libc/strtol/Makefile5
-rw-r--r--src/regress/lib/libc/strtol/strtoltest.c78
3 files changed, 86 insertions, 2 deletions
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 @@
1# $OpenBSD: Makefile,v 1.34 2012/07/11 10:46:23 naddy Exp $ 1# $OpenBSD: Makefile,v 1.35 2012/11/18 04:11:09 jsing Exp $
2 2
3SUBDIR+= _setjmp alloca atexit basename cephes cxa-atexit db dirname env 3SUBDIR+= _setjmp alloca atexit basename cephes cxa-atexit db dirname env
4SUBDIR+= fnmatch fpclassify getaddrinfo getcap getopt_long glob hsearch 4SUBDIR+= fnmatch fpclassify getaddrinfo getcap getopt_long glob hsearch
5SUBDIR+= longjmp locale malloc mkstemp netdb orientation popen printf 5SUBDIR+= longjmp locale malloc mkstemp netdb orientation popen printf
6SUBDIR+= regex setjmp setjmp-signal sigreturn sigsetjmp sprintf 6SUBDIR+= regex setjmp setjmp-signal sigreturn sigsetjmp sprintf
7SUBDIR+= stdio_threading stpncpy strerror strtod strtonum telldir time vis 7SUBDIR+= stdio_threading stpncpy strerror strtod strtol strtonum
8SUBDIR+= telldir time vis
8 9
9.if (${MACHINE_ARCH} != "vax") 10.if (${MACHINE_ARCH} != "vax")
10SUBDIR+= ieeefp 11SUBDIR+= 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 @@
1# $OpenBSD: Makefile,v 1.1 2012/11/18 04:11:09 jsing Exp $
2
3PROG= strtoltest
4
5.include <bsd.regress.mk>
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 @@
1/* $OpenBSD: strtoltest.c,v 1.1 2012/11/18 04:11:09 jsing Exp $ */
2/*
3 * Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <errno.h>
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22
23struct strtol_test {
24 char *input;
25 long output;
26 char end;
27 int base;
28 int err;
29};
30
31struct strtol_test strtol_tests[] = {
32 {"1234567890", 1234567890L, '\0', 0, 0},
33 {"0755", 493L, '\0', 0, 0},
34 {"0xdeadbeef", 3735928559L, '\0', 0, 0},
35 {"1234567890", 0L, '1', 1, EINVAL},
36 {"10101010", 170L, '\0', 2, 0},
37 {"755", 493L, '\0', 8, 0},
38 {"1234567890", 1234567890L, '\0', 10, 0},
39 {"abc", 0L, 'a', 10, 0},
40 {"123xyz", 123L, 'x', 10, 0},
41 {"deadbeef", 3735928559L, '\0', 16, 0},
42 {"DEADBEEF", 3735928559L, '\0', 16, 0},
43 {"deadzbeef", 57005L, 'z', 16, 0},
44 {"zzz", 46655L, '\0', 36, 0},
45 {"1234567890", 0L, '1', 37, EINVAL},
46 {"1234567890", 0L, '1', 123, EINVAL},
47};
48
49int
50main(int argc, char **argv)
51{
52 struct strtol_test *test;
53 int failure = 0;
54 char *end;
55 u_int i;
56 long n;
57
58 for (i = 0; i < (sizeof(strtol_tests) / sizeof(strtol_tests[0])); i++) {
59 test = &strtol_tests[i];
60 errno = 0;
61 n = strtol(test->input, &end, test->base);
62 if (n != test->output) {
63 fprintf(stderr, "TEST %i FAILED: %s base %i: %li\n",
64 i, test->input, test->base, n);
65 failure = 1;
66 } else if (*end != test->end) {
67 fprintf(stderr, "TEST %i FAILED: end is not %c: %c\n",
68 i, test->end, *end);
69 failure = 1;
70 } else if (errno != test->err) {
71 fprintf(stderr, "TEST %i FAILED: errno is not %i: %i\n",
72 i, test->err, errno);
73 failure = 1;
74 }
75 }
76
77 return failure;
78}