You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
lighttpd2/src/tests.c

62 lines
1.1 KiB

#include <stdio.h>
#include "base.h"
#include "log.h"
#include "http_request_parser.h"
#include "config_parser.h"
int request_test() {
chunkqueue *cq;
request *req;
http_request_ctx *ctx;
handler_t res;
cq = chunkqueue_new();
req = request_new();
ctx = http_request_parser_new(req, cq);
chunkqueue_append_mem(cq, CONST_STR_LEN(
"GET / HTTP/1.1\r\n"
"Host: www.example.com\r\n"
"\r\n"
"abc"
));
res = http_request_parse(NULL, NULL, ctx);
if (res != HANDLER_GO_ON) {
fprintf(stderr, "Parser return %i", res);
}
assert(req->http_method == HTTP_METHOD_GET);
assert(cq->length == 3);
http_request_parser_free(ctx);
return res == HANDLER_GO_ON ? 0 : 1;
}
int main() {
server *srv;
guint32 ip, netmask;
assert(parse_ipv4("10.0.3.8/24", &ip, &netmask));
printf("parsed ip: %s\n", inet_ntoa(*(struct in_addr*) &ip));
printf("parsed netmask: %s\n", inet_ntoa(*(struct in_addr*) &netmask));
guint8 ipv6[16];
guint network;
GString *s;
assert(parse_ipv6("::ffff:192.168.0.1/80", ipv6, &network));
s = ipv6_tostring(ipv6);
printf("parsed ipv6: %s/%u\n", s->str, network);
request_test();
return 0;
srv = server_new();
return 0;
}