mirror of
https://github.com/lammertb/libhttp.git
synced 2025-12-22 04:02:04 +03:00
Autoformat public and private integration tests using clang-format
This commit is contained in:
208
test/private.c
208
test/private.c
@@ -37,136 +37,142 @@
|
|||||||
* http://check.sourceforge.net/doc/check_html/index.html
|
* http://check.sourceforge.net/doc/check_html/index.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
START_TEST (test_parse_http_message)
|
START_TEST(test_parse_http_message)
|
||||||
{
|
{
|
||||||
struct mg_request_info ri;
|
struct mg_request_info ri;
|
||||||
char empty[] = "";
|
char empty[] = "";
|
||||||
char req1[] = "GET / HTTP/1.1\r\n\r\n";
|
char req1[] = "GET / HTTP/1.1\r\n\r\n";
|
||||||
char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
|
char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
|
||||||
char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
|
char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
|
||||||
char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz\r\n\r\n";
|
char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz\r\n\r\n";
|
||||||
char req5[] = "GET / HTTP/1.1\r\n\r\n";
|
char req5[] = "GET / HTTP/1.1\r\n\r\n";
|
||||||
char req6[] = "G";
|
char req6[] = "G";
|
||||||
char req7[] = " blah ";
|
char req7[] = " blah ";
|
||||||
char req8[] = " HTTP/1.1 200 OK \n\n";
|
char req8[] = " HTTP/1.1 200 OK \n\n";
|
||||||
char req9[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";
|
char req9[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";
|
||||||
|
|
||||||
ck_assert_int_eq(sizeof(req9) - 1, parse_http_message(req9, sizeof(req9), &ri));
|
ck_assert_int_eq(sizeof(req9) - 1,
|
||||||
ck_assert_int_eq(1, ri.num_headers);
|
parse_http_message(req9, sizeof(req9), &ri));
|
||||||
|
ck_assert_int_eq(1, ri.num_headers);
|
||||||
|
|
||||||
ck_assert_int_eq(sizeof(req1) - 1, parse_http_message(req1, sizeof(req1), &ri));
|
ck_assert_int_eq(sizeof(req1) - 1,
|
||||||
ck_assert_str_eq("1.1", ri.http_version);
|
parse_http_message(req1, sizeof(req1), &ri));
|
||||||
ck_assert_int_eq(0, ri.num_headers);
|
ck_assert_str_eq("1.1", ri.http_version);
|
||||||
|
ck_assert_int_eq(0, ri.num_headers);
|
||||||
|
|
||||||
ck_assert_int_eq(-1, parse_http_message(req2, sizeof(req2), &ri));
|
ck_assert_int_eq(-1, parse_http_message(req2, sizeof(req2), &ri));
|
||||||
ck_assert_int_eq(0, parse_http_message(req3, sizeof(req3), &ri));
|
ck_assert_int_eq(0, parse_http_message(req3, sizeof(req3), &ri));
|
||||||
ck_assert_int_eq(0, parse_http_message(req6, sizeof(req6), &ri));
|
ck_assert_int_eq(0, parse_http_message(req6, sizeof(req6), &ri));
|
||||||
ck_assert_int_eq(0, parse_http_message(req7, sizeof(req7), &ri));
|
ck_assert_int_eq(0, parse_http_message(req7, sizeof(req7), &ri));
|
||||||
ck_assert_int_eq(0, parse_http_message(empty, 0, &ri));
|
ck_assert_int_eq(0, parse_http_message(empty, 0, &ri));
|
||||||
ck_assert_int_eq(sizeof(req8) - 1, parse_http_message(req8, sizeof(req8), &ri));
|
ck_assert_int_eq(sizeof(req8) - 1,
|
||||||
|
parse_http_message(req8, sizeof(req8), &ri));
|
||||||
|
|
||||||
/* TODO(lsm): Fix this. Header value may span multiple lines. */
|
/* TODO(lsm): Fix this. Header value may span multiple lines. */
|
||||||
ck_assert_int_eq(sizeof(req4) - 1, parse_http_message(req4, sizeof(req4), &ri));
|
ck_assert_int_eq(sizeof(req4) - 1,
|
||||||
ck_assert_str_eq("1.1", ri.http_version);
|
parse_http_message(req4, sizeof(req4), &ri));
|
||||||
ck_assert_int_eq(3, ri.num_headers);
|
ck_assert_str_eq("1.1", ri.http_version);
|
||||||
ck_assert_str_eq("A", ri.http_headers[0].name);
|
ck_assert_int_eq(3, ri.num_headers);
|
||||||
ck_assert_str_eq("foo bar", ri.http_headers[0].value);
|
ck_assert_str_eq("A", ri.http_headers[0].name);
|
||||||
ck_assert_str_eq("B", ri.http_headers[1].name);
|
ck_assert_str_eq("foo bar", ri.http_headers[0].value);
|
||||||
ck_assert_str_eq("bar", ri.http_headers[1].value);
|
ck_assert_str_eq("B", ri.http_headers[1].name);
|
||||||
ck_assert_str_eq("baz\r\n\r", ri.http_headers[2].name);
|
ck_assert_str_eq("bar", ri.http_headers[1].value);
|
||||||
ck_assert_str_eq("", ri.http_headers[2].value);
|
ck_assert_str_eq("baz\r\n\r", ri.http_headers[2].name);
|
||||||
|
ck_assert_str_eq("", ri.http_headers[2].value);
|
||||||
|
|
||||||
ck_assert_int_eq(sizeof(req5) - 1, parse_http_message(req5, sizeof(req5), &ri));
|
ck_assert_int_eq(sizeof(req5) - 1,
|
||||||
ck_assert_str_eq("GET", ri.request_method);
|
parse_http_message(req5, sizeof(req5), &ri));
|
||||||
ck_assert_str_eq("1.1", ri.http_version);
|
ck_assert_str_eq("GET", ri.request_method);
|
||||||
|
ck_assert_str_eq("1.1", ri.http_version);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_match_prefix)
|
START_TEST(test_match_prefix)
|
||||||
{
|
{
|
||||||
ck_assert_int_eq(4, match_prefix("/api", 4, "/api"));
|
ck_assert_int_eq(4, match_prefix("/api", 4, "/api"));
|
||||||
ck_assert_int_eq(3, match_prefix("/a/", 3, "/a/b/c"));
|
ck_assert_int_eq(3, match_prefix("/a/", 3, "/a/b/c"));
|
||||||
ck_assert_int_eq(-1, match_prefix("/a/", 3, "/ab/c"));
|
ck_assert_int_eq(-1, match_prefix("/a/", 3, "/ab/c"));
|
||||||
ck_assert_int_eq(4, match_prefix("/*/", 3, "/ab/c"));
|
ck_assert_int_eq(4, match_prefix("/*/", 3, "/ab/c"));
|
||||||
ck_assert_int_eq(6, match_prefix("**", 2, "/a/b/c"));
|
ck_assert_int_eq(6, match_prefix("**", 2, "/a/b/c"));
|
||||||
ck_assert_int_eq(2, match_prefix("/*", 2, "/a/b/c"));
|
ck_assert_int_eq(2, match_prefix("/*", 2, "/a/b/c"));
|
||||||
ck_assert_int_eq(2, match_prefix("*/*", 3, "/a/b/c"));
|
ck_assert_int_eq(2, match_prefix("*/*", 3, "/a/b/c"));
|
||||||
ck_assert_int_eq(5, match_prefix("**/", 3, "/a/b/c"));
|
ck_assert_int_eq(5, match_prefix("**/", 3, "/a/b/c"));
|
||||||
ck_assert_int_eq(5, match_prefix("**.foo|**.bar", 13, "a.bar"));
|
ck_assert_int_eq(5, match_prefix("**.foo|**.bar", 13, "a.bar"));
|
||||||
ck_assert_int_eq(2, match_prefix("a|b|cd", 6, "cdef"));
|
ck_assert_int_eq(2, match_prefix("a|b|cd", 6, "cdef"));
|
||||||
ck_assert_int_eq(2, match_prefix("a|b|c?", 6, "cdef"));
|
ck_assert_int_eq(2, match_prefix("a|b|c?", 6, "cdef"));
|
||||||
ck_assert_int_eq(1, match_prefix("a|?|cd", 6, "cdef"));
|
ck_assert_int_eq(1, match_prefix("a|?|cd", 6, "cdef"));
|
||||||
ck_assert_int_eq(-1, match_prefix("/a/**.cgi", 9, "/foo/bar/x.cgi"));
|
ck_assert_int_eq(-1, match_prefix("/a/**.cgi", 9, "/foo/bar/x.cgi"));
|
||||||
ck_assert_int_eq(12, match_prefix("/a/**.cgi", 9, "/a/bar/x.cgi"));
|
ck_assert_int_eq(12, match_prefix("/a/**.cgi", 9, "/a/bar/x.cgi"));
|
||||||
ck_assert_int_eq(5, match_prefix("**/", 3, "/a/b/c"));
|
ck_assert_int_eq(5, match_prefix("**/", 3, "/a/b/c"));
|
||||||
ck_assert_int_eq(-1, match_prefix("**/$", 4, "/a/b/c"));
|
ck_assert_int_eq(-1, match_prefix("**/$", 4, "/a/b/c"));
|
||||||
ck_assert_int_eq(5, match_prefix("**/$", 4, "/a/b/"));
|
ck_assert_int_eq(5, match_prefix("**/$", 4, "/a/b/"));
|
||||||
ck_assert_int_eq(0, match_prefix("$", 1, ""));
|
ck_assert_int_eq(0, match_prefix("$", 1, ""));
|
||||||
ck_assert_int_eq(-1, match_prefix("$", 1, "x"));
|
ck_assert_int_eq(-1, match_prefix("$", 1, "x"));
|
||||||
ck_assert_int_eq(1, match_prefix("*$", 2, "x"));
|
ck_assert_int_eq(1, match_prefix("*$", 2, "x"));
|
||||||
ck_assert_int_eq(1, match_prefix("/$", 2, "/"));
|
ck_assert_int_eq(1, match_prefix("/$", 2, "/"));
|
||||||
ck_assert_int_eq(-1, match_prefix("**/$", 4, "/a/b/c"));
|
ck_assert_int_eq(-1, match_prefix("**/$", 4, "/a/b/c"));
|
||||||
ck_assert_int_eq(5, match_prefix("**/$", 4, "/a/b/"));
|
ck_assert_int_eq(5, match_prefix("**/$", 4, "/a/b/"));
|
||||||
ck_assert_int_eq(0, match_prefix("*", 1, "/hello/"));
|
ck_assert_int_eq(0, match_prefix("*", 1, "/hello/"));
|
||||||
ck_assert_int_eq(-1, match_prefix("**.a$|**.b$", 11, "/a/b.b/"));
|
ck_assert_int_eq(-1, match_prefix("**.a$|**.b$", 11, "/a/b.b/"));
|
||||||
ck_assert_int_eq(6, match_prefix("**.a$|**.b$", 11, "/a/b.b"));
|
ck_assert_int_eq(6, match_prefix("**.a$|**.b$", 11, "/a/b.b"));
|
||||||
ck_assert_int_eq(6, match_prefix("**.a$|**.b$", 11, "/a/B.A"));
|
ck_assert_int_eq(6, match_prefix("**.a$|**.b$", 11, "/a/B.A"));
|
||||||
ck_assert_int_eq(5, match_prefix("**o$", 4, "HELLO"));
|
ck_assert_int_eq(5, match_prefix("**o$", 4, "HELLO"));
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_remove_double_dots_and_double_slashes)
|
START_TEST(test_remove_double_dots_and_double_slashes)
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
char before[20], after[20];
|
char before[20], after[20];
|
||||||
} data[] = {
|
} data[] = {
|
||||||
{"////a", "/a"},
|
{"////a", "/a"},
|
||||||
{"/.....", "/."},
|
{"/.....", "/."},
|
||||||
{"/......", "/"},
|
{"/......", "/"},
|
||||||
{"...", "..."},
|
{"...", "..."},
|
||||||
{"/...///", "/./"},
|
{"/...///", "/./"},
|
||||||
{"/a...///", "/a.../"},
|
{"/a...///", "/a.../"},
|
||||||
{"/.x", "/.x"},
|
{"/.x", "/.x"},
|
||||||
{"/\\", "/"},
|
{"/\\", "/"},
|
||||||
{"/a\\", "/a\\"},
|
{"/a\\", "/a\\"},
|
||||||
{"/a\\\\...", "/a\\."},
|
{"/a\\\\...", "/a\\."},
|
||||||
};
|
};
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(data); i++) {
|
for (i = 0; i < ARRAY_SIZE(data); i++) {
|
||||||
remove_double_dots_and_double_slashes(data[i].before);
|
remove_double_dots_and_double_slashes(data[i].before);
|
||||||
ck_assert_str_eq(data[i].before, data[i].after);
|
ck_assert_str_eq(data[i].before, data[i].after);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_is_valid_uri)
|
START_TEST(test_is_valid_uri)
|
||||||
{
|
{
|
||||||
ck_assert_int_eq(1, is_valid_uri("/api"));
|
ck_assert_int_eq(1, is_valid_uri("/api"));
|
||||||
ck_assert_int_eq(0, is_valid_uri("api"));
|
ck_assert_int_eq(0, is_valid_uri("api"));
|
||||||
ck_assert_int_eq(1, is_valid_uri("*"));
|
ck_assert_int_eq(1, is_valid_uri("*"));
|
||||||
ck_assert_int_eq(0, is_valid_uri("*xy"));
|
ck_assert_int_eq(0, is_valid_uri("*xy"));
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
Suite * make_private_suite (void) {
|
Suite *make_private_suite(void)
|
||||||
|
{
|
||||||
|
|
||||||
Suite * const suite = suite_create("Private");
|
Suite *const suite = suite_create("Private");
|
||||||
|
|
||||||
TCase * const http_message = tcase_create("HTTP Message");
|
TCase *const http_message = tcase_create("HTTP Message");
|
||||||
TCase * const url_parsing = tcase_create("URL Parsing");
|
TCase *const url_parsing = tcase_create("URL Parsing");
|
||||||
|
|
||||||
tcase_add_test(http_message, test_parse_http_message);
|
tcase_add_test(http_message, test_parse_http_message);
|
||||||
suite_add_tcase(suite, http_message);
|
suite_add_tcase(suite, http_message);
|
||||||
|
|
||||||
tcase_add_test(url_parsing, test_match_prefix);
|
tcase_add_test(url_parsing, test_match_prefix);
|
||||||
tcase_add_test(url_parsing, test_remove_double_dots_and_double_slashes);
|
tcase_add_test(url_parsing, test_remove_double_dots_and_double_slashes);
|
||||||
tcase_add_test(url_parsing, test_is_valid_uri);
|
tcase_add_test(url_parsing, test_is_valid_uri);
|
||||||
suite_add_tcase(suite, url_parsing);
|
suite_add_tcase(suite, url_parsing);
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|||||||
351
test/public.c
351
test/public.c
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#define mg_Sleep(x) (Sleep(x*1000))
|
#define mg_Sleep(x) (Sleep(x * 1000))
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#define mg_Sleep(x) (sleep(x))
|
#define mg_Sleep(x) (sleep(x))
|
||||||
@@ -38,253 +38,268 @@
|
|||||||
* http://check.sourceforge.net/doc/check_html/index.html
|
* http://check.sourceforge.net/doc/check_html/index.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
START_TEST (test_mg_version)
|
START_TEST(test_mg_version)
|
||||||
{
|
{
|
||||||
const char *ver = mg_version();
|
const char *ver = mg_version();
|
||||||
unsigned major=0, minor=0;
|
unsigned major = 0, minor = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ck_assert(ver != NULL);
|
ck_assert(ver != NULL);
|
||||||
ck_assert_str_eq(ver, CIVETWEB_VERSION);
|
ck_assert_str_eq(ver, CIVETWEB_VERSION);
|
||||||
|
|
||||||
/* check structure of version string */
|
|
||||||
ret = sscanf(ver, "%u.%u", &major, &minor);
|
|
||||||
ck_assert_int_eq(ret, 2);
|
|
||||||
ck_assert_uint_ge(major, 1);
|
|
||||||
|
|
||||||
|
/* check structure of version string */
|
||||||
|
ret = sscanf(ver, "%u.%u", &major, &minor);
|
||||||
|
ck_assert_int_eq(ret, 2);
|
||||||
|
ck_assert_uint_ge(major, 1);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_get_valid_options)
|
START_TEST(test_mg_get_valid_options)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const struct mg_option *default_options = mg_get_valid_options();
|
const struct mg_option *default_options = mg_get_valid_options();
|
||||||
|
|
||||||
ck_assert(default_options != NULL);
|
ck_assert(default_options != NULL);
|
||||||
|
|
||||||
for (i = 0; default_options[i].name != NULL; i++) {
|
for (i = 0; default_options[i].name != NULL; i++) {
|
||||||
ck_assert(default_options[i].name != NULL);
|
ck_assert(default_options[i].name != NULL);
|
||||||
ck_assert(strlen(default_options[i].name) > 0);
|
ck_assert(strlen(default_options[i].name) > 0);
|
||||||
ck_assert(((int)default_options[i].type) > 0);
|
ck_assert(((int)default_options[i].type) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ck_assert(i > 0);
|
ck_assert(i > 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_get_builtin_mime_type)
|
START_TEST(test_mg_get_builtin_mime_type)
|
||||||
{
|
{
|
||||||
ck_assert_str_eq(mg_get_builtin_mime_type("x.txt"), "text/plain");
|
ck_assert_str_eq(mg_get_builtin_mime_type("x.txt"), "text/plain");
|
||||||
ck_assert_str_eq(mg_get_builtin_mime_type("x.html"), "text/html");
|
ck_assert_str_eq(mg_get_builtin_mime_type("x.html"), "text/html");
|
||||||
ck_assert_str_eq(mg_get_builtin_mime_type("x.HTML"), "text/html");
|
ck_assert_str_eq(mg_get_builtin_mime_type("x.HTML"), "text/html");
|
||||||
ck_assert_str_eq(mg_get_builtin_mime_type("x.hTmL"), "text/html");
|
ck_assert_str_eq(mg_get_builtin_mime_type("x.hTmL"), "text/html");
|
||||||
ck_assert_str_eq(mg_get_builtin_mime_type("/abc/def/ghi.htm"), "text/html");
|
ck_assert_str_eq(mg_get_builtin_mime_type("/abc/def/ghi.htm"), "text/html");
|
||||||
ck_assert_str_eq(mg_get_builtin_mime_type("x.unknown_extention_xyz"), "text/plain");
|
ck_assert_str_eq(mg_get_builtin_mime_type("x.unknown_extention_xyz"),
|
||||||
|
"text/plain");
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_strncasecmp)
|
START_TEST(test_mg_strncasecmp)
|
||||||
{
|
{
|
||||||
ck_assert(mg_strncasecmp("abc", "abc", 3) == 0);
|
ck_assert(mg_strncasecmp("abc", "abc", 3) == 0);
|
||||||
ck_assert(mg_strncasecmp("abc", "abcd", 3) == 0);
|
ck_assert(mg_strncasecmp("abc", "abcd", 3) == 0);
|
||||||
ck_assert(mg_strncasecmp("abc", "abcd", 4) != 0);
|
ck_assert(mg_strncasecmp("abc", "abcd", 4) != 0);
|
||||||
ck_assert(mg_strncasecmp("a", "A", 1) == 0);
|
ck_assert(mg_strncasecmp("a", "A", 1) == 0);
|
||||||
|
|
||||||
ck_assert(mg_strncasecmp("A", "B", 1) < 0);
|
ck_assert(mg_strncasecmp("A", "B", 1) < 0);
|
||||||
ck_assert(mg_strncasecmp("A", "b", 1) < 0);
|
ck_assert(mg_strncasecmp("A", "b", 1) < 0);
|
||||||
ck_assert(mg_strncasecmp("a", "B", 1) < 0);
|
ck_assert(mg_strncasecmp("a", "B", 1) < 0);
|
||||||
ck_assert(mg_strncasecmp("a", "b", 1) < 0);
|
ck_assert(mg_strncasecmp("a", "b", 1) < 0);
|
||||||
ck_assert(mg_strncasecmp("b", "A", 1) > 0);
|
ck_assert(mg_strncasecmp("b", "A", 1) > 0);
|
||||||
ck_assert(mg_strncasecmp("B", "A", 1) > 0);
|
ck_assert(mg_strncasecmp("B", "A", 1) > 0);
|
||||||
ck_assert(mg_strncasecmp("b", "a", 1) > 0);
|
ck_assert(mg_strncasecmp("b", "a", 1) > 0);
|
||||||
ck_assert(mg_strncasecmp("B", "a", 1) > 0);
|
ck_assert(mg_strncasecmp("B", "a", 1) > 0);
|
||||||
|
|
||||||
ck_assert(mg_strncasecmp("xAx", "xBx", 3) < 0);
|
ck_assert(mg_strncasecmp("xAx", "xBx", 3) < 0);
|
||||||
ck_assert(mg_strncasecmp("xAx", "xbx", 3) < 0);
|
ck_assert(mg_strncasecmp("xAx", "xbx", 3) < 0);
|
||||||
ck_assert(mg_strncasecmp("xax", "xBx", 3) < 0);
|
ck_assert(mg_strncasecmp("xax", "xBx", 3) < 0);
|
||||||
ck_assert(mg_strncasecmp("xax", "xbx", 3) < 0);
|
ck_assert(mg_strncasecmp("xax", "xbx", 3) < 0);
|
||||||
ck_assert(mg_strncasecmp("xbx", "xAx", 3) > 0);
|
ck_assert(mg_strncasecmp("xbx", "xAx", 3) > 0);
|
||||||
ck_assert(mg_strncasecmp("xBx", "xAx", 3) > 0);
|
ck_assert(mg_strncasecmp("xBx", "xAx", 3) > 0);
|
||||||
ck_assert(mg_strncasecmp("xbx", "xax", 3) > 0);
|
ck_assert(mg_strncasecmp("xbx", "xax", 3) > 0);
|
||||||
ck_assert(mg_strncasecmp("xBx", "xax", 3) > 0);
|
ck_assert(mg_strncasecmp("xBx", "xax", 3) > 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_get_cookie)
|
START_TEST(test_mg_get_cookie)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
|
|
||||||
ck_assert_int_eq(-2, mg_get_cookie("", "foo", NULL, sizeof(buf)));
|
ck_assert_int_eq(-2, mg_get_cookie("", "foo", NULL, sizeof(buf)));
|
||||||
ck_assert_int_eq(-2, mg_get_cookie("", "foo", buf, 0));
|
ck_assert_int_eq(-2, mg_get_cookie("", "foo", buf, 0));
|
||||||
ck_assert_int_eq(-1, mg_get_cookie("", "foo", buf, sizeof(buf)));
|
ck_assert_int_eq(-1, mg_get_cookie("", "foo", buf, sizeof(buf)));
|
||||||
ck_assert_int_eq(-1, mg_get_cookie("", NULL, buf, sizeof(buf)));
|
ck_assert_int_eq(-1, mg_get_cookie("", NULL, buf, sizeof(buf)));
|
||||||
ck_assert_int_eq(1, mg_get_cookie("a=1; b=2; c; d", "a", buf, sizeof(buf)));
|
ck_assert_int_eq(1, mg_get_cookie("a=1; b=2; c; d", "a", buf, sizeof(buf)));
|
||||||
ck_assert_str_eq("1", buf);
|
ck_assert_str_eq("1", buf);
|
||||||
ck_assert_int_eq(1, mg_get_cookie("a=1; b=2; c; d", "b", buf, sizeof(buf)));
|
ck_assert_int_eq(1, mg_get_cookie("a=1; b=2; c; d", "b", buf, sizeof(buf)));
|
||||||
ck_assert_str_eq("2", buf);
|
ck_assert_str_eq("2", buf);
|
||||||
ck_assert_int_eq(3, mg_get_cookie("a=1; b=123", "b", buf, sizeof(buf)));
|
ck_assert_int_eq(3, mg_get_cookie("a=1; b=123", "b", buf, sizeof(buf)));
|
||||||
ck_assert_str_eq("123", buf);
|
ck_assert_str_eq("123", buf);
|
||||||
ck_assert_int_eq(-1, mg_get_cookie("a=1; b=2; c; d", "c", buf, sizeof(buf)));
|
ck_assert_int_eq(-1,
|
||||||
|
mg_get_cookie("a=1; b=2; c; d", "c", buf, sizeof(buf)));
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_md5)
|
START_TEST(test_mg_md5)
|
||||||
{
|
{
|
||||||
char buf[33];
|
char buf[33];
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
memset(buf, 77, sizeof(buf));
|
memset(buf, 77, sizeof(buf));
|
||||||
ret = mg_md5(buf, NULL);
|
ret = mg_md5(buf, NULL);
|
||||||
ck_assert_str_eq(buf, "d41d8cd98f00b204e9800998ecf8427e");
|
ck_assert_str_eq(buf, "d41d8cd98f00b204e9800998ecf8427e");
|
||||||
ck_assert_str_eq(ret, "d41d8cd98f00b204e9800998ecf8427e");
|
ck_assert_str_eq(ret, "d41d8cd98f00b204e9800998ecf8427e");
|
||||||
ck_assert_ptr_eq(ret, buf);
|
ck_assert_ptr_eq(ret, buf);
|
||||||
|
|
||||||
memset(buf, 77, sizeof(buf));
|
memset(buf, 77, sizeof(buf));
|
||||||
ret = mg_md5(buf, "The quick brown fox jumps over the lazy dog.", NULL);
|
ret = mg_md5(buf, "The quick brown fox jumps over the lazy dog.", NULL);
|
||||||
ck_assert_str_eq(buf, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
ck_assert_str_eq(buf, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
ck_assert_str_eq(ret, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
ck_assert_str_eq(ret, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
ck_assert_ptr_eq(ret, buf);
|
ck_assert_ptr_eq(ret, buf);
|
||||||
|
|
||||||
memset(buf, 77, sizeof(buf));
|
memset(buf, 77, sizeof(buf));
|
||||||
ret = mg_md5(buf, "", "The qu", "ick bro", "", "wn fox ju", "m", "ps over the la", "", "", "zy dog.", "", NULL);
|
ret = mg_md5(buf,
|
||||||
ck_assert_str_eq(buf, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
"",
|
||||||
ck_assert_str_eq(ret, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
"The qu",
|
||||||
ck_assert_ptr_eq(ret, buf);
|
"ick bro",
|
||||||
|
"",
|
||||||
|
"wn fox ju",
|
||||||
|
"m",
|
||||||
|
"ps over the la",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"zy dog.",
|
||||||
|
"",
|
||||||
|
NULL);
|
||||||
|
ck_assert_str_eq(buf, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
|
ck_assert_str_eq(ret, "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
|
ck_assert_ptr_eq(ret, buf);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_url_encode)
|
START_TEST(test_mg_url_encode)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
memset(buf, 77, sizeof(buf));
|
memset(buf, 77, sizeof(buf));
|
||||||
ret = mg_url_encode("abc", buf, sizeof(buf));
|
ret = mg_url_encode("abc", buf, sizeof(buf));
|
||||||
ck_assert_int_eq(3, ret);
|
ck_assert_int_eq(3, ret);
|
||||||
ck_assert_str_eq("abc", buf);
|
ck_assert_str_eq("abc", buf);
|
||||||
|
|
||||||
memset(buf, 77, sizeof(buf));
|
memset(buf, 77, sizeof(buf));
|
||||||
ret = mg_url_encode("a%b/c&d.e", buf, sizeof(buf));
|
ret = mg_url_encode("a%b/c&d.e", buf, sizeof(buf));
|
||||||
ck_assert_int_eq(15, ret);
|
ck_assert_int_eq(15, ret);
|
||||||
ck_assert_str_eq("a%25b%2fc%26d.e", buf);
|
ck_assert_str_eq("a%25b%2fc%26d.e", buf);
|
||||||
|
|
||||||
memset(buf, 77, sizeof(buf));
|
memset(buf, 77, sizeof(buf));
|
||||||
ret = mg_url_encode("%%%", buf, 4);
|
ret = mg_url_encode("%%%", buf, 4);
|
||||||
ck_assert_int_eq(-1, ret);
|
ck_assert_int_eq(-1, ret);
|
||||||
ck_assert_str_eq("%25", buf);
|
ck_assert_str_eq("%25", buf);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_url_decode)
|
START_TEST(test_mg_url_decode)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = mg_url_decode("abc", 3, buf, sizeof(buf), 0);
|
ret = mg_url_decode("abc", 3, buf, sizeof(buf), 0);
|
||||||
ck_assert_int_eq(ret, 3);
|
ck_assert_int_eq(ret, 3);
|
||||||
ck_assert_str_eq(buf, "abc");
|
ck_assert_str_eq(buf, "abc");
|
||||||
|
|
||||||
ret = mg_url_decode("abcdef", 3, buf, sizeof(buf), 0);
|
ret = mg_url_decode("abcdef", 3, buf, sizeof(buf), 0);
|
||||||
ck_assert_int_eq(ret, 3);
|
ck_assert_int_eq(ret, 3);
|
||||||
ck_assert_str_eq(buf, "abc");
|
ck_assert_str_eq(buf, "abc");
|
||||||
|
|
||||||
ret = mg_url_decode("x+y", 3, buf, sizeof(buf), 0);
|
ret = mg_url_decode("x+y", 3, buf, sizeof(buf), 0);
|
||||||
ck_assert_int_eq(ret, 3);
|
ck_assert_int_eq(ret, 3);
|
||||||
ck_assert_str_eq(buf, "x+y");
|
ck_assert_str_eq(buf, "x+y");
|
||||||
|
|
||||||
ret = mg_url_decode("x+y", 3, buf, sizeof(buf), 1);
|
ret = mg_url_decode("x+y", 3, buf, sizeof(buf), 1);
|
||||||
ck_assert_int_eq(ret, 3);
|
ck_assert_int_eq(ret, 3);
|
||||||
ck_assert_str_eq(buf, "x y");
|
ck_assert_str_eq(buf, "x y");
|
||||||
|
|
||||||
ret = mg_url_decode("%25", 3, buf, sizeof(buf), 1);
|
ret = mg_url_decode("%25", 3, buf, sizeof(buf), 1);
|
||||||
ck_assert_int_eq(ret, 1);
|
ck_assert_int_eq(ret, 1);
|
||||||
ck_assert_str_eq(buf, "%");
|
ck_assert_str_eq(buf, "%");
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
START_TEST (test_mg_start_stop_http_server)
|
START_TEST(test_mg_start_stop_http_server)
|
||||||
{
|
{
|
||||||
struct mg_context *ctx;
|
struct mg_context *ctx;
|
||||||
const char *OPTIONS[] = {
|
const char *OPTIONS[] = {
|
||||||
"document_root", ".",
|
"document_root", ".", "listening_ports", "8080", NULL,
|
||||||
"listening_ports", "8080",
|
};
|
||||||
NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
ctx = mg_start(NULL, NULL, OPTIONS);
|
ctx = mg_start(NULL, NULL, OPTIONS);
|
||||||
ck_assert(ctx != NULL);
|
ck_assert(ctx != NULL);
|
||||||
mg_Sleep(2);
|
mg_Sleep(2);
|
||||||
mg_stop(ctx);
|
mg_stop(ctx);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
START_TEST (test_mg_start_stop_https_server)
|
START_TEST(test_mg_start_stop_https_server)
|
||||||
{
|
{
|
||||||
struct mg_context *ctx;
|
struct mg_context *ctx;
|
||||||
const char *OPTIONS[] = {
|
const char *OPTIONS[] = {
|
||||||
"document_root", ".",
|
"document_root",
|
||||||
"listening_ports", "8080,8443s",
|
".",
|
||||||
"ssl_certificate", "resources/ssl_cert.pem", // TODO: check working path of CI test system
|
"listening_ports",
|
||||||
NULL,
|
"8080,8443s",
|
||||||
};
|
"ssl_certificate",
|
||||||
|
"resources/ssl_cert.pem", // TODO: check working path of CI test system
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
ctx = mg_start(NULL, NULL, OPTIONS);
|
ctx = mg_start(NULL, NULL, OPTIONS);
|
||||||
ck_assert(ctx != NULL);
|
ck_assert(ctx != NULL);
|
||||||
mg_Sleep(2);
|
mg_Sleep(2);
|
||||||
mg_stop(ctx);
|
mg_stop(ctx);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
||||||
Suite * make_public_suite (void) {
|
Suite *make_public_suite(void)
|
||||||
|
{
|
||||||
|
|
||||||
Suite * const suite = suite_create("Public");
|
Suite *const suite = suite_create("Public");
|
||||||
|
|
||||||
TCase * const version = tcase_create("Version");
|
TCase *const version = tcase_create("Version");
|
||||||
TCase * const get_valid_options = tcase_create("Options");
|
TCase *const get_valid_options = tcase_create("Options");
|
||||||
TCase * const get_builtin_mime_type = tcase_create("MIME types");
|
TCase *const get_builtin_mime_type = tcase_create("MIME types");
|
||||||
TCase * const tstrncasecmp = tcase_create("strcasecmp");
|
TCase *const tstrncasecmp = tcase_create("strcasecmp");
|
||||||
TCase * const urlencodingdecoding = tcase_create("URL encoding decoding");
|
TCase *const urlencodingdecoding = tcase_create("URL encoding decoding");
|
||||||
TCase * const cookies = tcase_create("Cookies");
|
TCase *const cookies = tcase_create("Cookies");
|
||||||
TCase * const md5 = tcase_create("MD5");
|
TCase *const md5 = tcase_create("MD5");
|
||||||
TCase * const startstophttp = tcase_create("Start Stop HTTP Server");
|
TCase *const startstophttp = tcase_create("Start Stop HTTP Server");
|
||||||
TCase * const startstophttps = tcase_create("Start Stop HTTPS Server");
|
TCase *const startstophttps = tcase_create("Start Stop HTTPS Server");
|
||||||
|
|
||||||
tcase_add_test(version, test_mg_version);
|
tcase_add_test(version, test_mg_version);
|
||||||
suite_add_tcase(suite, version);
|
suite_add_tcase(suite, version);
|
||||||
|
|
||||||
tcase_add_test(get_valid_options, test_mg_get_valid_options);
|
tcase_add_test(get_valid_options, test_mg_get_valid_options);
|
||||||
suite_add_tcase(suite, get_valid_options);
|
suite_add_tcase(suite, get_valid_options);
|
||||||
|
|
||||||
tcase_add_test(get_builtin_mime_type, test_mg_get_builtin_mime_type);
|
tcase_add_test(get_builtin_mime_type, test_mg_get_builtin_mime_type);
|
||||||
suite_add_tcase(suite, get_builtin_mime_type);
|
suite_add_tcase(suite, get_builtin_mime_type);
|
||||||
|
|
||||||
tcase_add_test(tstrncasecmp, test_mg_strncasecmp);
|
tcase_add_test(tstrncasecmp, test_mg_strncasecmp);
|
||||||
suite_add_tcase(suite, tstrncasecmp);
|
suite_add_tcase(suite, tstrncasecmp);
|
||||||
|
|
||||||
tcase_add_test(urlencodingdecoding, test_mg_url_encode);
|
tcase_add_test(urlencodingdecoding, test_mg_url_encode);
|
||||||
tcase_add_test(urlencodingdecoding, test_mg_url_decode);
|
tcase_add_test(urlencodingdecoding, test_mg_url_decode);
|
||||||
suite_add_tcase(suite, urlencodingdecoding);
|
suite_add_tcase(suite, urlencodingdecoding);
|
||||||
|
|
||||||
tcase_add_test(cookies, test_mg_get_cookie);
|
tcase_add_test(cookies, test_mg_get_cookie);
|
||||||
suite_add_tcase(suite, cookies);
|
suite_add_tcase(suite, cookies);
|
||||||
|
|
||||||
tcase_add_test(md5, test_mg_md5);
|
tcase_add_test(md5, test_mg_md5);
|
||||||
suite_add_tcase(suite, md5);
|
suite_add_tcase(suite, md5);
|
||||||
|
|
||||||
tcase_add_test(startstophttp, test_mg_start_stop_http_server);
|
tcase_add_test(startstophttp, test_mg_start_stop_http_server);
|
||||||
suite_add_tcase(suite, startstophttp);
|
suite_add_tcase(suite, startstophttp);
|
||||||
|
|
||||||
tcase_add_test(startstophttps, test_mg_start_stop_https_server);
|
tcase_add_test(startstophttps, test_mg_start_stop_https_server);
|
||||||
suite_add_tcase(suite, startstophttps);
|
suite_add_tcase(suite, startstophttps);
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user