From 40e8fc960e0b6315a918be990e1e3a0df7ee516f Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Wed, 15 Feb 2012 12:07:25 -0800 Subject: [PATCH] Create a test that explicitly checks that a key exists only once in a name/value block. --- tests/main.c | 2 + tests/spdylay_frame_test.c | 86 ++++++++++++++++++++++++++++++++++++++ tests/spdylay_frame_test.h | 1 + 3 files changed, 89 insertions(+) diff --git a/tests/main.c b/tests/main.c index f144a84f..f670504b 100644 --- a/tests/main.c +++ b/tests/main.c @@ -134,6 +134,8 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "frame_nv_sort", test_spdylay_frame_nv_sort) || !CU_add_test(pSuite, "frame_nv_downcase", test_spdylay_frame_nv_downcase) || + !CU_add_test(pSuite, "frame_nv_downcase", + test_spdylay_frame_pack_nv_duplicate_keys) || !CU_add_test(pSuite, "stream_add_pushed_stream", test_spdylay_stream_add_pushed_stream)) { CU_cleanup_registry(); diff --git a/tests/spdylay_frame_test.c b/tests/spdylay_frame_test.c index 73a22e95..b9b59a62 100644 --- a/tests/spdylay_frame_test.c +++ b/tests/spdylay_frame_test.c @@ -60,6 +60,92 @@ void test_spdylay_frame_unpack_nv() spdylay_frame_nv_del(nv); } +void test_spdylay_frame_pack_nv_duplicate_keys() +{ + int i; + uint8_t out[1024]; + const char *nv_src[] = { + "method", "GET", + "scheme", "https", + "url", "/", + "X-hEad", "foo", + "x-heaD", "bar", + "version", "HTTP/1.1", + NULL + }; + char **nv = spdylay_frame_nv_copy(nv_src); + spdylay_frame_nv_downcase(nv); + spdylay_frame_nv_sort(nv); + size_t inlen = spdylay_frame_pack_nv(out, nv); + const uint8_t *outptr = out; + int pairs = spdylay_get_uint16(outptr); + CU_ASSERT(pairs == 5); + outptr += 2; + + int len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 6); + CU_ASSERT(memcmp(outptr, "method", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 3); + CU_ASSERT(memcmp(outptr, "GET", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 6); + CU_ASSERT(memcmp(outptr, "scheme", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 5); + CU_ASSERT(memcmp(outptr, "https", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 3); + CU_ASSERT(memcmp(outptr, "url", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 1); + CU_ASSERT(memcmp(outptr, "/", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 7); + CU_ASSERT(memcmp(outptr, "version", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 8); + CU_ASSERT(memcmp(outptr, "HTTP/1.1", len) == 0); + outptr += len; + + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 6); + CU_ASSERT(memcmp(outptr, "x-head", len) == 0); + outptr += len; + + len = spdylay_get_uint16(outptr); + outptr += 2; + CU_ASSERT(len == 7); + CU_ASSERT(memcmp(outptr, "foo\0bar", len) == 0); + outptr += len; + + spdylay_frame_nv_del(nv); +} + void test_spdylay_frame_count_nv_space() { CU_ASSERT(83 == spdylay_frame_count_nv_space((char**)headers)); diff --git a/tests/spdylay_frame_test.h b/tests/spdylay_frame_test.h index 6484e565..7c62e836 100644 --- a/tests/spdylay_frame_test.h +++ b/tests/spdylay_frame_test.h @@ -26,6 +26,7 @@ #define SPDYLAY_FRAME_TEST_H void test_spdylay_frame_unpack_nv(); +void test_spdylay_frame_pack_nv_duplicate_keys(); void test_spdylay_frame_count_nv_space(); void test_spdylay_frame_count_unpack_nv_space(); void test_spdylay_frame_pack_ping();