From e77ff4187f29a2ae79119e5b36e463808fc245ee Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 21 Apr 2016 01:47:29 +0300 Subject: [PATCH] test/buffer: cover n_add_for_cb when evbuffer_prepend() need to allocate buffer Regression-for: 0abd0393eaf029e1ead8a09b479ea6830f7152ee ("Fix n_add_for_cb in evbuffer_prepend() in case of new buffer required") --- test/regress_buffer.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/regress_buffer.c b/test/regress_buffer.c index c945599d..32b0f1c2 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -1866,12 +1866,23 @@ end: evbuffer_free(buf2); } +static void +check_prepend(struct evbuffer *buffer, + const struct evbuffer_cb_info *cbinfo, + void *arg) +{ + tt_int_op(cbinfo->orig_size, ==, 3); + tt_int_op(cbinfo->n_added, ==, 8096); + tt_int_op(cbinfo->n_deleted, ==, 0); +end: + ; +} /* Some cases that we didn't get in test_evbuffer() above, for more coverage. */ static void test_evbuffer_prepend(void *ptr) { struct evbuffer *buf1 = NULL, *buf2 = NULL; - char tmp[128]; + char tmp[128], *buffer = malloc(8096); int n; buf1 = evbuffer_new(); @@ -1919,6 +1930,21 @@ test_evbuffer_prepend(void *ptr) tmp[n]='\0'; tt_str_op(tmp,==,"Here is string 1000. Here is string 999. "); + /* Case 5: evbuffer_prepend() will need a new buffer, with callbacks */ + memset(buffer, 'A', 8096); + evbuffer_free(buf2); + buf2 = evbuffer_new(); + tt_assert(buf2); + evbuffer_prepend(buf2, "foo", 3); + evbuffer_add_cb(buf2, check_prepend, NULL); + evbuffer_prepend(buf2, buffer, 8096); + evbuffer_remove_cb(buf2, check_prepend, NULL); + evbuffer_validate(buf2); + tt_nstr_op(8096,(char *)evbuffer_pullup(buf2, 8096),==,buffer); + evbuffer_drain(buf2, 8096); + tt_nstr_op(3,(char *)evbuffer_pullup(buf2, 3),==,"foo"); + evbuffer_drain(buf2, 3); + end: if (buf1) evbuffer_free(buf1); -- 2.40.0