Browse Source

More tests for mg_fetch()

Sergey Lyubka 13 years ago
parent
commit
84e26ccddd
1 changed files with 8 additions and 2 deletions
  1. 8 2
      test/unit_test.c

+ 8 - 2
test/unit_test.c

@@ -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);