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:
@@ -37,7 +37,7 @@
|
||||
* 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;
|
||||
char empty[] = "";
|
||||
@@ -51,10 +51,12 @@ START_TEST (test_parse_http_message)
|
||||
char req8[] = " HTTP/1.1 200 OK \n\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,
|
||||
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,
|
||||
parse_http_message(req1, sizeof(req1), &ri));
|
||||
ck_assert_str_eq("1.1", ri.http_version);
|
||||
ck_assert_int_eq(0, ri.num_headers);
|
||||
|
||||
@@ -63,10 +65,12 @@ START_TEST (test_parse_http_message)
|
||||
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(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. */
|
||||
ck_assert_int_eq(sizeof(req4) - 1, parse_http_message(req4, sizeof(req4), &ri));
|
||||
ck_assert_int_eq(sizeof(req4) - 1,
|
||||
parse_http_message(req4, sizeof(req4), &ri));
|
||||
ck_assert_str_eq("1.1", ri.http_version);
|
||||
ck_assert_int_eq(3, ri.num_headers);
|
||||
ck_assert_str_eq("A", ri.http_headers[0].name);
|
||||
@@ -76,14 +80,15 @@ START_TEST (test_parse_http_message)
|
||||
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,
|
||||
parse_http_message(req5, sizeof(req5), &ri));
|
||||
ck_assert_str_eq("GET", ri.request_method);
|
||||
ck_assert_str_eq("1.1", ri.http_version);
|
||||
}
|
||||
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(3, match_prefix("/a/", 3, "/a/b/c"));
|
||||
@@ -117,7 +122,7 @@ START_TEST (test_match_prefix)
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_remove_double_dots_and_double_slashes)
|
||||
START_TEST(test_remove_double_dots_and_double_slashes)
|
||||
{
|
||||
struct {
|
||||
char before[20], after[20];
|
||||
@@ -143,7 +148,7 @@ START_TEST (test_remove_double_dots_and_double_slashes)
|
||||
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(0, is_valid_uri("api"));
|
||||
@@ -153,12 +158,13 @@ START_TEST (test_is_valid_uri)
|
||||
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 url_parsing = tcase_create("URL Parsing");
|
||||
TCase *const http_message = tcase_create("HTTP Message");
|
||||
TCase *const url_parsing = tcase_create("URL Parsing");
|
||||
|
||||
tcase_add_test(http_message, test_parse_http_message);
|
||||
suite_add_tcase(suite, http_message);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <Windows.h>
|
||||
#define mg_Sleep(x) (Sleep(x*1000))
|
||||
#define mg_Sleep(x) (Sleep(x * 1000))
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define mg_Sleep(x) (sleep(x))
|
||||
@@ -38,10 +38,10 @@
|
||||
* http://check.sourceforge.net/doc/check_html/index.html
|
||||
*/
|
||||
|
||||
START_TEST (test_mg_version)
|
||||
START_TEST(test_mg_version)
|
||||
{
|
||||
const char *ver = mg_version();
|
||||
unsigned major=0, minor=0;
|
||||
unsigned major = 0, minor = 0;
|
||||
int ret;
|
||||
|
||||
ck_assert(ver != NULL);
|
||||
@@ -51,12 +51,11 @@ START_TEST (test_mg_version)
|
||||
ret = sscanf(ver, "%u.%u", &major, &minor);
|
||||
ck_assert_int_eq(ret, 2);
|
||||
ck_assert_uint_ge(major, 1);
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_mg_get_valid_options)
|
||||
START_TEST(test_mg_get_valid_options)
|
||||
{
|
||||
int i;
|
||||
const struct mg_option *default_options = mg_get_valid_options();
|
||||
@@ -74,19 +73,20 @@ START_TEST (test_mg_get_valid_options)
|
||||
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.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("x.unknown_extention_xyz"), "text/plain");
|
||||
ck_assert_str_eq(mg_get_builtin_mime_type("x.unknown_extention_xyz"),
|
||||
"text/plain");
|
||||
}
|
||||
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", "abcd", 3) == 0);
|
||||
@@ -114,7 +114,7 @@ START_TEST (test_mg_strncasecmp)
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_mg_get_cookie)
|
||||
START_TEST(test_mg_get_cookie)
|
||||
{
|
||||
char buf[20];
|
||||
|
||||
@@ -128,12 +128,13 @@ START_TEST (test_mg_get_cookie)
|
||||
ck_assert_str_eq("2", 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_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
|
||||
|
||||
|
||||
START_TEST (test_mg_md5)
|
||||
START_TEST(test_mg_md5)
|
||||
{
|
||||
char buf[33];
|
||||
char *ret;
|
||||
@@ -151,7 +152,19 @@ START_TEST (test_mg_md5)
|
||||
ck_assert_ptr_eq(ret, 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,
|
||||
"",
|
||||
"The qu",
|
||||
"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);
|
||||
@@ -159,7 +172,7 @@ START_TEST (test_mg_md5)
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_mg_url_encode)
|
||||
START_TEST(test_mg_url_encode)
|
||||
{
|
||||
char buf[20];
|
||||
int ret;
|
||||
@@ -182,7 +195,7 @@ START_TEST (test_mg_url_encode)
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_mg_url_decode)
|
||||
START_TEST(test_mg_url_decode)
|
||||
{
|
||||
char buf[20];
|
||||
int ret;
|
||||
@@ -210,13 +223,11 @@ START_TEST (test_mg_url_decode)
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST (test_mg_start_stop_http_server)
|
||||
START_TEST(test_mg_start_stop_http_server)
|
||||
{
|
||||
struct mg_context *ctx;
|
||||
const char *OPTIONS[] = {
|
||||
"document_root", ".",
|
||||
"listening_ports", "8080",
|
||||
NULL,
|
||||
"document_root", ".", "listening_ports", "8080", NULL,
|
||||
};
|
||||
|
||||
ctx = mg_start(NULL, NULL, OPTIONS);
|
||||
@@ -226,13 +237,16 @@ START_TEST (test_mg_start_stop_http_server)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST (test_mg_start_stop_https_server)
|
||||
START_TEST(test_mg_start_stop_https_server)
|
||||
{
|
||||
struct mg_context *ctx;
|
||||
const char *OPTIONS[] = {
|
||||
"document_root", ".",
|
||||
"listening_ports", "8080,8443s",
|
||||
"ssl_certificate", "resources/ssl_cert.pem", // TODO: check working path of CI test system
|
||||
"document_root",
|
||||
".",
|
||||
"listening_ports",
|
||||
"8080,8443s",
|
||||
"ssl_certificate",
|
||||
"resources/ssl_cert.pem", // TODO: check working path of CI test system
|
||||
NULL,
|
||||
};
|
||||
|
||||
@@ -244,19 +258,20 @@ START_TEST (test_mg_start_stop_https_server)
|
||||
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 get_valid_options = tcase_create("Options");
|
||||
TCase * const get_builtin_mime_type = tcase_create("MIME types");
|
||||
TCase * const tstrncasecmp = tcase_create("strcasecmp");
|
||||
TCase * const urlencodingdecoding = tcase_create("URL encoding decoding");
|
||||
TCase * const cookies = tcase_create("Cookies");
|
||||
TCase * const md5 = tcase_create("MD5");
|
||||
TCase * const startstophttp = tcase_create("Start Stop HTTP Server");
|
||||
TCase * const startstophttps = tcase_create("Start Stop HTTPS Server");
|
||||
TCase *const version = tcase_create("Version");
|
||||
TCase *const get_valid_options = tcase_create("Options");
|
||||
TCase *const get_builtin_mime_type = tcase_create("MIME types");
|
||||
TCase *const tstrncasecmp = tcase_create("strcasecmp");
|
||||
TCase *const urlencodingdecoding = tcase_create("URL encoding decoding");
|
||||
TCase *const cookies = tcase_create("Cookies");
|
||||
TCase *const md5 = tcase_create("MD5");
|
||||
TCase *const startstophttp = tcase_create("Start Stop HTTP Server");
|
||||
TCase *const startstophttps = tcase_create("Start Stop HTTPS Server");
|
||||
|
||||
tcase_add_test(version, test_mg_version);
|
||||
suite_add_tcase(suite, version);
|
||||
|
||||
Reference in New Issue
Block a user