diff --git a/test/unit_test.c b/test/unit_test.c index 6acc50e569bbed9ea2ddec59ae101a1a4b8e2ca7..d599342bed0e84c100f54f5cf8040c83857a55a4 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -175,12 +175,19 @@ static void *event_handler(enum mg_event event, struct mg_connection *conn) { return NULL; } +static const char *OPTIONS[] = { + "document_root", ".", + "listening_ports", LISTENING_ADDR, + NULL, +}; + +static void test_mg_upload(void) { + struct mg_context *ctx; + ASSERT((ctx = mg_start(event_handler, NULL, OPTIONS)) != NULL); + mg_stop(ctx); +} + static void test_mg_fetch(void) { - static const char *options[] = { - "document_root", ".", - "listening_ports", LISTENING_ADDR, - NULL, - }; char buf[2000], buf2[2000]; int n, length; struct mg_context *ctx; @@ -189,7 +196,7 @@ static void test_mg_fetch(void) { struct file file; FILE *fp; - ASSERT((ctx = mg_start(event_handler, NULL, options)) != NULL); + ASSERT((ctx = mg_start(event_handler, NULL, OPTIONS)) != NULL); // Failed fetch, pass invalid URL ASSERT(mg_fetch(ctx, "localhost", tmp_file, buf, sizeof(buf), &ri) == NULL); @@ -369,10 +376,9 @@ static void *user_data_tester(enum mg_event event, struct mg_connection *conn) { } static void test_user_data(void) { - static const char *options[] = {"listening_ports", LISTENING_ADDR, NULL}; struct mg_context *ctx; - ASSERT((ctx = mg_start(user_data_tester, (void *) 123, options)) != NULL); + ASSERT((ctx = mg_start(user_data_tester, (void *) 123, OPTIONS)) != NULL); ASSERT(ctx->user_data == (void *) 123); call_user(fc(ctx), MG_NEW_REQUEST); mg_stop(ctx); @@ -380,8 +386,7 @@ static void test_user_data(void) { static void test_mg_stat(void) { static struct mg_context ctx; - struct file file; - memset(&file, 'A', sizeof(file)); + struct file file = STRUCT_FILE_INITIALIZER; ASSERT(!mg_stat(fc(&ctx), " does not exist ", &file)); } @@ -415,6 +420,7 @@ int __cdecl main(void) { test_next_option(); test_user_data(); test_mg_stat(); + test_mg_upload(); #ifdef USE_LUA test_lua(); #endif