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

[tor-commits] [tor/master] Rewrite the find_str_at_start_of_line unit tests



commit 781c6676ca413421204136e9086ca15a9d74ac26
Author: Esteban Manchado Velázquez <emanchado@xxxxxxxxxxxx>
Date:   Wed Feb 8 23:45:53 2012 +0100

    Rewrite the find_str_at_start_of_line unit tests
---
 src/test/test_util.c |   40 +++++++++++++++++++++++++---------------
 1 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index 732712b..ec4405f 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1508,24 +1508,34 @@ static void
 test_util_find_str_at_start_of_line(void *ptr)
 {
   const char *long_string =
-    "hello world. hello world. hello hello. howdy.\n"
-    "hello hello world\n";
+    "howdy world. how are you? i hope it's fine.\n"
+    "hello kitty\n"
+    "third line";
+  char *line2 = strchr(long_string,'\n')+1;
+  char *line3 = strchr(line2,'\n')+1;
+  const char *short_string = "hello kitty\n"
+    "third line\n";
+  char *short_line2 = strchr(short_string,'\n')+1;
 
   (void)ptr;
 
-  /* not-found case. */
-  tt_assert(! find_str_at_start_of_line(long_string, "fred"));
-
-  /* not-found case where haystack doesn't end with \n */
-  tt_assert(! find_str_at_start_of_line("foobar\nbaz", "fred"));
-
-  /* start-of-string case */
-  tt_assert(long_string ==
-            find_str_at_start_of_line(long_string, "hello world."));
-
-  /* start-of-line case */
-  tt_assert(strchr(long_string,'\n')+1 ==
-            find_str_at_start_of_line(long_string, "hello hello"));
+  test_eq_ptr(long_string, find_str_at_start_of_line(long_string, ""));
+  test_eq_ptr(NULL, find_str_at_start_of_line(long_string, "nonsense"));
+  test_eq_ptr(NULL, find_str_at_start_of_line(long_string, "\n"));
+  test_eq_ptr(NULL, find_str_at_start_of_line(long_string, "how "));
+  test_eq_ptr(NULL, find_str_at_start_of_line(long_string, "kitty"));
+  test_eq_ptr(long_string, find_str_at_start_of_line(long_string, "h"));
+  test_eq_ptr(long_string, find_str_at_start_of_line(long_string, "how"));
+  test_eq_ptr(line2, find_str_at_start_of_line(long_string, "he"));
+  test_eq_ptr(line2, find_str_at_start_of_line(long_string, "hell"));
+  test_eq_ptr(line2, find_str_at_start_of_line(long_string, "hello k"));
+  test_eq_ptr(line2, find_str_at_start_of_line(long_string, "hello kitty\n"));
+  test_eq_ptr(line2, find_str_at_start_of_line(long_string, "hello kitty\nt"));
+  test_eq_ptr(line3, find_str_at_start_of_line(long_string, "third"));
+  test_eq_ptr(line3, find_str_at_start_of_line(long_string, "third line"));
+  test_eq_ptr(NULL,  find_str_at_start_of_line(long_string, "third line\n"));
+  test_eq_ptr(short_line2, find_str_at_start_of_line(short_string,
+                                                     "third line\n"));
  done:
   ;
 }



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