From 6ac53d4c783340ae9139c7f4dcfe9bfddace5892 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 25 Sep 2016 02:57:21 +0200 Subject: runserver: reimplemented http server without libevent yeah, this patch implements a "complete" http server for static files. It is not the best code possible, and would be easily DDoS'able if used in production, as it spawns a thread for each request, without limiting. I'm sickish and this is the best code I can deliver now. At least it works! ;) --- tests/blogc-runserver/check_mime.c | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/blogc-runserver/check_mime.c (limited to 'tests/blogc-runserver/check_mime.c') diff --git a/tests/blogc-runserver/check_mime.c b/tests/blogc-runserver/check_mime.c new file mode 100644 index 0000000..5d11766 --- /dev/null +++ b/tests/blogc-runserver/check_mime.c @@ -0,0 +1,92 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2015-2016 Rafael G. Martins + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include +#include +#include +#include "../../src/blogc-runserver/mime.h" + + +int +__wrap_access(const char *pathname, int mode) +{ + assert_string_equal(pathname, mock_type(const char*)); + assert_int_equal(mode, F_OK); + return mock_type(int); +} + + +static void +test_guess_content_type(void **state) +{ + assert_string_equal(br_mime_guess_content_type("foo.html"), "text/html"); + assert_string_equal(br_mime_guess_content_type("foo.jpg"), "image/jpeg"); + assert_string_equal(br_mime_guess_content_type("foo.mp4"), "video/mp4"); + assert_string_equal(br_mime_guess_content_type("foo.bola"), "application/octet-stream"); +} + + +static void +test_guess_index(void **state) +{ + char *t; + will_return(__wrap_access, "dir/index.html"); + will_return(__wrap_access, 0); + t = br_mime_guess_index("dir"); + assert_string_equal(t, "dir/index.html"); + free(t); + will_return(__wrap_access, "dir/index.html"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.htm"); + will_return(__wrap_access, 0); + t = br_mime_guess_index("dir"); + assert_string_equal(t, "dir/index.htm"); + free(t); + will_return(__wrap_access, "dir/index.html"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.htm"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.shtml"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.xml"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.txt"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.xhtml"); + will_return(__wrap_access, 0); + t = br_mime_guess_index("dir"); + assert_string_equal(t, "dir/index.xhtml"); + free(t); + will_return(__wrap_access, "dir/index.html"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.htm"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.shtml"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.xml"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.txt"); + will_return(__wrap_access, 1); + will_return(__wrap_access, "dir/index.xhtml"); + will_return(__wrap_access, 1); + assert_null(br_mime_guess_index("dir")); +} + + +int +main(void) +{ + const UnitTest tests[] = { + unit_test(test_guess_content_type), + unit_test(test_guess_index), + }; + return run_tests(tests); +} -- cgit v1.2.3-18-g5258