void test_nghttp2_bufs_reset(void) { int rv; nghttp2_bufs bufs; nghttp2_buf_chain *ci; ssize_t offset = 9; rv = nghttp2_bufs_init3(&bufs, 250, 3, 1, offset); CU_ASSERT(0 == rv); rv = nghttp2_bufs_add(&bufs, "foo", 3); CU_ASSERT(0 == rv); rv = nghttp2_bufs_advance(&bufs); CU_ASSERT(0 == rv); rv = nghttp2_bufs_add(&bufs, "bar", 3); CU_ASSERT(0 == rv); CU_ASSERT(6 == nghttp2_bufs_len(&bufs)); nghttp2_bufs_reset(&bufs); CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); CU_ASSERT(bufs.cur == bufs.head); for(ci = bufs.head; ci; ci = ci->next) { CU_ASSERT(offset == ci->buf.pos - ci->buf.begin); CU_ASSERT(ci->buf.pos == ci->buf.last); } CU_ASSERT(bufs.head->next == NULL); nghttp2_bufs_free(&bufs); }
void test_nghttp2_bufs_realloc(void) { int rv; nghttp2_bufs bufs; rv = nghttp2_bufs_init3(&bufs, 266, 3, 1, 10); CU_ASSERT(0 == rv); /* Create new buffer to see that these buffers are deallocated on realloc */ rv = nghttp2_bufs_advance(&bufs); CU_ASSERT(0 == rv); rv = nghttp2_bufs_realloc(&bufs, 522); CU_ASSERT(0 == rv); CU_ASSERT(512 == nghttp2_bufs_cur_avail(&bufs)); rv = nghttp2_bufs_realloc(&bufs, 9); CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); nghttp2_bufs_free(&bufs); }
int nghttp2_bufs_init2(nghttp2_bufs *bufs, size_t chunk_length, size_t max_chunk, size_t offset) { return nghttp2_bufs_init3(bufs, chunk_length, max_chunk, max_chunk, offset); }