test/evbuffer_peek: add regress in case we have first buffer greater

This commit is contained in:
Azat Khuzhin 2014-11-11 14:25:47 +03:00 committed by Nick Mathewson
parent ba59923ab8
commit e2d139dd7e

View File

@ -1843,6 +1843,34 @@ end:
}
static void
test_evbuffer_peek_first_gt(void *info)
{
struct evbuffer *buf = NULL, *tmp_buf = NULL;
struct evbuffer_ptr ptr;
struct evbuffer_iovec v[2];
buf = evbuffer_new();
tmp_buf = evbuffer_new();
evbuffer_add_printf(tmp_buf, "Contents of chunk 100\n");
evbuffer_add_buffer(buf, tmp_buf);
evbuffer_add_printf(tmp_buf, "Contents of chunk 1\n");
evbuffer_add_buffer(buf, tmp_buf);
evbuffer_ptr_set(buf, &ptr, 0, EVBUFFER_PTR_SET);
/** The only case that matters*/
tt_int_op(evbuffer_peek(buf, -1, &ptr, NULL, 0), ==, 2);
/** Just in case */
tt_int_op(evbuffer_peek(buf, -1, &ptr, v, 2), ==, 2);
end:
if (buf)
evbuffer_free(buf);
if (tmp_buf)
evbuffer_free(tmp_buf);
}
static void
test_evbuffer_peek(void *info)
{
@ -2210,6 +2238,7 @@ struct testcase_t evbuffer_testcases[] = {
{ "multicast_drain", test_evbuffer_multicast_drain, 0, NULL, NULL },
{ "prepend", test_evbuffer_prepend, TT_FORK, NULL, NULL },
{ "peek", test_evbuffer_peek, 0, NULL, NULL },
{ "peek_first_gt", test_evbuffer_peek_first_gt, 0, NULL, NULL },
{ "freeze_start", test_evbuffer_freeze, 0, &nil_setup, (void*)"start" },
{ "freeze_end", test_evbuffer_freeze, 0, &nil_setup, (void*)"end" },
{ "add_iovec", test_evbuffer_add_iovec, 0, NULL, NULL},