diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-06-21 11:20:33 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-06-21 11:20:33 -0400 |
commit | 6595f55020e4a73e2ccf7e87dcea4c1f0362f4aa (patch) | |
tree | 18cead6517aae61fe8646a3566969e800b87dead /src/test/test_buffers.c | |
parent | aafeffe02af5b3c8306fe36eec00baaabc8e68eb (diff) | |
download | tor-6595f55020e4a73e2ccf7e87dcea4c1f0362f4aa.tar.gz tor-6595f55020e4a73e2ccf7e87dcea4c1f0362f4aa.zip |
unit tests for peek_buf_startswith()
Diffstat (limited to 'src/test/test_buffers.c')
-rw-r--r-- | src/test/test_buffers.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c index 07114a8571..3989a45480 100644 --- a/src/test/test_buffers.c +++ b/src/test/test_buffers.c @@ -838,10 +838,37 @@ test_buffers_find_contentlen(void *arg) ; } +static void +test_buffer_peek_startswith(void *arg) +{ + (void)arg; + buf_t *buf; + buf = buf_new(); + tt_ptr_op(buf, OP_NE, NULL); + + tt_assert(peek_buf_startswith(buf, "")); + tt_assert(! peek_buf_startswith(buf, "X")); + + write_to_buf("Tor", 3, buf); + + tt_assert(peek_buf_startswith(buf, "")); + tt_assert(peek_buf_startswith(buf, "T")); + tt_assert(peek_buf_startswith(buf, "To")); + tt_assert(peek_buf_startswith(buf, "Tor")); + tt_assert(! peek_buf_startswith(buf, "Top")); + tt_assert(! peek_buf_startswith(buf, "For")); + tt_assert(! peek_buf_startswith(buf, "Tork")); + tt_assert(! peek_buf_startswith(buf, "Torpor")); + + done: + buf_free(buf); +} + struct testcase_t buffer_tests[] = { { "basic", test_buffers_basic, TT_FORK, NULL, NULL }, { "copy", test_buffer_copy, TT_FORK, NULL, NULL }, { "pullup", test_buffer_pullup, TT_FORK, NULL, NULL }, + { "startswith", test_buffer_peek_startswith, 0, NULL, NULL }, { "ext_or_cmd", test_buffer_ext_or_cmd, TT_FORK, NULL, NULL }, { "allocation_tracking", test_buffer_allocation_tracking, TT_FORK, NULL, NULL }, |