diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-02-20 23:38:55 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-02-20 23:38:55 +0000 |
commit | 8b8d38162b1720467a42e043383b91f7100faf64 (patch) | |
tree | 4a2af4434de3ead5a28d7e4ffd7e75dda00c596f | |
parent | 1c5d641d898d27d1c6c1ec067f949140a68953cd (diff) | |
download | tor-8b8d38162b1720467a42e043383b91f7100faf64.tar.gz tor-8b8d38162b1720467a42e043383b91f7100faf64.zip |
r18278@catbus: nickm | 2008-02-20 18:29:07 -0500
Unit tests for buf_find_string_offset()
svn:r13632
-rw-r--r-- | src/or/test.c | 17 |
1 files changed, 16 insertions, 1 deletions
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 { |