summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-26 21:50:55 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-26 21:50:55 -0400
commit4780bd9c0286b149ab51aae8a5937a823660bb51 (patch)
tree7dcd74f14d3b4692c11e45c2b71807a8ad4d522b
parent907004a179d476481da9f613cccdabb5cca306ac (diff)
downloadlibfhp-4780bd9c0286b149ab51aae8a5937a823660bb51.tar.bz2
libfhp-4780bd9c0286b149ab51aae8a5937a823660bb51.zip
add die() to test
-rw-r--r--test.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/test.c b/test.c
index 3d16363..3749ce7 100644
--- a/test.c
+++ b/test.c
@@ -6,6 +6,23 @@
#define UNUSED(a) ((void) (a))
+static void die(
+ char *test,
+ char *fn,
+ fhp_err_t err
+) {
+ char buf[1024];
+
+ if (fhp_strerror(err, buf, sizeof(buf)) == FHP_OK) {
+ fprintf(stderr, "ERROR: %s(): %s(): %s\n", test, fn, buf);
+ } else {
+ fprintf(stderr, "ERROR: die(): fhp_strerror() failed\n");
+ }
+
+ /* exit app */
+ exit(EXIT_FAILURE);
+}
+
static const char *
str_test_basic =
"GET / HTTP/1.1\r\n"
@@ -20,10 +37,18 @@ test_basic_cb(
uint8_t * const buf,
size_t len
) {
+ fhp_err_t err;
+
UNUSED(fhp);
UNUSED(buf);
- fprintf(stderr, "test_basic_cb(): token = %u, len = %lu\n", token, len);
+ // get token name
+ char token_buf[64];
+ if ((err = fhp_strtoken(token, token_buf, sizeof(token_buf))) != FHP_OK)
+ return false;
+
+ // debug
+ fprintf(stderr, "test_basic_cb(): token = %s, len = %lu\n", token_buf, len);
// return success
return true;
@@ -31,21 +56,16 @@ test_basic_cb(
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);
+ die("test_basic", "fhp_init", err);
}
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);
+ die("test_basic", "fhp_push", err);
}
}