diff --git a/tests/failmalloc.c b/tests/failmalloc.c index 6cbe2a3d..f243db7c 100644 --- a/tests/failmalloc.c +++ b/tests/failmalloc.c @@ -59,7 +59,8 @@ int main(int argc, char* argv[]) test_nghttp2_session_send) || !CU_add_test(pSuite, "failmalloc_session_recv", test_nghttp2_session_recv) || - !CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame)) { + !CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame) || + !CU_add_test(pSuite, "failmalloc_hd", test_nghttp2_hd)) { CU_cleanup_registry(); return CU_get_error(); } diff --git a/tests/failmalloc_test.c b/tests/failmalloc_test.c index 53268732..cb12cfd0 100644 --- a/tests/failmalloc_test.c +++ b/tests/failmalloc_test.c @@ -445,3 +445,89 @@ void test_nghttp2_frame(void) TEST_FAILMALLOC_RUN(run_nghttp2_frame_pack_headers); TEST_FAILMALLOC_RUN(run_nghttp2_frame_pack_settings); } + +static int deflate_inflate(nghttp2_hd_deflater *deflater, + nghttp2_hd_inflater *inflater, + nghttp2_bufs *bufs, + nghttp2_nv *nva, size_t nvlen) +{ + int rv; + + rv = nghttp2_hd_deflate_hd(deflater, bufs, nva, nvlen); + + if(rv != 0) { + return rv; + } + + rv = inflate_hd(inflater, NULL, bufs, 0); + + if(rv < 0) { + return rv; + } + + nghttp2_bufs_reset(bufs); + + return 0; +} + +static void run_nghttp2_hd(void) +{ + nghttp2_hd_deflater deflater; + nghttp2_hd_inflater inflater; + nghttp2_bufs bufs; + int rv; + nghttp2_nv nva1[] = { + MAKE_NV(":scheme", "https"), + MAKE_NV(":authority", "example.org"), + MAKE_NV(":path", "/slashdot"), + MAKE_NV("accept-encoding", "gzip, deflate") + }; + nghttp2_nv nva2[] = { + MAKE_NV(":scheme", "https"), + MAKE_NV(":authority", "example.org"), + MAKE_NV(":path", "/style.css"), + MAKE_NV("cookie", "nghttp2=FTW") + }; + + rv = frame_pack_bufs_init(&bufs); + + if(rv != 0) { + return; + } + + rv = nghttp2_hd_deflate_init(&deflater); + + if(rv != 0) { + goto deflate_init_fail; + } + + rv = nghttp2_hd_inflate_init(&inflater); + + if(rv != 0) { + goto inflate_init_fail; + } + + rv = deflate_inflate(&deflater, &inflater, &bufs, nva1, ARRLEN(nva1)); + + if(rv != 0) { + goto deflate_hd_fail; + } + + rv = deflate_inflate(&deflater, &inflater, &bufs, nva2, ARRLEN(nva2)); + + if(rv != 0) { + goto deflate_hd_fail; + } + + deflate_hd_fail: + nghttp2_hd_inflate_free(&inflater); + inflate_init_fail: + nghttp2_hd_deflate_free(&deflater); + deflate_init_fail: + nghttp2_bufs_free(&bufs); +} + +void test_nghttp2_hd(void) +{ + TEST_FAILMALLOC_RUN(run_nghttp2_hd); +} diff --git a/tests/failmalloc_test.h b/tests/failmalloc_test.h index 6b377e7c..1969bc12 100644 --- a/tests/failmalloc_test.h +++ b/tests/failmalloc_test.h @@ -28,5 +28,6 @@ void test_nghttp2_session_send(void); void test_nghttp2_session_recv(void); void test_nghttp2_frame(void); +void test_nghttp2_hd(void); #endif /* FAILMALLOC_TEST_H */ diff --git a/tests/nghttp2_test_helper.c b/tests/nghttp2_test_helper.c index 4c69dc30..828bf4f5 100644 --- a/tests/nghttp2_test_helper.c +++ b/tests/nghttp2_test_helper.c @@ -207,7 +207,9 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, processed += rv; if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { - add_out(out, &nv); + if(out) { + add_out(out, &nv); + } } if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { break;