aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-05-13 15:15:41 -0400
committerNick Mathewson <nickm@torproject.org>2011-05-15 20:20:29 -0400
commit3b6cbf253494303f612eeb09a6fbb30a7c15c7fa (patch)
treec7cc77c25edb68e869c78e47ed934fa1efebbc29 /src/test/test_util.c
parentb147c01295deb8c09807fda3b5e4945edcfaf81a (diff)
downloadtor-3b6cbf253494303f612eeb09a6fbb30a7c15c7fa.tar
tor-3b6cbf253494303f612eeb09a6fbb30a7c15c7fa.tar.gz
Add a function to pull off the final component of a path
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 0da45df49..23cd059cf 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1195,6 +1195,35 @@ test_util_listdir(void *ptr)
}
}
+static void
+test_util_parent_dir(void *ptr)
+{
+ char *cp;
+ (void)ptr;
+
+#define T(input,expect_ok,output) \
+ do { \
+ int ok; \
+ cp = tor_strdup(input); \
+ ok = get_parent_directory(cp); \
+ tt_int_op(ok, ==, expect_ok); \
+ if (ok==0) \
+ tt_str_op(cp, ==, output); \
+ tor_free(cp); \
+ } while (0);
+
+ T("/home/wombat/knish", 0, "/home/wombat");
+ T("/home/wombat/knish/", 0, "/home/wombat");
+ T("./home/wombat/knish/", 0, "./home/wombat");
+ T("./wombat", 0, ".");
+ T("", -1, "");
+ T("/", -1, "");
+ T("////", -1, "");
+
+ done:
+ tor_free(cp);
+}
+
#ifdef MS_WINDOWS
static void
test_util_load_win_lib(void *ptr)
@@ -1286,6 +1315,7 @@ struct testcase_t util_tests[] = {
UTIL_TEST(find_str_at_start_of_line, 0),
UTIL_TEST(asprintf, 0),
UTIL_TEST(listdir, 0),
+ UTIL_TEST(parent_dir, 0),
#ifdef MS_WINDOWS
UTIL_TEST(load_win_lib, 0),
#endif