소스 검색

Fix unit_test, still not working properly

mingodad 9 년 전
부모
커밋
af2cb138be
2개의 변경된 파일15개의 추가작업 그리고 13개의 파일을 삭제
  1. 2 1
      Makefile
  2. 13 12
      test/unit_test.c

+ 2 - 1
Makefile

@@ -253,6 +253,7 @@ clean:
 	$(RMRF) lib$(CPROG).so.$(major)
 	$(RMRF) lib$(CPROG).so.$(major)
 	$(RMRF) lib$(CPROG).so.$(version).0
 	$(RMRF) lib$(CPROG).so.$(version).0
 	$(RMRF) $(CPROG)
 	$(RMRF) $(CPROG)
+	$(RMF) $(UNIT_TEST_PROG)
 
 
 distclean: clean
 distclean: clean
 	@$(RMRF) VS2012/Debug VS2012/*/Debug  VS2012/*/*/Debug
 	@$(RMRF) VS2012/Debug VS2012/*/Debug  VS2012/*/*/Debug
@@ -277,7 +278,7 @@ lib$(CPROG).dll: CFLAGS += -fPIC
 lib$(CPROG).dll: $(LIB_OBJECTS)
 lib$(CPROG).dll: $(LIB_OBJECTS)
 	$(LCC) -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) $(LIBS) -Wl,--out-implib,lib$(CPROG).dll.a
 	$(LCC) -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) $(LIBS) -Wl,--out-implib,lib$(CPROG).dll.a
 
 
-$(UNIT_TEST_PROG): CFLAGS += -Isrc
+$(UNIT_TEST_PROG): CFLAGS += -Isrc -g
 $(UNIT_TEST_PROG): $(LIB_SOURCES) $(LIB_INLINE) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS)
 $(UNIT_TEST_PROG): $(LIB_SOURCES) $(LIB_INLINE) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS)
 	$(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) $(LIBS)
 	$(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) $(LIBS)
 
 

+ 13 - 12
test/unit_test.c

@@ -79,7 +79,7 @@ static void test_parse_http_message()
 	char req1[] = "GET / HTTP/1.1\r\n\r\n";
 	char req1[] = "GET / HTTP/1.1\r\n\r\n";
 	char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
 	char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
 	char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
 	char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
-	char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz\r\n\r\n";
+	char req4[] = "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nbaz:\r\n\r\n";
 	char req5[] = "GET / HTTP/1.1\r\n\r\n";
 	char req5[] = "GET / HTTP/1.1\r\n\r\n";
 	char req6[] = "G";
 	char req6[] = "G";
 	char req7[] = " blah ";
 	char req7[] = " blah ";
@@ -108,7 +108,7 @@ static void test_parse_http_message()
 	ASSERT(strcmp(ri.http_headers[0].value, "foo bar") == 0);
 	ASSERT(strcmp(ri.http_headers[0].value, "foo bar") == 0);
 	ASSERT(strcmp(ri.http_headers[1].name, "B") == 0);
 	ASSERT(strcmp(ri.http_headers[1].name, "B") == 0);
 	ASSERT(strcmp(ri.http_headers[1].value, "bar") == 0);
 	ASSERT(strcmp(ri.http_headers[1].value, "bar") == 0);
-	ASSERT(strcmp(ri.http_headers[2].name, "baz\r\n\r") == 0);
+	ASSERT(strcmp(ri.http_headers[2].name, "baz") == 0);
 	ASSERT(strcmp(ri.http_headers[2].value, "") == 0);
 	ASSERT(strcmp(ri.http_headers[2].value, "") == 0);
 
 
 	ASSERT(parse_http_message(req5, sizeof(req5), &ri) == sizeof(req5) - 1);
 	ASSERT(parse_http_message(req5, sizeof(req5), &ri) == sizeof(req5) - 1);
@@ -630,7 +630,7 @@ static void test_mg_download(int use_ssl)
 	                           "HTTP/1.1\r\n"
 	                           "HTTP/1.1\r\n"
 	                           "Transfer-Encoding: chunked\r\n"
 	                           "Transfer-Encoding: chunked\r\n"
 	                           "\r\n%x\r\n%s\r\n0\r\n\r\n",
 	                           "\r\n%x\r\n%s\r\n0\r\n\r\n",
-	                           strlen(test_data),
+	                           (uint32_t)strlen(test_data),
 	                           test_data)) != NULL);
 	                           test_data)) != NULL);
 	h = mg_get_header(conn, "Content-Length");
 	h = mg_get_header(conn, "Content-Length");
 	ASSERT(h == NULL);
 	ASSERT(h == NULL);
@@ -663,7 +663,7 @@ static void test_mg_download(int use_ssl)
 	                           test_data[4],
 	                           test_data[4],
 	                           test_data[5],
 	                           test_data[5],
 	                           test_data[6],
 	                           test_data[6],
-	                           strlen(test_data + 7),
+	                           (uint32_t)strlen(test_data + 7),
 	                           test_data + 7)) != NULL);
 	                           test_data + 7)) != NULL);
 	h = mg_get_header(conn, "Content-Length");
 	h = mg_get_header(conn, "Content-Length");
 	ASSERT(h == NULL);
 	ASSERT(h == NULL);
@@ -835,12 +835,12 @@ static void test_mg_websocket_client_connect(int use_ssl)
 	ut_mg_stop(ctx);
 	ut_mg_stop(ctx);
 }
 }
 
 
-static int alloc_printf(char **buf, size_t size, char *fmt, ...)
+static int alloc_printf(char **out_buf, char *buf, size_t size, char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 	int ret = 0;
 	int ret = 0;
 	va_start(ap, fmt);
 	va_start(ap, fmt);
-	ret = alloc_vprintf(buf, size, fmt, ap);
+	ret = alloc_vprintf(out_buf, buf, size, fmt, ap);
 	va_end(ap);
 	va_end(ap);
 	return ret;
 	return ret;
 }
 }
@@ -863,6 +863,7 @@ static void test_mg_upload(void)
 	ASSERT((file_data = read_file("unit_test.c", &file_len)) != NULL);
 	ASSERT((file_data = read_file("unit_test.c", &file_len)) != NULL);
 	post_data = NULL;
 	post_data = NULL;
 	post_data_len = alloc_printf(&post_data,
 	post_data_len = alloc_printf(&post_data,
+                                 NULL,
 	                             0,
 	                             0,
 	                             "--%s\r\n"
 	                             "--%s\r\n"
 	                             "Content-Disposition: form-data; "
 	                             "Content-Disposition: form-data; "
@@ -1008,7 +1009,7 @@ static void check_lua_expr(lua_State *L, const char *expr, const char *value)
 	const char *v, *var_name = "myVar";
 	const char *v, *var_name = "myVar";
 	char buf[100];
 	char buf[100];
 
 
-	snprintf(buf, sizeof(buf), "%s = %s", var_name, expr);
+	mg_snprintf(buf, sizeof(buf), "%s = %s", var_name, expr);
 	(void)luaL_dostring(L, buf);
 	(void)luaL_dostring(L, buf);
 	lua_getglobal(L, var_name);
 	lua_getglobal(L, var_name);
 	v = lua_tostring(L, -1);
 	v = lua_tostring(L, -1);
@@ -1033,7 +1034,7 @@ static void test_lua(void)
 	    parse_http_message(conn.buf, conn.data_len, &conn.request_info);
 	    parse_http_message(conn.buf, conn.data_len, &conn.request_info);
 	conn.content_len = conn.data_len - conn.request_len;
 	conn.content_len = conn.data_len - conn.request_len;
 
 
-	prepare_lua_environment(&conn, L, "unit_test", LUA_ENV_TYPE_PLAIN_LUA_PAGE);
+	prepare_lua_environment(&ctx, &conn, NULL, L, "unit_test", LUA_ENV_TYPE_PLAIN_LUA_PAGE);
 	ASSERT(lua_gettop(L) == 4);
 	ASSERT(lua_gettop(L) == 4);
 
 
 	check_lua_expr(L, "'hi'", "hi");
 	check_lua_expr(L, "'hi'", "hi");
@@ -1079,13 +1080,13 @@ static void test_alloc_vprintf(void)
 {
 {
 	char buf[MG_BUF_LEN], *p = buf;
 	char buf[MG_BUF_LEN], *p = buf;
 
 
-	ASSERT(alloc_printf(&p, sizeof(buf), "%s", "hi") == 2);
+	ASSERT(alloc_printf(&p, buf, sizeof(buf), "%s", "hi") == 2);
 	ASSERT(p == buf);
 	ASSERT(p == buf);
-	ASSERT(alloc_printf(&p, sizeof(buf), "%s", "") == 0);
-	ASSERT(alloc_printf(&p, sizeof(buf), "") == 0);
+	ASSERT(alloc_printf(&p, buf, sizeof(buf), "%s", "") == 0);
+	ASSERT(alloc_printf(&p, buf, sizeof(buf), "") == 0);
 
 
 	/* Pass small buffer, make sure alloc_printf allocates */
 	/* Pass small buffer, make sure alloc_printf allocates */
-	ASSERT(alloc_printf(&p, 1, "%s", "hello") == 5);
+	ASSERT(alloc_printf(&p, buf, 1, "%s", "hello") == 5);
 	ASSERT(p != buf);
 	ASSERT(p != buf);
 	mg_free(p);
 	mg_free(p);
 }
 }