2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2012 Twist Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "nghttp2_npn_test.h"
29 #include <CUnit/CUnit.h>
30 #include <nghttp2/nghttp2.h>
32 static void http2(void) {
33 const unsigned char p[] = {8, 'h', 't', 't', 'p', '/', '1', '.',
34 '1', 5, 'h', '2', '-', '1', '4', 6,
35 's', 'p', 'd', 'y', '/', '3'};
38 CU_ASSERT(1 == nghttp2_select_next_protocol(&out, &outlen, p, sizeof(p)));
39 CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen);
40 CU_ASSERT(memcmp(NGHTTP2_PROTO_VERSION_ID, out, outlen) == 0);
43 static void http11(void) {
44 const unsigned char spdy[] = {
45 6, 's', 'p', 'd', 'y', '/', '4', 8, 's', 'p', 'd', 'y', '/',
46 '2', '.', '1', 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
51 nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy)));
52 CU_ASSERT(8 == outlen);
53 CU_ASSERT(memcmp("http/1.1", out, outlen) == 0);
56 static void no_overlap(void) {
57 const unsigned char spdy[] = {
58 6, 's', 'p', 'd', 'y', '/', '4', 8, 's', 'p', 'd', 'y', '/',
59 '2', '.', '1', 8, 'h', 't', 't', 'p', '/', '1', '.', '0',
61 unsigned char outlen = 0;
62 unsigned char *out = NULL;
64 nghttp2_select_next_protocol(&out, &outlen, spdy, sizeof(spdy)));
65 CU_ASSERT(0 == outlen);
66 CU_ASSERT(NULL == out);
69 void test_nghttp2_npn(void) {