1 Star 1 Fork 44

API_chacuo / facil.io

forked from 三字经 / facil.io 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tests.c 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
Bo 提交于 2018-10-01 01:57 . Test mime registry initialization
#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;
}
C
1
https://gitee.com/laoxin_chacuo/facil.io.git
git@gitee.com:laoxin_chacuo/facil.io.git
laoxin_chacuo
facil.io
facil.io
master

搜索帮助