Add test for nghttp2_hd_deflate_hd_vec

This commit is contained in:
Tatsuhiro Tsujikawa 2016-08-16 11:11:06 +09:00
parent c4d36aeff7
commit c6111b3792
3 changed files with 54 additions and 0 deletions

View File

@ -383,6 +383,8 @@ int main(int argc _U_, char *argv[] _U_) {
!CU_add_test(pSuite, "hd_no_index", test_nghttp2_hd_no_index) || !CU_add_test(pSuite, "hd_no_index", test_nghttp2_hd_no_index) ||
!CU_add_test(pSuite, "hd_deflate_bound", test_nghttp2_hd_deflate_bound) || !CU_add_test(pSuite, "hd_deflate_bound", test_nghttp2_hd_deflate_bound) ||
!CU_add_test(pSuite, "hd_public_api", test_nghttp2_hd_public_api) || !CU_add_test(pSuite, "hd_public_api", test_nghttp2_hd_public_api) ||
!CU_add_test(pSuite, "hd_deflate_hd_vec",
test_nghttp2_hd_deflate_hd_vec) ||
!CU_add_test(pSuite, "hd_decode_length", test_nghttp2_hd_decode_length) || !CU_add_test(pSuite, "hd_decode_length", test_nghttp2_hd_decode_length) ||
!CU_add_test(pSuite, "hd_huff_encode", test_nghttp2_hd_huff_encode) || !CU_add_test(pSuite, "hd_huff_encode", test_nghttp2_hd_huff_encode) ||
!CU_add_test(pSuite, "adjust_local_window_size", !CU_add_test(pSuite, "adjust_local_window_size",

View File

@ -1265,6 +1265,57 @@ void test_nghttp2_hd_public_api(void) {
nghttp2_hd_deflate_del(deflater); nghttp2_hd_deflate_del(deflater);
} }
void test_nghttp2_hd_deflate_hd_vec(void) {
nghttp2_hd_deflater *deflater;
nghttp2_hd_inflater *inflater;
nghttp2_nv nva[] = {
MAKE_NV(":method", "PUT"), MAKE_NV(":scheme", "https"),
MAKE_NV(":authority", "localhost:3000"),
MAKE_NV(":path", "/usr/foo/alpha/bravo"),
MAKE_NV("content-type", "image/png"),
MAKE_NV("content-length", "1000000007"),
};
uint8_t buf[4096];
ssize_t blocklen;
nghttp2_mem *mem;
uint8_t *bufsin[2];
size_t buflens[2] = {0};
size_t buflen;
nghttp2_bufs bufs;
nva_out out;
mem = nghttp2_mem_default();
nva_out_init(&out);
nghttp2_hd_deflate_new(&deflater, 4096);
nghttp2_hd_inflate_new(&inflater);
buflen = nghttp2_hd_deflate_bound(deflater, nva, ARRLEN(nva));
bufsin[0] = &buf[0];
bufsin[1] = &buf[buflen / 2];
blocklen = nghttp2_hd_deflate_hd_vec(deflater, bufsin, ARRLEN(bufsin),
buflen / 2, buflens, 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) {
size_t k = (size_t)((1 << prefix) - 1); size_t k = (size_t)((1 << prefix) - 1);
size_t len = 0; size_t len = 0;

View File

@ -47,6 +47,7 @@ void test_nghttp2_hd_deflate_inflate(void);
void test_nghttp2_hd_no_index(void); void test_nghttp2_hd_no_index(void);
void test_nghttp2_hd_deflate_bound(void); void test_nghttp2_hd_deflate_bound(void);
void test_nghttp2_hd_public_api(void); void test_nghttp2_hd_public_api(void);
void test_nghttp2_hd_deflate_hd_vec(void);
void test_nghttp2_hd_decode_length(void); void test_nghttp2_hd_decode_length(void);
void test_nghttp2_hd_huff_encode(void); void test_nghttp2_hd_huff_encode(void);