Browse Source

Minor adjustments in unit_test.c

bel 10 năm trước cách đây
mục cha
commit
bcd9f39bb7
1 tập tin đã thay đổi với 23 bổ sung11 xóa
  1. 23 11
      test/unit_test.c

+ 23 - 11
test/unit_test.c

@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014 the Civetweb developers
+/* Copyright (c) 2013-2015 the Civetweb developers
  * Copyright (c) 2004-2013 Sergey Lyubka
  * Copyright (c) 2004-2013 Sergey Lyubka
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -220,7 +220,8 @@ static char *read_file(const char *path, int *size)
 	char *data = NULL;
 	char *data = NULL;
 	if ((fp = fopen(path, "rb")) != NULL && !fstat(fileno(fp), &st)) {
 	if ((fp = fopen(path, "rb")) != NULL && !fstat(fileno(fp), &st)) {
 		*size = (int)st.st_size;
 		*size = (int)st.st_size;
-		ASSERT((data = mg_malloc(*size)) != NULL);
+		data = mg_malloc(*size);
+		ASSERT(data != NULL);
 		ASSERT(fread(data, 1, *size, fp) == (size_t)*size);
 		ASSERT(fread(data, 1, *size, fp) == (size_t)*size);
 		fclose(fp);
 		fclose(fp);
 	}
 	}
@@ -321,6 +322,10 @@ static int begin_request_handler_cb(struct mg_connection *conn)
 			write_now = to_write > fetch_data_size ? fetch_data_size : to_write;
 			write_now = to_write > fetch_data_size ? fetch_data_size : to_write;
 			bytes_written = mg_write(conn, fetch_data, write_now);
 			bytes_written = mg_write(conn, fetch_data, write_now);
 			ASSERT(bytes_written == write_now);
 			ASSERT(bytes_written == write_now);
+			if (bytes_written < 0) {
+				ASSERT(0);
+				break;
+			}
 			to_write -= bytes_written;
 			to_write -= bytes_written;
 		}
 		}
 		close_connection(conn);
 		close_connection(conn);
@@ -426,7 +431,8 @@ static char *read_conn(struct mg_connection *conn, int *size)
 	*size = 0;
 	*size = 0;
 	while ((len = mg_read(conn, buf, sizeof(buf))) > 0) {
 	while ((len = mg_read(conn, buf, sizeof(buf))) > 0) {
 		*size += len;
 		*size += len;
-		ASSERT((data = mg_realloc(data, *size)) != NULL);
+		data = mg_realloc(data, *size);
+		ASSERT(data != NULL);
 		memcpy(data + *size - len, buf, len);
 		memcpy(data + *size - len, buf, len);
 	}
 	}
 	return data;
 	return data;
@@ -444,10 +450,12 @@ static void ut_mg_stop(struct mg_context *ctx)
 #ifdef MEMORY_DEBUGGING
 #ifdef MEMORY_DEBUGGING
 	ASSERT(mg_memory_debug_blockCount == 0);
 	ASSERT(mg_memory_debug_blockCount == 0);
 	ASSERT(mg_memory_debug_totalMemUsed == 0);
 	ASSERT(mg_memory_debug_totalMemUsed == 0);
+	mg_memory_debug_blockCount = 0;
+	mg_memory_debug_totalMemUsed = 0;
 #endif
 #endif
-	mg_sleep(
-	    31000); /* This is required to ensure the operating system already
-	               allows to use the port again */
+
+	mg_sleep(31000); /* This is required to ensure the operating system already
+	                    allows to use the port again */
 }
 }
 
 
 static void test_mg_download(int use_ssl)
 static void test_mg_download(int use_ssl)
@@ -462,12 +470,15 @@ static void test_mg_download(int use_ssl)
 	struct mg_context *ctx;
 	struct mg_context *ctx;
 	const struct mg_request_info *ri;
 	const struct mg_request_info *ri;
 
 
-	if (use_ssl)
+	if (use_ssl) {
 		port = atoi(HTTPS_PORT);
 		port = atoi(HTTPS_PORT);
-	else
+	} else {
 		port = atoi(HTTP_PORT);
 		port = atoi(HTTP_PORT);
+	}
 
 
-	ASSERT((ctx = mg_start(&CALLBACKS, NULL, OPTIONS)) != NULL);
+	ctx = mg_start(&CALLBACKS, NULL, OPTIONS);
+
+	ASSERT(ctx != NULL);
 
 
 	ASSERT(mg_download(NULL, port, use_ssl, ebuf, sizeof(ebuf), "%s", "") ==
 	ASSERT(mg_download(NULL, port, use_ssl, ebuf, sizeof(ebuf), "%s", "") ==
 	       NULL);
 	       NULL);
@@ -1287,8 +1298,9 @@ static void test_md5(void)
 	md5_val[16] = 0;
 	md5_val[16] = 0;
 	md5_init(&md5_state);
 	md5_init(&md5_state);
 	md5_finish(&md5_state, md5_val);
 	md5_finish(&md5_state, md5_val);
-	ASSERT(strcmp((const char *)md5_val, "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9"
-	                                     "\x80\x09\x98\xec\xf8\x42\x7e") == 0);
+	ASSERT(strcmp((const char *)md5_val,
+	              "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9"
+	              "\x80\x09\x98\xec\xf8\x42\x7e") == 0);
 	sprintf(md5_str,
 	sprintf(md5_str,
 	        "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
 	        "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
 	        md5_val[0],
 	        md5_val[0],