aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorEsteban Manchado Velázquez <emanchado@demiurgo.org>2012-02-10 23:33:37 +0100
committerNick Mathewson <nickm@torproject.org>2012-03-08 20:49:25 -0500
commit22a915bcd21f4dadff11e951099e7b9e15f8ad7f (patch)
treec76cc559f2a774e6e289729b0fd3cecc0d5271ed /src/test
parent275b81ec5dff524c55558248ae9c6a2a0273eb9c (diff)
downloadtor-22a915bcd21f4dadff11e951099e7b9e15f8ad7f.tar.gz
tor-22a915bcd21f4dadff11e951099e7b9e15f8ad7f.zip
Improve get_parent_directory unit tests
* Add more test cases to the get_parent_directory tests * Switch the parameter order so that the expected value is the first one
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_util.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 4c3a364eed..e0d3540ae6 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1652,24 +1652,40 @@ test_util_parent_dir(void *ptr)
char *cp;
(void)ptr;
-#define T(input,expect_ok,output) \
+#define T(output,expect_ok,input) \
do { \
int ok; \
cp = tor_strdup(input); \
ok = get_parent_directory(cp); \
- tt_int_op(ok, ==, expect_ok); \
+ tt_int_op(expect_ok, ==, ok); \
if (ok==0) \
- tt_str_op(cp, ==, output); \
+ tt_str_op(output, ==, cp); \
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("/home/wombat", 0, "/home/wombat/knish");
+ T("/home/wombat", 0, "/home/wombat/knish/");
+ T("/home/wombat", 0, "/home/wombat/knish///");
+ T("./home/wombat", 0, "./home/wombat/knish/");
+ T(".", 0, "./wombat");
+ T(".", 0, "./wombat/");
+ T(".", 0, "./wombat//");
+ T("wombat", 0, "wombat/foo");
+ T("wombat/..", 0, "wombat/../foo");
+ T("wombat/../", 0, "wombat/..//foo"); /* Is this correct? */
+ T("wombat", 0, "wombat/..//");
+ T("wombat", 0, "wombat/foo/");
+ T("wombat", 0, "wombat/.foo");
+ T("wombat", 0, "wombat/.foo/");
+
T("", -1, "");
- T("/", -1, "");
- T("////", -1, "");
+ T("", -1, ".");
+ T("", -1, "..");
+ T("", -1, "../");
+ T("", -1, "/");
+ T("", -1, "////");
+ T("", -1, "wombat");
+ T("", -1, "wombat/");
done:
tor_free(cp);