diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-08-02 13:40:19 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-08-02 13:50:00 -0400 |
commit | 46ef4487d3914cac1aba148ec58ff271bda3c636 (patch) | |
tree | 300a4fdfb5f8714ae970fe78c9bd9beeda6c378b /src/test/test_buffers.c | |
parent | cd9d39d54bbc9998938e9acddb1ec34507fc9108 (diff) | |
download | tor-46ef4487d3914cac1aba148ec58ff271bda3c636.tar.gz tor-46ef4487d3914cac1aba148ec58ff271bda3c636.zip |
Remove generic_buffer_*() functions as needless.
These functions were there so that we could abstract the differences
between evbuffer and buf_t. But with the bufferevent removal, this
no longer serves a purpose.
Diffstat (limited to 'src/test/test_buffers.c')
-rw-r--r-- | src/test/test_buffers.c | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c index a8a2d95f2b..4977b0e8b7 100644 --- a/src/test/test_buffers.c +++ b/src/test/test_buffers.c @@ -303,42 +303,42 @@ test_buffer_pullup(void *arg) static void test_buffer_copy(void *arg) { - generic_buffer_t *buf=NULL, *buf2=NULL; + buf_t *buf=NULL, *buf2=NULL; const char *s; size_t len; char b[256]; int i; (void)arg; - buf = generic_buffer_new(); + buf = buf_new(); tt_assert(buf); /* Copy an empty buffer. */ tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf)); tt_assert(buf2); - tt_int_op(0, OP_EQ, generic_buffer_len(buf2)); + tt_int_op(0, OP_EQ, buf_datalen(buf2)); /* Now try with a short buffer. */ s = "And now comes an act of enormous enormance!"; len = strlen(s); - generic_buffer_add(buf, s, len); - tt_int_op(len, OP_EQ, generic_buffer_len(buf)); + write_to_buf(s, len, buf); + tt_int_op(len, OP_EQ, buf_datalen(buf)); /* Add junk to buf2 so we can test replacing.*/ - generic_buffer_add(buf2, "BLARG", 5); + write_to_buf("BLARG", 5, buf2); tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf)); - tt_int_op(len, OP_EQ, generic_buffer_len(buf2)); - generic_buffer_get(buf2, b, len); + tt_int_op(len, OP_EQ, buf_datalen(buf2)); + fetch_from_buf(b, len, buf2); tt_mem_op(b, OP_EQ, s, len); /* Now free buf2 and retry so we can test allocating */ - generic_buffer_free(buf2); + buf_free(buf2); buf2 = NULL; tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf)); - tt_int_op(len, OP_EQ, generic_buffer_len(buf2)); - generic_buffer_get(buf2, b, len); + tt_int_op(len, OP_EQ, buf_datalen(buf2)); + fetch_from_buf(b, len, buf2); tt_mem_op(b, OP_EQ, s, len); /* Clear buf for next test */ - generic_buffer_get(buf, b, len); - tt_int_op(generic_buffer_len(buf),OP_EQ,0); + fetch_from_buf(b, len, buf); + tt_int_op(buf_datalen(buf),OP_EQ,0); /* Okay, now let's try a bigger buffer. */ s = "Quis autem vel eum iure reprehenderit qui in ea voluptate velit " @@ -347,95 +347,94 @@ test_buffer_copy(void *arg) len = strlen(s); for (i = 0; i < 256; ++i) { b[0]=i; - generic_buffer_add(buf, b, 1); - generic_buffer_add(buf, s, len); + write_to_buf(b, 1, buf); + write_to_buf(s, len, buf); } tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf)); - tt_int_op(generic_buffer_len(buf2), OP_EQ, generic_buffer_len(buf)); + tt_int_op(buf_datalen(buf2), OP_EQ, buf_datalen(buf)); for (i = 0; i < 256; ++i) { - generic_buffer_get(buf2, b, len+1); + fetch_from_buf(b, len+1, buf2); tt_int_op((unsigned char)b[0],OP_EQ,i); tt_mem_op(b+1, OP_EQ, s, len); } done: if (buf) - generic_buffer_free(buf); + buf_free(buf); if (buf2) - generic_buffer_free(buf2); + buf_free(buf2); } static void test_buffer_ext_or_cmd(void *arg) { ext_or_cmd_t *cmd = NULL; - generic_buffer_t *buf = generic_buffer_new(); + buf_t *buf = buf_new(); char *tmp = NULL; (void) arg; /* Empty -- should give "not there. */ - tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_EQ, cmd); /* Three bytes: shouldn't work. */ - generic_buffer_add(buf, "\x00\x20\x00", 3); - tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + write_to_buf("\x00\x20\x00", 3, buf); + tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_EQ, cmd); - tt_int_op(3, OP_EQ, generic_buffer_len(buf)); + tt_int_op(3, OP_EQ, buf_datalen(buf)); /* 0020 0000: That's a nil command. It should work. */ - generic_buffer_add(buf, "\x00", 1); - tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + write_to_buf("\x00", 1, buf); + tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_NE, cmd); tt_int_op(0x20, OP_EQ, cmd->cmd); tt_int_op(0, OP_EQ, cmd->len); - tt_int_op(0, OP_EQ, generic_buffer_len(buf)); + tt_int_op(0, OP_EQ, buf_datalen(buf)); ext_or_cmd_free(cmd); cmd = NULL; /* Now try a length-6 command with one byte missing. */ - generic_buffer_add(buf, "\x10\x21\x00\x06""abcde", 9); - tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + write_to_buf("\x10\x21\x00\x06""abcde", 9, buf); + tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_EQ, cmd); - generic_buffer_add(buf, "f", 1); - tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + write_to_buf("f", 1, buf); + tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_NE, cmd); tt_int_op(0x1021, OP_EQ, cmd->cmd); tt_int_op(6, OP_EQ, cmd->len); tt_mem_op("abcdef", OP_EQ, cmd->body, 6); - tt_int_op(0, OP_EQ, generic_buffer_len(buf)); + tt_int_op(0, OP_EQ, buf_datalen(buf)); ext_or_cmd_free(cmd); cmd = NULL; /* Now try a length-10 command with 4 extra bytes. */ - generic_buffer_add(buf, "\xff\xff\x00\x0a" - "loremipsum\x10\x00\xff\xff", 18); - tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + write_to_buf("\xff\xff\x00\x0aloremipsum\x10\x00\xff\xff", 18, buf); + tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_NE, cmd); tt_int_op(0xffff, OP_EQ, cmd->cmd); tt_int_op(10, OP_EQ, cmd->len); tt_mem_op("loremipsum", OP_EQ, cmd->body, 10); - tt_int_op(4, OP_EQ, generic_buffer_len(buf)); + tt_int_op(4, OP_EQ, buf_datalen(buf)); ext_or_cmd_free(cmd); cmd = NULL; /* Finally, let's try a maximum-length command. We already have the header * waiting. */ - tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tmp = tor_malloc_zero(65535); - generic_buffer_add(buf, tmp, 65535); - tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd)); + write_to_buf(tmp, 65535, buf); + tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd)); tt_ptr_op(NULL, OP_NE, cmd); tt_int_op(0x1000, OP_EQ, cmd->cmd); tt_int_op(0xffff, OP_EQ, cmd->len); tt_mem_op(tmp, OP_EQ, cmd->body, 65535); - tt_int_op(0, OP_EQ, generic_buffer_len(buf)); + tt_int_op(0, OP_EQ, buf_datalen(buf)); ext_or_cmd_free(cmd); cmd = NULL; done: ext_or_cmd_free(cmd); - generic_buffer_free(buf); + buf_free(buf); tor_free(tmp); } |