diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/chunk-parser-1.c | 58 | ||||
-rw-r--r-- | test/http-parser-1.c | 112 |
2 files changed, 85 insertions, 85 deletions
diff --git a/test/chunk-parser-1.c b/test/chunk-parser-1.c index 6804a17..335a39b 100644 --- a/test/chunk-parser-1.c +++ b/test/chunk-parser-1.c @@ -23,7 +23,7 @@ static void buf_set(const char *s) { struct mog_file *file; - http->chunked = 1; + http->_p.chunked = 1; reset(); tmpfp = tmpfile(); assert(tmpfp != NULL && "tmpfile(3) failed"); @@ -46,16 +46,16 @@ int main(void) buf_set("666\r\n"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_DONE); - assert(http->content_len == 0x666); - assert(http->chunk_state == MOG_CHUNK_STATE_DATA); + assert(http->_p.content_len == 0x666); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DATA); } if ("incomplete chunk") { buf_set("666\r"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_CONTINUE); - assert(http->content_len == 0x666); - assert(http->chunk_state == MOG_CHUNK_STATE_SIZE); + assert(http->_p.content_len == 0x666); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_SIZE); } if ("bad chunk") { @@ -68,8 +68,8 @@ int main(void) buf_set("abcde; foo=bar\r\n"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_DONE); - assert(http->content_len == 0xabcde); - assert(http->chunk_state == MOG_CHUNK_STATE_DATA); + assert(http->_p.content_len == 0xabcde); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DATA); } if ("chunk with complete header and data") { @@ -77,8 +77,8 @@ int main(void) buf_set("5\r\nabcde"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_CONTINUE); - assert(http->content_len == 0); - assert(http->chunk_state == MOG_CHUNK_STATE_SIZE); + assert(http->_p.content_len == 0); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_SIZE); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde", sizeof(tmp))); } @@ -88,33 +88,33 @@ int main(void) buf_set("5\r\nabcde\r\n3"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_CONTINUE); - assert(http->content_len == 3); - assert(http->chunk_state == MOG_CHUNK_STATE_SIZE); + assert(http->_p.content_len == 3); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_SIZE); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } if ("multiple chunks with end") { char tmp[8]; buf_set("5\r\nabcde\r\n3\r\n123\r\n0\r\n\r\n"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_DONE); - assert(http->chunk_state == MOG_CHUNK_STATE_DONE); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DONE); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde123", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } if ("multiple chunks with trailer") { char tmp[8]; buf_set("5\r\nabcde\r\n3\r\n123\r\n0\r\nFoo: bar\r\n\r\n"); state = mog_chunk_parse(http, buf, len); - assert(http->chunk_state == MOG_CHUNK_STATE_DONE); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DONE); assert(state == MOG_PARSER_DONE); - assert(http->content_len == 0); + assert(http->_p.content_len == 0); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde123", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } if ("multiple chunks with almost end") { @@ -122,11 +122,11 @@ int main(void) buf_set("5\r\nabcde\r\n3\r\n123\r\n0\r\n"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_DONE); - assert(http->chunk_state == MOG_CHUNK_STATE_DATA); - assert(http->content_len == 0); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DATA); + assert(http->_p.content_len == 0); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde123", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } if ("multiple chunks with almost end (more)") { @@ -134,11 +134,11 @@ int main(void) buf_set("5\r\nabcde\r\n3\r\n123\r\n0\r\n\r"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_CONTINUE); - assert(http->chunk_state == MOG_CHUNK_STATE_TRAILER); - assert(http->content_len == 0); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_TRAILER); + assert(http->_p.content_len == 0); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde123", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } if ("multiple chunks with incomplete") { @@ -146,11 +146,11 @@ int main(void) buf_set("5\r\nabcde\r\n3\r\n12"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_DONE); - assert(http->chunk_state == MOG_CHUNK_STATE_DATA); - assert(http->content_len == 1); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DATA); + assert(http->_p.content_len == 1); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abcde12", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } if ("incomplete data") { @@ -158,11 +158,11 @@ int main(void) buf_set("666\r\nabc"); state = mog_chunk_parse(http, buf, len); assert(state == MOG_PARSER_DONE); - assert(http->chunk_state == MOG_CHUNK_STATE_DATA); - assert(http->content_len == (0x666 - sizeof(tmp))); + assert(http->_p.chunk_state == MOG_CHUNK_STATE_DATA); + assert(http->_p.content_len == (0x666 - sizeof(tmp))); assert(sizeof(tmp) == pread(tmpfd, tmp, sizeof(tmp), 0)); assert(0 == memcmp(tmp, "abc", sizeof(tmp))); - assert(http->offset == len); + assert(http->_p.offset == len); } reset(); diff --git a/test/http-parser-1.c b/test/http-parser-1.c index 688e0a5..861c19f 100644 --- a/test/http-parser-1.c +++ b/test/http-parser-1.c @@ -14,8 +14,8 @@ static void assert_path_equal(const char *str) { size_t slen = strlen(str); - assert(0 == memcmp(str, buf + http->path_tip, slen)); - assert(http->path_end == http->path_tip + slen); + assert(0 == memcmp(str, buf + http->_p.path_tip, slen)); + assert(http->_p.path_end == http->_p.path_tip + slen); } static void reset(void) @@ -36,9 +36,9 @@ int main(void) if ("normal HTTP GET request") { buf_set("GET /foo HTTP/1.1\r\nHost: 127.6.6.6\r\n\r\n"); state = mog_http_parse(http, buf, len); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent && "not persistent"); + assert(http->_p.persistent && "not persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -46,9 +46,9 @@ int main(void) if ("normal HTTP GET request with redundant leading slash") { buf_set("GET //foo HTTP/1.1\r\nHost: 127.6.6.6\r\n\r\n"); state = mog_http_parse(http, buf, len); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent && "not persistent"); + assert(http->_p.persistent && "not persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -59,9 +59,9 @@ int main(void) "Connection: close\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent == 0 && "should not be persistent"); + assert(http->_p.persistent == 0 && "should not be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -71,9 +71,9 @@ int main(void) "Connection:\r\n keep-alive\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -99,9 +99,9 @@ int main(void) "Host: 127.6.6.6\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->http_method == MOG_HTTP_METHOD_HEAD + assert(http->_p.http_method == MOG_HTTP_METHOD_HEAD && "http_method should be HEAD "); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -113,13 +113,13 @@ int main(void) "\r\n" "partial body request"); state = mog_http_parse(http, buf, len); - assert(http->content_len == 12345); - assert(http->http_method == MOG_HTTP_METHOD_PUT + assert(http->_p.content_len == 12345); + assert(http->_p.http_method == MOG_HTTP_METHOD_PUT && "http_method should be PUT"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); - assert(strcmp(buf + http->offset, "partial body request") == 0 + assert(strcmp(buf + http->_p.offset, "partial body request") == 0 && "buffer repositioned to body start"); } @@ -130,14 +130,14 @@ int main(void) "\r\n" "16\r\npartial..."); state = mog_http_parse(http, buf, len); - assert(http->chunked); - assert(http->has_trailer_md5 == 0); - assert(http->http_method == MOG_HTTP_METHOD_PUT + assert(http->_p.chunked); + assert(http->_p.has_trailer_md5 == 0); + assert(http->_p.http_method == MOG_HTTP_METHOD_PUT && "http_method should be PUT"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); - assert(strcmp(buf + http->offset, "16\r\npartial...") == 0 + assert(strcmp(buf + http->_p.offset, "16\r\npartial...") == 0 && "buffer repositioned to body start"); } @@ -149,16 +149,16 @@ int main(void) "\r\n" "16\r\npartial..."); state = mog_http_parse(http, buf, len); - assert(http->range_beg == 666); - assert(http->range_end == 666666); - assert(http->has_content_range == 1); - assert(http->has_trailer_md5 == 0); - assert(http->http_method == MOG_HTTP_METHOD_PUT + assert(http->_p.range_beg == 666); + assert(http->_p.range_end == 666666); + assert(http->_p.has_content_range == 1); + assert(http->_p.has_trailer_md5 == 0); + assert(http->_p.http_method == MOG_HTTP_METHOD_PUT && "http_method should be PUT"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); - assert(strcmp(buf + http->offset, "16\r\npartial...") == 0 + assert(strcmp(buf + http->_p.offset, "16\r\npartial...") == 0 && "buffer repositioned to body start"); } @@ -170,14 +170,14 @@ int main(void) "\r\n" "16\r\npartial..."); state = mog_http_parse(http, buf, len); - assert(http->chunked); - assert(http->has_trailer_md5 == 1); - assert(http->http_method == MOG_HTTP_METHOD_PUT + assert(http->_p.chunked); + assert(http->_p.has_trailer_md5 == 1); + assert(http->_p.http_method == MOG_HTTP_METHOD_PUT && "http_method should be PUT"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); - assert(strcmp(buf + http->offset, "16\r\npartial...") == 0 + assert(strcmp(buf + http->_p.offset, "16\r\npartial...") == 0 && "buffer repositioned to body start"); } @@ -186,11 +186,11 @@ int main(void) "Host: 127.6.6.6\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->content_len == 0); - assert(http->has_trailer_md5 == 0); - assert(http->http_method == MOG_HTTP_METHOD_DELETE + assert(http->_p.content_len == 0); + assert(http->_p.has_trailer_md5 == 0); + assert(http->_p.http_method == MOG_HTTP_METHOD_DELETE && "http_method should be DELETE"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -200,11 +200,11 @@ int main(void) "Host: 127.6.6.6\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->content_len == 0); - assert(http->has_trailer_md5 == 0); - assert(http->http_method == MOG_HTTP_METHOD_MKCOL + assert(http->_p.content_len == 0); + assert(http->_p.has_trailer_md5 == 0); + assert(http->_p.http_method == MOG_HTTP_METHOD_MKCOL && "http_method should be MKCOL"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -215,12 +215,12 @@ int main(void) "Range: bytes=5-55\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->has_range == 1); - assert(http->range_beg == 5 && "range_beg didn't match"); - assert(http->range_end == 55 && "range_end didn't match"); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.has_range == 1); + assert(http->_p.range_beg == 5 && "range_beg didn't match"); + assert(http->_p.range_end == 55 && "range_end didn't match"); + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -231,12 +231,12 @@ int main(void) "Range: bytes=-55\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->has_range == 1); - assert(http->range_beg == -1 && "range_beg didn't match"); - assert(http->range_end == 55 && "range_end didn't match"); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.has_range == 1); + assert(http->_p.range_beg == -1 && "range_beg didn't match"); + assert(http->_p.range_end == 55 && "range_end didn't match"); + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } @@ -247,12 +247,12 @@ int main(void) "Range: bytes=55-\r\n" "\r\n"); state = mog_http_parse(http, buf, len); - assert(http->has_range == 1); - assert(http->range_beg == 55 && "range_beg didn't match"); - assert(http->range_end == -1 && "range_end didn't match"); - assert(http->http_method == MOG_HTTP_METHOD_GET + assert(http->_p.has_range == 1); + assert(http->_p.range_beg == 55 && "range_beg didn't match"); + assert(http->_p.range_end == -1 && "range_end didn't match"); + assert(http->_p.http_method == MOG_HTTP_METHOD_GET && "http_method should be GET"); - assert(http->persistent == 1 && "should be persistent"); + assert(http->_p.persistent == 1 && "should be persistent"); assert(state == MOG_PARSER_DONE && "parser not done"); assert_path_equal("/foo"); } |