summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-26 18:51:11 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-26 18:51:11 -0400
commit8a3c72fdaabdc8c565a8c91361a2f8d38c892e1e (patch)
tree44d11e53a0345844b2d44319e5ad648454e249d4 /test.c
downloadlibfhp-8a3c72fdaabdc8c565a8c91361a2f8d38c892e1e.tar.bz2
libfhp-8a3c72fdaabdc8c565a8c91361a2f8d38c892e1e.zip
initial commit
Diffstat (limited to 'test.c')
-rw-r--r--test.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..3d16363
--- /dev/null
+++ b/test.c
@@ -0,0 +1,59 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <fhp/fhp.h>
+
+#define UNUSED(a) ((void) (a))
+
+static const char *
+str_test_basic =
+ "GET / HTTP/1.1\r\n"
+ "Host: pablotron.org\r\n"
+ "Connection: close\r\n"
+ "\r\n";
+
+static bool
+test_basic_cb(
+ fhp_t *fhp,
+ fhp_token_t token,
+ uint8_t * const buf,
+ size_t len
+) {
+ UNUSED(fhp);
+ UNUSED(buf);
+
+ fprintf(stderr, "test_basic_cb(): token = %u, len = %lu\n", token, len);
+
+ // return success
+ return true;
+}
+
+static void
+test_basic(void) {
+ char buf[1024];
+ fhp_err_t err;
+ fhp_t fhp;
+
+ if ((err = fhp_init(&fhp, test_basic_cb, NULL)) != FHP_OK) {
+ fhp_strerror(err, buf, sizeof(buf));
+ fprintf(stderr, "ERROR: fhp_init(): %s\n", buf);
+ exit(EXIT_FAILURE);
+ }
+
+ size_t len = strlen(str_test_basic);
+ if ((err = fhp_push(&fhp, (uint8_t*) str_test_basic, len)) != FHP_OK) {
+ fhp_strerror(err, buf, sizeof(buf));
+ fprintf(stderr, "ERROR: fhp_push(): %s\n", buf);
+ exit(EXIT_FAILURE);
+ }
+}
+
+int main(int argc, char *argv[]) {
+ UNUSED(argc);
+ UNUSED(argv);
+
+ test_basic();
+
+ return EXIT_SUCCESS;
+}