#include #include #include // Test cases taken from the basename(3) manpage on my Arch Linux system (which are taken from SUSv2). TestResult test_dirname_usr_lib() { char path[] = "/usr/lib"; char* dir = dirname(path); validate(!strcmp(dir, "/usr")); test_success; } TestResult test_basename_usr_lib() { char path[] = "/usr/lib"; char* name = basename(path); validate(!strcmp(name, "lib")); test_success; } TestResult test_dirname_absolute_usr() { char path[] = "/usr/"; char* dir = dirname(path); validate(!strcmp(dir, "/")); test_success; } TestResult test_basename_absolute_usr() { char path[] = "/usr/"; char* name = basename(path); validate(!strcmp(name, "usr")); test_success; } TestResult test_dirname_relative_usr() { char path[] = "usr"; char* dir = dirname(path); validate(!strcmp(dir, ".")); test_success; } TestResult test_basename_relative_usr() { char path[] = "usr"; char* name = basename(path); validate(!strcmp(name, "usr")); test_success; } TestResult test_dirname_root() { char path[] = "/"; char* dir = dirname(path); validate(!strcmp(dir, "/")); test_success; } TestResult test_basename_root() { char path[] = "/"; char* name = basename(path); validate(!strcmp(name, "/")); test_success; } TestResult test_dirname_self() { char path[] = "."; char* dir = dirname(path); validate(!strcmp(dir, ".")); test_success; } TestResult test_basename_self() { char path[] = "."; char* name = basename(path); validate(!strcmp(name, ".")); test_success; } TestResult test_dirname_parent() { char path[] = ".."; char* dir = dirname(path); validate(!strcmp(dir, ".")); test_success; } TestResult test_basename_parent() { char path[] = ".."; char* name = basename(path); validate(!strcmp(name, "..")); test_success; } Result test_main() { test_prelude; run_test(test_basename_usr_lib); run_test(test_basename_absolute_usr); run_test(test_basename_relative_usr); run_test(test_basename_root); run_test(test_basename_self); run_test(test_basename_parent); run_test(test_dirname_usr_lib); run_test(test_dirname_absolute_usr); run_test(test_dirname_relative_usr); run_test(test_dirname_root); run_test(test_dirname_self); run_test(test_dirname_parent); return {}; }