void test_nghttp2_bufs_next_present(void) { int rv; nghttp2_bufs bufs; rv = nghttp2_bufs_init(&bufs, 250, 3); CU_ASSERT(0 == rv); CU_ASSERT(0 == nghttp2_bufs_next_present(&bufs)); rv = nghttp2_bufs_advance(&bufs); CU_ASSERT(0 == rv); nghttp2_bufs_rewind(&bufs); CU_ASSERT(0 == nghttp2_bufs_next_present(&bufs)); bufs.cur = bufs.head->next; rv = nghttp2_bufs_addb(&bufs, 1); CU_ASSERT(0 == rv); nghttp2_bufs_rewind(&bufs); CU_ASSERT(0 != nghttp2_bufs_next_present(&bufs)); nghttp2_bufs_free(&bufs); }
void test_nghttp2_hd_inflate_indexed(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; ssize_t blocklen; nghttp2_nv nv = MAKE_NV(":path", "/"); 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); nghttp2_bufs_addb(&bufs, (1 << 7) | 4); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(1 == blocklen); CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* index = 0 is error */ nghttp2_bufs_addb(&bufs, 1 << 7); blocklen = nghttp2_bufs_len(&bufs); CU_ASSERT(1 == blocklen); CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == inflate_hd(&inflater, &out, &bufs, 0, mem)); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); }
void test_nghttp2_bufs_addb(void) { int rv; nghttp2_bufs bufs; ssize_t i; rv = nghttp2_bufs_init(&bufs, 1000, 3); CU_ASSERT(0 == rv); rv = nghttp2_bufs_addb(&bufs, 14); CU_ASSERT(0 == rv); CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1 == nghttp2_bufs_len(&bufs)); CU_ASSERT(14 == *bufs.cur->buf.pos); for(i = 0; i < 999; ++i) { rv = nghttp2_bufs_addb(&bufs, 254); CU_ASSERT(0 == rv); CU_ASSERT(i + 2 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(i + 2 == nghttp2_bufs_len(&bufs)); CU_ASSERT(254 == *(bufs.cur->buf.last - 1)); CU_ASSERT(bufs.cur == bufs.head); } rv = nghttp2_bufs_addb(&bufs, 253); CU_ASSERT(0 == rv); CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); CU_ASSERT(253 == *(bufs.cur->buf.last - 1)); CU_ASSERT(bufs.cur == bufs.head->next); rv = nghttp2_bufs_addb_hold(&bufs, 15); CU_ASSERT(0 == rv); CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); CU_ASSERT(15 == *(bufs.cur->buf.last)); /* test fast version */ nghttp2_bufs_fast_addb(&bufs, 240); CU_ASSERT(2 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1002 == nghttp2_bufs_len(&bufs)); CU_ASSERT(240 == *(bufs.cur->buf.last - 1)); nghttp2_bufs_fast_addb_hold(&bufs, 113); CU_ASSERT(2 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(1002 == nghttp2_bufs_len(&bufs)); CU_ASSERT(113 == *(bufs.cur->buf.last)); /* addb_hold when last == end */ bufs.cur->buf.last = bufs.cur->buf.end; rv = nghttp2_bufs_addb_hold(&bufs, 19); CU_ASSERT(0 == rv); CU_ASSERT(0 == nghttp2_buf_len(&bufs.cur->buf)); CU_ASSERT(2000 == nghttp2_bufs_len(&bufs)); CU_ASSERT(19 == *(bufs.cur->buf.last)); nghttp2_bufs_free(&bufs); }