summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/test.c b/test.c
index 42e6f78..66ada5a 100644
--- a/test.c
+++ b/test.c
@@ -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;
}