From 061f0bb4fbc24353ff0974a3f0ff2af5b6acabd1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 1 Oct 2008 23:04:59 +0000 Subject: Regress driver for fnmatch(3). Needs more tests. --- regress/lib/libc/fnmatch/Makefile | 8 +++++++ regress/lib/libc/fnmatch/fnm_test.c | 45 ++++++++++++++++++++++++++++++++++++ regress/lib/libc/fnmatch/fnm_test.in | 5 ++++ 3 files changed, 58 insertions(+) create mode 100644 regress/lib/libc/fnmatch/Makefile create mode 100644 regress/lib/libc/fnmatch/fnm_test.c create mode 100644 regress/lib/libc/fnmatch/fnm_test.in (limited to 'regress/lib/libc') diff --git a/regress/lib/libc/fnmatch/Makefile b/regress/lib/libc/fnmatch/Makefile new file mode 100644 index 00000000000..b2f357105f0 --- /dev/null +++ b/regress/lib/libc/fnmatch/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1 2008/10/01 23:04:58 millert Exp $ + +PROG= fnm_test + +run-regress-${PROG}: + ./${PROG} ${.CURDIR}/${PROG}.in + +.include diff --git a/regress/lib/libc/fnmatch/fnm_test.c b/regress/lib/libc/fnmatch/fnm_test.c new file mode 100644 index 00000000000..e9870100951 --- /dev/null +++ b/regress/lib/libc/fnmatch/fnm_test.c @@ -0,0 +1,45 @@ +/* $OpenBSD: fnm_test.c,v 1.1 2008/10/01 23:04:58 millert Exp $ */ + +/* + * Public domain, 2008, Todd C. Miller + */ + +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + FILE *fp = stdin; + char pattern[1024], string[1024]; + int errors = 0, flags, got, want; + + if (argc > 1) { + if ((fp = fopen(argv[1], "r")) == NULL) + err(1, "%s", argv[1]); + } + + /* + * Read in test file, which is formatted thusly: + * + * pattern string flags expected_result + * + */ + for (;;) { + got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags, + &want); + if (got == EOF) + break; + if (got == 4) { + got = fnmatch(pattern, string, flags); + if (got != want) { + warnx("%s %s %d: want %d, got %d", pattern, + string, flags, want, got); + errors++; + } + } + } + exit(errors); +} diff --git a/regress/lib/libc/fnmatch/fnm_test.in b/regress/lib/libc/fnmatch/fnm_test.in new file mode 100644 index 00000000000..3c707f8a191 --- /dev/null +++ b/regress/lib/libc/fnmatch/fnm_test.in @@ -0,0 +1,5 @@ +/bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 +/bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 +/bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 +[[:alpha:][:alnum:]]*.c foo1.c 0x4 0 +[[:upper:]]* FOO 0x0 0 -- cgit v1.2.3