mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-14 19:03:20 +00:00
More tests for mg_fetch()
This commit is contained in:
1 parent
e6bb39a2d3
commit
84e26ccddd
1 file changed
+8
-2
+8
-2
@@ -133,7 +133,8 @@ static void *event_handler(enum mg_event event,
|
|||||||
const struct mg_request_info *request_info) {
|
const struct mg_request_info *request_info) {
|
||||||
if (event == MG_NEW_REQUEST && !strcmp(request_info->uri, "/data")) {
|
if (event == MG_NEW_REQUEST && !strcmp(request_info->uri, "/data")) {
|
||||||
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
|
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);
|
"%s", (int) strlen(fetch_data), fetch_data);
|
||||||
return "";
|
return "";
|
||||||
} else if (event == MG_EVENT_LOG) {
|
} else if (event == MG_EVENT_LOG) {
|
||||||
@@ -170,9 +171,14 @@ static void test_mg_fetch(void) {
|
|||||||
// Successful fetch
|
// Successful fetch
|
||||||
ASSERT((fp = mg_fetch(ctx, "http://localhost:33796/data",
|
ASSERT((fp = mg_fetch(ctx, "http://localhost:33796/data",
|
||||||
tmp_file, &ri)) != NULL);
|
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));
|
ASSERT((length = ftell(fp)) == (int) strlen(fetch_data));
|
||||||
fseek(fp, 0, SEEK_SET);
|
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);
|
ASSERT(memcmp(buf, fetch_data, length) == 0);
|
||||||
|
|
||||||
remove(tmp_file);
|
remove(tmp_file);
|
||||||
|
|||||||
Reference in new issue
Block a user