From 1ab7330e119d0c5a082e73e82e9f0617d45a7b57 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 31 Jul 2013 14:40:56 +0000 Subject: * test/request.c (status, status_chunked): Revert r1910. Expect hostname of 127.0.0.1. * test/utils.c (session_server, sessi git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@1919 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845 --- test/request.c | 143 ++++++++++++++++++++++----------------------------------- test/utils.c | 4 +- 2 files changed, 56 insertions(+), 91 deletions(-) diff --git a/test/request.c b/test/request.c index 5a70c99..3444061 100644 --- a/test/request.c +++ b/test/request.c @@ -2067,70 +2067,24 @@ static void status_cb(void *userdata, ne_session_status status, } } -static void print_addr(char *buf, size_t buflen, const char *recvs, - const ne_inet_addr *i1, const ne_inet_addr *i2) -{ - char a1[64], a2[64]; - - if (i2 == NULL) - ne_snprintf(buf, buflen, - "lookup(localhost)-" - "connecting(localhost,%s)-" - "connected(localhost)-" - "send(0,5000)-" - "send(5000,5000)-" - "%s" - "disconnected(localhost)-", - ne_iaddr_print(i1, a1, sizeof a1), - recvs); - else - ne_snprintf(buf, buflen, - "lookup(localhost)-" - "connecting(localhost,%s)-" - "connecting(localhost,%s)-" - "connected(localhost)-" - "send(0,5000)-" - "send(5000,5000)-" - "%s" - "disconnected(localhost)-", - ne_iaddr_print(i1, a1, sizeof a1), - ne_iaddr_print(i2, a2, sizeof a2), - recvs); -} - -static int notifier(const char *response, const char *recvs) +static int status(void) { ne_session *sess; ne_buffer *buf = ne_buffer_create(); - ne_sock_addr *sa = ne_addr_resolve("localhost", 0); - const ne_inet_addr *ia, *ia2; - char *expect[3]; - int expects, match; - - ONN("could not resolve localhost", ne_addr_result(sa)); - - ia = ne_addr_first(sa); - ia2 = ne_addr_next(sa); - ONV(ne_addr_next(sa) != NULL, - ("dumb test cannot handle localhost with three addresses, sorry")); - - expect[0] = ne_malloc(BUFSIZ); - print_addr(expect[0], BUFSIZ, recvs, ia, NULL); - - if (ia2) { - expects = 3; - expect[1] = ne_malloc(BUFSIZ); - expect[2] = ne_malloc(BUFSIZ); - print_addr(expect[1], BUFSIZ, recvs, ia, ia2); - print_addr(expect[2], BUFSIZ, recvs, ia2, ia); - } - else { - expects = 1; - } + char expect[1024]; + + ne_snprintf(expect, sizeof expect, + "lookup(127.0.0.1)-" + "connecting(127.0.0.1,127.0.0.1)-" + "connected(127.0.0.1)-" + "send(0,5000)-" + "send(5000,5000)-" + "recv(0,5)-" + "recv(5,5)-" + "disconnected(127.0.0.1)-"); - ne_addr_destroy(sa); - - CALL(make_session(&sess, single_serve_string, (char *)response)); + CALL(make_session(&sess, single_serve_string, RESP200 + "Content-Length: 5\r\n\r\n" "abcde")); ne_set_notifier(sess, status_cb, buf); @@ -2139,43 +2093,54 @@ static int notifier(const char *response, const char *recvs) ne_session_destroy(sess); CALL(await_server()); - match = 0; - NE_DEBUG(NE_DBG_HTTP, "test: Got %s\n", buf->data); - while (expects-- && !match) { - NE_DEBUG(NE_DBG_HTTP, "test: Checking %s\n", expect[expects]); - if (strcmp(expect[expects], buf->data) == 0) - match = 1; - } - - ONV(!match, + ONV(strcmp(expect, buf->data), ("status event sequence mismatch: got [%s] not [%s]", - buf->data, expect[0])); + buf->data, expect)); ne_buffer_destroy(buf); return OK; } -static int status_plain(void) -{ - return notifier(/* body */ - RESP200 "Content-Length: 5\r\n\r\n" "abcde", - /* receive status */ - "recv(0,5)-" - "recv(5,5)-"); -} - static int status_chunked(void) { - return notifier(/* body */ - RESP200 TE_CHUNKED "\r\n" ABCDE_CHUNKS, - /* receive status */ - "recv(0,-1)-" - "recv(1,-1)-" - "recv(2,-1)-" - "recv(3,-1)-" - "recv(4,-1)-" - "recv(5,-1)-"); + ne_session *sess; + ne_buffer *buf = ne_buffer_create(); + char expect[1024]; + + /* This sequence is not exactly guaranteed by the API, but it's + * what the current implementation should do. */ + ne_snprintf(expect, sizeof expect, + "lookup(127.0.0.1)-" + "connecting(127.0.0.1,127.0.0.1)-" + "connected(127.0.0.1)-" + "send(0,5000)-" + "send(5000,5000)-" + "recv(0,-1)-" + "recv(1,-1)-" + "recv(2,-1)-" + "recv(3,-1)-" + "recv(4,-1)-" + "recv(5,-1)-" + "disconnected(127.0.0.1)-"); + + CALL(make_session(&sess, single_serve_string, + RESP200 TE_CHUNKED "\r\n" ABCDE_CHUNKS)); + + ne_set_notifier(sess, status_cb, buf); + + CALL(any_2xx_request_body(sess, "/status")); + + ne_session_destroy(sess); + CALL(await_server()); + + ONV(strcmp(expect, buf->data), + ("status event sequence mismatch: got [%s] not [%s]", + buf->data, expect)); + + ne_buffer_destroy(buf); + + return OK; } static const unsigned char raw_127[4] = "\x7f\0\0\01"; /* 127.0.0.1 */ @@ -2475,7 +2440,7 @@ ne_test tests[] = { T(hooks), T(hook_self_destroy), T(icy_protocol), - T(status_plain), + T(status), T(status_chunked), T(local_addr), T(dereg_progress), diff --git a/test/utils.c b/test/utils.c index 9548337..3addbe1 100644 --- a/test/utils.c +++ b/test/utils.c @@ -181,7 +181,7 @@ int session_server(ne_session **sess, server_fn fn, void *userdata) CALL(new_spawn_server(1, fn, userdata, &port)); - *sess = ne_session_create("http", "localhost", port); + *sess = ne_session_create("http", "127.0.0.1", port); return OK; } @@ -198,7 +198,7 @@ int proxied_session_server(ne_session **sess, const char *scheme, NE_DEBUG(NE_DBG_HTTP, "test: Using proxied session to port %u.\n", port); - ne_session_proxy(*sess, "localhost", port); + ne_session_proxy(*sess, "127.0.0.1", port); return OK; } -- cgit v1.2.1