added test for config parser

This commit is contained in:
overflowerror 2019-03-12 17:34:56 +01:00
parent 81a2ba362c
commit aaf97aa645
3 changed files with 43 additions and 3 deletions

View file

@ -5,7 +5,7 @@ LDFLAGS = -lpthread -lrt
BIN_NAME = cfloor BIN_NAME = cfloor
OBJS = obj/networking.o obj/linked.o obj/logging.o obj/signals.o obj/headers.o obj/misc.o obj/status.o obj/files.o obj/mime.o obj/cgi.o obj/util.o obj/ssl.o OBJS = obj/networking.o obj/linked.o obj/logging.o obj/signals.o obj/headers.o obj/misc.o obj/status.o obj/files.o obj/mime.o obj/cgi.o obj/util.o obj/ssl.o obj/config.o
DEPS = $(OBJS:%.o=%.d) DEPS = $(OBJS:%.o=%.d)
all: $(BIN_NAME) all: $(BIN_NAME)

View file

@ -15,6 +15,9 @@
#include "signals.h" #include "signals.h"
#include "headers.h" #include "headers.h"
#include "util.h" #include "util.h"
#include "config.h"
#include "files.h"
#include "cgi.h"
bool global = true; bool global = true;
bool overall = true; bool overall = true;
@ -234,6 +237,29 @@ void testHeaders() {
headers_free(&headers); headers_free(&headers);
} }
void testConfig() {
struct config* config = config_parse(fopen("test.conf", "r"));
checkNull(config, "null check");
checkInt(config->nrBinds, 1, "bind no check");
checkString(config->binds[0]->addr, "0.0.0.0", "bind addr check");
checkString(config->binds[0]->port, "80", "bind port check");
checkInt(config->binds[0]->nrSites, 1, "site no check");
checkInt(config->binds[0]->sites[0]->nrHostnames, 1, "site hostname no check");
checkString(config->binds[0]->sites[0]->hostnames[0], "example.com", "site hostname check");
checkString(config->binds[0]->sites[0]->documentRoot, "/var/www", "site document root check");
checkInt(config->binds[0]->sites[0]->nrHandlers, 1, "handler no check");
checkString(config->binds[0]->sites[0]->handlers[0]->dir, "/", "handler dir check");
checkInt(config->binds[0]->sites[0]->handlers[0]->type, FILE_HANDLER_NO, "handler type no check");
checkVoid(config->binds[0]->sites[0]->handlers[0]->handler, &fileHandler, "handler ptr check");
checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/var/www", "handler settings root check");
checkInt(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.number, 1, "handler settings index no");
checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.files[0], "index.html", "handler settings index check");
config_destroy(config);
}
void test(const char* name, void (*testFunction)()) { void test(const char* name, void (*testFunction)()) {
printf("%s\n", name); printf("%s\n", name);
printf("%.*s\n", (int) strlen(name), printf("%.*s\n", (int) strlen(name),
@ -246,11 +272,15 @@ void test(const char* name, void (*testFunction)()) {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
/**test("logging", &testLogging);
test("util", &testUtil); test("util", &testUtil);
test("linked lists", &testLinkedList); test("linked lists", &testLinkedList);
test("logging", &testLogging);
test("signals", &testTimers); test("signals", &testTimers);
test("headers", &testHeaders); test("headers", &testHeaders);*/
setLogging(stderr, DEFAULT_LOGLEVEL, true);
test("config", &testConfig);
printf("\nOverall: %s\n", overall ? "OK" : "FAILED"); printf("\nOverall: %s\n", overall ? "OK" : "FAILED");

10
test.conf Normal file
View file

@ -0,0 +1,10 @@
bind 0.0.0.0:80 {
site {
hostname = example.com
root = /var/www
handler / {
type = file
index = index.html
}
}
}