first commit
CI / Build (clang, clang++, ubuntu-22.04, linux, 3.10, master, x86,x86_64) (push) Canceled after 0s
CI / Build (clang, clang++, windows-2022, windows, 3.10, master, x86,x86_64) (push) Canceled after 0s
CI / Release (push) Canceled after 0s

This commit is contained in:
2026-09-13 22:18:11 +01:00
commit 08c03ac533
6701 changed files with 1577314 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
# XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem
if(HAVE_CUNIT)
string(REPLACE " " ";" c_flags "${WARNCFLAGS}")
add_compile_options(${c_flags})
include_directories(
"${CMAKE_SOURCE_DIR}/lib/includes"
"${CMAKE_SOURCE_DIR}/lib"
"${CMAKE_SOURCE_DIR}/src/includes"
"${CMAKE_BINARY_DIR}/lib/includes"
${CUNIT_INCLUDE_DIRS}
)
set(MAIN_SOURCES
main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c
nghttp2_test_helper.c
nghttp2_frame_test.c
nghttp2_stream_test.c
nghttp2_session_test.c
nghttp2_hd_test.c
nghttp2_npn_test.c
nghttp2_helper_test.c
nghttp2_buf_test.c
)
add_executable(main EXCLUDE_FROM_ALL
${MAIN_SOURCES}
)
target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS})
target_link_libraries(main
nghttp2_static
${CUNIT_LIBRARIES}
)
add_test(main main)
add_dependencies(check main)
if(ENABLE_FAILMALLOC)
set(FAILMALLOC_SOURCES
failmalloc.c failmalloc_test.c
malloc_wrapper.c
nghttp2_test_helper.c
)
add_executable(failmalloc EXCLUDE_FROM_ALL
${FAILMALLOC_SOURCES}
)
target_link_libraries(failmalloc
nghttp2_static
${CUNIT_LIBRARIES}
)
add_test(failmalloc failmalloc)
add_dependencies(check failmalloc)
endif()
if(ENABLE_APP)
# EXTRA_DIST = end_to_end.py
# TESTS += end_to_end.py
endif()
endif()
+92
View File
@@ -0,0 +1,92 @@
# nghttp2 - HTTP/2 C Library
# Copyright (c) 2012 Tatsuhiro Tsujikawa
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SUBDIRS = testdata
EXTRA_DIST = CMakeLists.txt
if HAVE_CUNIT
check_PROGRAMS = main
if ENABLE_FAILMALLOC
check_PROGRAMS += failmalloc
endif # ENABLE_FAILMALLOC
OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \
nghttp2_test_helper.c \
nghttp2_frame_test.c \
nghttp2_stream_test.c \
nghttp2_session_test.c \
nghttp2_hd_test.c \
nghttp2_npn_test.c \
nghttp2_helper_test.c \
nghttp2_buf_test.c
HFILES = nghttp2_pq_test.h nghttp2_map_test.h nghttp2_queue_test.h \
nghttp2_session_test.h \
nghttp2_frame_test.h nghttp2_stream_test.h nghttp2_hd_test.h \
nghttp2_npn_test.h nghttp2_helper_test.h \
nghttp2_test_helper.h \
nghttp2_buf_test.h
main_SOURCES = $(HFILES) $(OBJECTS)
if ENABLE_STATIC
main_LDADD = ${top_builddir}/lib/libnghttp2.la
else
# With static lib disabled and symbol hiding enabled, we have to link object
# files directly because the tests use symbols not included in public API.
main_LDADD = ${top_builddir}/lib/.libs/*.o
endif
main_LDADD += @CUNIT_LIBS@ @TESTLDADD@
main_LDFLAGS = -static
if ENABLE_FAILMALLOC
failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \
malloc_wrapper.c malloc_wrapper.h \
nghttp2_test_helper.c nghttp2_test_helper.h
failmalloc_LDADD = $(main_LDADD)
failmalloc_LDFLAGS = $(main_LDFLAGS)
endif # ENABLE_FAILMALLOC
AM_CFLAGS = $(WARNCFLAGS) \
-I${top_srcdir}/lib \
-I${top_srcdir}/lib/includes \
-I${top_builddir}/lib/includes \
@CUNIT_CFLAGS@ @DEFS@
TESTS = main
if ENABLE_FAILMALLOC
TESTS += failmalloc
endif # ENABLE_FAILMALLOC
if ENABLE_APP
# EXTRA_DIST = end_to_end.py
# TESTS += end_to_end.py
endif # ENABLE_APP
endif # HAVE_CUNIT
File diff suppressed because it is too large Load Diff
+79
View File
@@ -0,0 +1,79 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>
/* include test cases' include files here */
#include "failmalloc_test.h"
static int init_suite1(void) { return 0; }
static int clean_suite1(void) { return 0; }
int main() {
CU_pSuite pSuite = NULL;
unsigned int num_tests_failed;
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return (int)CU_get_error();
/* add a suite to the registry */
pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1);
if (NULL == pSuite) {
CU_cleanup_registry();
return (int)CU_get_error();
}
/* add the tests to the suite */
if (!CU_add_test(pSuite, "failmalloc_session_send",
test_nghttp2_session_send) ||
!CU_add_test(pSuite, "failmalloc_session_send_server",
test_nghttp2_session_send_server) ||
!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_hd", test_nghttp2_hd)) {
CU_cleanup_registry();
return (int)CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
num_tests_failed = CU_get_number_of_tests_failed();
CU_cleanup_registry();
if (CU_get_error() == CUE_SUCCESS) {
return (int)num_tests_failed;
} else {
printf("CUnit Error: %s\n", CU_get_error_msg());
return (int)CU_get_error();
}
}
+576
View File
@@ -0,0 +1,576 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012, 2014 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "failmalloc_test.h"
#include <CUnit/CUnit.h>
#include <stdio.h>
#include <assert.h>
#include "nghttp2_session.h"
#include "nghttp2_stream.h"
#include "nghttp2_frame.h"
#include "nghttp2_helper.h"
#include "malloc_wrapper.h"
#include "nghttp2_test_helper.h"
typedef struct {
uint8_t data[8192];
uint8_t *datamark, *datalimit;
} data_feed;
typedef struct {
data_feed *df;
size_t data_source_length;
} my_user_data;
static void data_feed_init(data_feed *df, nghttp2_bufs *bufs) {
nghttp2_buf *buf;
size_t data_length;
buf = &bufs->head->buf;
data_length = nghttp2_buf_len(buf);
assert(data_length <= sizeof(df->data));
memcpy(df->data, buf->pos, data_length);
df->datamark = df->data;
df->datalimit = df->data + data_length;
}
static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data,
size_t len, int flags, void *user_data) {
(void)session;
(void)data;
(void)flags;
(void)user_data;
return (ssize_t)len;
}
static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data,
size_t len, int flags, void *user_data) {
data_feed *df = ((my_user_data *)user_data)->df;
size_t avail = (size_t)(df->datalimit - df->datamark);
size_t wlen = nghttp2_min(avail, len);
(void)session;
(void)flags;
memcpy(data, df->datamark, wlen);
df->datamark += wlen;
return (ssize_t)wlen;
}
static ssize_t fixed_length_data_source_read_callback(
nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
my_user_data *ud = (my_user_data *)user_data;
size_t wlen;
(void)session;
(void)stream_id;
(void)buf;
(void)source;
if (len < ud->data_source_length) {
wlen = len;
} else {
wlen = ud->data_source_length;
}
ud->data_source_length -= wlen;
if (ud->data_source_length == 0) {
*data_flags = NGHTTP2_DATA_FLAG_EOF;
}
return (ssize_t)wlen;
}
#define TEST_FAILMALLOC_RUN(FUN) \
do { \
int nmalloc, i; \
\
nghttp2_failmalloc = 0; \
nghttp2_nmalloc = 0; \
FUN(); \
nmalloc = nghttp2_nmalloc; \
\
nghttp2_failmalloc = 1; \
for (i = 0; i < nmalloc; ++i) { \
nghttp2_nmalloc = 0; \
nghttp2_failstart = i; \
/* printf("i=%zu\n", i); */ \
FUN(); \
/* printf("nmalloc=%d\n", nghttp2_nmalloc); */ \
} \
nghttp2_failmalloc = 0; \
} while (0)
static void run_nghttp2_session_send(void) {
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"),
MAKE_NV(":scheme", "https")};
nghttp2_data_provider data_prd;
nghttp2_settings_entry iv[2];
my_user_data ud;
int rv;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = null_send_callback;
data_prd.read_callback = fixed_length_data_source_read_callback;
ud.data_source_length = 64 * 1024;
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[0].value = 4096;
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
iv[1].value = 100;
rv = nghttp2_session_client_new3(&session, &callbacks, &ud, NULL,
nghttp2_mem_fm());
if (rv != 0) {
goto client_new_fail;
}
rv = nghttp2_submit_request(session, NULL, nv, ARRLEN(nv), &data_prd, NULL);
if (rv < 0) {
goto fail;
}
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, nv,
ARRLEN(nv), NULL);
if (rv < 0) {
goto fail;
}
rv = nghttp2_session_send(session);
if (rv != 0) {
goto fail;
}
/* The HEADERS submitted by the previous nghttp2_submit_headers will
have stream ID 3. Send HEADERS to that stream. */
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, NULL, nv,
ARRLEN(nv), NULL);
if (rv != 0) {
goto fail;
}
rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd);
if (rv != 0) {
goto fail;
}
rv = nghttp2_session_send(session);
if (rv != 0) {
goto fail;
}
rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 3, NGHTTP2_CANCEL);
if (rv != 0) {
goto fail;
}
rv = nghttp2_session_send(session);
if (rv != 0) {
goto fail;
}
rv = nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL);
if (rv != 0) {
goto fail;
}
rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2);
if (rv != 0) {
goto fail;
}
rv = nghttp2_session_send(session);
if (rv != 0) {
goto fail;
}
rv = nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 100, NGHTTP2_NO_ERROR,
NULL, 0);
if (rv != 0) {
goto fail;
}
rv = nghttp2_session_send(session);
if (rv != 0) {
goto fail;
}
fail:
nghttp2_session_del(session);
client_new_fail:;
}
void test_nghttp2_session_send(void) {
TEST_FAILMALLOC_RUN(run_nghttp2_session_send);
}
static void run_nghttp2_session_send_server(void) {
nghttp2_session *session;
nghttp2_session_callbacks *callbacks;
int rv;
const uint8_t *txdata;
ssize_t txdatalen;
const uint8_t origin[] = "nghttp2.org";
const uint8_t altsvc_field_value[] = "h2=\":443\"";
static const uint8_t nghttp2[] = "https://nghttp2.org";
static const nghttp2_origin_entry ov = {
(uint8_t *)nghttp2,
sizeof(nghttp2) - 1,
};
rv = nghttp2_session_callbacks_new(&callbacks);
if (rv != 0) {
return;
}
rv = nghttp2_session_server_new3(&session, callbacks, NULL, NULL,
nghttp2_mem_fm());
nghttp2_session_callbacks_del(callbacks);
if (rv != 0) {
return;
}
rv = nghttp2_submit_altsvc(session, NGHTTP2_FLAG_NONE, 0, origin,
sizeof(origin) - 1, altsvc_field_value,
sizeof(altsvc_field_value) - 1);
if (rv != 0) {
goto fail;
}
rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, &ov, 1);
if (rv != 0) {
goto fail;
}
txdatalen = nghttp2_session_mem_send(session, &txdata);
if (txdatalen < 0) {
goto fail;
}
fail:
nghttp2_session_del(session);
}
void test_nghttp2_session_send_server(void) {
TEST_FAILMALLOC_RUN(run_nghttp2_session_send_server);
}
static void run_nghttp2_session_recv(void) {
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
nghttp2_hd_deflater deflater;
nghttp2_frame frame;
nghttp2_bufs bufs;
nghttp2_nv nv[] = {
MAKE_NV(":method", "GET"),
MAKE_NV(":scheme", "https"),
MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/"),
};
nghttp2_settings_entry iv[2];
my_user_data ud;
data_feed df;
int rv;
nghttp2_nv *nva;
size_t nvlen;
rv = frame_pack_bufs_init(&bufs);
if (rv != 0) {
return;
}
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.recv_callback = data_feed_recv_callback;
ud.df = &df;
nghttp2_failmalloc_pause();
nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
nghttp2_session_server_new3(&session, &callbacks, &ud, NULL,
nghttp2_mem_fm());
/* Client preface */
nghttp2_bufs_add(&bufs, NGHTTP2_CLIENT_MAGIC, NGHTTP2_CLIENT_MAGIC_LEN);
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
nghttp2_failmalloc_pause();
/* SETTINGS */
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[0].value = 4096;
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
iv[1].value = 100;
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE,
nghttp2_frame_iv_copy(iv, 2, nghttp2_mem_fm()),
2);
nghttp2_frame_pack_settings(&bufs, &frame.settings);
nghttp2_frame_settings_free(&frame.settings, nghttp2_mem_fm());
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
nghttp2_failmalloc_pause();
/* HEADERS */
nvlen = ARRLEN(nv);
nghttp2_nv_array_copy(&nva, nv, nvlen, nghttp2_mem_fm());
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM, 1,
NGHTTP2_HCAT_REQUEST, NULL, nva, nvlen);
nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater);
nghttp2_frame_headers_free(&frame.headers, nghttp2_mem_fm());
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
/* PING */
nghttp2_failmalloc_pause();
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_NONE, NULL);
nghttp2_frame_pack_ping(&bufs, &frame.ping);
nghttp2_frame_ping_free(&frame.ping);
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
/* RST_STREAM */
nghttp2_failmalloc_pause();
nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR);
nghttp2_frame_pack_rst_stream(&bufs, &frame.rst_stream);
nghttp2_frame_rst_stream_free(&frame.rst_stream);
nghttp2_bufs_reset(&bufs);
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
fail:
nghttp2_bufs_free(&bufs);
nghttp2_session_del(session);
nghttp2_hd_deflate_free(&deflater);
}
void test_nghttp2_session_recv(void) {
TEST_FAILMALLOC_RUN(run_nghttp2_session_recv);
}
static void run_nghttp2_frame_pack_headers(void) {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_frame frame, oframe;
nghttp2_bufs bufs;
nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"),
MAKE_NV(":scheme", "https")};
int rv;
nghttp2_nv *nva;
size_t nvlen;
rv = frame_pack_bufs_init(&bufs);
if (rv != 0) {
return;
}
rv = nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
if (rv != 0) {
goto deflate_init_fail;
}
rv = nghttp2_hd_inflate_init(&inflater, nghttp2_mem_fm());
if (rv != 0) {
goto inflate_init_fail;
}
nvlen = ARRLEN(nv);
rv = nghttp2_nv_array_copy(&nva, nv, nvlen, nghttp2_mem_fm());
if (rv < 0) {
goto nv_copy_fail;
}
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM, 1,
NGHTTP2_HCAT_REQUEST, NULL, nva, nvlen);
rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater);
if (rv != 0) {
goto fail;
}
rv = unpack_framebuf(&oframe, &bufs);
if (rv != 0) {
goto fail;
}
nghttp2_frame_headers_free(&oframe.headers, nghttp2_mem_fm());
fail:
nghttp2_frame_headers_free(&frame.headers, nghttp2_mem_fm());
nv_copy_fail:
nghttp2_hd_inflate_free(&inflater);
inflate_init_fail:
nghttp2_hd_deflate_free(&deflater);
deflate_init_fail:
nghttp2_bufs_free(&bufs);
}
static void run_nghttp2_frame_pack_settings(void) {
nghttp2_frame frame, oframe;
nghttp2_bufs bufs;
nghttp2_buf *buf;
nghttp2_settings_entry iv[2], *iv_copy;
int rv;
rv = frame_pack_bufs_init(&bufs);
if (rv != 0) {
return;
}
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[0].value = 4096;
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
iv[1].value = 100;
iv_copy = nghttp2_frame_iv_copy(iv, 2, nghttp2_mem_fm());
if (iv_copy == NULL) {
goto iv_copy_fail;
}
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, iv_copy, 2);
rv = nghttp2_frame_pack_settings(&bufs, &frame.settings);
if (rv != 0) {
goto fail;
}
buf = &bufs.head->buf;
rv = nghttp2_frame_unpack_settings_payload2(
&oframe.settings.iv, &oframe.settings.niv, buf->pos + NGHTTP2_FRAME_HDLEN,
nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN, nghttp2_mem_fm());
if (rv != 0) {
goto fail;
}
nghttp2_frame_settings_free(&oframe.settings, nghttp2_mem_fm());
fail:
nghttp2_frame_settings_free(&frame.settings, nghttp2_mem_fm());
iv_copy_fail:
nghttp2_bufs_free(&bufs);
}
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, nghttp2_mem *mem) {
int rv;
rv = nghttp2_hd_deflate_hd_bufs(deflater, bufs, nva, nvlen);
if (rv != 0) {
return rv;
}
rv = (int)inflate_hd(inflater, NULL, bufs, 0, mem);
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"), MAKE_NV("foo", "bar")};
nghttp2_nv nva2[] = {
MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/style.css"), MAKE_NV("cookie", "nghttp2=FTW"),
MAKE_NV("foo", "bar2")};
rv = frame_pack_bufs_init(&bufs);
if (rv != 0) {
return;
}
rv = nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
if (rv != 0) {
goto deflate_init_fail;
}
rv = nghttp2_hd_inflate_init(&inflater, nghttp2_mem_fm());
if (rv != 0) {
goto inflate_init_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva1, ARRLEN(nva1),
nghttp2_mem_fm());
if (rv != 0) {
goto deflate_hd_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva2, ARRLEN(nva2),
nghttp2_mem_fm());
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); }
+38
View File
@@ -0,0 +1,38 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef FAILMALLOC_TEST_H
#define FAILMALLOC_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_session_send(void);
void test_nghttp2_session_send_server(void);
void test_nghttp2_session_recv(void);
void test_nghttp2_frame(void);
void test_nghttp2_hd(void);
#endif /* FAILMALLOC_TEST_H */
+444
View File
@@ -0,0 +1,444 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>
/* include test cases' include files here */
#include "nghttp2_pq_test.h"
#include "nghttp2_map_test.h"
#include "nghttp2_queue_test.h"
#include "nghttp2_session_test.h"
#include "nghttp2_frame_test.h"
#include "nghttp2_stream_test.h"
#include "nghttp2_hd_test.h"
#include "nghttp2_npn_test.h"
#include "nghttp2_helper_test.h"
#include "nghttp2_buf_test.h"
extern int nghttp2_enable_strict_preface;
static int init_suite1(void) { return 0; }
static int clean_suite1(void) { return 0; }
int main() {
CU_pSuite pSuite = NULL;
unsigned int num_tests_failed;
nghttp2_enable_strict_preface = 0;
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return (int)CU_get_error();
/* add a suite to the registry */
pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1);
if (NULL == pSuite) {
CU_cleanup_registry();
return (int)CU_get_error();
}
/* add the tests to the suite */
if (!CU_add_test(pSuite, "pq", test_nghttp2_pq) ||
!CU_add_test(pSuite, "pq_update", test_nghttp2_pq_update) ||
!CU_add_test(pSuite, "pq_remove", test_nghttp2_pq_remove) ||
!CU_add_test(pSuite, "map", test_nghttp2_map) ||
!CU_add_test(pSuite, "map_functional", test_nghttp2_map_functional) ||
!CU_add_test(pSuite, "map_each_free", test_nghttp2_map_each_free) ||
!CU_add_test(pSuite, "queue", test_nghttp2_queue) ||
!CU_add_test(pSuite, "npn", test_nghttp2_npn) ||
!CU_add_test(pSuite, "session_recv", test_nghttp2_session_recv) ||
!CU_add_test(pSuite, "session_recv_invalid_stream_id",
test_nghttp2_session_recv_invalid_stream_id) ||
!CU_add_test(pSuite, "session_recv_invalid_frame",
test_nghttp2_session_recv_invalid_frame) ||
!CU_add_test(pSuite, "session_recv_eof", test_nghttp2_session_recv_eof) ||
!CU_add_test(pSuite, "session_recv_data",
test_nghttp2_session_recv_data) ||
!CU_add_test(pSuite, "session_recv_data_no_auto_flow_control",
test_nghttp2_session_recv_data_no_auto_flow_control) ||
!CU_add_test(pSuite, "session_recv_continuation",
test_nghttp2_session_recv_continuation) ||
!CU_add_test(pSuite, "session_recv_headers_with_priority",
test_nghttp2_session_recv_headers_with_priority) ||
!CU_add_test(pSuite, "session_recv_headers_with_padding",
test_nghttp2_session_recv_headers_with_padding) ||
!CU_add_test(pSuite, "session_recv_headers_early_response",
test_nghttp2_session_recv_headers_early_response) ||
!CU_add_test(pSuite, "session_recv_headers_for_closed_stream",
test_nghttp2_session_recv_headers_for_closed_stream) ||
!CU_add_test(pSuite, "session_server_recv_push_response",
test_nghttp2_session_server_recv_push_response) ||
!CU_add_test(pSuite, "session_recv_premature_headers",
test_nghttp2_session_recv_premature_headers) ||
!CU_add_test(pSuite, "session_recv_unknown_frame",
test_nghttp2_session_recv_unknown_frame) ||
!CU_add_test(pSuite, "session_recv_unexpected_continuation",
test_nghttp2_session_recv_unexpected_continuation) ||
!CU_add_test(pSuite, "session_recv_settings_header_table_size",
test_nghttp2_session_recv_settings_header_table_size) ||
!CU_add_test(pSuite, "session_recv_too_large_frame_length",
test_nghttp2_session_recv_too_large_frame_length) ||
!CU_add_test(pSuite, "session_recv_extension",
test_nghttp2_session_recv_extension) ||
!CU_add_test(pSuite, "session_recv_altsvc",
test_nghttp2_session_recv_altsvc) ||
!CU_add_test(pSuite, "session_recv_origin",
test_nghttp2_session_recv_origin) ||
!CU_add_test(pSuite, "session_continue", test_nghttp2_session_continue) ||
!CU_add_test(pSuite, "session_add_frame",
test_nghttp2_session_add_frame) ||
!CU_add_test(pSuite, "session_on_request_headers_received",
test_nghttp2_session_on_request_headers_received) ||
!CU_add_test(pSuite, "session_on_response_headers_received",
test_nghttp2_session_on_response_headers_received) ||
!CU_add_test(pSuite, "session_on_headers_received",
test_nghttp2_session_on_headers_received) ||
!CU_add_test(pSuite, "session_on_push_response_headers_received",
test_nghttp2_session_on_push_response_headers_received) ||
!CU_add_test(pSuite, "session_on_priority_received",
test_nghttp2_session_on_priority_received) ||
!CU_add_test(pSuite, "session_on_rst_stream_received",
test_nghttp2_session_on_rst_stream_received) ||
!CU_add_test(pSuite, "session_on_settings_received",
test_nghttp2_session_on_settings_received) ||
!CU_add_test(pSuite, "session_on_push_promise_received",
test_nghttp2_session_on_push_promise_received) ||
!CU_add_test(pSuite, "session_on_ping_received",
test_nghttp2_session_on_ping_received) ||
!CU_add_test(pSuite, "session_on_goaway_received",
test_nghttp2_session_on_goaway_received) ||
!CU_add_test(pSuite, "session_on_window_update_received",
test_nghttp2_session_on_window_update_received) ||
!CU_add_test(pSuite, "session_on_data_received",
test_nghttp2_session_on_data_received) ||
!CU_add_test(pSuite, "session_on_data_received_fail_fast",
test_nghttp2_session_on_data_received_fail_fast) ||
!CU_add_test(pSuite, "session_on_altsvc_received",
test_nghttp2_session_on_altsvc_received) ||
!CU_add_test(pSuite, "session_send_headers_start_stream",
test_nghttp2_session_send_headers_start_stream) ||
!CU_add_test(pSuite, "session_send_headers_reply",
test_nghttp2_session_send_headers_reply) ||
!CU_add_test(pSuite, "session_send_headers_frame_size_error",
test_nghttp2_session_send_headers_frame_size_error) ||
!CU_add_test(pSuite, "session_send_headers_push_reply",
test_nghttp2_session_send_headers_push_reply) ||
!CU_add_test(pSuite, "session_send_rst_stream",
test_nghttp2_session_send_rst_stream) ||
!CU_add_test(pSuite, "session_send_push_promise",
test_nghttp2_session_send_push_promise) ||
!CU_add_test(pSuite, "session_is_my_stream_id",
test_nghttp2_session_is_my_stream_id) ||
!CU_add_test(pSuite, "session_upgrade2", test_nghttp2_session_upgrade2) ||
!CU_add_test(pSuite, "session_reprioritize_stream",
test_nghttp2_session_reprioritize_stream) ||
!CU_add_test(
pSuite, "session_reprioritize_stream_with_idle_stream_dep",
test_nghttp2_session_reprioritize_stream_with_idle_stream_dep) ||
!CU_add_test(pSuite, "submit_data", test_nghttp2_submit_data) ||
!CU_add_test(pSuite, "submit_data_read_length_too_large",
test_nghttp2_submit_data_read_length_too_large) ||
!CU_add_test(pSuite, "submit_data_read_length_smallest",
test_nghttp2_submit_data_read_length_smallest) ||
!CU_add_test(pSuite, "submit_data_twice",
test_nghttp2_submit_data_twice) ||
!CU_add_test(pSuite, "submit_request_with_data",
test_nghttp2_submit_request_with_data) ||
!CU_add_test(pSuite, "submit_request_without_data",
test_nghttp2_submit_request_without_data) ||
!CU_add_test(pSuite, "submit_response_with_data",
test_nghttp2_submit_response_with_data) ||
!CU_add_test(pSuite, "submit_response_without_data",
test_nghttp2_submit_response_without_data) ||
!CU_add_test(pSuite, "Submit_response_push_response",
test_nghttp2_submit_response_push_response) ||
!CU_add_test(pSuite, "submit_trailer", test_nghttp2_submit_trailer) ||
!CU_add_test(pSuite, "submit_headers_start_stream",
test_nghttp2_submit_headers_start_stream) ||
!CU_add_test(pSuite, "submit_headers_reply",
test_nghttp2_submit_headers_reply) ||
!CU_add_test(pSuite, "submit_headers_push_reply",
test_nghttp2_submit_headers_push_reply) ||
!CU_add_test(pSuite, "submit_headers", test_nghttp2_submit_headers) ||
!CU_add_test(pSuite, "submit_headers_continuation",
test_nghttp2_submit_headers_continuation) ||
!CU_add_test(pSuite, "submit_headers_continuation_extra_large",
test_nghttp2_submit_headers_continuation_extra_large) ||
!CU_add_test(pSuite, "submit_priority", test_nghttp2_submit_priority) ||
!CU_add_test(pSuite, "session_submit_settings",
test_nghttp2_submit_settings) ||
!CU_add_test(pSuite, "session_submit_settings_update_local_window_size",
test_nghttp2_submit_settings_update_local_window_size) ||
!CU_add_test(pSuite, "session_submit_settings_multiple_times",
test_nghttp2_submit_settings_multiple_times) ||
!CU_add_test(pSuite, "session_submit_push_promise",
test_nghttp2_submit_push_promise) ||
!CU_add_test(pSuite, "submit_window_update",
test_nghttp2_submit_window_update) ||
!CU_add_test(pSuite, "submit_window_update_local_window_size",
test_nghttp2_submit_window_update_local_window_size) ||
!CU_add_test(pSuite, "submit_shutdown_notice",
test_nghttp2_submit_shutdown_notice) ||
!CU_add_test(pSuite, "submit_invalid_nv",
test_nghttp2_submit_invalid_nv) ||
!CU_add_test(pSuite, "submit_extension", test_nghttp2_submit_extension) ||
!CU_add_test(pSuite, "submit_altsvc", test_nghttp2_submit_altsvc) ||
!CU_add_test(pSuite, "submit_origin", test_nghttp2_submit_origin) ||
!CU_add_test(pSuite, "submit_rst_stream",
test_nghttp2_submit_rst_stream) ||
!CU_add_test(pSuite, "session_open_stream",
test_nghttp2_session_open_stream) ||
!CU_add_test(pSuite, "session_open_stream_with_idle_stream_dep",
test_nghttp2_session_open_stream_with_idle_stream_dep) ||
!CU_add_test(pSuite, "session_get_next_ob_item",
test_nghttp2_session_get_next_ob_item) ||
!CU_add_test(pSuite, "session_pop_next_ob_item",
test_nghttp2_session_pop_next_ob_item) ||
!CU_add_test(pSuite, "session_reply_fail",
test_nghttp2_session_reply_fail) ||
!CU_add_test(pSuite, "session_max_concurrent_streams",
test_nghttp2_session_max_concurrent_streams) ||
!CU_add_test(pSuite, "session_stop_data_with_rst_stream",
test_nghttp2_session_stop_data_with_rst_stream) ||
!CU_add_test(pSuite, "session_defer_data",
test_nghttp2_session_defer_data) ||
!CU_add_test(pSuite, "session_flow_control",
test_nghttp2_session_flow_control) ||
!CU_add_test(pSuite, "session_flow_control_data_recv",
test_nghttp2_session_flow_control_data_recv) ||
!CU_add_test(pSuite, "session_flow_control_data_with_padding_recv",
test_nghttp2_session_flow_control_data_with_padding_recv) ||
!CU_add_test(pSuite, "session_data_read_temporal_failure",
test_nghttp2_session_data_read_temporal_failure) ||
!CU_add_test(pSuite, "session_on_stream_close",
test_nghttp2_session_on_stream_close) ||
!CU_add_test(pSuite, "session_on_ctrl_not_send",
test_nghttp2_session_on_ctrl_not_send) ||
!CU_add_test(pSuite, "session_get_outbound_queue_size",
test_nghttp2_session_get_outbound_queue_size) ||
!CU_add_test(pSuite, "session_get_effective_local_window_size",
test_nghttp2_session_get_effective_local_window_size) ||
!CU_add_test(pSuite, "session_set_option",
test_nghttp2_session_set_option) ||
!CU_add_test(pSuite, "session_data_backoff_by_high_pri_frame",
test_nghttp2_session_data_backoff_by_high_pri_frame) ||
!CU_add_test(pSuite, "session_pack_data_with_padding",
test_nghttp2_session_pack_data_with_padding) ||
!CU_add_test(pSuite, "session_pack_headers_with_padding",
test_nghttp2_session_pack_headers_with_padding) ||
!CU_add_test(pSuite, "pack_settings_payload",
test_nghttp2_pack_settings_payload) ||
!CU_add_test(pSuite, "session_stream_dep_add",
test_nghttp2_session_stream_dep_add) ||
!CU_add_test(pSuite, "session_stream_dep_remove",
test_nghttp2_session_stream_dep_remove) ||
!CU_add_test(pSuite, "session_stream_dep_add_subtree",
test_nghttp2_session_stream_dep_add_subtree) ||
!CU_add_test(pSuite, "session_stream_dep_remove_subtree",
test_nghttp2_session_stream_dep_remove_subtree) ||
!CU_add_test(
pSuite, "session_stream_dep_all_your_stream_are_belong_to_us",
test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us) ||
!CU_add_test(pSuite, "session_stream_attach_item",
test_nghttp2_session_stream_attach_item) ||
!CU_add_test(pSuite, "session_stream_attach_item_subtree",
test_nghttp2_session_stream_attach_item_subtree) ||
!CU_add_test(pSuite, "session_stream_get_state",
test_nghttp2_session_stream_get_state) ||
!CU_add_test(pSuite, "session_stream_get_something",
test_nghttp2_session_stream_get_something) ||
!CU_add_test(pSuite, "session_find_stream",
test_nghttp2_session_find_stream) ||
!CU_add_test(pSuite, "session_keep_closed_stream",
test_nghttp2_session_keep_closed_stream) ||
!CU_add_test(pSuite, "session_keep_idle_stream",
test_nghttp2_session_keep_idle_stream) ||
!CU_add_test(pSuite, "session_detach_idle_stream",
test_nghttp2_session_detach_idle_stream) ||
!CU_add_test(pSuite, "session_large_dep_tree",
test_nghttp2_session_large_dep_tree) ||
!CU_add_test(pSuite, "session_graceful_shutdown",
test_nghttp2_session_graceful_shutdown) ||
!CU_add_test(pSuite, "session_on_header_temporal_failure",
test_nghttp2_session_on_header_temporal_failure) ||
!CU_add_test(pSuite, "session_recv_client_magic",
test_nghttp2_session_recv_client_magic) ||
!CU_add_test(pSuite, "session_delete_data_item",
test_nghttp2_session_delete_data_item) ||
!CU_add_test(pSuite, "session_open_idle_stream",
test_nghttp2_session_open_idle_stream) ||
!CU_add_test(pSuite, "session_cancel_reserved_remote",
test_nghttp2_session_cancel_reserved_remote) ||
!CU_add_test(pSuite, "session_reset_pending_headers",
test_nghttp2_session_reset_pending_headers) ||
!CU_add_test(pSuite, "session_send_data_callback",
test_nghttp2_session_send_data_callback) ||
!CU_add_test(pSuite, "session_on_begin_headers_temporal_failure",
test_nghttp2_session_on_begin_headers_temporal_failure) ||
!CU_add_test(pSuite, "session_defer_then_close",
test_nghttp2_session_defer_then_close) ||
!CU_add_test(pSuite, "session_detach_item_from_closed_stream",
test_nghttp2_session_detach_item_from_closed_stream) ||
!CU_add_test(pSuite, "session_flooding", test_nghttp2_session_flooding) ||
!CU_add_test(pSuite, "session_change_stream_priority",
test_nghttp2_session_change_stream_priority) ||
!CU_add_test(pSuite, "session_create_idle_stream",
test_nghttp2_session_create_idle_stream) ||
!CU_add_test(pSuite, "session_repeated_priority_change",
test_nghttp2_session_repeated_priority_change) ||
!CU_add_test(pSuite, "session_repeated_priority_submission",
test_nghttp2_session_repeated_priority_submission) ||
!CU_add_test(pSuite, "session_set_local_window_size",
test_nghttp2_session_set_local_window_size) ||
!CU_add_test(pSuite, "session_cancel_from_before_frame_send",
test_nghttp2_session_cancel_from_before_frame_send) ||
!CU_add_test(pSuite, "session_too_many_settings",
test_nghttp2_session_too_many_settings) ||
!CU_add_test(pSuite, "session_removed_closed_stream",
test_nghttp2_session_removed_closed_stream) ||
!CU_add_test(pSuite, "session_pause_data",
test_nghttp2_session_pause_data) ||
!CU_add_test(pSuite, "session_no_closed_streams",
test_nghttp2_session_no_closed_streams) ||
!CU_add_test(pSuite, "session_set_stream_user_data",
test_nghttp2_session_set_stream_user_data) ||
!CU_add_test(pSuite, "http_mandatory_headers",
test_nghttp2_http_mandatory_headers) ||
!CU_add_test(pSuite, "http_content_length",
test_nghttp2_http_content_length) ||
!CU_add_test(pSuite, "http_content_length_mismatch",
test_nghttp2_http_content_length_mismatch) ||
!CU_add_test(pSuite, "http_non_final_response",
test_nghttp2_http_non_final_response) ||
!CU_add_test(pSuite, "http_trailer_headers",
test_nghttp2_http_trailer_headers) ||
!CU_add_test(pSuite, "http_ignore_regular_header",
test_nghttp2_http_ignore_regular_header) ||
!CU_add_test(pSuite, "http_ignore_content_length",
test_nghttp2_http_ignore_content_length) ||
!CU_add_test(pSuite, "http_record_request_method",
test_nghttp2_http_record_request_method) ||
!CU_add_test(pSuite, "http_push_promise",
test_nghttp2_http_push_promise) ||
!CU_add_test(pSuite, "http_head_method_upgrade_workaround",
test_nghttp2_http_head_method_upgrade_workaround) ||
!CU_add_test(pSuite, "frame_pack_headers",
test_nghttp2_frame_pack_headers) ||
!CU_add_test(pSuite, "frame_pack_headers_frame_too_large",
test_nghttp2_frame_pack_headers_frame_too_large) ||
!CU_add_test(pSuite, "frame_pack_priority",
test_nghttp2_frame_pack_priority) ||
!CU_add_test(pSuite, "frame_pack_rst_stream",
test_nghttp2_frame_pack_rst_stream) ||
!CU_add_test(pSuite, "frame_pack_settings",
test_nghttp2_frame_pack_settings) ||
!CU_add_test(pSuite, "frame_pack_push_promise",
test_nghttp2_frame_pack_push_promise) ||
!CU_add_test(pSuite, "frame_pack_ping", test_nghttp2_frame_pack_ping) ||
!CU_add_test(pSuite, "frame_pack_goaway",
test_nghttp2_frame_pack_goaway) ||
!CU_add_test(pSuite, "frame_pack_window_update",
test_nghttp2_frame_pack_window_update) ||
!CU_add_test(pSuite, "frame_pack_altsvc",
test_nghttp2_frame_pack_altsvc) ||
!CU_add_test(pSuite, "frame_pack_origin",
test_nghttp2_frame_pack_origin) ||
!CU_add_test(pSuite, "nv_array_copy", test_nghttp2_nv_array_copy) ||
!CU_add_test(pSuite, "iv_check", test_nghttp2_iv_check) ||
!CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) ||
!CU_add_test(pSuite, "hd_deflate_same_indexed_repr",
test_nghttp2_hd_deflate_same_indexed_repr) ||
!CU_add_test(pSuite, "hd_inflate_indexed",
test_nghttp2_hd_inflate_indexed) ||
!CU_add_test(pSuite, "hd_inflate_indname_noinc",
test_nghttp2_hd_inflate_indname_noinc) ||
!CU_add_test(pSuite, "hd_inflate_indname_inc",
test_nghttp2_hd_inflate_indname_inc) ||
!CU_add_test(pSuite, "hd_inflate_indname_inc_eviction",
test_nghttp2_hd_inflate_indname_inc_eviction) ||
!CU_add_test(pSuite, "hd_inflate_newname_noinc",
test_nghttp2_hd_inflate_newname_noinc) ||
!CU_add_test(pSuite, "hd_inflate_newname_inc",
test_nghttp2_hd_inflate_newname_inc) ||
!CU_add_test(pSuite, "hd_inflate_clearall_inc",
test_nghttp2_hd_inflate_clearall_inc) ||
!CU_add_test(pSuite, "hd_inflate_zero_length_huffman",
test_nghttp2_hd_inflate_zero_length_huffman) ||
!CU_add_test(pSuite, "hd_inflate_expect_table_size_update",
test_nghttp2_hd_inflate_expect_table_size_update) ||
!CU_add_test(pSuite, "hd_inflate_unexpected_table_size_update",
test_nghttp2_hd_inflate_unexpected_table_size_update) ||
!CU_add_test(pSuite, "hd_ringbuf_reserve",
test_nghttp2_hd_ringbuf_reserve) ||
!CU_add_test(pSuite, "hd_change_table_size",
test_nghttp2_hd_change_table_size) ||
!CU_add_test(pSuite, "hd_deflate_inflate",
test_nghttp2_hd_deflate_inflate) ||
!CU_add_test(pSuite, "hd_no_index", test_nghttp2_hd_no_index) ||
!CU_add_test(pSuite, "hd_deflate_bound", test_nghttp2_hd_deflate_bound) ||
!CU_add_test(pSuite, "hd_public_api", test_nghttp2_hd_public_api) ||
!CU_add_test(pSuite, "hd_deflate_hd_vec",
test_nghttp2_hd_deflate_hd_vec) ||
!CU_add_test(pSuite, "hd_decode_length", test_nghttp2_hd_decode_length) ||
!CU_add_test(pSuite, "hd_huff_encode", test_nghttp2_hd_huff_encode) ||
!CU_add_test(pSuite, "hd_huff_decode", test_nghttp2_hd_huff_decode) ||
!CU_add_test(pSuite, "adjust_local_window_size",
test_nghttp2_adjust_local_window_size) ||
!CU_add_test(pSuite, "check_header_name",
test_nghttp2_check_header_name) ||
!CU_add_test(pSuite, "check_header_value",
test_nghttp2_check_header_value) ||
!CU_add_test(pSuite, "bufs_add", test_nghttp2_bufs_add) ||
!CU_add_test(pSuite, "bufs_add_stack_buffer_overflow_bug",
test_nghttp2_bufs_add_stack_buffer_overflow_bug) ||
!CU_add_test(pSuite, "bufs_addb", test_nghttp2_bufs_addb) ||
!CU_add_test(pSuite, "bufs_orb", test_nghttp2_bufs_orb) ||
!CU_add_test(pSuite, "bufs_remove", test_nghttp2_bufs_remove) ||
!CU_add_test(pSuite, "bufs_reset", test_nghttp2_bufs_reset) ||
!CU_add_test(pSuite, "bufs_advance", test_nghttp2_bufs_advance) ||
!CU_add_test(pSuite, "bufs_next_present",
test_nghttp2_bufs_next_present) ||
!CU_add_test(pSuite, "bufs_realloc", test_nghttp2_bufs_realloc)) {
CU_cleanup_registry();
return (int)CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
num_tests_failed = CU_get_number_of_tests_failed();
CU_cleanup_registry();
if (CU_get_error() == CUE_SUCCESS) {
return (int)num_tests_failed;
} else {
printf("CUnit Error: %s\n", CU_get_error_msg());
return (int)CU_get_error();
}
}
+85
View File
@@ -0,0 +1,85 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "malloc_wrapper.h"
int nghttp2_failmalloc = 0;
int nghttp2_failstart = 0;
int nghttp2_countmalloc = 1;
int nghttp2_nmalloc = 0;
#define CHECK_PREREQ \
do { \
if (nghttp2_failmalloc && nghttp2_nmalloc >= nghttp2_failstart) { \
return NULL; \
} \
if (nghttp2_countmalloc) { \
++nghttp2_nmalloc; \
} \
} while (0)
static void *my_malloc(size_t size, void *mud) {
(void)mud;
CHECK_PREREQ;
return malloc(size);
}
static void my_free(void *ptr, void *mud) {
(void)mud;
free(ptr);
}
static void *my_calloc(size_t nmemb, size_t size, void *mud) {
(void)mud;
CHECK_PREREQ;
return calloc(nmemb, size);
}
static void *my_realloc(void *ptr, size_t size, void *mud) {
(void)mud;
CHECK_PREREQ;
return realloc(ptr, size);
}
static nghttp2_mem mem = {NULL, my_malloc, my_free, my_calloc, my_realloc};
nghttp2_mem *nghttp2_mem_fm(void) { return &mem; }
static int failmalloc_bk, countmalloc_bk;
void nghttp2_failmalloc_pause(void) {
failmalloc_bk = nghttp2_failmalloc;
countmalloc_bk = nghttp2_countmalloc;
nghttp2_failmalloc = 0;
nghttp2_countmalloc = 0;
}
void nghttp2_failmalloc_unpause(void) {
nghttp2_failmalloc = failmalloc_bk;
nghttp2_countmalloc = countmalloc_bk;
}
+65
View File
@@ -0,0 +1,65 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef MALLOC_WRAPPER_H
#define MALLOC_WRAPPER_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include "nghttp2_mem.h"
/* Global variables to control the behavior of malloc() */
/* If nonzero, malloc failure mode is on */
extern int nghttp2_failmalloc;
/* If nghttp2_failstart <= nghttp2_nmalloc and nghttp2_failmalloc is
nonzero, malloc() fails. */
extern int nghttp2_failstart;
/* If nonzero, nghttp2_nmalloc is incremented if malloc() succeeds. */
extern int nghttp2_countmalloc;
/* The number of successful invocation of malloc(). This value is only
incremented if nghttp2_nmalloc is nonzero. */
extern int nghttp2_nmalloc;
/* Returns pointer to nghttp2_mem, which, when dereferenced, contains
specifically instrumented memory allocators for failmalloc
tests. */
nghttp2_mem *nghttp2_mem_fm(void);
/* Copies nghttp2_failmalloc and nghttp2_countmalloc to statically
allocated space and sets 0 to them. This will effectively make
malloc() work like normal malloc(). This is useful when you want to
disable malloc() failure mode temporarily. */
void nghttp2_failmalloc_pause(void);
/* Restores the values of nghttp2_failmalloc and nghttp2_countmalloc
with the values saved by the previous
nghttp2_failmalloc_pause(). */
void nghttp2_failmalloc_unpause(void);
#endif /* MALLOC_WRAPPER_H */
+342
View File
@@ -0,0 +1,342 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2014 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_buf_test.h"
#include <CUnit/CUnit.h>
#include "nghttp2_buf.h"
#include "nghttp2_test_helper.h"
void test_nghttp2_bufs_add(void) {
int rv;
nghttp2_bufs bufs;
uint8_t data[2048];
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 1000, 3, mem);
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);
}
/* Test for GH-232, stack-buffer-overflow */
void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void) {
int rv;
nghttp2_bufs bufs;
uint8_t data[1024];
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 100, 200, mem);
CU_ASSERT(0 == rv);
rv = nghttp2_bufs_add(&bufs, data, sizeof(data));
CU_ASSERT(0 == rv);
CU_ASSERT(sizeof(data) == nghttp2_bufs_len(&bufs));
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_bufs_addb(void) {
int rv;
nghttp2_bufs bufs;
ssize_t i;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 1000, 3, mem);
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((size_t)(i + 2) == nghttp2_buf_len(&bufs.cur->buf));
CU_ASSERT((size_t)(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);
}
void test_nghttp2_bufs_orb(void) {
int rv;
nghttp2_bufs bufs;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 1000, 3, mem);
CU_ASSERT(0 == rv);
*(bufs.cur->buf.last) = 0;
rv = nghttp2_bufs_orb_hold(&bufs, 15);
CU_ASSERT(0 == rv);
CU_ASSERT(0 == nghttp2_buf_len(&bufs.cur->buf));
CU_ASSERT(0 == nghttp2_bufs_len(&bufs));
CU_ASSERT(15 == *(bufs.cur->buf.last));
rv = nghttp2_bufs_orb(&bufs, 240);
CU_ASSERT(0 == rv);
CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf));
CU_ASSERT(1 == nghttp2_bufs_len(&bufs));
CU_ASSERT(255 == *(bufs.cur->buf.last - 1));
*(bufs.cur->buf.last) = 0;
nghttp2_bufs_fast_orb_hold(&bufs, 240);
CU_ASSERT(240 == *(bufs.cur->buf.last));
nghttp2_bufs_fast_orb(&bufs, 15);
CU_ASSERT(255 == *(bufs.cur->buf.last - 1));
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_bufs_remove(void) {
int rv;
nghttp2_bufs bufs;
nghttp2_buf_chain *chain;
int i;
uint8_t *out;
ssize_t outlen;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 1000, 3, mem);
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, (size_t)outlen));
CU_ASSERT(11 == nghttp2_bufs_len(&bufs));
mem->free(out, NULL);
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_bufs_reset(void) {
int rv;
nghttp2_bufs bufs;
nghttp2_buf_chain *ci;
size_t offset = 9;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init3(&bufs, 250, 3, 1, offset, mem);
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((ssize_t)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_bufs_advance(void) {
int rv;
nghttp2_bufs bufs;
int i;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 250, 3, mem);
CU_ASSERT(0 == rv);
for (i = 0; i < 2; ++i) {
rv = nghttp2_bufs_advance(&bufs);
CU_ASSERT(0 == rv);
}
rv = nghttp2_bufs_advance(&bufs);
CU_ASSERT(NGHTTP2_ERR_BUFFER_ERROR == rv);
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_bufs_next_present(void) {
int rv;
nghttp2_bufs bufs;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init(&bufs, 250, 3, mem);
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_bufs_realloc(void) {
int rv;
nghttp2_bufs bufs;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
rv = nghttp2_bufs_init3(&bufs, 266, 3, 1, 10, mem);
CU_ASSERT(0 == rv);
/* Create new buffer to see that these buffers are deallocated on
realloc */
rv = nghttp2_bufs_advance(&bufs);
CU_ASSERT(0 == rv);
rv = nghttp2_bufs_realloc(&bufs, 522);
CU_ASSERT(0 == rv);
CU_ASSERT(512 == nghttp2_bufs_cur_avail(&bufs));
rv = nghttp2_bufs_realloc(&bufs, 9);
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv);
nghttp2_bufs_free(&bufs);
}
+42
View File
@@ -0,0 +1,42 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2014 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_BUF_TEST_H
#define NGHTTP2_BUF_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_bufs_add(void);
void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void);
void test_nghttp2_bufs_addb(void);
void test_nghttp2_bufs_orb(void);
void test_nghttp2_bufs_remove(void);
void test_nghttp2_bufs_reset(void);
void test_nghttp2_bufs_advance(void);
void test_nghttp2_bufs_next_present(void);
void test_nghttp2_bufs_realloc(void);
#endif /* NGHTTP2_BUF_TEST_H */
+709
View File
@@ -0,0 +1,709 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_frame_test.h"
#include <assert.h>
#include <stdio.h>
#include <CUnit/CUnit.h>
#include "nghttp2_frame.h"
#include "nghttp2_helper.h"
#include "nghttp2_test_helper.h"
#include "nghttp2_priority_spec.h"
static nghttp2_nv make_nv(const char *name, const char *value) {
nghttp2_nv nv;
nv.name = (uint8_t *)name;
nv.value = (uint8_t *)value;
nv.namelen = strlen(name);
nv.valuelen = strlen(value);
nv.flags = NGHTTP2_NV_FLAG_NONE;
return nv;
}
#define HEADERS_LENGTH 7
static nghttp2_nv *headers(nghttp2_mem *mem) {
nghttp2_nv *nva = mem->malloc(sizeof(nghttp2_nv) * HEADERS_LENGTH, NULL);
nva[0] = make_nv("method", "GET");
nva[1] = make_nv("scheme", "https");
nva[2] = make_nv("url", "/");
nva[3] = make_nv("x-head", "foo");
nva[4] = make_nv("x-head", "bar");
nva[5] = make_nv("version", "HTTP/1.1");
nva[6] = make_nv("x-empty", "");
return nva;
}
static void check_frame_header(size_t length, uint8_t type, uint8_t flags,
int32_t stream_id, nghttp2_frame_hd *hd) {
CU_ASSERT(length == hd->length);
CU_ASSERT(type == hd->type);
CU_ASSERT(flags == hd->flags);
CU_ASSERT(stream_id == hd->stream_id);
CU_ASSERT(0 == hd->reserved);
}
void test_nghttp2_frame_pack_headers() {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_headers frame, oframe;
nghttp2_bufs bufs;
nghttp2_nv *nva;
nghttp2_priority_spec pri_spec;
size_t nvlen;
nva_out out;
size_t hdblocklen;
int rv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nva_out_init(&out);
nghttp2_hd_deflate_init(&deflater, mem);
nghttp2_hd_inflate_init(&inflater, mem);
nva = headers(mem);
nvlen = HEADERS_LENGTH;
nghttp2_priority_spec_default_init(&pri_spec);
nghttp2_frame_headers_init(
&frame, NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS, 1000000007,
NGHTTP2_HCAT_REQUEST, &pri_spec, nva, nvlen);
rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);
nghttp2_bufs_rewind(&bufs);
CU_ASSERT(0 == rv);
CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
NGHTTP2_HEADERS,
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS,
1000000007, &oframe.hd);
/* We did not include PRIORITY flag */
CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == oframe.pri_spec.weight);
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN;
CU_ASSERT((ssize_t)hdblocklen ==
inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem));
CU_ASSERT(7 == out.nvlen);
CU_ASSERT(nvnameeq("method", &out.nva[0]));
CU_ASSERT(nvvalueeq("GET", &out.nva[0]));
nghttp2_frame_headers_free(&oframe, mem);
nva_out_reset(&out, mem);
nghttp2_bufs_reset(&bufs);
memset(&oframe, 0, sizeof(oframe));
/* Next, include NGHTTP2_FLAG_PRIORITY */
nghttp2_priority_spec_init(&frame.pri_spec, 1000000009, 12, 1);
frame.hd.flags |= NGHTTP2_FLAG_PRIORITY;
rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);
CU_ASSERT(0 == rv);
CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
NGHTTP2_HEADERS,
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS |
NGHTTP2_FLAG_PRIORITY,
1000000007, &oframe.hd);
CU_ASSERT(1000000009 == oframe.pri_spec.stream_id);
CU_ASSERT(12 == oframe.pri_spec.weight);
CU_ASSERT(1 == oframe.pri_spec.exclusive);
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN -
nghttp2_frame_priority_len(oframe.hd.flags);
CU_ASSERT((ssize_t)hdblocklen ==
inflate_hd(&inflater, &out, &bufs,
NGHTTP2_FRAME_HDLEN +
nghttp2_frame_priority_len(oframe.hd.flags),
mem));
nghttp2_nv_array_sort(out.nva, out.nvlen);
CU_ASSERT(nvnameeq("method", &out.nva[0]));
nghttp2_frame_headers_free(&oframe, mem);
nva_out_reset(&out, mem);
nghttp2_bufs_reset(&bufs);
nghttp2_bufs_free(&bufs);
nghttp2_frame_headers_free(&frame, mem);
nghttp2_hd_inflate_free(&inflater);
nghttp2_hd_deflate_free(&deflater);
}
void test_nghttp2_frame_pack_headers_frame_too_large(void) {
nghttp2_hd_deflater deflater;
nghttp2_headers frame;
nghttp2_bufs bufs;
nghttp2_nv *nva;
size_t big_vallen = NGHTTP2_HD_MAX_NV;
nghttp2_nv big_hds[16];
size_t big_hdslen = ARRLEN(big_hds);
size_t i;
int rv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
for (i = 0; i < big_hdslen; ++i) {
big_hds[i].name = (uint8_t *)"header";
big_hds[i].value = mem->malloc(big_vallen + 1, NULL);
memset(big_hds[i].value, '0' + (int)i, big_vallen);
big_hds[i].value[big_vallen] = '\0';
big_hds[i].namelen = strlen((char *)big_hds[i].name);
big_hds[i].valuelen = big_vallen;
big_hds[i].flags = NGHTTP2_NV_FLAG_NONE;
}
nghttp2_nv_array_copy(&nva, big_hds, big_hdslen, mem);
nghttp2_hd_deflate_init(&deflater, mem);
nghttp2_frame_headers_init(
&frame, NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS, 1000000007,
NGHTTP2_HCAT_REQUEST, NULL, nva, big_hdslen);
rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == rv);
nghttp2_frame_headers_free(&frame, mem);
nghttp2_bufs_free(&bufs);
for (i = 0; i < big_hdslen; ++i) {
mem->free(big_hds[i].value, NULL);
}
nghttp2_hd_deflate_free(&deflater);
}
void test_nghttp2_frame_pack_priority(void) {
nghttp2_priority frame, oframe;
nghttp2_bufs bufs;
nghttp2_priority_spec pri_spec;
int rv;
frame_pack_bufs_init(&bufs);
/* First, pack priority with priority group and weight */
nghttp2_priority_spec_init(&pri_spec, 1000000009, 12, 1);
nghttp2_frame_priority_init(&frame, 1000000007, &pri_spec);
rv = nghttp2_frame_pack_priority(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 5 == nghttp2_bufs_len(&bufs));
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(5, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007,
&oframe.hd);
CU_ASSERT(1000000009 == oframe.pri_spec.stream_id);
CU_ASSERT(12 == oframe.pri_spec.weight);
CU_ASSERT(1 == oframe.pri_spec.exclusive);
nghttp2_frame_priority_free(&oframe);
nghttp2_bufs_reset(&bufs);
nghttp2_bufs_free(&bufs);
nghttp2_frame_priority_free(&frame);
}
void test_nghttp2_frame_pack_rst_stream(void) {
nghttp2_rst_stream frame, oframe;
nghttp2_bufs bufs;
int rv;
frame_pack_bufs_init(&bufs);
nghttp2_frame_rst_stream_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR);
rv = nghttp2_frame_pack_rst_stream(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs));
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007,
&oframe.hd);
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
nghttp2_frame_rst_stream_free(&oframe);
nghttp2_bufs_reset(&bufs);
/* Unknown error code is passed to callback as is */
frame.error_code = 1000000009;
rv = nghttp2_frame_pack_rst_stream(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007,
&oframe.hd);
CU_ASSERT(1000000009 == oframe.error_code);
nghttp2_frame_rst_stream_free(&oframe);
nghttp2_frame_rst_stream_free(&frame);
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_frame_pack_settings() {
nghttp2_settings frame, oframe;
nghttp2_bufs bufs;
int i;
int rv;
nghttp2_settings_entry iv[] = {{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 256},
{NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, 16384},
{NGHTTP2_SETTINGS_HEADER_TABLE_SIZE, 4096}};
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nghttp2_frame_settings_init(&frame, NGHTTP2_FLAG_NONE,
nghttp2_frame_iv_copy(iv, 3, mem), 3);
rv = nghttp2_frame_pack_settings(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH ==
nghttp2_bufs_len(&bufs));
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, NGHTTP2_SETTINGS,
NGHTTP2_FLAG_NONE, 0, &oframe.hd);
CU_ASSERT(3 == oframe.niv);
for (i = 0; i < 3; ++i) {
CU_ASSERT(iv[i].settings_id == oframe.iv[i].settings_id);
CU_ASSERT(iv[i].value == oframe.iv[i].value);
}
nghttp2_bufs_free(&bufs);
nghttp2_frame_settings_free(&frame, mem);
nghttp2_frame_settings_free(&oframe, mem);
}
void test_nghttp2_frame_pack_push_promise() {
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_push_promise frame, oframe;
nghttp2_bufs bufs;
nghttp2_nv *nva;
size_t nvlen;
nva_out out;
size_t hdblocklen;
int rv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
nva_out_init(&out);
nghttp2_hd_deflate_init(&deflater, mem);
nghttp2_hd_inflate_init(&inflater, mem);
nva = headers(mem);
nvlen = HEADERS_LENGTH;
nghttp2_frame_push_promise_init(&frame, NGHTTP2_FLAG_END_HEADERS, 1000000007,
(1U << 31) - 1, nva, nvlen);
rv = nghttp2_frame_pack_push_promise(&bufs, &frame, &deflater);
CU_ASSERT(0 == rv);
CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
NGHTTP2_PUSH_PROMISE, NGHTTP2_FLAG_END_HEADERS, 1000000007,
&oframe.hd);
CU_ASSERT((1U << 31) - 1 == oframe.promised_stream_id);
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN - 4;
CU_ASSERT((ssize_t)hdblocklen ==
inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN + 4, mem));
CU_ASSERT(7 == out.nvlen);
CU_ASSERT(nvnameeq("method", &out.nva[0]));
CU_ASSERT(nvvalueeq("GET", &out.nva[0]));
nva_out_reset(&out, mem);
nghttp2_bufs_free(&bufs);
nghttp2_frame_push_promise_free(&oframe, mem);
nghttp2_frame_push_promise_free(&frame, mem);
nghttp2_hd_inflate_free(&inflater);
nghttp2_hd_deflate_free(&deflater);
}
void test_nghttp2_frame_pack_ping(void) {
nghttp2_ping frame, oframe;
nghttp2_bufs bufs;
const uint8_t opaque_data[] = "01234567";
int rv;
frame_pack_bufs_init(&bufs);
nghttp2_frame_ping_init(&frame, NGHTTP2_FLAG_ACK, opaque_data);
rv = nghttp2_frame_pack_ping(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 == nghttp2_bufs_len(&bufs));
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(8, NGHTTP2_PING, NGHTTP2_FLAG_ACK, 0, &oframe.hd);
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, sizeof(opaque_data) - 1) ==
0);
nghttp2_bufs_free(&bufs);
nghttp2_frame_ping_free(&oframe);
nghttp2_frame_ping_free(&frame);
}
void test_nghttp2_frame_pack_goaway() {
nghttp2_goaway frame, oframe;
nghttp2_bufs bufs;
size_t opaque_data_len = 16;
uint8_t *opaque_data;
int rv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
opaque_data = mem->malloc(opaque_data_len, NULL);
memcpy(opaque_data, "0123456789abcdef", opaque_data_len);
nghttp2_frame_goaway_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR,
opaque_data, opaque_data_len);
rv = nghttp2_frame_pack_goaway(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 + opaque_data_len ==
nghttp2_bufs_len(&bufs));
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
CU_ASSERT(1000000007 == oframe.last_stream_id);
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
CU_ASSERT(opaque_data_len == oframe.opaque_data_len);
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0);
nghttp2_frame_goaway_free(&oframe, mem);
nghttp2_bufs_reset(&bufs);
/* Unknown error code is passed to callback as is */
frame.error_code = 1000000009;
rv = nghttp2_frame_pack_goaway(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
CU_ASSERT(1000000009 == oframe.error_code);
nghttp2_frame_goaway_free(&oframe, mem);
nghttp2_frame_goaway_free(&frame, mem);
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_frame_pack_window_update(void) {
nghttp2_window_update frame, oframe;
nghttp2_bufs bufs;
int rv;
frame_pack_bufs_init(&bufs);
nghttp2_frame_window_update_init(&frame, NGHTTP2_FLAG_NONE, 1000000007, 4096);
rv = nghttp2_frame_pack_window_update(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs));
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs));
check_frame_header(4, NGHTTP2_WINDOW_UPDATE, NGHTTP2_FLAG_NONE, 1000000007,
&oframe.hd);
CU_ASSERT(4096 == oframe.window_size_increment);
nghttp2_bufs_free(&bufs);
nghttp2_frame_window_update_free(&oframe);
nghttp2_frame_window_update_free(&frame);
}
void test_nghttp2_frame_pack_altsvc(void) {
nghttp2_extension frame, oframe;
nghttp2_ext_altsvc altsvc, oaltsvc;
nghttp2_bufs bufs;
int rv;
size_t payloadlen;
static const uint8_t origin[] = "nghttp2.org";
static const uint8_t field_value[] = "h2=\":443\"";
nghttp2_buf buf;
uint8_t *rawbuf;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
frame.payload = &altsvc;
oframe.payload = &oaltsvc;
rawbuf = nghttp2_mem_malloc(mem, 32);
nghttp2_buf_wrap_init(&buf, rawbuf, 32);
buf.last = nghttp2_cpymem(buf.last, origin, sizeof(origin) - 1);
buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1);
nghttp2_frame_altsvc_init(&frame, 1000000007, buf.pos, sizeof(origin) - 1,
buf.pos + sizeof(origin) - 1,
sizeof(field_value) - 1);
payloadlen = 2 + sizeof(origin) - 1 + sizeof(field_value) - 1;
rv = nghttp2_frame_pack_altsvc(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs));
rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs);
CU_ASSERT(0 == rv);
check_frame_header(payloadlen, NGHTTP2_ALTSVC, NGHTTP2_FLAG_NONE, 1000000007,
&oframe.hd);
CU_ASSERT(sizeof(origin) - 1 == oaltsvc.origin_len);
CU_ASSERT(0 == memcmp(origin, oaltsvc.origin, sizeof(origin) - 1));
CU_ASSERT(sizeof(field_value) - 1 == oaltsvc.field_value_len);
CU_ASSERT(0 ==
memcmp(field_value, oaltsvc.field_value, sizeof(field_value) - 1));
nghttp2_frame_altsvc_free(&oframe, mem);
nghttp2_frame_altsvc_free(&frame, mem);
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_frame_pack_origin(void) {
nghttp2_extension frame, oframe;
nghttp2_ext_origin origin, oorigin;
nghttp2_bufs bufs;
nghttp2_buf *buf;
int rv;
size_t payloadlen;
static const uint8_t example[] = "https://example.com";
static const uint8_t nghttp2[] = "https://nghttp2.org";
nghttp2_origin_entry ov[] = {
{
(uint8_t *)example,
sizeof(example) - 1,
},
{
NULL,
0,
},
{
(uint8_t *)nghttp2,
sizeof(nghttp2) - 1,
},
};
nghttp2_mem *mem;
mem = nghttp2_mem_default();
frame_pack_bufs_init(&bufs);
frame.payload = &origin;
oframe.payload = &oorigin;
nghttp2_frame_origin_init(&frame, ov, 3);
payloadlen = 2 + sizeof(example) - 1 + 2 + 2 + sizeof(nghttp2) - 1;
rv = nghttp2_frame_pack_origin(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs));
rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs);
CU_ASSERT(0 == rv);
check_frame_header(payloadlen, NGHTTP2_ORIGIN, NGHTTP2_FLAG_NONE, 0,
&oframe.hd);
CU_ASSERT(2 == oorigin.nov);
CU_ASSERT(sizeof(example) - 1 == oorigin.ov[0].origin_len);
CU_ASSERT(0 == memcmp(example, oorigin.ov[0].origin, sizeof(example) - 1));
CU_ASSERT(sizeof(nghttp2) - 1 == oorigin.ov[1].origin_len);
CU_ASSERT(0 == memcmp(nghttp2, oorigin.ov[1].origin, sizeof(nghttp2) - 1));
nghttp2_frame_origin_free(&oframe, mem);
/* Check the case where origin length is too large */
buf = &bufs.head->buf;
nghttp2_put_uint16be(buf->pos + NGHTTP2_FRAME_HDLEN,
(uint16_t)(payloadlen - 1));
rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs);
CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR == rv);
nghttp2_bufs_reset(&bufs);
memset(&oframe, 0, sizeof(oframe));
memset(&oorigin, 0, sizeof(oorigin));
oframe.payload = &oorigin;
/* Empty ORIGIN frame */
nghttp2_frame_origin_init(&frame, NULL, 0);
rv = nghttp2_frame_pack_origin(&bufs, &frame);
CU_ASSERT(0 == rv);
CU_ASSERT(NGHTTP2_FRAME_HDLEN == nghttp2_bufs_len(&bufs));
rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs);
CU_ASSERT(0 == rv);
check_frame_header(0, NGHTTP2_ORIGIN, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
CU_ASSERT(0 == oorigin.nov);
CU_ASSERT(NULL == oorigin.ov);
nghttp2_frame_origin_free(&oframe, mem);
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_nv_array_copy(void) {
nghttp2_nv *nva;
ssize_t rv;
nghttp2_nv emptynv[] = {MAKE_NV("", ""), MAKE_NV("", "")};
nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")};
nghttp2_nv bignv;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
bignv.name = (uint8_t *)"echo";
bignv.namelen = strlen("echo");
bignv.valuelen = (1 << 14) - 1;
bignv.value = mem->malloc(bignv.valuelen, NULL);
bignv.flags = NGHTTP2_NV_FLAG_NONE;
memset(bignv.value, '0', bignv.valuelen);
rv = nghttp2_nv_array_copy(&nva, NULL, 0, mem);
CU_ASSERT(0 == rv);
CU_ASSERT(NULL == nva);
rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv), mem);
CU_ASSERT(0 == rv);
CU_ASSERT(nva[0].namelen == 0);
CU_ASSERT(nva[0].valuelen == 0);
CU_ASSERT(nva[1].namelen == 0);
CU_ASSERT(nva[1].valuelen == 0);
nghttp2_nv_array_del(nva, mem);
rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv), mem);
CU_ASSERT(0 == rv);
CU_ASSERT(nva[0].namelen == 5);
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
CU_ASSERT(nva[0].valuelen == 5);
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
CU_ASSERT(nva[1].namelen == 7);
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
CU_ASSERT(nva[1].valuelen == 5);
CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));
nghttp2_nv_array_del(nva, mem);
/* Large header field is acceptable */
rv = nghttp2_nv_array_copy(&nva, &bignv, 1, mem);
CU_ASSERT(0 == rv);
nghttp2_nv_array_del(nva, mem);
mem->free(bignv.value, NULL);
}
void test_nghttp2_iv_check(void) {
nghttp2_settings_entry iv[5];
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
iv[0].value = 100;
iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[1].value = 1024;
CU_ASSERT(nghttp2_iv_check(iv, 2));
iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
iv[1].value = NGHTTP2_MAX_WINDOW_SIZE;
CU_ASSERT(nghttp2_iv_check(iv, 2));
/* Too large window size */
iv[1].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1;
CU_ASSERT(0 == nghttp2_iv_check(iv, 2));
/* ENABLE_PUSH only allows 0 or 1 */
iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH;
iv[1].value = 0;
CU_ASSERT(nghttp2_iv_check(iv, 2));
iv[1].value = 1;
CU_ASSERT(nghttp2_iv_check(iv, 2));
iv[1].value = 3;
CU_ASSERT(!nghttp2_iv_check(iv, 2));
/* Undefined SETTINGS ID is allowed */
iv[1].settings_id = 1000000009;
iv[1].value = 0;
CU_ASSERT(nghttp2_iv_check(iv, 2));
/* Full size SETTINGS_HEADER_TABLE_SIZE (UINT32_MAX) must be
accepted */
iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[1].value = UINT32_MAX;
CU_ASSERT(nghttp2_iv_check(iv, 2));
/* Too small SETTINGS_MAX_FRAME_SIZE */
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN - 1;
CU_ASSERT(!nghttp2_iv_check(iv, 1));
/* Too large SETTINGS_MAX_FRAME_SIZE */
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MAX + 1;
CU_ASSERT(!nghttp2_iv_check(iv, 1));
/* Max and min SETTINGS_MAX_FRAME_SIZE */
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN;
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
iv[1].value = NGHTTP2_MAX_FRAME_SIZE_MAX;
CU_ASSERT(nghttp2_iv_check(iv, 2));
}
+46
View File
@@ -0,0 +1,46 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_FRAME_TEST_H
#define NGHTTP2_FRAME_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_frame_pack_headers(void);
void test_nghttp2_frame_pack_headers_frame_too_large(void);
void test_nghttp2_frame_pack_priority(void);
void test_nghttp2_frame_pack_rst_stream(void);
void test_nghttp2_frame_pack_settings(void);
void test_nghttp2_frame_pack_push_promise(void);
void test_nghttp2_frame_pack_ping(void);
void test_nghttp2_frame_pack_goaway(void);
void test_nghttp2_frame_pack_window_update(void);
void test_nghttp2_frame_pack_altsvc(void);
void test_nghttp2_frame_pack_origin(void);
void test_nghttp2_nv_array_copy(void);
void test_nghttp2_iv_check(void);
#endif /* NGHTTP2_FRAME_TEST_H */
File diff suppressed because it is too large Load Diff
+55
View File
@@ -0,0 +1,55 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2013 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_HD_TEST_H
#define NGHTTP2_HD_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_hd_deflate(void);
void test_nghttp2_hd_deflate_same_indexed_repr(void);
void test_nghttp2_hd_inflate_indexed(void);
void test_nghttp2_hd_inflate_indname_noinc(void);
void test_nghttp2_hd_inflate_indname_inc(void);
void test_nghttp2_hd_inflate_indname_inc_eviction(void);
void test_nghttp2_hd_inflate_newname_noinc(void);
void test_nghttp2_hd_inflate_newname_inc(void);
void test_nghttp2_hd_inflate_clearall_inc(void);
void test_nghttp2_hd_inflate_zero_length_huffman(void);
void test_nghttp2_hd_inflate_expect_table_size_update(void);
void test_nghttp2_hd_inflate_unexpected_table_size_update(void);
void test_nghttp2_hd_ringbuf_reserve(void);
void test_nghttp2_hd_change_table_size(void);
void test_nghttp2_hd_deflate_inflate(void);
void test_nghttp2_hd_no_index(void);
void test_nghttp2_hd_deflate_bound(void);
void test_nghttp2_hd_public_api(void);
void test_nghttp2_hd_deflate_hd_vec(void);
void test_nghttp2_hd_decode_length(void);
void test_nghttp2_hd_huff_encode(void);
void test_nghttp2_hd_huff_decode(void);
#endif /* NGHTTP2_HD_TEST_H */
+169
View File
@@ -0,0 +1,169 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2013 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_helper_test.h"
#include <CUnit/CUnit.h>
#include "nghttp2_helper.h"
void test_nghttp2_adjust_local_window_size(void) {
int32_t local_window_size = 100;
int32_t recv_window_size = 50;
int32_t recv_reduction = 0;
int32_t delta;
delta = 0;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(100 == local_window_size);
CU_ASSERT(50 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(0 == delta);
delta = 49;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(100 == local_window_size);
CU_ASSERT(1 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(49 == delta);
delta = 1;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(100 == local_window_size);
CU_ASSERT(0 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(1 == delta);
delta = 1;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(101 == local_window_size);
CU_ASSERT(0 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(1 == delta);
delta = -1;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(100 == local_window_size);
CU_ASSERT(-1 == recv_window_size);
CU_ASSERT(1 == recv_reduction);
CU_ASSERT(0 == delta);
delta = 1;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(101 == local_window_size);
CU_ASSERT(0 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(0 == delta);
delta = 100;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(201 == local_window_size);
CU_ASSERT(0 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(100 == delta);
delta = -3;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(198 == local_window_size);
CU_ASSERT(-3 == recv_window_size);
CU_ASSERT(3 == recv_reduction);
CU_ASSERT(0 == delta);
recv_window_size += 3;
delta = 3;
CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size,
&recv_reduction, &delta));
CU_ASSERT(201 == local_window_size);
CU_ASSERT(3 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(0 == delta);
local_window_size = 100;
recv_window_size = 50;
recv_reduction = 0;
delta = INT32_MAX;
CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL ==
nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size, &recv_reduction,
&delta));
CU_ASSERT(100 == local_window_size);
CU_ASSERT(50 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(INT32_MAX == delta);
delta = INT32_MIN;
CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL ==
nghttp2_adjust_local_window_size(&local_window_size,
&recv_window_size, &recv_reduction,
&delta));
CU_ASSERT(100 == local_window_size);
CU_ASSERT(50 == recv_window_size);
CU_ASSERT(0 == recv_reduction);
CU_ASSERT(INT32_MIN == delta);
}
#define check_header_name(S) \
nghttp2_check_header_name((const uint8_t *)S, sizeof(S) - 1)
void test_nghttp2_check_header_name(void) {
CU_ASSERT(check_header_name(":path"));
CU_ASSERT(check_header_name("path"));
CU_ASSERT(check_header_name("!#$%&'*+-.^_`|~"));
CU_ASSERT(!check_header_name(":PATH"));
CU_ASSERT(!check_header_name("path:"));
CU_ASSERT(!check_header_name(""));
CU_ASSERT(!check_header_name(":"));
}
#define check_header_value(S) \
nghttp2_check_header_value((const uint8_t *)S, sizeof(S) - 1)
void test_nghttp2_check_header_value(void) {
uint8_t goodval[] = {'a', 'b', 0x80u, 'c', 0xffu, 'd', '\t', ' '};
uint8_t badval1[] = {'a', 0x1fu, 'b'};
uint8_t badval2[] = {'a', 0x7fu, 'b'};
CU_ASSERT(check_header_value(" !|}~"));
CU_ASSERT(check_header_value(goodval));
CU_ASSERT(!check_header_value(badval1));
CU_ASSERT(!check_header_value(badval2));
}
+36
View File
@@ -0,0 +1,36 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2013 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_HELPER_TEST_H
#define NGHTTP2_HELPER_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_adjust_local_window_size(void);
void test_nghttp2_check_header_name(void);
void test_nghttp2_check_header_value(void);
#endif /* NGHTTP2_HELPER_TEST_H */
+181
View File
@@ -0,0 +1,181 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_map_test.h"
#include <CUnit/CUnit.h>
#include "nghttp2_map.h"
typedef struct strentry {
nghttp2_map_entry map_entry;
const char *str;
} strentry;
static void strentry_init(strentry *entry, key_type key, const char *str) {
nghttp2_map_entry_init(&entry->map_entry, key);
entry->str = str;
}
void test_nghttp2_map(void) {
strentry foo, FOO, bar, baz, shrubbery;
nghttp2_map map;
nghttp2_map_init(&map, nghttp2_mem_default());
strentry_init(&foo, 1, "foo");
strentry_init(&FOO, 1, "FOO");
strentry_init(&bar, 2, "bar");
strentry_init(&baz, 3, "baz");
strentry_init(&shrubbery, 4, "shrubbery");
CU_ASSERT(0 == nghttp2_map_insert(&map, &foo.map_entry));
CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0);
CU_ASSERT(1 == nghttp2_map_size(&map));
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT ==
nghttp2_map_insert(&map, &FOO.map_entry));
CU_ASSERT(1 == nghttp2_map_size(&map));
CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0);
CU_ASSERT(0 == nghttp2_map_insert(&map, &bar.map_entry));
CU_ASSERT(2 == nghttp2_map_size(&map));
CU_ASSERT(0 == nghttp2_map_insert(&map, &baz.map_entry));
CU_ASSERT(3 == nghttp2_map_size(&map));
CU_ASSERT(0 == nghttp2_map_insert(&map, &shrubbery.map_entry));
CU_ASSERT(4 == nghttp2_map_size(&map));
CU_ASSERT(strcmp("baz", ((strentry *)nghttp2_map_find(&map, 3))->str) == 0);
nghttp2_map_remove(&map, 3);
CU_ASSERT(3 == nghttp2_map_size(&map));
CU_ASSERT(NULL == nghttp2_map_find(&map, 3));
nghttp2_map_remove(&map, 1);
CU_ASSERT(2 == nghttp2_map_size(&map));
CU_ASSERT(NULL == nghttp2_map_find(&map, 1));
/* Erasing non-existent entry */
nghttp2_map_remove(&map, 1);
CU_ASSERT(2 == nghttp2_map_size(&map));
CU_ASSERT(NULL == nghttp2_map_find(&map, 1));
CU_ASSERT(strcmp("bar", ((strentry *)nghttp2_map_find(&map, 2))->str) == 0);
CU_ASSERT(strcmp("shrubbery", ((strentry *)nghttp2_map_find(&map, 4))->str) ==
0);
nghttp2_map_free(&map);
}
static void shuffle(int *a, int n) {
int i;
for (i = n - 1; i >= 1; --i) {
size_t j = (size_t)((double)(i + 1) * rand() / (RAND_MAX + 1.0));
int t = a[j];
a[j] = a[i];
a[i] = t;
}
}
static int eachfun(nghttp2_map_entry *entry, void *ptr) {
(void)entry;
(void)ptr;
return 0;
}
#define NUM_ENT 6000
static strentry arr[NUM_ENT];
static int order[NUM_ENT];
void test_nghttp2_map_functional(void) {
nghttp2_map map;
int i;
nghttp2_map_init(&map, nghttp2_mem_default());
for (i = 0; i < NUM_ENT; ++i) {
strentry_init(&arr[i], i + 1, "foo");
order[i] = i + 1;
}
/* insertion */
shuffle(order, NUM_ENT);
for (i = 0; i < NUM_ENT; ++i) {
CU_ASSERT(0 == nghttp2_map_insert(&map, &arr[order[i] - 1].map_entry));
}
/* traverse */
nghttp2_map_each(&map, eachfun, NULL);
/* find */
shuffle(order, NUM_ENT);
for (i = 0; i < NUM_ENT; ++i) {
nghttp2_map_find(&map, order[i]);
}
/* remove */
shuffle(order, NUM_ENT);
for (i = 0; i < NUM_ENT; ++i) {
CU_ASSERT(0 == nghttp2_map_remove(&map, order[i]));
}
/* each_free (but no op function for testing purpose) */
for (i = 0; i < NUM_ENT; ++i) {
strentry_init(&arr[i], i + 1, "foo");
}
/* insert once again */
for (i = 0; i < NUM_ENT; ++i) {
CU_ASSERT(0 == nghttp2_map_insert(&map, &arr[i].map_entry));
}
nghttp2_map_each_free(&map, eachfun, NULL);
nghttp2_map_free(&map);
}
static int entry_free(nghttp2_map_entry *entry, void *ptr) {
nghttp2_mem *mem = ptr;
mem->free(entry, NULL);
return 0;
}
void test_nghttp2_map_each_free(void) {
nghttp2_mem *mem = nghttp2_mem_default();
strentry *foo = mem->malloc(sizeof(strentry), NULL),
*bar = mem->malloc(sizeof(strentry), NULL),
*baz = mem->malloc(sizeof(strentry), NULL),
*shrubbery = mem->malloc(sizeof(strentry), NULL);
nghttp2_map map;
nghttp2_map_init(&map, nghttp2_mem_default());
strentry_init(foo, 1, "foo");
strentry_init(bar, 2, "bar");
strentry_init(baz, 3, "baz");
strentry_init(shrubbery, 4, "shrubbery");
nghttp2_map_insert(&map, &foo->map_entry);
nghttp2_map_insert(&map, &bar->map_entry);
nghttp2_map_insert(&map, &baz->map_entry);
nghttp2_map_insert(&map, &shrubbery->map_entry);
nghttp2_map_each_free(&map, entry_free, mem);
nghttp2_map_free(&map);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_MAP_TEST_H
#define NGHTTP2_MAP_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_map(void);
void test_nghttp2_map_functional(void);
void test_nghttp2_map_each_free(void);
#endif /* NGHTTP2_MAP_TEST_H */
+72
View File
@@ -0,0 +1,72 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Twist Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_npn_test.h"
#include <string.h>
#include <CUnit/CUnit.h>
#include <nghttp2/nghttp2.h>
static void http2(void) {
const unsigned char p[] = {8, 'h', 't', 't', 'p', '/', '1', '.', '1', 2,
'h', '2', 6, 's', 'p', 'd', 'y', '/', '3'};
unsigned char outlen;
unsigned char *out;
CU_ASSERT(1 == nghttp2_select_next_protocol(&out, &outlen, p, sizeof(p)));
CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen);
CU_ASSERT(memcmp(NGHTTP2_PROTO_VERSION_ID, out, outlen) == 0);
}
static void http11(void) {
const unsigned char spdy[] = {
6, 's', 'p', 'd', 'y', '/', '4', 8, 's', 'p', 'd', 'y', '/',
'2', '.', '1', 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
};
unsigned char outlen;
unsigned char *out;
CU_ASSERT(0 ==
nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy)));
CU_ASSERT(8 == outlen);
CU_ASSERT(memcmp("http/1.1", out, outlen) == 0);
}
static void no_overlap(void) {
const unsigned char spdy[] = {
6, 's', 'p', 'd', 'y', '/', '4', 8, 's', 'p', 'd', 'y', '/',
'2', '.', '1', 8, 'h', 't', 't', 'p', '/', '1', '.', '0',
};
unsigned char outlen = 0;
unsigned char *out = NULL;
CU_ASSERT(-1 ==
nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy)));
CU_ASSERT(0 == outlen);
CU_ASSERT(NULL == out);
}
void test_nghttp2_npn(void) {
http2();
http11();
no_overlap();
}
+34
View File
@@ -0,0 +1,34 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Twist Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_NPN_TEST_H
#define NGHTTP2_NPN_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_npn(void);
#endif /* NGHTTP2_NPN_TEST_H */
+226
View File
@@ -0,0 +1,226 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_pq_test.h"
#include <CUnit/CUnit.h>
#include "nghttp2_pq.h"
typedef struct {
nghttp2_pq_entry ent;
const char *s;
} string_entry;
static string_entry *string_entry_new(const char *s) {
nghttp2_mem *mem;
string_entry *ent;
mem = nghttp2_mem_default();
ent = nghttp2_mem_malloc(mem, sizeof(string_entry));
ent->s = s;
return ent;
}
static void string_entry_del(string_entry *ent) { free(ent); }
static int pq_less(const void *lhs, const void *rhs) {
return strcmp(((string_entry *)lhs)->s, ((string_entry *)rhs)->s) < 0;
}
void test_nghttp2_pq(void) {
int i;
nghttp2_pq pq;
string_entry *top;
nghttp2_pq_init(&pq, pq_less, nghttp2_mem_default());
CU_ASSERT(nghttp2_pq_empty(&pq));
CU_ASSERT(0 == nghttp2_pq_size(&pq));
CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("foo")->ent));
CU_ASSERT(0 == nghttp2_pq_empty(&pq));
CU_ASSERT(1 == nghttp2_pq_size(&pq));
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("foo", top->s) == 0);
CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("bar")->ent));
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("bar", top->s) == 0);
CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("baz")->ent));
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("bar", top->s) == 0);
CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("C")->ent));
CU_ASSERT(4 == nghttp2_pq_size(&pq));
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("C", top->s) == 0);
string_entry_del(top);
nghttp2_pq_pop(&pq);
CU_ASSERT(3 == nghttp2_pq_size(&pq));
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("bar", top->s) == 0);
nghttp2_pq_pop(&pq);
string_entry_del(top);
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("baz", top->s) == 0);
nghttp2_pq_pop(&pq);
string_entry_del(top);
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(strcmp("foo", top->s) == 0);
nghttp2_pq_pop(&pq);
string_entry_del(top);
CU_ASSERT(nghttp2_pq_empty(&pq));
CU_ASSERT(0 == nghttp2_pq_size(&pq));
CU_ASSERT(NULL == nghttp2_pq_top(&pq));
/* Add bunch of entry to see realloc works */
for (i = 0; i < 10000; ++i) {
CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("foo")->ent));
CU_ASSERT((size_t)(i + 1) == nghttp2_pq_size(&pq));
}
for (i = 10000; i > 0; --i) {
top = (string_entry *)nghttp2_pq_top(&pq);
CU_ASSERT(NULL != top);
nghttp2_pq_pop(&pq);
string_entry_del(top);
CU_ASSERT((size_t)(i - 1) == nghttp2_pq_size(&pq));
}
nghttp2_pq_free(&pq);
}
typedef struct {
nghttp2_pq_entry ent;
int key;
int val;
} node;
static int node_less(const void *lhs, const void *rhs) {
node *ln = (node *)lhs;
node *rn = (node *)rhs;
return ln->key < rn->key;
}
static int node_update(nghttp2_pq_entry *item, void *arg) {
node *nd = (node *)item;
(void)arg;
if ((nd->key % 2) == 0) {
nd->key *= -1;
return 1;
} else {
return 0;
}
}
void test_nghttp2_pq_update(void) {
nghttp2_pq pq;
node nodes[10];
int i;
node *nd;
int ans[] = {-8, -6, -4, -2, 0, 1, 3, 5, 7, 9};
nghttp2_pq_init(&pq, node_less, nghttp2_mem_default());
for (i = 0; i < (int)(sizeof(nodes) / sizeof(nodes[0])); ++i) {
nodes[i].key = i;
nodes[i].val = i;
nghttp2_pq_push(&pq, &nodes[i].ent);
}
nghttp2_pq_update(&pq, node_update, NULL);
for (i = 0; i < (int)(sizeof(nodes) / sizeof(nodes[0])); ++i) {
nd = (node *)nghttp2_pq_top(&pq);
CU_ASSERT(ans[i] == nd->key);
nghttp2_pq_pop(&pq);
}
nghttp2_pq_free(&pq);
}
static void push_nodes(nghttp2_pq *pq, node *dest, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
dest[i].key = (int)i;
dest[i].val = (int)i;
nghttp2_pq_push(pq, &dest[i].ent);
}
}
static void check_nodes(nghttp2_pq *pq, size_t n, int *ans_key, int *ans_val) {
size_t i;
for (i = 0; i < n; ++i) {
node *nd = (node *)nghttp2_pq_top(pq);
CU_ASSERT(ans_key[i] == nd->key);
CU_ASSERT(ans_val[i] == nd->val);
nghttp2_pq_pop(pq);
}
}
void test_nghttp2_pq_remove(void) {
nghttp2_pq pq;
node nodes[10];
int ans_key1[] = {1, 2, 3, 4, 5};
int ans_val1[] = {1, 2, 3, 4, 5};
int ans_key2[] = {0, 1, 2, 4, 5};
int ans_val2[] = {0, 1, 2, 4, 5};
int ans_key3[] = {0, 1, 2, 3, 4};
int ans_val3[] = {0, 1, 2, 3, 4};
nghttp2_pq_init(&pq, node_less, nghttp2_mem_default());
push_nodes(&pq, nodes, 6);
nghttp2_pq_remove(&pq, &nodes[0].ent);
check_nodes(&pq, 5, ans_key1, ans_val1);
nghttp2_pq_free(&pq);
nghttp2_pq_init(&pq, node_less, nghttp2_mem_default());
push_nodes(&pq, nodes, 6);
nghttp2_pq_remove(&pq, &nodes[3].ent);
check_nodes(&pq, 5, ans_key2, ans_val2);
nghttp2_pq_free(&pq);
nghttp2_pq_init(&pq, node_less, nghttp2_mem_default());
push_nodes(&pq, nodes, 6);
nghttp2_pq_remove(&pq, &nodes[5].ent);
check_nodes(&pq, 5, ans_key3, ans_val3);
nghttp2_pq_free(&pq);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_PQ_TEST_H
#define NGHTTP2_PQ_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_pq(void);
void test_nghttp2_pq_update(void);
void test_nghttp2_pq_remove(void);
#endif /* NGHTTP2_PQ_TEST_H */
+48
View File
@@ -0,0 +1,48 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_queue_test.h"
#include <CUnit/CUnit.h>
#include "nghttp2_queue.h"
void test_nghttp2_queue(void) {
int ints[] = {1, 2, 3, 4, 5};
int i;
nghttp2_queue queue;
nghttp2_queue_init(&queue);
CU_ASSERT(nghttp2_queue_empty(&queue));
for (i = 0; i < 5; ++i) {
nghttp2_queue_push(&queue, &ints[i]);
CU_ASSERT_EQUAL(ints[0], *(int *)(nghttp2_queue_front(&queue)));
CU_ASSERT(!nghttp2_queue_empty(&queue));
}
for (i = 0; i < 5; ++i) {
CU_ASSERT_EQUAL(ints[i], *(int *)(nghttp2_queue_front(&queue)));
nghttp2_queue_pop(&queue);
}
CU_ASSERT(nghttp2_queue_empty(&queue));
nghttp2_queue_free(&queue);
}
+34
View File
@@ -0,0 +1,34 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_QUEUE_TEST_H
#define NGHTTP2_QUEUE_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_queue(void);
#endif /* NGHTTP2_QUEUE_TEST_H */
File diff suppressed because it is too large Load Diff
+176
View File
@@ -0,0 +1,176 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_SESSION_TEST_H
#define NGHTTP2_SESSION_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
void test_nghttp2_session_recv(void);
void test_nghttp2_session_recv_invalid_stream_id(void);
void test_nghttp2_session_recv_invalid_frame(void);
void test_nghttp2_session_recv_eof(void);
void test_nghttp2_session_recv_data(void);
void test_nghttp2_session_recv_data_no_auto_flow_control(void);
void test_nghttp2_session_recv_continuation(void);
void test_nghttp2_session_recv_headers_with_priority(void);
void test_nghttp2_session_recv_headers_with_padding(void);
void test_nghttp2_session_recv_headers_early_response(void);
void test_nghttp2_session_recv_headers_for_closed_stream(void);
void test_nghttp2_session_server_recv_push_response(void);
void test_nghttp2_session_recv_premature_headers(void);
void test_nghttp2_session_recv_unknown_frame(void);
void test_nghttp2_session_recv_unexpected_continuation(void);
void test_nghttp2_session_recv_settings_header_table_size(void);
void test_nghttp2_session_recv_too_large_frame_length(void);
void test_nghttp2_session_recv_extension(void);
void test_nghttp2_session_recv_altsvc(void);
void test_nghttp2_session_recv_origin(void);
void test_nghttp2_session_continue(void);
void test_nghttp2_session_add_frame(void);
void test_nghttp2_session_on_request_headers_received(void);
void test_nghttp2_session_on_response_headers_received(void);
void test_nghttp2_session_on_headers_received(void);
void test_nghttp2_session_on_push_response_headers_received(void);
void test_nghttp2_session_on_priority_received(void);
void test_nghttp2_session_on_rst_stream_received(void);
void test_nghttp2_session_on_settings_received(void);
void test_nghttp2_session_on_push_promise_received(void);
void test_nghttp2_session_on_ping_received(void);
void test_nghttp2_session_on_goaway_received(void);
void test_nghttp2_session_on_window_update_received(void);
void test_nghttp2_session_on_data_received(void);
void test_nghttp2_session_on_data_received_fail_fast(void);
void test_nghttp2_session_on_altsvc_received(void);
void test_nghttp2_session_send_headers_start_stream(void);
void test_nghttp2_session_send_headers_reply(void);
void test_nghttp2_session_send_headers_frame_size_error(void);
void test_nghttp2_session_send_headers_push_reply(void);
void test_nghttp2_session_send_rst_stream(void);
void test_nghttp2_session_send_push_promise(void);
void test_nghttp2_session_is_my_stream_id(void);
void test_nghttp2_session_upgrade2(void);
void test_nghttp2_session_reprioritize_stream(void);
void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void);
void test_nghttp2_submit_data(void);
void test_nghttp2_submit_data_read_length_too_large(void);
void test_nghttp2_submit_data_read_length_smallest(void);
void test_nghttp2_submit_data_twice(void);
void test_nghttp2_submit_request_with_data(void);
void test_nghttp2_submit_request_without_data(void);
void test_nghttp2_submit_response_with_data(void);
void test_nghttp2_submit_response_without_data(void);
void test_nghttp2_submit_response_push_response(void);
void test_nghttp2_submit_trailer(void);
void test_nghttp2_submit_headers_start_stream(void);
void test_nghttp2_submit_headers_reply(void);
void test_nghttp2_submit_headers_push_reply(void);
void test_nghttp2_submit_headers(void);
void test_nghttp2_submit_headers_continuation(void);
void test_nghttp2_submit_headers_continuation_extra_large(void);
void test_nghttp2_submit_priority(void);
void test_nghttp2_submit_settings(void);
void test_nghttp2_submit_settings_update_local_window_size(void);
void test_nghttp2_submit_settings_multiple_times(void);
void test_nghttp2_submit_push_promise(void);
void test_nghttp2_submit_window_update(void);
void test_nghttp2_submit_window_update_local_window_size(void);
void test_nghttp2_submit_shutdown_notice(void);
void test_nghttp2_submit_invalid_nv(void);
void test_nghttp2_submit_extension(void);
void test_nghttp2_submit_altsvc(void);
void test_nghttp2_submit_origin(void);
void test_nghttp2_submit_rst_stream(void);
void test_nghttp2_session_open_stream(void);
void test_nghttp2_session_open_stream_with_idle_stream_dep(void);
void test_nghttp2_session_get_next_ob_item(void);
void test_nghttp2_session_pop_next_ob_item(void);
void test_nghttp2_session_reply_fail(void);
void test_nghttp2_session_max_concurrent_streams(void);
void test_nghttp2_session_stop_data_with_rst_stream(void);
void test_nghttp2_session_defer_data(void);
void test_nghttp2_session_flow_control(void);
void test_nghttp2_session_flow_control_data_recv(void);
void test_nghttp2_session_flow_control_data_with_padding_recv(void);
void test_nghttp2_session_data_read_temporal_failure(void);
void test_nghttp2_session_on_stream_close(void);
void test_nghttp2_session_on_ctrl_not_send(void);
void test_nghttp2_session_get_outbound_queue_size(void);
void test_nghttp2_session_get_effective_local_window_size(void);
void test_nghttp2_session_set_option(void);
void test_nghttp2_session_data_backoff_by_high_pri_frame(void);
void test_nghttp2_session_pack_data_with_padding(void);
void test_nghttp2_session_pack_headers_with_padding(void);
void test_nghttp2_pack_settings_payload(void);
void test_nghttp2_session_stream_dep_add(void);
void test_nghttp2_session_stream_dep_remove(void);
void test_nghttp2_session_stream_dep_add_subtree(void);
void test_nghttp2_session_stream_dep_remove_subtree(void);
void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void);
void test_nghttp2_session_stream_attach_item(void);
void test_nghttp2_session_stream_attach_item_subtree(void);
void test_nghttp2_session_stream_get_state(void);
void test_nghttp2_session_stream_get_something(void);
void test_nghttp2_session_find_stream(void);
void test_nghttp2_session_keep_closed_stream(void);
void test_nghttp2_session_keep_idle_stream(void);
void test_nghttp2_session_detach_idle_stream(void);
void test_nghttp2_session_large_dep_tree(void);
void test_nghttp2_session_graceful_shutdown(void);
void test_nghttp2_session_on_header_temporal_failure(void);
void test_nghttp2_session_recv_client_magic(void);
void test_nghttp2_session_delete_data_item(void);
void test_nghttp2_session_open_idle_stream(void);
void test_nghttp2_session_cancel_reserved_remote(void);
void test_nghttp2_session_reset_pending_headers(void);
void test_nghttp2_session_send_data_callback(void);
void test_nghttp2_session_on_begin_headers_temporal_failure(void);
void test_nghttp2_session_defer_then_close(void);
void test_nghttp2_session_detach_item_from_closed_stream(void);
void test_nghttp2_session_flooding(void);
void test_nghttp2_session_change_stream_priority(void);
void test_nghttp2_session_create_idle_stream(void);
void test_nghttp2_session_repeated_priority_change(void);
void test_nghttp2_session_repeated_priority_submission(void);
void test_nghttp2_session_set_local_window_size(void);
void test_nghttp2_session_cancel_from_before_frame_send(void);
void test_nghttp2_session_too_many_settings(void);
void test_nghttp2_session_removed_closed_stream(void);
void test_nghttp2_session_pause_data(void);
void test_nghttp2_session_no_closed_streams(void);
void test_nghttp2_session_set_stream_user_data(void);
void test_nghttp2_http_mandatory_headers(void);
void test_nghttp2_http_content_length(void);
void test_nghttp2_http_content_length_mismatch(void);
void test_nghttp2_http_non_final_response(void);
void test_nghttp2_http_trailer_headers(void);
void test_nghttp2_http_ignore_regular_header(void);
void test_nghttp2_http_ignore_content_length(void);
void test_nghttp2_http_record_request_method(void);
void test_nghttp2_http_push_promise(void);
void test_nghttp2_http_head_method_upgrade_workaround(void);
#endif /* NGHTTP2_SESSION_TEST_H */
+29
View File
@@ -0,0 +1,29 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_stream_test.h"
#include <CUnit/CUnit.h>
#include "nghttp2_stream.h"
+32
View File
@@ -0,0 +1,32 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_STREAM_TEST_H
#define NGHTTP2_STREAM_TEST_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif /* NGHTTP2_STREAM_TEST_H */
+431
View File
@@ -0,0 +1,431 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_test_helper.h"
#include <assert.h>
#include <CUnit/CUnit.h>
#include "nghttp2_helper.h"
#include "nghttp2_priority_spec.h"
int unpack_framebuf(nghttp2_frame *frame, nghttp2_bufs *bufs) {
nghttp2_buf *buf;
/* Assuming we have required data in first buffer. We don't decode
header block so, we don't mind its space */
buf = &bufs->head->buf;
return unpack_frame(frame, buf->pos, nghttp2_buf_len(buf));
}
int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len) {
int rv = 0;
const uint8_t *payload = in + NGHTTP2_FRAME_HDLEN;
size_t payloadlen = len - NGHTTP2_FRAME_HDLEN;
size_t payloadoff;
nghttp2_mem *mem;
mem = nghttp2_mem_default();
nghttp2_frame_unpack_frame_hd(&frame->hd, in);
switch (frame->hd.type) {
case NGHTTP2_HEADERS:
payloadoff = ((frame->hd.flags & NGHTTP2_FLAG_PADDED) > 0);
rv = nghttp2_frame_unpack_headers_payload(&frame->headers,
payload + payloadoff);
break;
case NGHTTP2_PRIORITY:
nghttp2_frame_unpack_priority_payload(&frame->priority, payload);
break;
case NGHTTP2_RST_STREAM:
nghttp2_frame_unpack_rst_stream_payload(&frame->rst_stream, payload);
break;
case NGHTTP2_SETTINGS:
rv = nghttp2_frame_unpack_settings_payload2(
&frame->settings.iv, &frame->settings.niv, payload, payloadlen, mem);
break;
case NGHTTP2_PUSH_PROMISE:
rv = nghttp2_frame_unpack_push_promise_payload(&frame->push_promise,
payload);
break;
case NGHTTP2_PING:
nghttp2_frame_unpack_ping_payload(&frame->ping, payload);
break;
case NGHTTP2_GOAWAY:
nghttp2_frame_unpack_goaway_payload2(&frame->goaway, payload, payloadlen,
mem);
break;
case NGHTTP2_WINDOW_UPDATE:
nghttp2_frame_unpack_window_update_payload(&frame->window_update, payload);
break;
case NGHTTP2_ALTSVC:
assert(payloadlen > 2);
nghttp2_frame_unpack_altsvc_payload2(&frame->ext, payload, payloadlen, mem);
break;
case NGHTTP2_ORIGIN:
rv = nghttp2_frame_unpack_origin_payload(&frame->ext, payload, payloadlen,
mem);
break;
default:
/* Must not be reachable */
assert(0);
}
return rv;
}
int strmemeq(const char *a, const uint8_t *b, size_t bn) {
const uint8_t *c;
if (!a || !b) {
return 0;
}
c = b + bn;
for (; *a && b != c && *a == *b; ++a, ++b)
;
return !*a && b == c;
}
int nvnameeq(const char *a, nghttp2_nv *nv) {
return strmemeq(a, nv->name, nv->namelen);
}
int nvvalueeq(const char *a, nghttp2_nv *nv) {
return strmemeq(a, nv->value, nv->valuelen);
}
void nva_out_init(nva_out *out) {
memset(out->nva, 0, sizeof(out->nva));
out->nvlen = 0;
}
void nva_out_reset(nva_out *out, nghttp2_mem *mem) {
size_t i;
for (i = 0; i < out->nvlen; ++i) {
mem->free(out->nva[i].name, NULL);
mem->free(out->nva[i].value, NULL);
}
memset(out->nva, 0, sizeof(out->nva));
out->nvlen = 0;
}
void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem) {
nghttp2_nv *onv = &out->nva[out->nvlen];
if (nv->namelen) {
onv->name = mem->malloc(nv->namelen, NULL);
memcpy(onv->name, nv->name, nv->namelen);
} else {
onv->name = NULL;
}
if (nv->valuelen) {
onv->value = mem->malloc(nv->valuelen, NULL);
memcpy(onv->value, nv->value, nv->valuelen);
} else {
onv->value = NULL;
}
onv->namelen = nv->namelen;
onv->valuelen = nv->valuelen;
onv->flags = nv->flags;
++out->nvlen;
}
ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem) {
ssize_t rv;
nghttp2_nv nv;
int inflate_flags;
nghttp2_buf_chain *ci;
nghttp2_buf *buf;
nghttp2_buf bp;
int fin;
size_t processed;
processed = 0;
for (ci = bufs->head; ci; ci = ci->next) {
buf = &ci->buf;
fin = nghttp2_buf_len(buf) == 0 || ci->next == NULL;
bp = *buf;
if (offset) {
size_t n;
n = nghttp2_min(offset, nghttp2_buf_len(&bp));
bp.pos += n;
offset -= n;
}
for (;;) {
inflate_flags = 0;
rv = nghttp2_hd_inflate_hd2(inflater, &nv, &inflate_flags, bp.pos,
nghttp2_buf_len(&bp), fin);
if (rv < 0) {
return rv;
}
bp.pos += rv;
processed += (size_t)rv;
if (inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
if (out) {
add_out(out, &nv, mem);
}
}
if (inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
break;
}
if ((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 &&
nghttp2_buf_len(&bp) == 0) {
break;
}
}
}
nghttp2_hd_inflate_end_headers(inflater);
return (ssize_t)processed;
}
int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater,
int32_t stream_id, uint8_t flags, const nghttp2_nv *nva,
size_t nvlen, nghttp2_mem *mem) {
nghttp2_nv *dnva;
nghttp2_frame frame;
int rv;
nghttp2_nv_array_copy(&dnva, nva, nvlen, mem);
nghttp2_frame_headers_init(&frame.headers, flags, stream_id,
NGHTTP2_HCAT_HEADERS, NULL, dnva, nvlen);
rv = nghttp2_frame_pack_headers(bufs, &frame.headers, deflater);
nghttp2_frame_headers_free(&frame.headers, mem);
return rv;
}
int pack_push_promise(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater,
int32_t stream_id, uint8_t flags,
int32_t promised_stream_id, const nghttp2_nv *nva,
size_t nvlen, nghttp2_mem *mem) {
nghttp2_nv *dnva;
nghttp2_frame frame;
int rv;
nghttp2_nv_array_copy(&dnva, nva, nvlen, mem);
nghttp2_frame_push_promise_init(&frame.push_promise, flags, stream_id,
promised_stream_id, dnva, nvlen);
rv = nghttp2_frame_pack_push_promise(bufs, &frame.push_promise, deflater);
nghttp2_frame_push_promise_free(&frame.push_promise, mem);
return rv;
}
int frame_pack_bufs_init(nghttp2_bufs *bufs) {
/* 1 for Pad Length */
return nghttp2_bufs_init2(bufs, 4096, 16, NGHTTP2_FRAME_HDLEN + 1,
nghttp2_mem_default());
}
void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size) {
/* 1 for Pad Length */
nghttp2_bufs_init2(bufs, chunk_size, 16, NGHTTP2_FRAME_HDLEN + 1,
nghttp2_mem_default());
}
static nghttp2_stream *open_stream_with_all(nghttp2_session *session,
int32_t stream_id, int32_t weight,
uint8_t exclusive,
nghttp2_stream *dep_stream) {
nghttp2_priority_spec pri_spec;
int32_t dep_stream_id;
if (dep_stream) {
dep_stream_id = dep_stream->stream_id;
} else {
dep_stream_id = 0;
}
nghttp2_priority_spec_init(&pri_spec, dep_stream_id, weight, exclusive);
return nghttp2_session_open_stream(session, stream_id,
NGHTTP2_STREAM_FLAG_NONE, &pri_spec,
NGHTTP2_STREAM_OPENED, NULL);
}
nghttp2_stream *open_stream(nghttp2_session *session, int32_t stream_id) {
return open_stream_with_all(session, stream_id, NGHTTP2_DEFAULT_WEIGHT, 0,
NULL);
}
nghttp2_stream *open_stream_with_dep(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream) {
return open_stream_with_all(session, stream_id, NGHTTP2_DEFAULT_WEIGHT, 0,
dep_stream);
}
nghttp2_stream *open_stream_with_dep_weight(nghttp2_session *session,
int32_t stream_id, int32_t weight,
nghttp2_stream *dep_stream) {
return open_stream_with_all(session, stream_id, weight, 0, dep_stream);
}
nghttp2_stream *open_stream_with_dep_excl(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream) {
return open_stream_with_all(session, stream_id, NGHTTP2_DEFAULT_WEIGHT, 1,
dep_stream);
}
nghttp2_outbound_item *create_data_ob_item(nghttp2_mem *mem) {
nghttp2_outbound_item *item;
item = mem->malloc(sizeof(nghttp2_outbound_item), NULL);
memset(item, 0, sizeof(nghttp2_outbound_item));
return item;
}
nghttp2_stream *open_sent_stream(nghttp2_session *session, int32_t stream_id) {
nghttp2_priority_spec pri_spec;
nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0);
return open_sent_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec,
NGHTTP2_STREAM_OPENED, NULL);
}
nghttp2_stream *open_sent_stream2(nghttp2_session *session, int32_t stream_id,
nghttp2_stream_state initial_state) {
nghttp2_priority_spec pri_spec;
nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0);
return open_sent_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec,
initial_state, NULL);
}
nghttp2_stream *open_sent_stream3(nghttp2_session *session, int32_t stream_id,
uint8_t flags,
nghttp2_priority_spec *pri_spec_in,
nghttp2_stream_state initial_state,
void *stream_user_data) {
nghttp2_stream *stream;
assert(nghttp2_session_is_my_stream_id(session, stream_id));
stream = nghttp2_session_open_stream(session, stream_id, flags, pri_spec_in,
initial_state, stream_user_data);
session->last_sent_stream_id =
nghttp2_max(session->last_sent_stream_id, stream_id);
session->next_stream_id =
nghttp2_max(session->next_stream_id, (uint32_t)stream_id + 2);
return stream;
}
nghttp2_stream *open_sent_stream_with_dep(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream) {
return open_sent_stream_with_dep_weight(session, stream_id,
NGHTTP2_DEFAULT_WEIGHT, dep_stream);
}
nghttp2_stream *open_sent_stream_with_dep_weight(nghttp2_session *session,
int32_t stream_id,
int32_t weight,
nghttp2_stream *dep_stream) {
nghttp2_stream *stream;
assert(nghttp2_session_is_my_stream_id(session, stream_id));
stream = open_stream_with_all(session, stream_id, weight, 0, dep_stream);
session->last_sent_stream_id =
nghttp2_max(session->last_sent_stream_id, stream_id);
session->next_stream_id =
nghttp2_max(session->next_stream_id, (uint32_t)stream_id + 2);
return stream;
}
nghttp2_stream *open_recv_stream(nghttp2_session *session, int32_t stream_id) {
nghttp2_priority_spec pri_spec;
nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0);
return open_recv_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec,
NGHTTP2_STREAM_OPENED, NULL);
}
nghttp2_stream *open_recv_stream2(nghttp2_session *session, int32_t stream_id,
nghttp2_stream_state initial_state) {
nghttp2_priority_spec pri_spec;
nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0);
return open_recv_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec,
initial_state, NULL);
}
nghttp2_stream *open_recv_stream3(nghttp2_session *session, int32_t stream_id,
uint8_t flags,
nghttp2_priority_spec *pri_spec_in,
nghttp2_stream_state initial_state,
void *stream_user_data) {
nghttp2_stream *stream;
assert(!nghttp2_session_is_my_stream_id(session, stream_id));
stream = nghttp2_session_open_stream(session, stream_id, flags, pri_spec_in,
initial_state, stream_user_data);
session->last_recv_stream_id =
nghttp2_max(session->last_recv_stream_id, stream_id);
return stream;
}
nghttp2_stream *open_recv_stream_with_dep(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream) {
return open_recv_stream_with_dep_weight(session, stream_id,
NGHTTP2_DEFAULT_WEIGHT, dep_stream);
}
nghttp2_stream *open_recv_stream_with_dep_weight(nghttp2_session *session,
int32_t stream_id,
int32_t weight,
nghttp2_stream *dep_stream) {
nghttp2_stream *stream;
assert(!nghttp2_session_is_my_stream_id(session, stream_id));
stream = open_stream_with_all(session, stream_id, weight, 0, dep_stream);
session->last_recv_stream_id =
nghttp2_max(session->last_recv_stream_id, stream_id);
return stream;
}
+158
View File
@@ -0,0 +1,158 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_TEST_HELPER_H
#define NGHTTP2_TEST_HELPER_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include "nghttp2_frame.h"
#include "nghttp2_hd.h"
#include "nghttp2_session.h"
#define MAKE_NV(NAME, VALUE) \
{ \
(uint8_t *)(NAME), (uint8_t *)(VALUE), sizeof((NAME)) - 1, \
sizeof((VALUE)) - 1, NGHTTP2_NV_FLAG_NONE \
}
#define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0]))
#define assert_nv_equal(A, B, len, mem) \
do { \
size_t alloclen = sizeof(nghttp2_nv) * len; \
const nghttp2_nv *sa = A, *sb = B; \
nghttp2_nv *a = mem->malloc(alloclen, NULL); \
nghttp2_nv *b = mem->malloc(alloclen, NULL); \
ssize_t i_; \
memcpy(a, sa, alloclen); \
memcpy(b, sb, alloclen); \
nghttp2_nv_array_sort(a, len); \
nghttp2_nv_array_sort(b, len); \
for (i_ = 0; i_ < (ssize_t)len; ++i_) { \
CU_ASSERT(nghttp2_nv_equal(&a[i_], &b[i_])); \
} \
mem->free(b, NULL); \
mem->free(a, NULL); \
} while (0);
int unpack_framebuf(nghttp2_frame *frame, nghttp2_bufs *bufs);
int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len);
int strmemeq(const char *a, const uint8_t *b, size_t bn);
int nvnameeq(const char *a, nghttp2_nv *nv);
int nvvalueeq(const char *a, nghttp2_nv *nv);
typedef struct {
nghttp2_nv nva[256];
size_t nvlen;
} nva_out;
void nva_out_init(nva_out *out);
void nva_out_reset(nva_out *out, nghttp2_mem *mem);
void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem);
ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem);
int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater,
int32_t stream_id, uint8_t flags, const nghttp2_nv *nva,
size_t nvlen, nghttp2_mem *mem);
int pack_push_promise(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater,
int32_t stream_id, uint8_t flags,
int32_t promised_stream_id, const nghttp2_nv *nva,
size_t nvlen, nghttp2_mem *mem);
int frame_pack_bufs_init(nghttp2_bufs *bufs);
void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size);
nghttp2_stream *open_stream(nghttp2_session *session, int32_t stream_id);
nghttp2_stream *open_stream_with_dep(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream);
nghttp2_stream *open_stream_with_dep_weight(nghttp2_session *session,
int32_t stream_id, int32_t weight,
nghttp2_stream *dep_stream);
nghttp2_stream *open_stream_with_dep_excl(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream);
nghttp2_outbound_item *create_data_ob_item(nghttp2_mem *mem);
/* Opens stream. This stream is assumed to be sent from |session|,
and session->last_sent_stream_id and session->next_stream_id will
be adjusted accordingly. */
nghttp2_stream *open_sent_stream(nghttp2_session *session, int32_t stream_id);
nghttp2_stream *open_sent_stream2(nghttp2_session *session, int32_t stream_id,
nghttp2_stream_state initial_state);
nghttp2_stream *open_sent_stream3(nghttp2_session *session, int32_t stream_id,
uint8_t flags,
nghttp2_priority_spec *pri_spec_in,
nghttp2_stream_state initial_state,
void *stream_user_data);
nghttp2_stream *open_sent_stream_with_dep(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream);
nghttp2_stream *open_sent_stream_with_dep_weight(nghttp2_session *session,
int32_t stream_id,
int32_t weight,
nghttp2_stream *dep_stream);
/* Opens stream. This stream is assumed to be received by |session|,
and session->last_recv_stream_id will be adjusted accordingly. */
nghttp2_stream *open_recv_stream(nghttp2_session *session, int32_t stream_id);
nghttp2_stream *open_recv_stream2(nghttp2_session *session, int32_t stream_id,
nghttp2_stream_state initial_state);
nghttp2_stream *open_recv_stream3(nghttp2_session *session, int32_t stream_id,
uint8_t flags,
nghttp2_priority_spec *pri_spec_in,
nghttp2_stream_state initial_state,
void *stream_user_data);
nghttp2_stream *open_recv_stream_with_dep(nghttp2_session *session,
int32_t stream_id,
nghttp2_stream *dep_stream);
nghttp2_stream *open_recv_stream_with_dep_weight(nghttp2_session *session,
int32_t stream_id,
int32_t weight,
nghttp2_stream *dep_stream);
#endif /* NGHTTP2_TEST_HELPER_H */
+23
View File
@@ -0,0 +1,23 @@
# nghttp2 - HTTP/2 C Library
# Copyright (c) 2012 Tatsuhiro Tsujikawa
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
EXTRA_DIST = cacert.pem index.html privkey.pem
+533
View File
@@ -0,0 +1,533 @@
# Makefile.in generated by automake 1.16.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
# nghttp2 - HTTP/2 C Library
# Copyright (c) 2012 Tatsuhiro Tsujikawa
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
false; \
elif test -n '$(MAKE_HOST)'; then \
true; \
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
true; \
else \
false; \
fi; \
}
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
subdir = tests/testdata
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_boost_asio.m4 \
$(top_srcdir)/m4/ax_boost_base.m4 \
$(top_srcdir)/m4/ax_boost_system.m4 \
$(top_srcdir)/m4/ax_boost_thread.m4 \
$(top_srcdir)/m4/ax_check_compile_flag.m4 \
$(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \
$(top_srcdir)/m4/ax_python_devel.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
SOURCES =
DIST_SOURCES =
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
am__DIST_COMMON = $(srcdir)/Makefile.in
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
APPLDFLAGS = @APPLDFLAGS@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BOOST_ASIO_LIB = @BOOST_ASIO_LIB@
BOOST_CPPFLAGS = @BOOST_CPPFLAGS@
BOOST_LDFLAGS = @BOOST_LDFLAGS@
BOOST_SYSTEM_LIB = @BOOST_SYSTEM_LIB@
BOOST_THREAD_LIB = @BOOST_THREAD_LIB@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CUNIT_CFLAGS = @CUNIT_CFLAGS@
CUNIT_LIBS = @CUNIT_LIBS@
CXX = @CXX@
CXX1XCXXFLAGS = @CXX1XCXXFLAGS@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
CYTHON = @CYTHON@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
EXTRACFLAG = @EXTRACFLAG@
FGREP = @FGREP@
GREP = @GREP@
HAVE_CXX14 = @HAVE_CXX14@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
JANSSON_CFLAGS = @JANSSON_CFLAGS@
JANSSON_LIBS = @JANSSON_LIBS@
JEMALLOC_LIBS = @JEMALLOC_LIBS@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBCARES_CFLAGS = @LIBCARES_CFLAGS@
LIBCARES_LIBS = @LIBCARES_LIBS@
LIBEVENT_OPENSSL_CFLAGS = @LIBEVENT_OPENSSL_CFLAGS@
LIBEVENT_OPENSSL_LIBS = @LIBEVENT_OPENSSL_LIBS@
LIBEV_CFLAGS = @LIBEV_CFLAGS@
LIBEV_LIBS = @LIBEV_LIBS@
LIBMRUBY_CFLAGS = @LIBMRUBY_CFLAGS@
LIBMRUBY_LIBS = @LIBMRUBY_LIBS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
LIBXML2_LIBS = @LIBXML2_LIBS@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
LT_REVISION = @LT_REVISION@
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OPENSSL_CFLAGS = @OPENSSL_CFLAGS@
OPENSSL_LIBS = @OPENSSL_LIBS@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_VERSION_NUM = @PACKAGE_VERSION_NUM@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PYTHON = @PYTHON@
PYTHON_CPPFLAGS = @PYTHON_CPPFLAGS@
PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
PYTHON_EXTRA_LDFLAGS = @PYTHON_EXTRA_LDFLAGS@
PYTHON_EXTRA_LIBS = @PYTHON_EXTRA_LIBS@
PYTHON_LIBS = @PYTHON_LIBS@
PYTHON_PLATFORM = @PYTHON_PLATFORM@
PYTHON_PREFIX = @PYTHON_PREFIX@
PYTHON_SITE_PKG = @PYTHON_SITE_PKG@
PYTHON_VERSION = @PYTHON_VERSION@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@
SYSTEMD_LIBS = @SYSTEMD_LIBS@
TESTLDADD = @TESTLDADD@
VERSION = @VERSION@
WARNCFLAGS = @WARNCFLAGS@
WARNCXXFLAGS = @WARNCXXFLAGS@
ZLIB_CFLAGS = @ZLIB_CFLAGS@
ZLIB_LIBS = @ZLIB_LIBS@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
pkgpyexecdir = @pkgpyexecdir@
pkgpythondir = @pkgpythondir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
pyexecdir = @pyexecdir@
pythondir = @pythondir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
EXTRA_DIST = cacert.pem index.html privkey.pem
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tests/testdata/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --gnu tests/testdata/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
tags TAGS:
ctags CTAGS:
cscope cscopelist:
distdir: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) distdir-am
distdir-am: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
cscopelist-am ctags-am distclean distclean-generic \
distclean-libtool distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags-am uninstall uninstall-am
.PRECIOUS: Makefile
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
+14
View File
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICKTCCAdOgAwIBAgIJAIsolheWrwMZMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV
BAYTAlVTMQswCQYDVQQIDAJDQTENMAsGA1UEBwwEQ2l0eTESMBAGA1UECgwJU3Bk
eSBUZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3QxHTAbBgkqhkiG9w0BCQEWDnNwZHlA
bG9jYWxob3N0MB4XDTEyMDMwMTE5MTI0NVoXDTIzMDUxOTE5MTI0NVowcDELMAkG
A1UEBhMCVVMxCzAJBgNVBAgMAkNBMQ0wCwYDVQQHDARDaXR5MRIwEAYDVQQKDAlT
cGR5IFRlc3QxEjAQBgNVBAMMCWxvY2FsaG9zdDEdMBsGCSqGSIb3DQEJARYOc3Bk
eUBsb2NhbGhvc3QwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAw/2MgzAdlJDm29qH
ZlAibgs9mH+8keOtsRrb4B1PiCcZoHvN9eCVZ4WnzT+0zhHF+nO3YfwVFVC3w7TF
7fLB3QIDAQABo1AwTjAdBgNVHQ4EFgQUVP2Jw9RX6BB76aV5x2qk5qsrAIQwHwYD
VR0jBBgwFoAUVP2Jw9RX6BB76aV5x2qk5qsrAIQwDAYDVR0TBAUwAwEB/zANBgkq
hkiG9w0BAQUFAANBAKd9M5FzQLEZW1KPe9/XNZlgxZ2g3EC5Krxo5I4Ul3MnIYS9
u4K8t/iprhgOzjFH6+8LVk9v0Za+gU+K43CpUo4=
-----END CERTIFICATE-----
+1
View File
@@ -0,0 +1 @@
<html><body>small</body></html>
+9
View File
@@ -0,0 +1,9 @@
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBAMP9jIMwHZSQ5tvah2ZQIm4LPZh/vJHjrbEa2+AdT4gnGaB7zfXg
lWeFp80/tM4Rxfpzt2H8FRVQt8O0xe3ywd0CAwEAAQJBAIQ8PGP/QNYOdlT8OsLj
aneJCgQsm1Rro7ONBbFO1WxslvA6+uJsx4Rs8zLiS8cyqmJ/lmGa7zhwYSOvFQPa
XgECIQDgIcgM/2C67peTm1diKKIoGVVKFCfdRi+Dje6mTl2TQQIhAN/bcFWbG73j
cUVlIsr9Wk1dJzjPPWKeyirF1qd/WbOdAiEApTsCOeLCssxV3jF02B5QfPNAFx6I
zO2C9Z7awque/IECIGCHW3VOoTPMs7dc2Rf3D810cclJdArmtf6juOAZRjDxAiBS
AC+H685IBJ99N5nCbF9NWYIVSkuiKVQ8POYVZX+0Jg==
-----END RSA PRIVATE KEY-----