Commit 84e26ccd authored by Sergey Lyubka's avatar Sergey Lyubka

More tests for mg_fetch()

parent e6bb39a2
......@@ -133,7 +133,8 @@ static void *event_handler(enum mg_event event,
const struct mg_request_info *request_info) {
if (event == MG_NEW_REQUEST && !strcmp(request_info->uri, "/data")) {
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
"Content-Length: %d\r\n\r\n"
"Content-Length: %d\r\n"
"Content-Type: text/plain\r\n\r\n"
"%s", (int) strlen(fetch_data), fetch_data);
return "";
} else if (event == MG_EVENT_LOG) {
......@@ -170,9 +171,14 @@ static void test_mg_fetch(void) {
// Successful fetch
ASSERT((fp = mg_fetch(ctx, "http://localhost:33796/data",
tmp_file, &ri)) != NULL);
ASSERT(ri.num_headers == 2);
printf("%s: [%s]\n", __func__, ri.request_method);
ASSERT(!strcmp(ri.request_method, "HTTP/1.1"));
ASSERT(!strcmp(ri.uri, "200"));
ASSERT(!strcmp(ri.http_version, "OK"));
ASSERT((length = ftell(fp)) == (int) strlen(fetch_data));
fseek(fp, 0, SEEK_SET);
ASSERT(fread(buf, 1, length, fp) == length);
ASSERT(fread(buf, 1, length, fp) == (size_t) length);
ASSERT(memcmp(buf, fetch_data, length) == 0);
remove(tmp_file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment