Skip to content

Commit

Permalink
Add test for nghttp2_hd_deflate_hd_vec with 1 byte chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Aug 17, 2016
1 parent 40d217b commit 508c88f
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions tests/nghttp2_hd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,10 +1278,11 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
uint8_t buf[4096];
ssize_t blocklen;
nghttp2_mem *mem;
nghttp2_vec vec[2];
nghttp2_vec vec[256];
size_t buflen;
nghttp2_bufs bufs;
nva_out out;
size_t i;

mem = nghttp2_mem_default();

Expand All @@ -1297,8 +1298,7 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
vec[1].base = &buf[buflen / 2];
vec[1].len = buflen / 2;

blocklen =
nghttp2_hd_deflate_hd_vec(deflater, vec, ARRLEN(vec), nva, ARRLEN(nva));
blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva));

CU_ASSERT(blocklen > 0);

Expand Down Expand Up @@ -1336,8 +1336,7 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
nghttp2_hd_deflate_new(&deflater, 4096);
nghttp2_hd_inflate_new(&inflater);

blocklen =
nghttp2_hd_deflate_hd_vec(deflater, vec, ARRLEN(vec), nva, ARRLEN(nva));
blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva));

CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen);

Expand All @@ -1355,13 +1354,42 @@ void test_nghttp2_hd_deflate_hd_vec(void) {
vec[1].base = &buf[buflen / 2];
vec[1].len = (buflen / 2) - 1;

blocklen =
nghttp2_hd_deflate_hd_vec(deflater, vec, ARRLEN(vec), nva, ARRLEN(nva));
blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva));

CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == blocklen);

nghttp2_hd_inflate_del(inflater);
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) {
Expand Down

0 comments on commit 508c88f

Please sign in to comment.