diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2f22ee..a39df2e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,6 +31,7 @@ include_directories( set(main_SOURCES main.c + nghttp3_qpack_test.c nghttp3_tnode_test.c nghttp3_http_test.c nghttp3_test_helper.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 2524409..b8cc5c5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,6 +28,7 @@ check_PROGRAMS = main OBJECTS = \ main.c \ + nghttp3_qpack_test.c \ nghttp3_tnode_test.c \ nghttp3_http_test.c \ nghttp3_test_helper.c \ diff --git a/tests/main.c b/tests/main.c index 5df4800..9380773 100644 --- a/tests/main.c +++ b/tests/main.c @@ -42,6 +42,7 @@ int main(int argc, char **argv) { const MunitSuite suites[] = { tnode_suite, http_suite, + qpack_suite, {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, }; const MunitSuite suite = { diff --git a/tests/munit b/tests/munit index c0343f9..846ffca 160000 --- a/tests/munit +++ b/tests/munit @@ -1 +1 @@ -Subproject commit c0343f9d25ca2378fd61a1c5362a459cb1825b11 +Subproject commit 846ffcaa817c369cc2892f7bbb10f7b99eb08934 diff --git a/tests/nghttp3_qpack_test.c b/tests/nghttp3_qpack_test.c index 2f73b04..b7005fd 100644 --- a/tests/nghttp3_qpack_test.c +++ b/tests/nghttp3_qpack_test.c @@ -27,12 +27,29 @@ #include #include -#include +#include "munit/munit.h" #include "nghttp3_qpack.h" #include "nghttp3_macro.h" #include "nghttp3_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp3_qpack_encoder_encode), + munit_void_test(test_nghttp3_qpack_encoder_encode_try_encode), + munit_void_test(test_nghttp3_qpack_encoder_still_blocked), + munit_void_test(test_nghttp3_qpack_encoder_set_dtable_cap), + munit_void_test(test_nghttp3_qpack_decoder_feedback), + munit_void_test(test_nghttp3_qpack_decoder_stream_overflow), + munit_void_test(test_nghttp3_qpack_huffman), + munit_void_test(test_nghttp3_qpack_huffman_decode_failure_state), + munit_void_test(test_nghttp3_qpack_decoder_reconstruct_ricnt), + munit_test_end(), +}; + +const MunitSuite qpack_suite = { + "/qpack", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static void check_decode_header(nghttp3_qpack_decoder *dec, nghttp3_buf *pbuf, nghttp3_buf *rbuf, nghttp3_buf *ebuf, int64_t stream_id, const nghttp3_nv *nva, @@ -47,20 +64,20 @@ static void check_decode_header(nghttp3_qpack_decoder *dec, nghttp3_buf *pbuf, nread = nghttp3_qpack_decoder_read_encoder(dec, ebuf->pos, nghttp3_buf_len(ebuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(ebuf) == nread); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(ebuf), ==, nread); nghttp3_qpack_stream_context_init(&sctx, stream_id, mem); nread = nghttp3_qpack_decoder_read_request( dec, &sctx, &qnv, &flags, pbuf->pos, nghttp3_buf_len(pbuf), 0); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(pbuf) == nread); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(pbuf), ==, nread); for (; nghttp3_buf_len(rbuf);) { nread = nghttp3_qpack_decoder_read_request( dec, &sctx, &qnv, &flags, rbuf->pos, nghttp3_buf_len(rbuf), 1); - CU_ASSERT(nread > 0); + assert_true(nread > 0); if (nread < 0) { break; @@ -73,17 +90,17 @@ static void check_decode_header(nghttp3_qpack_decoder *dec, nghttp3_buf *pbuf, } if (flags & NGHTTP3_QPACK_DECODE_FLAG_EMIT) { nv = &nva[i++]; - CU_ASSERT(nv->namelen == qnv.name->len); - CU_ASSERT(0 == memcmp(nv->name, qnv.name->base, nv->namelen)); - CU_ASSERT(nv->valuelen == qnv.value->len); - CU_ASSERT(0 == memcmp(nv->value, qnv.value->base, nv->valuelen)); + assert_size(nv->namelen, ==, qnv.name->len); + assert_memory_equal(nv->namelen, nv->name, qnv.name->base); + assert_size(nv->valuelen, ==, qnv.value->len); + assert_memory_equal(nv->valuelen, nv->value, qnv.value->base); nghttp3_rcbuf_decref(qnv.name); nghttp3_rcbuf_decref(qnv.value); } } - CU_ASSERT(i == nvlen); + assert_size(i, ==, nvlen); nghttp3_qpack_stream_context_free(&sctx); nghttp3_buf_reset(pbuf); @@ -104,29 +121,29 @@ static void decode_header_block(nghttp3_qpack_decoder *dec, nghttp3_buf *pbuf, nread = nghttp3_qpack_decoder_read_request( dec, &sctx, &qnv, &flags, pbuf->pos, nghttp3_buf_len(pbuf), 0); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(pbuf) == nread); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(pbuf), ==, nread); for (;;) { nread = nghttp3_qpack_decoder_read_request( dec, &sctx, &qnv, &flags, rbuf->pos, nghttp3_buf_len(rbuf), 1); - CU_ASSERT(nread >= 0); + assert_true(nread >= 0); if (nread < 0) { break; } if (flags & NGHTTP3_QPACK_DECODE_FLAG_FINAL) { - CU_ASSERT(nread == 0); - CU_ASSERT(!(flags & NGHTTP3_QPACK_DECODE_FLAG_EMIT)); - CU_ASSERT(0 == nghttp3_buf_len(rbuf)); - CU_ASSERT(nghttp3_buf_len(&dec->dbuf) > 0); + assert_ptrdiff(0, ==, nread); + assert_false(flags & NGHTTP3_QPACK_DECODE_FLAG_EMIT); + assert_size(0, ==, nghttp3_buf_len(rbuf)); + assert_true(nghttp3_buf_len(&dec->dbuf) > 0); break; } - CU_ASSERT(nread > 0); - CU_ASSERT(flags & NGHTTP3_QPACK_DECODE_FLAG_EMIT); + assert_true(nread > 0); + assert_true(flags & NGHTTP3_QPACK_DECODE_FLAG_EMIT); nghttp3_rcbuf_decref(qnv.name); nghttp3_rcbuf_decref(qnv.value); @@ -166,7 +183,7 @@ void test_nghttp3_qpack_encoder_encode(void) { nghttp3_buf_init(&ebuf); rv = nghttp3_qpack_encoder_init(&enc, 4096, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_qpack_encoder_set_max_blocked_streams(&enc, 1); @@ -174,27 +191,27 @@ void test_nghttp3_qpack_encoder_encode(void) { rv = nghttp3_qpack_decoder_init(&dec, 4096, 1, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva, nghttp3_arraylen(nva)); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream = nghttp3_qpack_encoder_find_stream(&enc, 0); - CU_ASSERT(NULL != stream); - CU_ASSERT(nghttp3_qpack_encoder_stream_is_blocked(&enc, stream)); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_not_null(stream); + assert_true(nghttp3_qpack_encoder_stream_is_blocked(&enc, stream)); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); ref = *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 0); - CU_ASSERT(5 == ref->max_cnt); - CU_ASSERT(1 == ref->min_cnt); - CU_ASSERT(5 == nghttp3_qpack_stream_get_max_cnt(stream)); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_min_cnt(&enc)); - CU_ASSERT(2 == nghttp3_buf_len(&pbuf)); + assert_uint64(5, ==, ref->max_cnt); + assert_uint64(1, ==, ref->min_cnt); + assert_uint64(5, ==, nghttp3_qpack_stream_get_max_cnt(stream)); + assert_uint64(1, ==, nghttp3_qpack_encoder_get_min_cnt(&enc)); + assert_size(2, ==, nghttp3_buf_len(&pbuf)); check_decode_header(&dec, &pbuf, &rbuf, &ebuf, 0, nva, nghttp3_arraylen(nva), mem); @@ -202,24 +219,24 @@ void test_nghttp3_qpack_encoder_encode(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 4, nva, nghttp3_arraylen(nva)); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream = nghttp3_qpack_encoder_find_stream(&enc, 4); - CU_ASSERT(NULL == stream); + assert_null(stream); check_decode_header(&dec, &pbuf, &rbuf, &ebuf, 4, nva, nghttp3_arraylen(nva), mem); nghttp3_qpack_encoder_ack_header(&enc, 0); - CU_ASSERT(5 == enc.krcnt); + assert_uint64(5, ==, enc.krcnt); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 8, nva, nghttp3_arraylen(nva)); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(0, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); check_decode_header(&dec, &pbuf, &rbuf, &ebuf, 8, nva, nghttp3_arraylen(nva), mem); @@ -255,7 +272,7 @@ void test_nghttp3_qpack_encoder_encode_try_encode(void) { nghttp3_buf_init(&ebuf); rv = nghttp3_qpack_encoder_init(&enc, 4096, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_qpack_encoder_set_max_blocked_streams(&enc, 1); @@ -264,23 +281,23 @@ void test_nghttp3_qpack_encoder_encode_try_encode(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva, nghttp3_arraylen(nva)); - CU_ASSERT(0 == rv); - CU_ASSERT(3 == nghttp3_ringbuf_len(&enc.ctx.dtable)); + assert_int(0, ==, rv); + assert_size(3, ==, nghttp3_ringbuf_len(&enc.ctx.dtable)); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 0); - CU_ASSERT(nva[5].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[5].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[5].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[5].name, ent->nv.name->base); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 1); - CU_ASSERT(nva[3].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[3].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[3].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[3].name, ent->nv.name->base); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 2); - CU_ASSERT(nva[1].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[1].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[1].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[1].name, ent->nv.name->base); nghttp3_qpack_encoder_free(&enc); nghttp3_buf_reset(&ebuf); @@ -293,7 +310,7 @@ void test_nghttp3_qpack_encoder_encode_try_encode(void) { rv = nghttp3_qpack_encoder_init(&enc, 4096, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_qpack_encoder_set_max_blocked_streams(&enc, 1); @@ -302,33 +319,33 @@ void test_nghttp3_qpack_encoder_encode_try_encode(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva, nghttp3_arraylen(nva)); - CU_ASSERT(0 == rv); - CU_ASSERT(5 == nghttp3_ringbuf_len(&enc.ctx.dtable)); + assert_int(0, ==, rv); + assert_size(5, ==, nghttp3_ringbuf_len(&enc.ctx.dtable)); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 0); - CU_ASSERT(nva[6].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[6].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[6].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[6].name, ent->nv.name->base); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 1); - CU_ASSERT(nva[5].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[5].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[5].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[5].name, ent->nv.name->base); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 2); - CU_ASSERT(nva[3].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[3].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[3].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[3].name, ent->nv.name->base); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 3); - CU_ASSERT(nva[1].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[1].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[1].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[1].name, ent->nv.name->base); ent = *(nghttp3_qpack_entry **)nghttp3_ringbuf_get(&enc.ctx.dtable, 4); - CU_ASSERT(nva[0].namelen == ent->nv.name->len); - CU_ASSERT(0 == memcmp(nva[0].name, ent->nv.name->base, ent->nv.name->len)); + assert_size(nva[0].namelen, ==, ent->nv.name->len); + assert_memory_equal(ent->nv.name->len, nva[0].name, ent->nv.name->base); nghttp3_qpack_encoder_free(&enc); nghttp3_buf_free(&ebuf, mem); @@ -357,7 +374,7 @@ void test_nghttp3_qpack_encoder_still_blocked(void) { nghttp3_buf_init(&ebuf); rv = nghttp3_qpack_encoder_init(&enc, 4096, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_qpack_encoder_set_max_blocked_streams(&enc, 1); @@ -366,44 +383,44 @@ void test_nghttp3_qpack_encoder_still_blocked(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva1, nghttp3_arraylen(nva1)); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva2, nghttp3_arraylen(nva2)); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); stream = nghttp3_qpack_encoder_find_stream(&enc, 0); ref = *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 0); - CU_ASSERT(nghttp3_ringbuf_len(&stream->refs) > 1); - CU_ASSERT(ref->max_cnt != nghttp3_qpack_stream_get_max_cnt(stream)); + assert_true(nghttp3_ringbuf_len(&stream->refs) > 1); + assert_uint64(ref->max_cnt, !=, nghttp3_qpack_stream_get_max_cnt(stream)); ref = *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 1); - CU_ASSERT(ref->max_cnt == nghttp3_qpack_stream_get_max_cnt(stream)); + assert_uint64(ref->max_cnt, ==, nghttp3_qpack_stream_get_max_cnt(stream)); nghttp3_qpack_encoder_ack_header(&enc, 0); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); stream = nghttp3_qpack_encoder_find_stream(&enc, 0); ref = *(nghttp3_qpack_header_block_ref **)nghttp3_ringbuf_get(&stream->refs, 0); - CU_ASSERT(1 == nghttp3_ringbuf_len(&stream->refs)); - CU_ASSERT(ref->max_cnt == nghttp3_qpack_stream_get_max_cnt(stream)); + assert_size(1, ==, nghttp3_ringbuf_len(&stream->refs)); + assert_uint64(ref->max_cnt, ==, nghttp3_qpack_stream_get_max_cnt(stream)); nghttp3_qpack_encoder_ack_header(&enc, 0); - CU_ASSERT(0 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); - CU_ASSERT(NULL == nghttp3_qpack_encoder_find_stream(&enc, 0)); + assert_size(0, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_null(nghttp3_qpack_encoder_find_stream(&enc, 0)); nghttp3_qpack_encoder_free(&enc); nghttp3_buf_free(&ebuf, mem); @@ -433,7 +450,7 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { rv = nghttp3_qpack_encoder_init(&enc, 4096, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_qpack_encoder_set_max_blocked_streams(&enc, 3); @@ -441,24 +458,24 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { rv = nghttp3_qpack_decoder_init(&dec, 4096, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva1, nghttp3_arraylen(nva1)); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == enc.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - enc.ctx.dtable_size); + assert_int(0, ==, rv); + assert_uint64(1, ==, enc.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, enc.ctx.dtable_size); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); - CU_ASSERT(1 == dec.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - dec.ctx.dtable_size); - CU_ASSERT(4096 == dec.ctx.max_dtable_capacity); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); + assert_uint64(1, ==, dec.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, dec.ctx.dtable_size); + assert_size(4096, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 0, mem); nghttp3_buf_reset(&pbuf); @@ -468,24 +485,24 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 4, nva2, nghttp3_arraylen(nva2)); - CU_ASSERT(0 == rv); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + - strlen("vary") + strlen("bar2") + - NGHTTP3_QPACK_ENTRY_OVERHEAD == - enc.ctx.dtable_size); - CU_ASSERT(2 == enc.ctx.next_absidx); - CU_ASSERT(2 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + + strlen("vary") + strlen("bar2") + + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, enc.ctx.dtable_size); + assert_uint64(2, ==, enc.ctx.next_absidx); + assert_size(2, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); - CU_ASSERT(2 == dec.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + - strlen("vary") + strlen("bar2") + - NGHTTP3_QPACK_ENTRY_OVERHEAD == - dec.ctx.dtable_size); - CU_ASSERT(4096 == dec.ctx.max_dtable_capacity); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); + assert_uint64(2, ==, dec.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + + strlen("vary") + strlen("bar2") + + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, dec.ctx.dtable_size); + assert_size(4096, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 4, mem); nghttp3_buf_reset(&pbuf); @@ -494,29 +511,29 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { nghttp3_qpack_encoder_set_max_dtable_capacity(&enc, 0); - CU_ASSERT(0 == enc.ctx.max_dtable_capacity); - CU_ASSERT(2 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_size(0, ==, enc.ctx.max_dtable_capacity); + assert_size(2, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); /* Cannot index more headers because we set max_dtable_capacity to 0. */ rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 8, nva2, nghttp3_arraylen(nva2)); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == enc.ctx.max_dtable_capacity); - CU_ASSERT(2 == enc.ctx.next_absidx); - CU_ASSERT(2 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(0, ==, enc.ctx.max_dtable_capacity); + assert_uint64(2, ==, enc.ctx.next_absidx); + assert_size(2, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); - CU_ASSERT(2 == dec.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + - strlen("vary") + strlen("bar2") + - NGHTTP3_QPACK_ENTRY_OVERHEAD == - dec.ctx.dtable_size); - CU_ASSERT(4096 == dec.ctx.max_dtable_capacity); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); + assert_uint64(2, ==, dec.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + + strlen("vary") + strlen("bar2") + + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, dec.ctx.dtable_size); + assert_size(4096, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 8, mem); nghttp3_buf_reset(&pbuf); @@ -529,24 +546,24 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 12, nva2, nghttp3_arraylen(nva2)); - CU_ASSERT(0 == rv); - CU_ASSERT(strlen("vary") + strlen("bar2") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - enc.ctx.dtable_size); - CU_ASSERT(0 == enc.ctx.max_dtable_capacity); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(strlen("vary") + strlen("bar2") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, enc.ctx.dtable_size); + assert_size(0, ==, enc.ctx.max_dtable_capacity); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); /* decoder still has 2 entries because encoder does not emit Set Dynamic Table Capacity. */ - CU_ASSERT(2 == dec.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + - strlen("vary") + strlen("bar2") + - NGHTTP3_QPACK_ENTRY_OVERHEAD == - dec.ctx.dtable_size); - CU_ASSERT(4096 == dec.ctx.max_dtable_capacity); + assert_uint64(2, ==, dec.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD + + strlen("vary") + strlen("bar2") + + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, dec.ctx.dtable_size); + assert_size(4096, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 12, mem); nghttp3_buf_reset(&pbuf); @@ -559,20 +576,20 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 16, nva2, nghttp3_arraylen(nva2)); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == enc.ctx.dtable_size); - CU_ASSERT(0 == enc.ctx.max_dtable_capacity); - CU_ASSERT(0 == enc.last_max_dtable_update); - CU_ASSERT(SIZE_MAX == enc.min_dtable_update); - CU_ASSERT(0 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(0, ==, enc.ctx.dtable_size); + assert_size(0, ==, enc.ctx.max_dtable_capacity); + assert_size(0, ==, enc.last_max_dtable_update); + assert_size(SIZE_MAX, ==, enc.min_dtable_update); + assert_size(0, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); - CU_ASSERT(2 == dec.ctx.next_absidx); - CU_ASSERT(0 == dec.ctx.dtable_size); - CU_ASSERT(0 == dec.ctx.max_dtable_capacity); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); + assert_uint64(2, ==, dec.ctx.next_absidx); + assert_size(0, ==, dec.ctx.dtable_size); + assert_size(0, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 16, mem); nghttp3_buf_reset(&pbuf); @@ -591,19 +608,19 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 0, nva1, nghttp3_arraylen(nva1)); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == enc.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - enc.ctx.dtable_size); + assert_int(0, ==, rv); + assert_uint64(1, ==, enc.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, enc.ctx.dtable_size); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); - CU_ASSERT(1 == dec.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - dec.ctx.dtable_size); - CU_ASSERT(4096 == dec.ctx.max_dtable_capacity); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); + assert_uint64(1, ==, dec.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, dec.ctx.dtable_size); + assert_size(4096, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 0, mem); nghttp3_buf_reset(&pbuf); @@ -613,30 +630,30 @@ void test_nghttp3_qpack_encoder_set_dtable_cap(void) { nghttp3_qpack_encoder_set_max_dtable_capacity(&enc, 0); nghttp3_qpack_encoder_set_max_dtable_capacity(&enc, 1024); - CU_ASSERT(0 == enc.min_dtable_update); - CU_ASSERT(1024 == enc.last_max_dtable_update); + assert_size(0, ==, enc.min_dtable_update); + assert_size(1024, ==, enc.last_max_dtable_update); nghttp3_qpack_encoder_ack_header(&enc, 0); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf, &rbuf, &ebuf, 4, nva1, nghttp3_arraylen(nva1)); - CU_ASSERT(0 == rv); - CU_ASSERT(2 == enc.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - enc.ctx.dtable_size); - CU_ASSERT(SIZE_MAX == enc.min_dtable_update); - CU_ASSERT(1024 == enc.last_max_dtable_update); - CU_ASSERT(1024 == enc.ctx.max_dtable_capacity); + assert_int(0, ==, rv); + assert_uint64(2, ==, enc.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, enc.ctx.dtable_size); + assert_size(SIZE_MAX, ==, enc.min_dtable_update); + assert_size(1024, ==, enc.last_max_dtable_update); + assert_size(1024, ==, enc.ctx.max_dtable_capacity); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT(nread == (nghttp3_ssize)nghttp3_buf_len(&ebuf)); - CU_ASSERT(2 == dec.ctx.next_absidx); - CU_ASSERT(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD == - dec.ctx.dtable_size); - CU_ASSERT(1024 == dec.ctx.max_dtable_capacity); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); + assert_uint64(2, ==, dec.ctx.next_absidx); + assert_size(strlen("date") + strlen("bar1") + NGHTTP3_QPACK_ENTRY_OVERHEAD, + ==, dec.ctx.dtable_size); + assert_size(1024, ==, dec.ctx.max_dtable_capacity); decode_header_block(&dec, &pbuf, &rbuf, 4, mem); nghttp3_buf_reset(&pbuf); @@ -683,7 +700,7 @@ void test_nghttp3_qpack_decoder_feedback(void) { rv = nghttp3_qpack_encoder_init(&enc, 4096, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_qpack_encoder_set_max_blocked_streams(&enc, 2); @@ -691,43 +708,43 @@ void test_nghttp3_qpack_decoder_feedback(void) { rv = nghttp3_qpack_decoder_init(&dec, 4096, 2, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf1, &rbuf1, &ebuf, 0, nva1, nghttp3_arraylen(nva1)); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); rv = nghttp3_qpack_encoder_encode(&enc, &pbuf2, &rbuf2, &ebuf, 4, nva2, nghttp3_arraylen(nva2)); - CU_ASSERT(0 == rv); - CU_ASSERT(2 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(2, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(&ebuf) == nread); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); /* Process stream 4 first */ decode_header_block(&dec, &pbuf2, &rbuf2, 4, mem); - CU_ASSERT(2 == dec.written_icnt); + assert_uint64(2, ==, dec.written_icnt); nghttp3_qpack_decoder_write_decoder(&dec, &dbuf); nread = nghttp3_qpack_encoder_read_decoder(&enc, dbuf.pos, nghttp3_buf_len(&dbuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(&dbuf) == nread); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&dbuf), ==, nread); /* This will unblock all streams because higher insert count is acknowledged. */ - CU_ASSERT(0 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); - CU_ASSERT(1 == nghttp3_map_size(&enc.streams)); - CU_ASSERT(1 == nghttp3_pq_size(&enc.min_cnts)); - CU_ASSERT(0 == nghttp3_ksl_len(&enc.blocked_streams)); - CU_ASSERT(2 == enc.krcnt); + assert_size(0, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_size(1, ==, nghttp3_map_size(&enc.streams)); + assert_size(1, ==, nghttp3_pq_size(&enc.min_cnts)); + assert_size(0, ==, nghttp3_ksl_len(&enc.blocked_streams)); + assert_uint64(2, ==, enc.krcnt); /* Process stream 0 */ decode_header_block(&dec, &pbuf1, &rbuf1, 0, mem); @@ -737,10 +754,10 @@ void test_nghttp3_qpack_decoder_feedback(void) { nread = nghttp3_qpack_encoder_read_decoder(&enc, dbuf.pos, nghttp3_buf_len(&dbuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(&dbuf) == nread); - CU_ASSERT(0 == nghttp3_map_size(&enc.streams)); - CU_ASSERT(0 == nghttp3_pq_size(&enc.min_cnts)); - CU_ASSERT(2 == enc.krcnt); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&dbuf), ==, nread); + assert_size(0, ==, nghttp3_map_size(&enc.streams)); + assert_size(0, ==, nghttp3_pq_size(&enc.min_cnts)); + assert_uint64(2, ==, enc.krcnt); /* Encode another header, and then read encoder stream only. Write decoder stream. */ @@ -748,46 +765,46 @@ void test_nghttp3_qpack_decoder_feedback(void) { rv = nghttp3_qpack_encoder_encode(&enc, &pbuf3, &rbuf3, &ebuf, 8, nva3, nghttp3_arraylen(nva3)); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); nread = nghttp3_qpack_decoder_read_encoder(&dec, ebuf.pos, nghttp3_buf_len(&ebuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(&ebuf) == nread); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&ebuf), ==, nread); nghttp3_buf_reset(&dbuf); nghttp3_qpack_decoder_write_decoder(&dec, &dbuf); - CU_ASSERT(nghttp3_buf_len(&dbuf) > 0); - CU_ASSERT(3 == dec.written_icnt); + assert_true(nghttp3_buf_len(&dbuf) > 0); + assert_uint64(3, ==, dec.written_icnt); nread = nghttp3_qpack_encoder_read_decoder(&enc, dbuf.pos, nghttp3_buf_len(&dbuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(&dbuf) == nread); - CU_ASSERT(0 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); - CU_ASSERT(1 == nghttp3_map_size(&enc.streams)); - CU_ASSERT(3 == enc.krcnt); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&dbuf), ==, nread); + assert_size(0, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_size(1, ==, nghttp3_map_size(&enc.streams)); + assert_uint64(3, ==, enc.krcnt); /* Cancel stream 8 */ rv = nghttp3_qpack_decoder_cancel_stream(&dec, 8); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp3_buf_reset(&dbuf); nghttp3_qpack_decoder_write_decoder(&dec, &dbuf); - CU_ASSERT(nghttp3_buf_len(&dbuf) > 0); + assert_true(nghttp3_buf_len(&dbuf) > 0); nread = nghttp3_qpack_encoder_read_decoder(&enc, dbuf.pos, nghttp3_buf_len(&dbuf)); - CU_ASSERT((nghttp3_ssize)nghttp3_buf_len(&dbuf) == nread); - CU_ASSERT(0 == nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); - CU_ASSERT(0 == nghttp3_ksl_len(&enc.blocked_streams)); - CU_ASSERT(0 == nghttp3_pq_size(&enc.min_cnts)); - CU_ASSERT(0 == nghttp3_map_size(&enc.streams)); + assert_ptrdiff((nghttp3_ssize)nghttp3_buf_len(&dbuf), ==, nread); + assert_size(0, ==, nghttp3_qpack_encoder_get_num_blocked_streams(&enc)); + assert_size(0, ==, nghttp3_ksl_len(&enc.blocked_streams)); + assert_size(0, ==, nghttp3_pq_size(&enc.min_cnts)); + assert_size(0, ==, nghttp3_map_size(&enc.streams)); nghttp3_qpack_decoder_free(&dec); nghttp3_qpack_encoder_free(&enc); @@ -838,11 +855,11 @@ void test_nghttp3_qpack_huffman(void) { nwrite = nghttp3_qpack_huffman_decode(&ctx, dbuf, ebuf, (size_t)(end - ebuf), 1); if (nwrite <= 0) { - CU_ASSERT(nwrite > 0); + assert_true(nwrite > 0); continue; } - CU_ASSERT((sizeof(raw) == (size_t)nwrite)); - CU_ASSERT(0 == memcmp(raw, dbuf, sizeof(raw))); + assert_size(sizeof(raw), ==, (size_t)nwrite); + assert_memory_equal(sizeof(raw), raw, dbuf); } } @@ -855,13 +872,13 @@ void test_nghttp3_qpack_huffman_decode_failure_state(void) { nghttp3_qpack_huffman_decode_context_init(&ctx); nwrite = nghttp3_qpack_huffman_decode(&ctx, buf, data, sizeof(data) - 1, 0); - CU_ASSERT(0 == nwrite); - CU_ASSERT(!nghttp3_qpack_huffman_decode_failure_state(&ctx)); + assert_ptrdiff(0, ==, nwrite); + assert_false(nghttp3_qpack_huffman_decode_failure_state(&ctx)); nwrite = nghttp3_qpack_huffman_decode(&ctx, buf, data, 1, 0); - CU_ASSERT(0 == nwrite); - CU_ASSERT(nghttp3_qpack_huffman_decode_failure_state(&ctx)); + assert_ptrdiff(0, ==, nwrite); + assert_true(nghttp3_qpack_huffman_decode_failure_state(&ctx)); } void test_nghttp3_qpack_decoder_reconstruct_ricnt(void) { @@ -872,14 +889,14 @@ void test_nghttp3_qpack_decoder_reconstruct_ricnt(void) { rv = nghttp3_qpack_decoder_init(&dec, 100, 1, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); dec.ctx.next_absidx = 10; rv = nghttp3_qpack_decoder_reconstruct_ricnt(&dec, &ricnt, 3); - CU_ASSERT(0 == rv); - CU_ASSERT(8 == ricnt); + assert_int(0, ==, rv); + assert_uint64(8, ==, ricnt); nghttp3_qpack_decoder_free(&dec); } diff --git a/tests/nghttp3_qpack_test.h b/tests/nghttp3_qpack_test.h index e15cee5..a974197 100644 --- a/tests/nghttp3_qpack_test.h +++ b/tests/nghttp3_qpack_test.h @@ -29,14 +29,20 @@ # include #endif /* HAVE_CONFIG_H */ -void test_nghttp3_qpack_encoder_encode(void); -void test_nghttp3_qpack_encoder_encode_try_encode(void); -void test_nghttp3_qpack_encoder_still_blocked(void); -void test_nghttp3_qpack_encoder_set_dtable_cap(void); -void test_nghttp3_qpack_decoder_feedback(void); -void test_nghttp3_qpack_decoder_stream_overflow(void); -void test_nghttp3_qpack_huffman(void); -void test_nghttp3_qpack_huffman_decode_failure_state(void); -void test_nghttp3_qpack_decoder_reconstruct_ricnt(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit/munit.h" + +extern const MunitSuite qpack_suite; + +munit_void_test_decl(test_nghttp3_qpack_encoder_encode); +munit_void_test_decl(test_nghttp3_qpack_encoder_encode_try_encode); +munit_void_test_decl(test_nghttp3_qpack_encoder_still_blocked); +munit_void_test_decl(test_nghttp3_qpack_encoder_set_dtable_cap); +munit_void_test_decl(test_nghttp3_qpack_decoder_feedback); +munit_void_test_decl(test_nghttp3_qpack_decoder_stream_overflow); +munit_void_test_decl(test_nghttp3_qpack_huffman); +munit_void_test_decl(test_nghttp3_qpack_huffman_decode_failure_state); +munit_void_test_decl(test_nghttp3_qpack_decoder_reconstruct_ricnt); #endif /* NGHTTP3_QPACK_TEST_H */