[or-cvs] r13632: Unit tests for buf_find_string_offset() (in tor/trunk: . src/or)
nickm at seul.org
nickm at seul.org
Wed Feb 20 23:38:55 UTC 2008
Author: nickm
Date: 2008-02-20 18:38:55 -0500 (Wed, 20 Feb 2008)
New Revision: 13632
Modified:
tor/trunk/
tor/trunk/src/or/test.c
Log:
r18278 at catbus: nickm | 2008-02-20 18:29:07 -0500
Unit tests for buf_find_string_offset()
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r18278] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c 2008-02-20 23:38:53 UTC (rev 13631)
+++ tor/trunk/src/or/test.c 2008-02-20 23:38:55 UTC (rev 13632)
@@ -28,6 +28,7 @@
/* 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 @@
char str2[256];
buf_t *buf, *buf2;
+ const char *cp;
int j;
size_t r;
@@ -255,7 +257,20 @@
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
{
More information about the tor-commits
mailing list