diff options
| author | otto <> | 2004-08-03 20:38:36 +0000 |
|---|---|---|
| committer | otto <> | 2004-08-03 20:38:36 +0000 |
| commit | f68a61a8b8146755987133e926c423bf46e0c97a (patch) | |
| tree | 04e0feedc879e15b5d0fe1dd9f0b9a405dc95263 | |
| parent | ea13120433234de14cfef017f9b900c5d4e3874e (diff) | |
| download | openbsd-f68a61a8b8146755987133e926c423bf46e0c97a.tar.gz openbsd-f68a61a8b8146755987133e926c423bf46e0c97a.tar.bz2 openbsd-f68a61a8b8146755987133e926c423bf46e0c97a.zip | |
strtonum(3) regression tests.
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libc/strtonum/Makefile | 5 | ||||
| -rw-r--r-- | src/regress/lib/libc/strtonum/strtonumtest.c | 64 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/regress/lib/libc/strtonum/Makefile b/src/regress/lib/libc/strtonum/Makefile new file mode 100644 index 0000000000..e0e8ecd139 --- /dev/null +++ b/src/regress/lib/libc/strtonum/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/08/03 20:38:36 otto Exp $ | ||
| 2 | |||
| 3 | PROG= strtonumtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtonum/strtonumtest.c b/src/regress/lib/libc/strtonum/strtonumtest.c new file mode 100644 index 0000000000..7e82a007fe --- /dev/null +++ b/src/regress/lib/libc/strtonum/strtonumtest.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net> | ||
| 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 <limits.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | |||
| 22 | int fail; | ||
| 23 | |||
| 24 | void | ||
| 25 | test(const char *p, long long lb, long long ub, int ok) | ||
| 26 | { | ||
| 27 | long long val; | ||
| 28 | const char *q; | ||
| 29 | |||
| 30 | val = strtonum(p, lb, ub, &q); | ||
| 31 | if (ok && q != NULL) { | ||
| 32 | fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub); | ||
| 33 | fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q); | ||
| 34 | fail = 1; | ||
| 35 | } else if (!ok && q == NULL) { | ||
| 36 | fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val); | ||
| 37 | fprintf(stderr, "NUMBER ACCEPTED\n"); | ||
| 38 | fail = 1; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | int main(int argc, char *argv[]) | ||
| 43 | { | ||
| 44 | test("1", 0, 10, 1); | ||
| 45 | test("0", -2, 5, 1); | ||
| 46 | test("0", 2, 5, 0); | ||
| 47 | test("0", 2, LLONG_MAX, 0); | ||
| 48 | test("-2", 0, LLONG_MAX, 0); | ||
| 49 | test("0", -5, LLONG_MAX, 1); | ||
| 50 | test("-3", -3, LLONG_MAX, 1); | ||
| 51 | test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1); | ||
| 52 | test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1); | ||
| 53 | test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0); | ||
| 54 | test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0); | ||
| 55 | test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
| 56 | test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
| 57 | test("-2", 10, -1, 0); | ||
| 58 | test("-2", -10, -1, 1); | ||
| 59 | test("-20", -10, -1, 0); | ||
| 60 | test("20", -10, -1, 0); | ||
| 61 | |||
| 62 | return (fail); | ||
| 63 | } | ||
| 64 | |||
