void test_nghttp2_bufs_add(void) { int rv; nghttp2_bufs bufs; uint8_t data[2048]; rv = nghttp2_bufs_init(&bufs, 1000, 3); CU_ASSERT(0 == rv); CU_ASSERT(bufs.cur->buf.pos == bufs.cur->buf.last); rv = nghttp2_bufs_add(&bufs, data, 493); CU_ASSERT(0 == rv); CU_ASSERT(493 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(493 == nghttp2_bufs_len(&bufs)); CU_ASSERT(507 == nghttp2_bufs_cur_avail(&bufs)); rv = nghttp2_bufs_add(&bufs, data, 507); CU_ASSERT(0 == rv); CU_ASSERT(1000 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1000 == nghttp2_bufs_len(&bufs)); CU_ASSERT(bufs.cur == bufs.head); rv = nghttp2_bufs_add(&bufs, data, 1); CU_ASSERT(0 == rv); CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); CU_ASSERT(bufs.cur == bufs.head->next); nghttp2_bufs_free(&bufs); }
void test_nghttp2_bufs_reset(void) { int rv; nghttp2_bufs bufs; nghttp2_buf_chain *ci; ssize_t offset = 9; rv = nghttp2_bufs_init3(&bufs, 250, 3, 1, offset); CU_ASSERT(0 == rv); rv = nghttp2_bufs_add(&bufs, "foo", 3); CU_ASSERT(0 == rv); rv = nghttp2_bufs_advance(&bufs); CU_ASSERT(0 == rv); rv = nghttp2_bufs_add(&bufs, "bar", 3); CU_ASSERT(0 == rv); CU_ASSERT(6 == nghttp2_bufs_len(&bufs)); nghttp2_bufs_reset(&bufs); CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); CU_ASSERT(bufs.cur == bufs.head); for(ci = bufs.head; ci; ci = ci->next) { CU_ASSERT(offset == ci->buf.pos - ci->buf.begin); CU_ASSERT(ci->buf.pos == ci->buf.last); } CU_ASSERT(bufs.head->next == NULL); nghttp2_bufs_free(&bufs); }
void test_nghttp2_hd_inflate_zero_length_huffman(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; /* Literal header without indexing - new name */ uint8_t data[] = {0x40, 0x01, 0x78 /* 'x' */, 0x80}; nva_out out; nghttp2_mem *mem; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); nva_out_init(&out); nghttp2_bufs_add(&bufs, data, sizeof(data)); /* /\* Literal header without indexing - new name *\/ */ /* ptr[0] = 0x40; */ /* ptr[1] = 1; */ /* ptr[2] = 'x'; */ /* ptr[3] = 0x80; */ nghttp2_hd_inflate_init(&inflater, mem); CU_ASSERT(4 == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); CU_ASSERT(1 == out.nva[0].namelen); CU_ASSERT('x' == out.nva[0].name[0]); CU_ASSERT(NULL == out.nva[0].value); CU_ASSERT(0 == out.nva[0].valuelen); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); }
void test_nghttp2_bufs_remove(void) { int rv; nghttp2_bufs bufs; nghttp2_buf_chain *chain; int i; uint8_t *out; ssize_t outlen; rv = nghttp2_bufs_init(&bufs, 1000, 3); CU_ASSERT(0 == rv); nghttp2_buf_shift_right(&bufs.cur->buf, 10); rv = nghttp2_bufs_add(&bufs, "hello ", 6); CU_ASSERT(0 == rv); for(i = 0; i < 2; ++i) { chain = bufs.cur; rv = nghttp2_bufs_advance(&bufs); CU_ASSERT(0 == rv); CU_ASSERT(chain->next == bufs.cur); } rv = nghttp2_bufs_add(&bufs, "world", 5); CU_ASSERT(0 == rv); outlen = nghttp2_bufs_remove(&bufs, &out); CU_ASSERT(11 == outlen); CU_ASSERT(0 == memcmp("hello world", out, outlen)); CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); CU_ASSERT(bufs.cur->buf.pos == bufs.cur->buf.begin); free(out); nghttp2_bufs_free(&bufs); }