[tor-commits] [tor/release-0.4.3] Add unit test for buf_move_all(), including a failing case
ahf at torproject.org
ahf at torproject.org
Fri Jul 31 02:04:31 UTC 2020
commit 0a588821cb5540e901a3d5b07ac73a20905a2c64
Author: Nick Mathewson <nickm at torproject.org>
Date: Thu Jul 30 14:19:32 2020 -0400
Add unit test for buf_move_all(), including a failing case
The failing case is #if'd out for now, but will be fixed in the next
commit.
Testing for a fix for #40076.
---
src/test/test_buffers.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c
index 2f9ad1fbe3..67a49a5017 100644
--- a/src/test/test_buffers.c
+++ b/src/test/test_buffers.c
@@ -302,6 +302,71 @@ test_buffer_pullup(void *arg)
tor_free(tmp);
}
+static void
+test_buffers_move_all(void *arg)
+{
+ (void)arg;
+ buf_t *input = buf_new();
+ buf_t *output = buf_new();
+ char *s = NULL;
+
+#if 0
+ /* 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();
+#endif
+ 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)
{
@@ -799,6 +864,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 },
More information about the tor-commits
mailing list