summaryrefslogtreecommitdiff
path: root/test.c
blob: 3749ce73c8166a61ae3265a4cce50f3abb69261c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <fhp/fhp.h>

#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"
  "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
) {
  fhp_err_t err;

  UNUSED(fhp);
  UNUSED(buf);

  // 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;
}

static void
test_basic(void) {
  fhp_err_t err;
  fhp_t fhp;

  if ((err = fhp_init(&fhp, test_basic_cb, NULL)) != FHP_OK) {
    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) {
    die("test_basic", "fhp_push", err);
  }
}

int main(int argc, char *argv[]) {
  UNUSED(argc);
  UNUSED(argv);

  test_basic();

  return EXIT_SUCCESS;
}