forked from boazsegev/facil.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
87 lines (74 loc) · 2.1 KB
/
tests.c
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
80
81
82
83
84
85
86
87
#include "tests/mustache.c.h"
#include <fio.h>
#include <fiobj.h>
#include <http.h>
#include "resp_parser.h"
void resp_test(void);
int main(void) {
fio_test();
mustache_test();
fiobj_test();
http_tests();
resp_test();
}
void resp_test(void) {
const char OK[] = "+OK\r\n";
const char array_x3_i[] = "*3\r\n$3\r\nfoo\r\n$-1\r\n$3\r\nbar\r\n:-42\r\n";
resp_parser_s parser;
memset(&parser, 0, sizeof(parser));
FIO_ASSERT(!resp_parse(&parser, OK, sizeof(OK) - 1),
"RESP parser didn't parse the whole of the OK response data.");
FIO_ASSERT(!resp_parse(&parser, array_x3_i, sizeof(array_x3_i) - 1),
"RESP parser didn't parse the whole of the Array response data "
"(or parsed more).");
}
static int resp_on_number(resp_parser_s *parser, int64_t num) {
fprintf(stderr, "%ld\n", (long)num);
(void)parser;
return 0;
}
static int resp_on_okay(resp_parser_s *parser) {
fprintf(stderr, "OK\n");
(void)parser;
return 0;
}
static int resp_on_null(resp_parser_s *parser) {
fprintf(stderr, "NULL\n");
(void)parser;
return 0;
}
static int resp_on_start_string(resp_parser_s *parser, size_t str_len) {
fprintf(stderr, "starting string %ld long\n", (long)str_len);
(void)parser;
return 0;
}
static int resp_on_string_chunk(resp_parser_s *parser, void *data, size_t len) {
fprintf(stderr, "%.*s", (int)len, (char *)data);
(void)parser;
return 0;
}
static int resp_on_end_string(resp_parser_s *parser) {
fprintf(stderr, "\n");
(void)parser;
return 0;
}
static int resp_on_err_msg(resp_parser_s *parser, void *data, size_t len) {
fprintf(stderr, "Error message: %.*s\n", (int)len, (char *)data);
(void)parser;
return 0;
}
static int resp_on_start_array(resp_parser_s *parser, size_t array_len) {
fprintf(stderr, "starting array with %ld items\n", (long)array_len);
(void)parser;
return 0;
}
static int resp_on_message(resp_parser_s *parser) {
fprintf(stderr, "--- complete message ---\n");
(void)parser;
return 0;
}
static int resp_on_parser_error(resp_parser_s *parser) {
fprintf(stderr, "--- PARSER ERROR ---\n");
(void)parser;
return 0;
}