コード例 #1
0
ファイル: nghttp2_hd_test.c プロジェクト: LambdaOS/nghttp2
void test_nghttp2_hd_inflate_indname_inc(void) {
  nghttp2_hd_inflater inflater;
  nghttp2_bufs bufs;
  ssize_t blocklen;
  nghttp2_nv nv = MAKE_NV("user-agent", "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_indname_block(&bufs, 57, &nv,
                                               NGHTTP2_HD_WITH_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, 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);
}
コード例 #2
0
ファイル: nghttp2_hd_test.c プロジェクト: 0xfffffff7/nghttp2
void test_nghttp2_hd_inflate_indname_inc_eviction(void) {
  nghttp2_hd_inflater inflater;
  nghttp2_bufs bufs;
  ssize_t blocklen;
  uint8_t value[1025];
  nva_out out;
  nghttp2_nv nv;
  nghttp2_mem *mem;

  mem = nghttp2_mem_default();
  frame_pack_bufs_init(&bufs);

  nva_out_init(&out);
  nghttp2_hd_inflate_init(&inflater, mem);

  memset(value, '0', sizeof(value));
  value[sizeof(value) - 1] = '\0';
  nv.value = value;
  nv.valuelen = sizeof(value) - 1;

  nv.flags = NGHTTP2_NV_FLAG_NONE;

  CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 14, &nv, 1));
  CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 15, &nv, 1));
  CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 16, &nv, 1));
  CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 17, &nv, 1));

  blocklen = nghttp2_bufs_len(&bufs);

  CU_ASSERT(blocklen > 0);

  CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));

  CU_ASSERT(4 == out.nvlen);
  CU_ASSERT(14 == out.nva[0].namelen);
  CU_ASSERT(0 == memcmp("accept-charset", out.nva[0].name, out.nva[0].namelen));
  CU_ASSERT(sizeof(value) - 1 == out.nva[0].valuelen);

  nva_out_reset(&out, mem);
  nghttp2_bufs_reset(&bufs);

  CU_ASSERT(3 == inflater.ctx.hd_table.len);

  nghttp2_bufs_free(&bufs);
  nghttp2_hd_inflate_free(&inflater);
}
コード例 #3
0
ファイル: nghttp2_hd_test.c プロジェクト: LambdaOS/nghttp2
void test_nghttp2_hd_inflate_indname_noinc(void) {
  nghttp2_hd_inflater inflater;
  nghttp2_bufs bufs;
  ssize_t blocklen;
  nghttp2_nv nv[] = {/* Huffman */
                     MAKE_NV("user-agent", "nghttp2"),
                     /* Expecting no huffman */
                     MAKE_NV("user-agent", "x")};
  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_indname_block(&bufs, 57, &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);
}