From 4ebfa021ba415e1a265021aa85ec5d33845303fa Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Tue, 7 Feb 2012 14:16:55 -0800 Subject: [PATCH 1/2] Use pkg-config to get the cunit library. --- tests/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 18b4a779..f66d60c6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -36,8 +36,8 @@ HFILES = spdylay_pq_test.h spdylay_map_test.h spdylay_queue_test.h \ main_SOURCES = $(HFILES) $(OBJECTS) main_LDADD = ${top_builddir}/lib/libspdylay.la -main_LDFLAGS = -static -lcunit -lncurses -AM_CFLAGS = -Wall -g -O2 -I${top_srcdir}/lib -I${top_srcdir}/lib/includes +main_LDFLAGS = -static `pkg-config --libs cunit` -lncurses +AM_CFLAGS = -Wall -g -O2 -I${top_srcdir}/lib -I${top_srcdir}/lib/includes `pkg-config --cflags cunit` TESTS = main From 4298dc8a519c2e1abb0df166bb916b233b0ac6ca Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Tue, 7 Feb 2012 14:17:38 -0800 Subject: [PATCH 2/2] Erase the stream from the map after calling the on_stream_close callback --- lib/spdylay_session.c | 2 +- tests/main.c | 2 ++ tests/spdylay_session_test.c | 34 ++++++++++++++++++++++++++++++++++ tests/spdylay_session_test.h | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/spdylay_session.c b/lib/spdylay_session.c index f0b22e2a..ada02052 100644 --- a/lib/spdylay_session.c +++ b/lib/spdylay_session.c @@ -358,13 +358,13 @@ int spdylay_session_close_stream(spdylay_session *session, int32_t stream_id, { spdylay_stream *stream = spdylay_session_get_stream(session, stream_id); if(stream) { - spdylay_map_erase(&session->streams, stream_id); if(stream->state != SPDYLAY_STREAM_INITIAL && session->callbacks.on_stream_close_callback) { session->callbacks.on_stream_close_callback(session, stream_id, status_code, session->user_data); } + spdylay_map_erase(&session->streams, stream_id); spdylay_stream_free(stream); free(stream); return 0; diff --git a/tests/main.c b/tests/main.c index 006f24d9..5e56beeb 100644 --- a/tests/main.c +++ b/tests/main.c @@ -107,6 +107,8 @@ int main(int argc, char* argv[]) test_spdylay_session_get_next_ob_item) || !CU_add_test(pSuite, "session_pop_next_ob_item", test_spdylay_session_pop_next_ob_item) || + !CU_add_test(pSuite, "session_on_stream_close", + test_spdylay_session_on_stream_close) || !CU_add_test(pSuite, "frame_unpack_nv", test_spdylay_frame_unpack_nv) || !CU_add_test(pSuite, "frame_count_nv_space", test_spdylay_frame_count_nv_space) || diff --git a/tests/spdylay_session_test.c b/tests/spdylay_session_test.c index a67a9003..59ddd0e1 100644 --- a/tests/spdylay_session_test.c +++ b/tests/spdylay_session_test.c @@ -883,3 +883,37 @@ void test_spdylay_session_pop_next_ob_item() spdylay_session_del(session); } + +void stream_close_callback(spdylay_session *session, int32_t stream_id, + spdylay_status_code status_code, void *user_data) +{ + my_user_data* my_data = (my_user_data*)user_data; + void *stream_data = spdylay_session_get_stream_user_data(session, stream_id); + my_data->invalid = 1; + my_data->valid = stream_data != NULL ? 1 : 0; +} + +void test_spdylay_session_on_stream_close() +{ + spdylay_session *session; + spdylay_session_callbacks callbacks; + my_user_data user_data; + const char *nv[] = { NULL }; + spdylay_stream *stream; + int32_t stream_id = 1; + uint8_t pri = 3; + + memset(&callbacks, 0, sizeof(spdylay_session_callbacks)); + callbacks.on_stream_close_callback = stream_close_callback; + user_data.valid = 0; + user_data.invalid = 0; + + CU_ASSERT(spdylay_session_client_new(&session, &callbacks, &user_data) == 0); + stream = spdylay_session_open_stream(session, stream_id, SPDYLAY_FLAG_NONE, + pri, SPDYLAY_STREAM_OPENED, &user_data); + CU_ASSERT(stream != NULL); + CU_ASSERT(spdylay_session_close_stream(session, stream_id, SPDYLAY_OK) == 0); + CU_ASSERT(user_data.invalid == 1); /* Called the callback. */ + CU_ASSERT(user_data.valid == 1); + spdylay_session_del(session); +} diff --git a/tests/spdylay_session_test.h b/tests/spdylay_session_test.h index 66efd7bb..8385a2db 100644 --- a/tests/spdylay_session_test.h +++ b/tests/spdylay_session_test.h @@ -45,5 +45,6 @@ void test_spdylay_session_is_my_stream_id(); void test_spdylay_session_send_rst_stream(); void test_spdylay_session_get_next_ob_item(); void test_spdylay_session_pop_next_ob_item(); +void test_spdylay_session_on_stream_close(); #endif // SPDYLAY_SESSION_TEST_H