Hi Przemysław,
On 1/21/20 2:17 AM, Przemysław Fierek wrote:
This patch adds unit-tests for previously submitted
`l_ringbuf_append`
function.
---
unit/test-ringbuf.c | 83 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 1 deletion(-)
diff --git a/unit/test-ringbuf.c b/unit/test-ringbuf.c
index 906161b..ce2c5f9 100644
--- a/unit/test-ringbuf.c
+++ b/unit/test-ringbuf.c
@@ -131,6 +131,86 @@ static void test_printf(const void *data)
l_ringbuf_free(rb);
}
+static void test_append(const void *unused)
+{
+ static uint8_t data[6] = {1, 2, 3, 4, 5, 6};
+ static size_t rb_size = 12;
+ static size_t rb_capa = 16;
static const?
+ static size_t len_no_wrap;
+ static ssize_t appended, space_left;
one variable per line please
+ static void *rb_data;
Why are all these static?
+ struct l_ringbuf *rb;
+
+ rb = l_ringbuf_new(rb_size);
+ assert(rb != NULL);
+ assert(l_ringbuf_capacity(rb) == rb_capa);
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ space_left = minsize(l_ringbuf_avail(rb), sizeof(data));
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == space_left);
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(memcmp(rb_data, data, sizeof(data)) == 0);
+ l_ringbuf_drain(rb, sizeof(data));
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(memcmp(rb_data, data, sizeof(data)) == 0);
+ l_ringbuf_drain(rb, sizeof(data));
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(memcmp(rb_data, data, len_no_wrap) == 0);
+ l_ringbuf_drain(rb, len_no_wrap);
+
+ l_ringbuf_free(rb);
+}
+
+static void test_append2(const void *unused)
+{
+ static uint8_t expected_data1[14] = {3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4};
80 char line limit exceeded
+ static uint8_t expected_data2[2] = {5, 6};
+ static uint8_t data[6] = {1, 2, 3, 4, 5, 6};
+ static size_t rb_size = 12;
+ static size_t rb_capa = 16;
static const?
+ static size_t len_no_wrap;
+ static ssize_t appended, space_left;
+ static void
*rb_data;
Why static?
+ struct l_ringbuf *rb;
+
+ rb = l_ringbuf_new(rb_size);
+ assert(rb != NULL);
+ assert(l_ringbuf_capacity(rb) == rb_capa);
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ space_left = minsize(l_ringbuf_avail(rb), sizeof(data));
+ l_ringbuf_drain(rb, sizeof(data) - space_left);
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(len_no_wrap == sizeof(expected_data1));
+ assert(memcmp(expected_data1, rb_data, len_no_wrap) == 0);
+
+ l_ringbuf_drain(rb, len_no_wrap);
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(len_no_wrap == sizeof(expected_data2));
+ assert(memcmp(expected_data2, rb_data, len_no_wrap) == 0);
+
+ l_ringbuf_free(rb);
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -138,7 +218,8 @@ int main(int argc, char *argv[])
l_test_add("/ringbuf/power2", test_power2, NULL);
l_test_add("/ringbuf/alloc", test_alloc, NULL);
l_test_add("/ringbuf/printf", test_printf, NULL);
+ l_test_add("/ringbuf/append", test_append, NULL);
+ l_test_add("/ringbuf/append2", test_append2, NULL);
return l_test_run();
-
}
Regards,
-Denis