]> granicus.if.org Git - libevent/commitdiff
test/buffer: evbuffer_add_buffer() with empty chains
authorAzat Khuzhin <a3at.mail@gmail.com>
Fri, 17 Jun 2016 12:54:53 +0000 (15:54 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Fri, 17 Jun 2016 14:40:40 +0000 (17:40 +0300)
Reported-by: @EMPanisset
Link: https://github.com/libevent/libevent/issues/358#issuecomment-225345697
test/regress_buffer.c

index 3b8f6f9478621ec890acd399ed30570fb1b5f919..2f57c3b5b5399b2f3c0c554c9e14227cc9b978b7 100644 (file)
@@ -405,6 +405,66 @@ test_evbuffer_remove_buffer_with_empty3(void *ptr)
        evbuffer_free(buf);
 }
 
+static void
+test_evbuffer_add_buffer_with_empty(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(src, "foo", 3, NULL, NULL);
+       evbuffer_add_reference(src, NULL, 0, NULL, NULL);
+       evbuffer_add_buffer(src, buf);
+
+       evbuffer_add(buf, "foo", 3);
+
+       evbuffer_add_reference(dst, "foo", 3, NULL, NULL);
+       evbuffer_add_reference(dst, NULL, 0, NULL, NULL);
+       evbuffer_add_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);
+
+ end:
+       evbuffer_free(src);
+       evbuffer_free(dst);
+       evbuffer_free(buf);
+}
+
+static void
+test_evbuffer_add_buffer_with_empty2(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(src, NULL, 0, NULL, NULL);
+       evbuffer_add_buffer(src, buf);
+
+       evbuffer_add(buf, "foo", 3);
+
+       evbuffer_add_reference(dst, NULL, 0, NULL, NULL);
+       evbuffer_add_buffer(dst, buf);
+
+       tt_int_op(evbuffer_get_length(src), ==, 3);
+       tt_int_op(evbuffer_get_length(dst), ==, 3);
+
+       evbuffer_validate(src);
+       evbuffer_validate(dst);
+
+ end:
+       evbuffer_free(src);
+       evbuffer_free(dst);
+       evbuffer_free(buf);
+}
+
 static void
 test_evbuffer_reserve2(void *ptr)
 {
@@ -2427,6 +2487,8 @@ struct testcase_t evbuffer_testcases[] = {
        { "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 },
+       { "add_buffer_with_empty", test_evbuffer_add_buffer_with_empty, 0, NULL, NULL },
+       { "add_buffer_with_empty2", test_evbuffer_add_buffer_with_empty2, 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" },