From d256f7551cf9e0485dd7a30465dbbca3adc28041 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 26 May 2023 14:16:35 +0200 Subject: [PATCH] add tests --- http.c | 2 +- webserver.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/http.c b/http.c index 6ce72c0..c17781f 100644 --- a/http.c +++ b/http.c @@ -393,7 +393,7 @@ int processing (char *data, int len, conf_t *conf, char **pdata) case get_e: VERBOSE (DEBUG, PRINT ("Read file %s\n", filename)); len = readfile (&buffer, filename); - if (len == 0) { + if (len < 0) { sprintf (location, "http://%s/", conf->servername); len = error_404 (pdata, location); } else { diff --git a/webserver.c b/webserver.c index f10838e..ca44de7 100644 --- a/webserver.c +++ b/webserver.c @@ -206,9 +206,11 @@ int main (int argc, char *argv[]) // test: webserver.exe -p -1 2>&1 | grep -q 'incorrect port number' // test: webserver.exe -s 2>&1 | grep -q 'missing server name' // test: webserver.exe -r 2>&1 | grep -q 'missing directory name' -// test: webserver.exe > test.log & pid=$!; sleep 1; kill -QUIT $pid; grep -q 'Listening socket on port 8080' test.log -// test: webserver.exe -p 8000 > test.log & pid=$!; sleep 1; kill -ABRT $pid; grep -q 'Listening socket on port 8000' test.log -// test: webserver.exe -c iso-8859-1 -r webroot -s localhost & pid=$!; sleep 1; curl http://localhost:8080/index.html -v > test; kill -TERM $pid; grep -q 'Test' test +// test: webserver.exe >& test.log & pid=$!; sleep 1; kill -QUIT $pid; grep -q 'Listening socket on port 8080' test.log +// test: webserver.exe -p 8000 >& test.log & pid=$!; sleep 1; kill -ABRT $pid; grep -q 'Listening socket on port 8000' test.log +// test: webserver.exe -c iso-8859-1 -r webroot -s localhost >&/dev/null & pid=$!; sleep 1; curl http://localhost:8080/index.html -v > test; kill -TERM $pid; grep -q 'Test' test +// test: webserver.exe -v 3 -p 8001 >&/dev/null & pid=$!; sleep 1; curl http://localhost:8001/index.html -v > test; kill -TERM $pid +// test: webserver.exe -c iso-8859-1 -r webroot -s localhost >&/dev/null & pid=$!; sleep 1; curl http://localhost:8080/not_found.html -v > test; kill -TERM $pid; grep -q '404' test /* vim: set ts=4 sw=4 et: */ -- 2.30.2