[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Improve listdir unit tests



commit 275b81ec5dff524c55558248ae9c6a2a0273eb9c
Author: Esteban Manchado Velázquez <emanchado@xxxxxxxxxxxx>
Date:   Fri Feb 10 00:42:08 2012 +0100

    Improve listdir unit tests
---
 src/test/test_util.c |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index de570ac..4c3a364 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1600,24 +1600,41 @@ static void
 test_util_listdir(void *ptr)
 {
   smartlist_t *dir_contents = NULL;
-  char *fname1=NULL, *fname2=NULL, *dirname=NULL;
+  char *fname1=NULL, *fname2=NULL, *fname3=NULL, *dir1=NULL, *dirname=NULL;
+  int r;
   (void)ptr;
 
   fname1 = tor_strdup(get_fname("hopscotch"));
   fname2 = tor_strdup(get_fname("mumblety-peg"));
+  fname3 = tor_strdup(get_fname(".hidden-file"));
+  dir1   = tor_strdup(get_fname("some-directory"));
   dirname = tor_strdup(get_fname(NULL));
 
-  tt_int_op(write_str_to_file(fname1, "X\n", 0), ==, 0);
-  tt_int_op(write_str_to_file(fname2, "Y\n", 0), ==, 0);
+  test_eq(0, write_str_to_file(fname1, "X\n", 0));
+  test_eq(0, write_str_to_file(fname2, "Y\n", 0));
+  test_eq(0, write_str_to_file(fname3, "Z\n", 0));
+#ifdef MS_WINDOWS
+  r = mkdir(dir1);
+#else
+  r = mkdir(dir1, 0700);
+#endif
+  if (r) {
+    fprintf(stderr, "Can't create directory %s:", dir1);
+    perror("");
+    exit(1);
+  }
 
   dir_contents = tor_listdir(dirname);
-  tt_assert(dir_contents);
+  test_assert(dir_contents);
   /* make sure that each filename is listed. */
-  tt_assert(smartlist_string_isin_case(dir_contents, "hopscotch"));
-  tt_assert(smartlist_string_isin_case(dir_contents, "mumblety-peg"));
-
-  tt_assert(!smartlist_string_isin(dir_contents, "."));
-  tt_assert(!smartlist_string_isin(dir_contents, ".."));
+  test_eq(4, smartlist_len(dir_contents));
+  test_assert(smartlist_string_isin_case(dir_contents, "hopscotch"));
+  test_assert(smartlist_string_isin_case(dir_contents, "mumblety-peg"));
+  test_assert(smartlist_string_isin_case(dir_contents, ".hidden-file"));
+  test_assert(smartlist_string_isin_case(dir_contents, "some-directory"));
+
+  test_assert(!smartlist_string_isin(dir_contents, "."));
+  test_assert(!smartlist_string_isin(dir_contents, ".."));
 
  done:
   tor_free(fname1);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits