]> granicus.if.org Git - libevent/commitdiff
test: cleanup http/autofree_connection
authorAzat Khuzhin <azat@libevent.org>
Mon, 18 May 2020 22:05:50 +0000 (01:05 +0300)
committerAzat Khuzhin <azat@libevent.org>
Mon, 18 May 2020 22:06:12 +0000 (01:06 +0300)
test/regress_http.c

index 84f2191dca6d03d77693095830f4bbd53445e8d1..b7656cf8341c2963fb83b7558670e75e1cf18b51 100644 (file)
@@ -66,6 +66,8 @@
 #include "regress.h"
 #include "regress_testutils.h"
 
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+
 /* set if a test needs to call loopexit on a base */
 static struct event_base *exit_base;
 
@@ -1505,6 +1507,7 @@ http_autofree_connection_test(void *arg)
        struct evhttp_connection *evcon = NULL;
        struct evhttp_request *req[2] = { NULL };
        struct evhttp *http = http_setup(&port, data->base, 0);
+       size_t i;
 
        test_ok = 0;
 
@@ -1519,12 +1522,11 @@ http_autofree_connection_test(void *arg)
        req[1] = evhttp_request_new(http_request_empty_done, data->base);
 
        /* Add the information that we care about */
-       evhttp_add_header(evhttp_request_get_output_headers(req[0]), "Host", "somehost");
-       evhttp_add_header(evhttp_request_get_output_headers(req[0]), "Connection", "close");
-       evhttp_add_header(evhttp_request_get_output_headers(req[0]), "Empty", "itis");
-       evhttp_add_header(evhttp_request_get_output_headers(req[1]), "Host", "somehost");
-       evhttp_add_header(evhttp_request_get_output_headers(req[1]), "Connection", "close");
-       evhttp_add_header(evhttp_request_get_output_headers(req[1]), "Empty", "itis");
+       for (i = 0; i < ARRAY_SIZE(req); ++i) {
+               evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Host", "somehost");
+               evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Connection", "close");
+               evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Empty", "itis");
+       }
 
        /* We give ownership of the request to the connection */
        if (evhttp_make_request(evcon, req[0], EVHTTP_REQ_GET, "/test") == -1) {
@@ -5095,8 +5097,6 @@ http_timeout_read_client_test(void *arg)
  * Error callback tests
  */
 
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-
 #define ERRCBFLAG_GENCB  (0x01)
 #define ERRCBFLAG_ERRCB  (0x02)
 #define ERRCBFLAG_BOTHCB (ERRCBFLAG_GENCB | ERRCBFLAG_ERRCB)