diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-28 03:38:59 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-28 03:38:59 -0400 |
commit | e69874791daf88461c6813e5133bf775055ea2bf (patch) | |
tree | 147e4c0e721f778ed2ec3313c909c2dcd0f6e907 /test.c | |
parent | c10bcfa7def7a1093d78dcb15fd95388a633fc99 (diff) | |
download | libfhp-e69874791daf88461c6813e5133bf775055ea2bf.tar.bz2 libfhp-e69874791daf88461c6813e5133bf775055ea2bf.zip |
add cl_parser test
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -32,6 +32,7 @@ basic_str = "GET / HTTP/1.1\r\n" "Host: pablotron.org\r\n" "Connection: close\r\n" + "Content-Length: 123456\r\n" "Transfer-Encoding: deflate, chunked\r\n" "\r\n"; @@ -191,6 +192,52 @@ test_te_parser(void) { } } +/******************/ +/* cl parser test */ +/******************/ + +static char * +cl_parser_tests[] = { + " 12345 ", + "100", + "00120", + "123123123123", + "18446744073709551615", // UINT64_MAX + // "18446744073709551616", // UINT64_MAX + 1 + // "184--46744073709551615", // test embedded garbage + // "18446744073709551615 abc ", // test trailing garbage + NULL +}; + +static void +test_cl_parser(void) { + for (size_t i = 0; cl_parser_tests[i]; i++) { + fhp_err_t err; + + // get test string + char * const s = cl_parser_tests[i]; + + fprintf(stderr, "cl testing: \"%s\"\n", s); + + // init parser + fhp_cl_parser_t p; + fhp_cl_parser_init(&p); + + // parse data + if ((err = fhp_cl_parser_push(&p, (uint8_t*) s, strlen(s))) != FHP_OK) { + die("test_cl_parser", "fhp_cl_parser_push", err); + } + + // finish parsing + uint64_t val; + if ((err = fhp_cl_parser_done(&p, &val)) != FHP_OK) { + die("test_cl_parser", "fhp_cl_parser_push", err); + } + + fprintf(stderr, "cl test: \"%s\", val = %lu\n", s, val); + } +} + int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); @@ -198,6 +245,7 @@ int main(int argc, char *argv[]) { test_basic(); test_percent(); test_te_parser(); + test_cl_parser(); return EXIT_SUCCESS; } |