diff options
author | Bernhard Schmidt <berni@debian.org> | 2020-08-15 21:29:54 +0200 |
---|---|---|
committer | Bernhard Schmidt <berni@debian.org> | 2020-08-15 21:29:54 +0200 |
commit | 7c229d538824cb679351220ad8911f7b2daa7c23 (patch) | |
tree | 5c4d64b60da9018c7db3a9335a9787d326beade3 /tests/unit_tests/openvpn/test_buffer.c | |
parent | d3986a312f5fbcfd0e78e6b147eef419fb4e5f54 (diff) | |
parent | 1079962e4c06f88a54e50d997c1b7e84303d30b4 (diff) |
Update upstream source from tag 'upstream/2.5_beta1'
Update to upstream version '2.5~beta1'
with Debian dir d53f9a482ac24eb491a294b26c24bb1d87afad24
Diffstat (limited to 'tests/unit_tests/openvpn/test_buffer.c')
-rw-r--r-- | tests/unit_tests/openvpn/test_buffer.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index d083b78..d2188b0 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -33,6 +33,7 @@ #include <cmocka.h> #include "buffer.h" +#include "buffer.c" static void test_buffer_strprefix(void **state) @@ -62,7 +63,8 @@ struct test_buffer_list_aggregate_ctx { struct buffer_list *empty_buffers; }; -static int test_buffer_list_setup(void **state) +static int +test_buffer_list_setup(void **state) { struct test_buffer_list_aggregate_ctx *ctx = calloc(1, sizeof(*ctx)); ctx->empty = buffer_list_new(0); @@ -85,7 +87,8 @@ static int test_buffer_list_setup(void **state) return 0; } -static int test_buffer_list_teardown(void **state) +static int +test_buffer_list_teardown(void **state) { struct test_buffer_list_aggregate_ctx *ctx = *state; @@ -197,6 +200,48 @@ test_buffer_list_aggregate_separator_emptybuffers(void **state) assert_int_equal(BLEN(buf), 0); } +static void +test_buffer_free_gc_one(void **state) +{ + struct gc_arena gc = gc_new(); + struct buffer buf = alloc_buf_gc(1024, &gc); + + assert_ptr_equal(gc.list + 1, buf.data); + free_buf_gc(&buf, &gc); + assert_null(gc.list); + + gc_free(&gc); +} + +static void +test_buffer_free_gc_two(void **state) +{ + struct gc_arena gc = gc_new(); + struct buffer buf1 = alloc_buf_gc(1024, &gc); + struct buffer buf2 = alloc_buf_gc(1024, &gc); + struct buffer buf3 = alloc_buf_gc(1024, &gc); + + struct gc_entry *e; + + e = gc.list; + + assert_ptr_equal(e + 1, buf3.data); + assert_ptr_equal(e->next + 1, buf2.data); + assert_ptr_equal(e->next->next + 1, buf1.data); + + free_buf_gc(&buf2, &gc); + + assert_non_null(gc.list); + + while (e) + { + assert_ptr_not_equal(e + 1, buf2.data); + e = e->next; + } + + gc_free(&gc); +} + int main(void) { @@ -226,6 +271,8 @@ main(void) cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separator_emptybuffers, test_buffer_list_setup, test_buffer_list_teardown), + cmocka_unit_test(test_buffer_free_gc_one), + cmocka_unit_test(test_buffer_free_gc_two), }; return cmocka_run_group_tests_name("buffer", tests, NULL, NULL); |