Add test for nghttp2_hd_deflate_hd_vec with 1 byte chunk

This commit is contained in:
Tatsuhiro Tsujikawa 2016-08-17 22:59:48 +09:00
parent 40d217beb1
commit 508c88f659
1 changed files with 35 additions and 7 deletions

View File

@ -1278,10 +1278,11 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
uint8_t buf[4096]; uint8_t buf[4096];
ssize_t blocklen; ssize_t blocklen;
nghttp2_mem *mem; nghttp2_mem *mem;
nghttp2_vec vec[2]; nghttp2_vec vec[256];
size_t buflen; size_t buflen;
nghttp2_bufs bufs; nghttp2_bufs bufs;
nva_out out; nva_out out;
size_t i;
mem = nghttp2_mem_default(); mem = nghttp2_mem_default();
@ -1297,8 +1298,7 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
vec[1].base = &buf[buflen / 2]; vec[1].base = &buf[buflen / 2];
vec[1].len = buflen / 2; vec[1].len = buflen / 2;
blocklen = blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva));
nghttp2_hd_deflate_hd_vec(deflater, vec, ARRLEN(vec), nva, ARRLEN(nva));
CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen > 0);
@ -1336,8 +1336,7 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
nghttp2_hd_deflate_new(&deflater, 4096); nghttp2_hd_deflate_new(&deflater, 4096);
nghttp2_hd_inflate_new(&inflater); nghttp2_hd_inflate_new(&inflater);
blocklen = blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva));
nghttp2_hd_deflate_hd_vec(deflater, vec, ARRLEN(vec), nva, ARRLEN(nva));
CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen);
@ -1355,13 +1354,42 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
vec[1].base = &buf[buflen / 2]; vec[1].base = &buf[buflen / 2];
vec[1].len = (buflen / 2) - 1; vec[1].len = (buflen / 2) - 1;
blocklen = blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva));
nghttp2_hd_deflate_hd_vec(deflater, vec, ARRLEN(vec), nva, ARRLEN(nva));
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == blocklen); CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == blocklen);
nghttp2_hd_inflate_del(inflater); nghttp2_hd_inflate_del(inflater);
nghttp2_hd_deflate_del(deflater); nghttp2_hd_deflate_del(deflater);
/* check the case where chunk size is 1 */
nghttp2_hd_deflate_new(&deflater, 4096);
nghttp2_hd_inflate_new(&inflater);
buflen = nghttp2_hd_deflate_bound(deflater, nva, ARRLEN(nva));
assert(buflen <= ARRLEN(vec));
for (i = 0; i < buflen; ++i) {
vec[i].base = &buf[i];
vec[i].len = 1;
}
blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, buflen, nva, ARRLEN(nva));
CU_ASSERT(blocklen > 0);
nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem);
bufs.head->buf.last += blocklen;
CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem));
CU_ASSERT(ARRLEN(nva) == out.nvlen);
assert_nv_equal(nva, out.nva, ARRLEN(nva), mem);
nghttp2_bufs_wrap_free(&bufs);
nghttp2_hd_inflate_del(inflater);
nghttp2_hd_deflate_del(deflater);
nva_out_reset(&out, mem);
} }
static size_t encode_length(uint8_t *buf, uint64_t n, size_t prefix) { static size_t encode_length(uint8_t *buf, uint64_t n, size_t prefix) {