mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-01 05:52:32 +07:00
More tests for mg_fetch()
This commit is contained in:
+8
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user