void test_nghttp2_hd_inflate_newname_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; ssize_t blocklen; nghttp2_nv nv = MAKE_NV("x-rel", "nghttp2"); nva_out out; nghttp2_mem *mem; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv, 1)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); CU_ASSERT(1 == inflater.ctx.hd_table.len); assert_nv_equal( &nv, &GET_TABLE_ENT(&inflater.ctx, NGHTTP2_STATIC_TABLE_LENGTH + inflater.ctx.hd_table.len - 1)->nv, 1, mem); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); }
void test_nghttp2_hd_inflate_newname_noinc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; ssize_t blocklen; nghttp2_nv nv[] = {/* Expecting huffman for both */ MAKE_NV("my-long-content-length", "nghttp2"), /* Expecting no huffman for both */ MAKE_NV("x", "y"), /* Huffman for key only */ MAKE_NV("my-long-content-length", "y"), /* Huffman for value only */ MAKE_NV("x", "nghttp2")}; size_t i; nva_out out; nghttp2_mem *mem; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); for (i = 0; i < ARRLEN(nv); ++i) { CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv[i], NGHTTP2_HD_WITHOUT_INDEXING)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv[i], out.nva, 1, mem); CU_ASSERT(0 == inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); } nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); }
void test_nghttp2_hd_inflate_clearall_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; ssize_t blocklen; nghttp2_nv nv; uint8_t value[4061]; nva_out out; nghttp2_mem *mem; mem = nghttp2_mem_default(); bufs_large_init(&bufs, 8192); nva_out_init(&out); /* Total 4097 bytes space required to hold this entry */ nv.name = (uint8_t *)"alpha"; nv.namelen = strlen((char *)nv.name); memset(value, '0', sizeof(value)); value[sizeof(value) - 1] = '\0'; nv.value = value; nv.valuelen = sizeof(value) - 1; nv.flags = NGHTTP2_NV_FLAG_NONE; nghttp2_hd_inflate_init(&inflater, mem); CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv, 1)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); CU_ASSERT(0 == inflater.ctx.hd_table.len); nva_out_reset(&out, mem); /* Do it again */ CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); CU_ASSERT(0 == inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* This time, 4096 bytes space required, which is just fits in the header table */ nv.valuelen = sizeof(value) - 2; CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv, 1)); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(blocklen > 0); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); CU_ASSERT(1 == inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); }