]> granicus.if.org Git - libevent/commitdiff
test/buffer: evbuffer_remove_buffer() with empty chains (prepend)
authorAzat Khuzhin <a3at.mail@gmail.com>
Wed, 8 Jun 2016 10:41:30 +0000 (13:41 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Fri, 17 Jun 2016 14:20:35 +0000 (17:20 +0300)
Using:
- evbuffer_add()
- evbuffer_prepend_buffer()
- evbuffer_add_reference()
- evbuffer_remove_buffer()

test/regress_buffer.c

index c26d9751ee14c34e8665d6781a874ef74fda9458..3b8f6f9478621ec890acd399ed30570fb1b5f919 100644 (file)
@@ -364,6 +364,47 @@ test_evbuffer_remove_buffer_with_empty2(void *ptr)
        evbuffer_free(buf);
 }
 
+static void
+test_evbuffer_remove_buffer_with_empty3(void *ptr)
+{
+       struct evbuffer *src = evbuffer_new();
+       struct evbuffer *dst = evbuffer_new();
+       struct evbuffer *buf = evbuffer_new();
+
+       evbuffer_add(buf, "foo", 3);
+       evbuffer_add_reference(buf, NULL, 0, NULL, NULL);
+
+       evbuffer_add_reference(src, "foo", 3, NULL, NULL);
+       evbuffer_add_reference(src, NULL, 0, NULL, NULL);
+       evbuffer_prepend_buffer(src, buf);
+
+       evbuffer_add(buf, "foo", 3);
+       evbuffer_add_reference(buf, NULL, 0, NULL, NULL);
+
+       evbuffer_add_reference(dst, "foo", 3, NULL, NULL);
+       evbuffer_add_reference(dst, NULL, 0, NULL, NULL);
+       evbuffer_prepend_buffer(dst, buf);
+
+       tt_int_op(evbuffer_get_length(src), ==, 6);
+       tt_int_op(evbuffer_get_length(dst), ==, 6);
+
+       evbuffer_validate(src);
+       evbuffer_validate(dst);
+
+       evbuffer_remove_buffer(src, dst, 5);
+
+       evbuffer_validate(src);
+       evbuffer_validate(dst);
+
+       tt_int_op(evbuffer_get_length(src), ==, 1);
+       tt_int_op(evbuffer_get_length(dst), ==, 11);
+
+ end:
+       evbuffer_free(src);
+       evbuffer_free(dst);
+       evbuffer_free(buf);
+}
+
 static void
 test_evbuffer_reserve2(void *ptr)
 {
@@ -2385,6 +2426,7 @@ struct testcase_t evbuffer_testcases[] = {
        { "evbuffer", test_evbuffer, 0, NULL, NULL },
        { "remove_buffer_with_empty", test_evbuffer_remove_buffer_with_empty, 0, NULL, NULL },
        { "remove_buffer_with_empty2", test_evbuffer_remove_buffer_with_empty2, 0, NULL, NULL },
+       { "remove_buffer_with_empty3", test_evbuffer_remove_buffer_with_empty3, 0, NULL, NULL },
        { "reserve2", test_evbuffer_reserve2, 0, NULL, NULL },
        { "reserve_many", test_evbuffer_reserve_many, 0, NULL, NULL },
        { "reserve_many2", test_evbuffer_reserve_many, 0, &nil_setup, (void*)"add" },