summaryrefslogtreecommitdiff
path: root/tests/unit_tests/openvpn/test_buffer.c
diff options
context:
space:
mode:
authorBernhard Schmidt <berni@debian.org>2020-08-15 21:29:50 +0200
committerBernhard Schmidt <berni@debian.org>2020-08-15 21:29:50 +0200
commit1079962e4c06f88a54e50d997c1b7e84303d30b4 (patch)
tree4d019426928435425214ccedd6f89b70dbdf035d /tests/unit_tests/openvpn/test_buffer.c
parent620785fe268a1221c1ba7a9cb5a70f3140a4f1ca (diff)
New upstream version 2.5~beta1upstream/2.5_beta1
Diffstat (limited to 'tests/unit_tests/openvpn/test_buffer.c')
-rw-r--r--tests/unit_tests/openvpn/test_buffer.c51
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);