diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-07-30 14:27:29 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-07-30 14:27:29 -0400 |
commit | 69d775293714f3fdb582f7877191ade48f8f8124 (patch) | |
tree | 52a1a91f923615bc2d06f4ffa65364e0ff655a09 /src/test/test_buffers.c | |
parent | 3b8bf743ae6eca261dd46cde94371a4cca0c0689 (diff) | |
parent | c2d5ec5e43c2690656ea5a5a384683108782d149 (diff) | |
download | tor-69d775293714f3fdb582f7877191ade48f8f8124.tar.gz tor-69d775293714f3fdb582f7877191ade48f8f8124.zip |
Merge branch 'bug40076_042' into bug40076_043
Diffstat (limited to 'src/test/test_buffers.c')
-rw-r--r-- | src/test/test_buffers.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c index cc79426c1e..fbaa628fd7 100644 --- a/src/test/test_buffers.c +++ b/src/test/test_buffers.c @@ -303,6 +303,69 @@ test_buffer_pullup(void *arg) } static void +test_buffers_move_all(void *arg) +{ + (void)arg; + buf_t *input = buf_new(); + buf_t *output = buf_new(); + char *s = NULL; + + /* Move from empty buffer to nonempty buffer. (This is a regression test for + * #40076) */ + buf_add(output, "abc", 3); + buf_assert_ok(input); + buf_assert_ok(output); + buf_move_all(output, input); + buf_assert_ok(input); + buf_assert_ok(output); + tt_int_op(buf_datalen(output), OP_EQ, 3); + s = buf_extract(output, NULL); + tt_str_op(s, OP_EQ, "abc"); + buf_free(output); + buf_free(input); + tor_free(s); + + /* Move from empty to empty. */ + output = buf_new(); + input = buf_new(); + buf_move_all(output, input); + buf_assert_ok(input); + buf_assert_ok(output); + tt_int_op(buf_datalen(output), OP_EQ, 0); + buf_free(output); + buf_free(input); + + /* Move from nonempty to empty. */ + output = buf_new(); + input = buf_new(); + buf_add(input, "longstanding bugs", 17); + buf_move_all(output, input); + buf_assert_ok(input); + buf_assert_ok(output); + s = buf_extract(output, NULL); + tt_str_op(s, OP_EQ, "longstanding bugs"); + buf_free(output); + buf_free(input); + tor_free(s); + + /* Move from nonempty to nonempty. */ + output = buf_new(); + input = buf_new(); + buf_add(output, "the start of", 12); + buf_add(input, " a string", 9); + buf_move_all(output, input); + buf_assert_ok(input); + buf_assert_ok(output); + s = buf_extract(output, NULL); + tt_str_op(s, OP_EQ, "the start of a string"); + + done: + buf_free(output); + buf_free(input); + tor_free(s); +} + +static void test_buffer_copy(void *arg) { buf_t *buf=NULL, *buf2=NULL; @@ -799,6 +862,7 @@ 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 }, + { "move_all", test_buffers_move_all, 0, NULL, NULL }, { "startswith", test_buffer_peek_startswith, 0, NULL, NULL }, { "allocation_tracking", test_buffer_allocation_tracking, TT_FORK, NULL, NULL }, |