From 8b8d38162b1720467a42e043383b91f7100faf64 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 20 Feb 2008 23:38:55 +0000 Subject: [PATCH] r18278@catbus: nickm | 2008-02-20 18:29:07 -0500 Unit tests for buf_find_string_offset() svn:r13632 --- src/or/test.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/or/test.c b/src/or/test.c index 3dff0a42ec..f68bc97efa 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -28,6 +28,7 @@ const char tor_svn_revision[] = ""; /* These macros pull in declarations for some functions and structures that * are typically file-private. */ +#define BUFFERS_PRIVATE #define CONFIG_PRIVATE #define CONTROL_PRIVATE #define CRYPTO_PRIVATE @@ -117,6 +118,7 @@ test_buffers(void) char str2[256]; buf_t *buf, *buf2; + const char *cp; int j; size_t r; @@ -255,7 +257,20 @@ test_buffers(void) buf_free(buf); buf_free(buf2); - /*XXXX020 Test code to find chars and strings on buffers. */ + buf = buf_new_with_capacity(5); + cp = "Testing. This is a moderately long Testing string."; + for (j = 0; cp[j]; j++) + write_to_buf(cp+j, 1, buf); + test_eq(0, buf_find_string_offset(buf, "Testing", 7)); + test_eq(1, buf_find_string_offset(buf, "esting", 6)); + test_eq(1, buf_find_string_offset(buf, "est", 3)); + test_eq(39, buf_find_string_offset(buf, "ing str", 7)); + test_eq(35, buf_find_string_offset(buf, "Testing str", 11)); + test_eq(32, buf_find_string_offset(buf, "ng ", 3)); + test_eq(-1, buf_find_string_offset(buf, "shrdlu", 6)); + test_eq(-1, buf_find_string_offset(buf, "Testing thing", 13)); + test_eq(-1, buf_find_string_offset(buf, "ngx", 3)); + buf_free(buf); #if 0 {