瀏覽代碼

Unit test: use feature ifdef

bel2125 7 年之前
父節點
當前提交
0a99e19d6d
共有 2 個文件被更改,包括 25 次插入4 次删除
  1. 5 0
      test/public_func.c
  2. 20 4
      test/public_server.c

+ 5 - 0
test/public_func.c

@@ -115,6 +115,7 @@ START_TEST(test_mg_version)
 	ck_assert_int_eq(len, ret);
 	ck_assert_int_eq(len, ret);
 	free(buf);
 	free(buf);
 
 
+#if defined(USE_SERVER_STATS)
 	/* get context information for NULL */
 	/* get context information for NULL */
 	len = mg_get_context_info(ctx, NULL, 0);
 	len = mg_get_context_info(ctx, NULL, 0);
 	ck_assert_int_gt(len, 0);
 	ck_assert_int_gt(len, 0);
@@ -138,6 +139,10 @@ START_TEST(test_mg_version)
 	ck_assert_int_eq(len, ret);
 	ck_assert_int_eq(len, ret);
 	free(buf);
 	free(buf);
 	mg_stop(ctx);
 	mg_stop(ctx);
+#else
+    len = mg_get_context_info(ctx, NULL, 0);
+    ck_assert_int_eq(len, 0);
+#endif
 }
 }
 END_TEST
 END_TEST
 
 

+ 20 - 4
test/public_server.c

@@ -340,7 +340,7 @@ test_mg_stop(struct mg_context *ctx)
 
 
 
 
 static void
 static void
-test_mg_start_stop_http_server_impl(int ipv6)
+test_mg_start_stop_http_server_impl(int ipv6, int bound)
 {
 {
 	struct mg_context *ctx;
 	struct mg_context *ctx;
 	const char *OPTIONS[16];
 	const char *OPTIONS[16];
@@ -368,7 +368,19 @@ test_mg_start_stop_http_server_impl(int ipv6)
 	OPTIONS[optcnt++] = ".";
 	OPTIONS[optcnt++] = ".";
 #endif
 #endif
 	OPTIONS[optcnt++] = "listening_ports";
 	OPTIONS[optcnt++] = "listening_ports";
-	OPTIONS[optcnt++] = ((ipv6) ? "+8080" : "8080");
+	if (bound) {
+		OPTIONS[optcnt++] = ((ipv6) ? "[::1]:+8080" : "127.0.0.1:8080");
+	} else {
+		OPTIONS[optcnt++] = ((ipv6) ? "+8080" : "8080");
+		/* Test also tcp_nodelay - this option is not related
+		 * to interface binding, it's just tested here in this
+		 * combination to keep the number of tests smaller and
+		 * the test duration shorter.
+		 */
+		OPTIONS[optcnt++] = "tcp_nodelay";
+		OPTIONS[optcnt++] = "1";
+	}
+
 	OPTIONS[optcnt] = 0;
 	OPTIONS[optcnt] = 0;
 
 
 #if defined(MG_LEGACY_INTERFACE)
 #if defined(MG_LEGACY_INTERFACE)
@@ -545,7 +557,9 @@ test_mg_start_stop_http_server_impl(int ipv6)
 START_TEST(test_mg_start_stop_http_server)
 START_TEST(test_mg_start_stop_http_server)
 {
 {
 	mark_point();
 	mark_point();
-	test_mg_start_stop_http_server_impl(0);
+	test_mg_start_stop_http_server_impl(0, 0);
+	mark_point();
+	test_mg_start_stop_http_server_impl(0, 1);
 	mark_point();
 	mark_point();
 }
 }
 END_TEST
 END_TEST
@@ -555,7 +569,9 @@ START_TEST(test_mg_start_stop_http_server_ipv6)
 {
 {
 	mark_point();
 	mark_point();
 #if defined(USE_IPV6)
 #if defined(USE_IPV6)
-	test_mg_start_stop_http_server_impl(1);
+	test_mg_start_stop_http_server_impl(1, 0);
+	mark_point();
+	test_mg_start_stop_http_server_impl(1, 1);
 #endif
 #endif
 	mark_point();
 	mark_point();
 }
 }