2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tst_comstack.c,v 1.1 2007-01-11 10:30:41 adam Exp $
12 #include <yaz/comstack.h>
14 static void tst_http_request(void)
17 /* no content, no headers */
18 const char *http_buf =
19 /*123456789012345678 */
24 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
25 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
26 YAZ_CHECK_EQ(cs_complete_http(http_buf, 16), 0);
27 YAZ_CHECK_EQ(cs_complete_http(http_buf, 17), 0);
28 YAZ_CHECK_EQ(cs_complete_http(http_buf, 18), 18);
29 YAZ_CHECK_EQ(cs_complete_http(http_buf, 19), 18);
32 /* one header, no content */
33 const char *http_buf =
34 /*123456789012345678 */
40 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
41 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
42 YAZ_CHECK_EQ(cs_complete_http(http_buf, 34), 0);
43 YAZ_CHECK_EQ(cs_complete_http(http_buf, 35), 35);
44 YAZ_CHECK_EQ(cs_complete_http(http_buf, 36), 35);
47 /* one content-length header, length 0 */
48 const char *http_buf =
49 /*123456789012345678 */
51 "Content-Length: 0\r\n"
55 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
56 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
57 YAZ_CHECK_EQ(cs_complete_http(http_buf, 35), 0);
58 YAZ_CHECK_EQ(cs_complete_http(http_buf, 37), 37);
59 YAZ_CHECK_EQ(cs_complete_http(http_buf, 38), 37);
62 /* one content-length header, length 5 */
63 const char *http_buf =
64 /*123456789012345678 */
66 "Content-Length: 5\r\n"
71 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
72 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
73 YAZ_CHECK_EQ(cs_complete_http(http_buf, 41), 0);
74 YAZ_CHECK_EQ(cs_complete_http(http_buf, 42), 42);
75 YAZ_CHECK_EQ(cs_complete_http(http_buf, 43), 42);
78 /* LF only in GET, one content-length header, length 5 */
79 const char *http_buf =
80 /*123456789012345678 */
82 "Content-Length: 5\r\n"
87 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
88 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
89 YAZ_CHECK_EQ(cs_complete_http(http_buf, 40), 0);
90 YAZ_CHECK_EQ(cs_complete_http(http_buf, 41), 41);
91 YAZ_CHECK_EQ(cs_complete_http(http_buf, 42), 41);
94 /* LF only in all places, one content-length header, length 5 */
95 const char *http_buf =
96 /*123456789012345678 */
101 "GET / HTTP/1.0\r\n";
103 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
104 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
105 YAZ_CHECK_EQ(cs_complete_http(http_buf, 38), 0);
106 YAZ_CHECK_EQ(cs_complete_http(http_buf, 39), 39);
107 YAZ_CHECK_EQ(cs_complete_http(http_buf, 40), 39);
111 /* one header, unknown transfer-encoding (no content) */
112 const char *http_buf =
113 /*12345678901234567890123456789 */
115 "Transfer-Encoding: chunke_\r\n"
117 "GET / HTTP/1.0\r\n";
119 YAZ_CHECK_EQ(cs_complete_http(http_buf, 45), 0);
120 YAZ_CHECK_EQ(cs_complete_http(http_buf, 46), 46);
124 /* one header, one chunk */
125 const char *http_buf =
126 /*12345678901234567890123456789 */
128 "Transfer-Encoding: chunked\r\n"
133 "GET / HTTP/1.0\r\n";
135 YAZ_CHECK_EQ(cs_complete_http(http_buf, 58), 0);
136 YAZ_CHECK_EQ(cs_complete_http(http_buf, 59), 59);
140 /* one header, two chunks */
141 const char *http_buf =
142 /*12345678901234567890123456789 */
144 "Transfer-Encoding: chunked\r\n"
151 "GET / HTTP/1.0\r\n";
153 YAZ_CHECK_EQ(cs_complete_http(http_buf, 64), 0);
154 YAZ_CHECK_EQ(cs_complete_http(http_buf, 65), 65);
158 static void tst_http_response(void)
161 /* unlimited content, no headers */
162 const char *http_buf =
163 /*123456789012345678 */
164 "HTTP/1.1 200 OK\r\n"
166 "HTTP/1.1 200 OK\r\n";
168 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
169 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
170 YAZ_CHECK_EQ(cs_complete_http(http_buf, 24), 0);
173 /* response, content */
174 const char *http_buf =
175 /*123456789012345678 */
176 "HTTP/1.1 200 OK\r\n"
177 "Content-Length: 2\r\n"
180 "HTTP/1.1 200 OK\r\n";
182 YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0);
183 YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0);
184 YAZ_CHECK_EQ(cs_complete_http(http_buf, 39), 0);
185 YAZ_CHECK_EQ(cs_complete_http(http_buf, 40), 40);
186 YAZ_CHECK_EQ(cs_complete_http(http_buf, 41), 40);
191 int main (int argc, char **argv)
193 YAZ_CHECK_INIT(argc, argv);
203 * indent-tabs-mode: nil
205 * vim: shiftwidth=4 tabstop=8 expandtab