unbroke unit test

This commit is contained in:
Sergey Lyubka 2014-03-02 17:20:24 +00:00
parent 9c22771a43
commit fd7dc33645
2 changed files with 14 additions and 16 deletions

View File

@ -377,13 +377,14 @@ static int ts2(struct mg_connection *conn) {
static const char *test_server(void) { static const char *test_server(void) {
char buf1[100] = "", buf2[100] = ""; char buf1[100] = "", buf2[100] = "";
struct mg_server *server = mg_create_server((void *) "foo", evh1); struct mg_server *server = mg_create_server((void *) "foo", evh1);
struct mg_connection *conn;
ASSERT(server != NULL); ASSERT(server != NULL);
ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL); ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL);
ASSERT(mg_set_option(server, "document_root", ".") == NULL); ASSERT(mg_set_option(server, "document_root", ".") == NULL);
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf1) == 1); ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf2) == 1); ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); } { int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
ASSERT(strcmp(buf1, "foo ? 127.0.0.1") == 0); ASSERT(strcmp(buf1, "foo ? 127.0.0.1") == 0);
@ -460,13 +461,14 @@ static int cb3(struct mg_connection *conn) {
static const char *test_mg_connect(void) { static const char *test_mg_connect(void) {
char buf2[40] = "", buf3[40] = "", buf4[40] = ""; char buf2[40] = "", buf3[40] = "", buf4[40] = "";
struct mg_server *server = mg_create_server(NULL, NULL); // cb4h struct mg_server *server = mg_create_server(NULL, NULL); // cb4h
struct mg_connection *conn;
ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL); ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL);
ASSERT(mg_set_option(server, "document_root", ".") == NULL); ASSERT(mg_set_option(server, "document_root", ".") == NULL);
ASSERT(mg_connect(server, "", 0, 0, NULL, NULL) == 0); ASSERT(mg_connect(server, "", 0, 0) == NULL);
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf2) == 1); ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
ASSERT(mg_connect(server, "127.0.0.1", 29, 0, cb3, buf3) == 1); ASSERT((conn = mg_connect(server, "127.0.0.1", 29, 0)) != NULL);
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf4) == 1); ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); } { int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
@ -572,8 +574,7 @@ static const char *test_rewrites(void) {
ASSERT(mg_set_option(server, "url_rewrites", "/xx=./mongoose.h") == NULL); ASSERT(mg_set_option(server, "url_rewrites", "/xx=./mongoose.h") == NULL);
ASSERT(mg_connect(server, "127.0.0.1", ASSERT(mg_connect(server, "127.0.0.1",
atoi(mg_get_option(server, "listening_port")), atoi(mg_get_option(server, "listening_port")), 0) != NULL);
0, us1, buf1) == 1);
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); } { int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
//printf("[%s]\n", buf1); //printf("[%s]\n", buf1);

View File

@ -4139,7 +4139,7 @@ static void call_http_client_handler(struct connection *conn, int code) {
conn->mg_conn.content_len = conn->ns_conn->recv_iobuf.len; conn->mg_conn.content_len = conn->ns_conn->recv_iobuf.len;
} }
conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf; conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf;
if (call_user(conn, -1) || code == MG_CONNECT_FAILURE || if (call_user(conn, MG_CONNECT) || code == MG_CONNECT_FAILURE ||
code == MG_DOWNLOAD_FAILURE) { code == MG_DOWNLOAD_FAILURE) {
conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY; conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
} }
@ -4553,13 +4553,10 @@ static void mg_ev_handler(struct ns_connection *nc, enum ns_event ev, void *p) {
break; break;
case NS_CONNECT: case NS_CONNECT:
{ conn->mg_conn.status_code = * (int *) p;
int ok = * (int *) p; if (conn->mg_conn.status_code != 0 ||
conn->mg_conn.status_code = ok == 0 ? call_user(conn, MG_CONNECT) == MG_FALSE) {
MG_CONNECT_SUCCESS : MG_CONNECT_FAILURE; nc->flags |= NSF_CLOSE_IMMEDIATELY;
if (call_user(conn, MG_CONNECT) != 0 || ok != 0) {
nc->flags |= NSF_CLOSE_IMMEDIATELY;
}
} }
break; break;