Browse Source

More unit tests

bel 10 years ago
parent
commit
047c7ef33a
1 changed files with 42 additions and 2 deletions
  1. 42 2
      test/public.c

+ 42 - 2
test/public.c

@@ -587,7 +587,7 @@ START_TEST(test_request_handlers)
 	mg_close_connection(conn);
 	mg_close_connection(conn);
 
 
 
 
-	/* Get static data (if the CI test environment permits it) */
+	/* Get static data */
 	conn = mg_download("localhost",
 	conn = mg_download("localhost",
 	                   atoi(HTTP_PORT),
 	                   atoi(HTTP_PORT),
 	                   0,
 	                   0,
@@ -608,6 +608,46 @@ START_TEST(test_request_handlers)
 	mg_close_connection(conn);
 	mg_close_connection(conn);
 
 
 
 
+	/* Get directory listing */
+	conn = mg_download("localhost",
+	                   atoi(HTTP_PORT),
+	                   0,
+	                   ebuf,
+	                   sizeof(ebuf),
+	                   "%s",
+	                   "GET / HTTP/1.0\r\n\r\n");
+	ck_assert(conn != NULL);
+	ri = mg_get_request_info(conn);
+
+	ck_assert(ri != NULL);
+	ck_assert_str_eq(ri->uri, "200");
+	i = mg_read(conn, buf, sizeof(buf));
+	ck_assert(i > 6);
+    buf[6] = 0;
+	ck_assert_str_eq(buf, "<html>");
+	mg_close_connection(conn);
+
+
+	/* POST to static file (will not work) */
+	conn = mg_download("localhost",
+	                   atoi(HTTP_PORT),
+	                   0,
+	                   ebuf,
+	                   sizeof(ebuf),
+	                   "%s",
+	                   "POST /hello.txt HTTP/1.0\r\n\r\n");
+	ck_assert(conn != NULL);
+	ri = mg_get_request_info(conn);
+
+	ck_assert(ri != NULL);
+	ck_assert_str_eq(ri->uri, "405");
+	i = mg_read(conn, buf, sizeof(buf));
+	ck_assert(i >= 29);
+    buf[29] = 0;
+    ck_assert_str_eq(buf, "Error 405: Method Not Allowed");
+	mg_close_connection(conn);
+
+
 	/* Close the server */
 	/* Close the server */
 	g_ctx = NULL;
 	g_ctx = NULL;
 	mg_stop(ctx);
 	mg_stop(ctx);
@@ -663,7 +703,7 @@ Suite *make_public_suite(void)
 	return suite;
 	return suite;
 }
 }
 
 
-#if 1
+#if 0
 /* Used to debug test cases without using the check framework */
 /* Used to debug test cases without using the check framework */
 void main(void)
 void main(void)
 {
 {