aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorEsteban Manchado Velázquez <emanchado@demiurgo.org>2012-02-08 23:45:53 +0100
committerNick Mathewson <nickm@torproject.org>2012-03-08 20:49:24 -0500
commit781c6676ca413421204136e9086ca15a9d74ac26 (patch)
tree7bb72e748923f0a714acb364b61cc94df6f945aa /src/test/test_util.c
parent667f5ea409a8f3950aedd60e85d23bddeb8ad9b6 (diff)
downloadtor-781c6676ca413421204136e9086ca15a9d74ac26.tar
tor-781c6676ca413421204136e9086ca15a9d74ac26.tar.gz
Rewrite the find_str_at_start_of_line unit tests
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 732712b8e..ec4405f59 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:
;
}