From: Esteban Manchado Velázquez Date: Wed, 8 Feb 2012 22:45:53 +0000 (+0100) Subject: Rewrite the find_str_at_start_of_line unit tests X-Git-Tag: tor-0.2.3.13-alpha~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=781c6676ca413421204136e9086ca15a9d74ac26;p=thirdparty%2Ftor.git Rewrite the find_str_at_start_of_line unit tests --- diff --git a/src/test/test_util.c b/src/test/test_util.c index 732712b8e5..ec4405f59a 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: ; }