diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-03-19 22:26:06 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-03-19 22:26:06 -0400 |
commit | a9baddd7d07b9fe15e212985a808a79773ec72e4 (patch) | |
tree | fce0a089eedeacef8b25b409c2ba50f5f30a8327 /basename.c | |
download | libc-testsuite-a9baddd7d07b9fe15e212985a808a79773ec72e4.tar.gz |
initial check-in, taken from old libc svn repo with significant additions
Diffstat (limited to 'basename.c')
-rw-r--r-- | basename.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/basename.c b/basename.c new file mode 100644 index 0000000..2f0ee2a --- /dev/null +++ b/basename.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <string.h> +#include <libgen.h> +#include <stdlib.h> + +#define TEST(p, b) ( \ +tmp = strdup((p)), s = basename(tmp), \ +!strcmp((b),s) || \ +(printf(__FILE__ ":%d: basename(\"%s\") returned \"%s\"; expected \"%s\"\n", \ +__LINE__, (p), s, (b)), err++, 0), free(tmp), 0 ) + +int test_basename(void) +{ + char *tmp, *s; + int err=0; + + if (strcmp(basename(NULL), ".")) { + printf(__FILE__ ":%d: basename(NULL) returned \"%s\"; " + "expected \".\"\n", __LINE__, basename(NULL)); + err++; + } + TEST("", "."); + TEST("/usr/lib", "lib"); + TEST("/usr/", "usr"); + TEST("/", "/"); + TEST("///", "/"); + TEST("//usr//lib//", "lib"); + + return err; +} |