]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: propagate errors in libtests
authorDan Fandrich <dan@coneharvesters.com>
Fri, 29 Sep 2023 23:32:48 +0000 (16:32 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Wed, 4 Oct 2023 19:15:57 +0000 (12:15 -0700)
Use the test macros to automatically propagate some errors, and check
and log others while running the tests. This can help in debugging
exactly why a test has failed.

27 files changed:
tests/data/test2306
tests/libtest/lib1510.c
tests/libtest/lib1512.c
tests/libtest/lib1518.c
tests/libtest/lib1522.c
tests/libtest/lib1533.c
tests/libtest/lib1540.c
tests/libtest/lib1551.c
tests/libtest/lib1554.c
tests/libtest/lib1567.c
tests/libtest/lib1569.c
tests/libtest/lib1903.c
tests/libtest/lib1906.c
tests/libtest/lib1907.c
tests/libtest/lib1915.c
tests/libtest/lib1919.c
tests/libtest/lib1940.c
tests/libtest/lib1945.c
tests/libtest/lib1947.c
tests/libtest/lib1948.c
tests/libtest/lib2306.c
tests/libtest/lib519.c
tests/libtest/lib541.c
tests/libtest/lib552.c
tests/libtest/lib586.c
tests/libtest/lib589.c
tests/libtest/lib677.c

index 620f7b5ecc1200a42892cd3e2d7b495a9e88fbde..da2f25a213251e9f21988840913303a732988541 100644 (file)
@@ -54,6 +54,14 @@ http://%HOSTIP:%HTTPPORT/%TESTNUMBER http://%HOSTIP:%HTTPPORT/%TESTNUMBER0002
 #
 # Verify data after the test has been "shot"
 <verify>
+# hyper doesn't like the bad header in the second request
+<errorcode>
+%if hyper
+1
+%else
+0
+%endif
+</errorcode>
 <protocol>
 GET /%TESTNUMBER HTTP/1.1\r
 Host: %HOSTIP:%HTTPPORT\r
index 7b0e12ce9462f4abf72f8439a22f3108fa844a24..927927e492bebc0042feacfc45e6c5cf6fa2b334 100644 (file)
@@ -83,6 +83,8 @@ int test(char *URL)
     easy_setopt(curl, CURLOPT_URL, target_url);
 
     res = curl_easy_perform(curl);
+    if(res)
+      goto test_cleanup;
 
     abort_on_test_timeout();
   }
index 2ca0fe6205281ed82a332823592667e5cfbc17b0..670781982728c84b68e548a7127d36f00eda0e8e 100644 (file)
@@ -80,8 +80,11 @@ int test(char *URL)
   easy_setopt(curl[0], CURLOPT_RESOLVE, slist);
 
   /* run NUM_HANDLES transfers */
-  for(i = 0; (i < NUM_HANDLES) && !res; i++)
+  for(i = 0; (i < NUM_HANDLES) && !res; i++) {
     res = curl_easy_perform(curl[i]);
+    if(res)
+      goto test_cleanup;
+  }
 
 test_cleanup:
 
index 9805a2206b87623d302e04003df5f70f0919045c..aa0de41550cb059f4079fadef429811f680a0d5f 100644 (file)
@@ -81,7 +81,7 @@ int test(char *URL)
   curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount);
   curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
   curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl);
-  res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
+  test_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
 
   printf("res %d\n"
          "status %d\n"
index 1fbd7b92ce812bdd56e21a11449af75d27c0f524..f5e87e014f4e84d62a4869c9011c2794ce2c4562 100644 (file)
@@ -51,7 +51,7 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd,
 
 int test(char *URL)
 {
-  CURLcode code;
+  CURLcode code = TEST_ERR_MAJOR_BAD;
   CURLcode res;
   struct curl_slist *pHeaderList = NULL;
   CURL *curl = curl_easy_init();
@@ -97,5 +97,5 @@ test_cleanup:
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
-  return 0;
+  return (int)code;
 }
index 555fb962b5294c352ca7bd1b592b49c419a65785..0c9f8fa95a1fc508302cc5340743a559c162f81b 100644 (file)
@@ -106,7 +106,7 @@ static int perform_and_check_connections(CURL *curl, const char *description,
 
   res = curl_easy_perform(curl);
   if(res != CURLE_OK) {
-    fprintf(stderr, "curl_easy_perform() failed\n");
+    fprintf(stderr, "curl_easy_perform() failed with %d\n", (int)res);
     return TEST_ERR_MAJOR_BAD;
   }
 
index 8ea82a2634f88f947a6d42b2ab84f0e7fbb30c4a..4786e47928599da6e55f990b0ff8808a22f2efc9 100644 (file)
@@ -84,7 +84,6 @@ static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp)
 int test(char *URL)
 {
   CURL *curls = NULL;
-  int i = 0;
   int res = 0;
   struct transfer_status st;
 
@@ -114,8 +113,5 @@ test_cleanup:
   curl_easy_cleanup(curls);
   curl_global_cleanup();
 
-  if(res)
-    i = res;
-
-  return i; /* return the final return code */
+  return (int)res; /* return the final return code */
 }
index f693cb1fd12d19d3611eaaa065dbed1c11068bcb..784113aaf3bb97008edc00c44751269c3fb638f7 100644 (file)
@@ -39,11 +39,15 @@ int test(char *URL)
     curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     res = curl_easy_perform(curl);
+    if(res)
+      goto test_cleanup;
 
     fprintf(stderr, "****************************** Do it again\n");
     res = curl_easy_perform(curl);
-    curl_easy_cleanup(curl);
   }
+
+test_cleanup:
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
   return (int)res;
 }
index b0e94b8fba4131549a58de1ea7ff12d24d49140e..181044d057c86c27c00ae16d7fea8692d00ffa0d 100644 (file)
@@ -46,7 +46,7 @@ static void my_unlock(CURL *handle, curl_lock_data data, void *useptr)
 int test(char *URL)
 {
   CURLcode res = CURLE_OK;
-  CURLSH *share;
+  CURLSH *share = NULL;
   int i;
 
   global_init(CURL_GLOBAL_ALL);
@@ -54,8 +54,7 @@ int test(char *URL)
   share = curl_share_init();
   if(!share) {
     fprintf(stderr, "curl_share_init() failed\n");
-    curl_global_cleanup();
-    return TEST_ERR_MAJOR_BAD;
+    goto test_cleanup;
   }
 
   curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
@@ -75,18 +74,22 @@ int test(char *URL)
 
       /* Perform the request, res will get the return code */
       res = curl_easy_perform(curl);
-      /* Check for errors */
-      if(res != CURLE_OK)
-        fprintf(stderr, "curl_easy_perform() failed: %s\n",
-                curl_easy_strerror(res));
 
       /* always cleanup */
       curl_easy_cleanup(curl);
+
+      /* Check for errors */
+      if(res != CURLE_OK) {
+        fprintf(stderr, "curl_easy_perform() failed: %s\n",
+                curl_easy_strerror(res));
+        goto test_cleanup;
+      }
     }
   }
 
+test_cleanup:
   curl_share_cleanup(share);
   curl_global_cleanup();
 
-  return 0;
+  return (int)res;
 }
index 82f2f014ac87e33120dfa3ff40927ae5b630bf36..26b438dd09e0ac49b35a3880f9f9bc28a2c673e5 100644 (file)
 
 int test(char *URL)
 {
-  CURL *curl;
+  CURL *curl = NULL;
   CURLcode res = CURLE_OK;
+  CURLU *u = NULL;
 
   global_init(CURL_GLOBAL_ALL);
   curl = curl_easy_init();
   if(curl) {
-    CURLU *u = curl_url();
+    u = curl_url();
     if(u) {
       curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
       curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
       curl_url_set(u, CURLUPART_URL, URL, 0);
       curl_easy_setopt(curl, CURLOPT_CURLU, u);
       res = curl_easy_perform(curl);
+      if(res)
+        goto test_cleanup;
 
       fprintf(stderr, "****************************** Do it again\n");
       res = curl_easy_perform(curl);
-      curl_url_cleanup(u);
     }
-    curl_easy_cleanup(curl);
   }
+
+test_cleanup:
+  curl_url_cleanup(u);
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
   return (int)res;
 }
index 941bcc26d4515b4a7f022db1f36687d810d14cae..e24a387e33d1823b54ce745d41c0debf4727e192 100644 (file)
 
 int test(char *URL)
 {
-  CURLcode ret;
+  CURLcode res = CURLE_OK;
   CURL *hnd;
-  curl_global_init(CURL_GLOBAL_ALL);
+  global_init(CURL_GLOBAL_ALL);
 
-  hnd = curl_easy_init();
-  curl_easy_setopt(hnd, CURLOPT_URL, URL);
-  curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
-  curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
+  easy_init(hnd);
+  easy_setopt(hnd, CURLOPT_URL, URL);
+  easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
+  easy_setopt(hnd, CURLOPT_HEADER, 1L);
 
-  ret = curl_easy_perform(hnd);
+  res = curl_easy_perform(hnd);
+  if(res)
+    goto test_cleanup;
 
   curl_easy_setopt(hnd, CURLOPT_URL, libtest_arg2);
-  ret = curl_easy_perform(hnd);
-  curl_easy_cleanup(hnd);
+  res = curl_easy_perform(hnd);
 
+test_cleanup:
+  curl_easy_cleanup(hnd);
   curl_global_cleanup();
-  return (int)ret;
+  return (int)res;
 }
index 79baa17dd3f48a7644ea81a32af439af29ffbe34..a8a767e5c0b0777b282b32ecae73a56bafa19519 100644 (file)
 
 int test(char *URL)
 {
+  CURLcode res = CURLE_OK;
   CURL *ch = NULL;
-  curl_global_init(CURL_GLOBAL_ALL);
+  global_init(CURL_GLOBAL_ALL);
 
-  ch = curl_easy_init();
-  if(!ch)
-    goto cleanup;
+  easy_init(ch);
 
-  curl_easy_setopt(ch, CURLOPT_URL, URL);
-  curl_easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2);
-  curl_easy_perform(ch);
+  easy_setopt(ch, CURLOPT_URL, URL);
+  easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2);
+  res = curl_easy_perform(ch);
+  if(res)
+    goto test_cleanup;
 
   curl_easy_reset(ch);
 
-  curl_easy_setopt(ch, CURLOPT_URL, URL);
-  curl_easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2);
-  curl_easy_perform(ch);
+  easy_setopt(ch, CURLOPT_URL, URL);
+  easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2);
+  res = curl_easy_perform(ch);
 
-cleanup:
+test_cleanup:
   curl_easy_cleanup(ch);
   curl_global_cleanup();
 
-  return 0;
+  return (int)res;
 }
index c0d485f69ef5afc72d1df65b07ff500236159b72..02e8a31a7287d3b69faa61517aa1e095a1222b7d 100644 (file)
 
 int test(char *URL)
 {
-  char *url_after;
+  CURLcode res = CURLE_OK;
+  char *url_after = NULL;
   CURLU *curlu = curl_url();
-  CURL *curl = curl_easy_init();
-  CURLcode curl_code;
   char error_buffer[CURL_ERROR_SIZE] = "";
+  CURL *curl;
+
+  easy_init(curl);
 
   curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME);
-  curl_easy_setopt(curl, CURLOPT_CURLU, curlu);
-  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  easy_setopt(curl, CURLOPT_CURLU, curlu);
+  easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
+  easy_setopt(curl, CURLOPT_VERBOSE, 1L);
   /* set a port number that makes this request fail */
-  curl_easy_setopt(curl, CURLOPT_PORT, 1L);
-  curl_code = curl_easy_perform(curl);
-  if(!curl_code)
+  easy_setopt(curl, CURLOPT_PORT, 1L);
+  res = curl_easy_perform(curl);
+  if(res != CURLE_COULDNT_CONNECT && res != CURLE_OPERATION_TIMEDOUT) {
     fprintf(stderr, "failure expected, "
-            "curl_easy_perform returned %ld: <%s>, <%s>\n",
-            (long) curl_code, curl_easy_strerror(curl_code), error_buffer);
+            "curl_easy_perform returned %d: <%s>, <%s>\n",
+            (int) res, curl_easy_strerror(res), error_buffer);
+    if(res == CURLE_OK)
+      res = TEST_ERR_MAJOR_BAD;  /* force an error return */
+    goto test_cleanup;
+  }
+  res = CURLE_OK;  /* reset for next use */
 
   /* print the used url */
   curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
   fprintf(stderr, "curlu now: <%s>\n", url_after);
   curl_free(url_after);
+  url_after = NULL;
 
   /* now reset CURLOP_PORT to go back to originally set port number */
-  curl_easy_setopt(curl, CURLOPT_PORT, 0L);
+  easy_setopt(curl, CURLOPT_PORT, 0L);
 
-  curl_code = curl_easy_perform(curl);
-  if(curl_code)
+  res = curl_easy_perform(curl);
+  if(res)
     fprintf(stderr, "success expected, "
             "curl_easy_perform returned %ld: <%s>, <%s>\n",
-            (long) curl_code, curl_easy_strerror(curl_code), error_buffer);
+            (long) res, curl_easy_strerror(res), error_buffer);
 
   /* print url */
   curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
   fprintf(stderr, "curlu now: <%s>\n", url_after);
-  curl_free(url_after);
 
+test_cleanup:
+  curl_free(url_after);
   curl_easy_cleanup(curl);
   curl_url_cleanup(curlu);
   curl_global_cleanup();
 
-  return 0;
+  return (int)res;
 }
index d0876dc5811349d90019f4d8d1c719f01d5212fe..41cea379e024d0c5e66d3c11f9495d02d8775d7d 100644 (file)
@@ -31,7 +31,7 @@ int test(char *URL)
 {
   char *url_after;
   CURL *curl;
-  CURLcode curl_code;
+  CURLcode res = CURLE_OK;
   char error_buffer[CURL_ERROR_SIZE] = "";
 
   curl_global_init(CURL_GLOBAL_DEFAULT);
@@ -39,11 +39,11 @@ int test(char *URL)
   curl_easy_setopt(curl, CURLOPT_URL, URL);
   curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-  curl_code = curl_easy_perform(curl);
-  if(!curl_code)
+  res = curl_easy_perform(curl);
+  if(!res)
     fprintf(stderr, "failure expected, "
             "curl_easy_perform returned %ld: <%s>, <%s>\n",
-            (long) curl_code, curl_easy_strerror(curl_code), error_buffer);
+            (long) res, curl_easy_strerror(res), error_buffer);
 
   /* print the used url */
   if(!curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url_after))
@@ -52,5 +52,5 @@ int test(char *URL)
   curl_easy_cleanup(curl);
   curl_global_cleanup();
 
-  return 0;
+  return (int)res;
 }
index 290212fdccda3f7c5971069f22fddb1476316226..0672c70d6462a00f65f354af5ecdd6a2b090c84f 100644 (file)
@@ -98,36 +98,39 @@ static CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *e,
 
 int test(char *URL)
 {
-  CURLcode ret = CURLE_OK;
+  CURLcode res = CURLE_OK;
   CURL *hnd;
   struct state st = {0};
 
-  curl_global_init(CURL_GLOBAL_ALL);
+  global_init(CURL_GLOBAL_ALL);
 
-  hnd = curl_easy_init();
-  if(hnd) {
-    curl_easy_setopt(hnd, CURLOPT_URL, URL);
-    curl_easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsread);
-    curl_easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st);
-    curl_easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
-    curl_easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st);
-    curl_easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
-    ret = curl_easy_perform(hnd);
-    curl_easy_cleanup(hnd);
-    printf("First request returned %d\n", (int)ret);
-  }
-  hnd = curl_easy_init();
-  if(hnd) {
-    curl_easy_setopt(hnd, CURLOPT_URL, URL);
-    curl_easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsreadfail);
-    curl_easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st);
-    curl_easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
-    curl_easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st);
-    curl_easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
-    ret = curl_easy_perform(hnd);
-    curl_easy_cleanup(hnd);
-    printf("Second request returned %d\n", (int)ret);
-  }
+  easy_init(hnd);
+  easy_setopt(hnd, CURLOPT_URL, URL);
+  easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsread);
+  easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st);
+  easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
+  easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st);
+  easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
+  res = curl_easy_perform(hnd);
+  curl_easy_cleanup(hnd);
+  hnd = NULL;
+  printf("First request returned %d\n", (int)res);
+  res = CURLE_OK;
+
+  easy_init(hnd);
+  easy_setopt(hnd, CURLOPT_URL, URL);
+  easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsreadfail);
+  easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st);
+  easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
+  easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st);
+  easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
+  res = curl_easy_perform(hnd);
+  curl_easy_cleanup(hnd);
+  hnd = NULL;
+  printf("Second request returned %d\n", (int)res);
+
+test_cleanup:
+  curl_easy_cleanup(hnd);
   curl_global_cleanup();
-  return (int)ret;
+  return (int)res;
 }
index 39ba1d96c4dd8e7d7bfa984d478f94fe0f543f4a..37457c0682d1c6776edc615ee0d6ea37918fa463 100644 (file)
 
 int test(char *URL)
 {
+  CURLcode res = CURLE_OK;
   CURL *curl;
-  curl_global_init(CURL_GLOBAL_ALL);
+  int i;
 
-  curl = curl_easy_init();
-  if(curl) {
-    int i;
-    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
-    curl_easy_setopt(curl, CURLOPT_XOAUTH2_BEARER,
-                     "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1");
-    curl_easy_setopt(curl, CURLOPT_SASL_AUTHZID,
-                     "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2");
-    curl_easy_setopt(curl, CURLOPT_URL, URL);
+  global_init(CURL_GLOBAL_ALL);
+  easy_init(curl);
+  easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER);
+  easy_setopt(curl, CURLOPT_XOAUTH2_BEARER,
+                   "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1");
+  easy_setopt(curl, CURLOPT_SASL_AUTHZID,
+                   "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2");
+  easy_setopt(curl, CURLOPT_URL, URL);
 
-    for(i = 0; i < 2; i++)
-      /* the second request needs to do connection reuse */
-      curl_easy_perform(curl);
-
-    curl_easy_cleanup(curl);
+  for(i = 0; i < 2; i++) {
+    /* the second request needs to do connection reuse */
+    res = curl_easy_perform(curl);
+    if(res)
+      goto test_cleanup;
   }
+
+test_cleanup:
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
-  return 0;
+  return (int)res;
 }
index 5e90f6a366705143b5ff3eeb9c339a01c0d7ecd0..8bc094362164a939098036a2a5c89a881bef1e83 100644 (file)
@@ -83,37 +83,36 @@ static size_t write_cb(char *data, size_t n, size_t l, void *userp)
 }
 int test(char *URL)
 {
-  CURL *easy;
+  CURL *easy = NULL;
+  CURLcode res = CURLE_OK;
 
-  curl_global_init(CURL_GLOBAL_DEFAULT);
+  global_init(CURL_GLOBAL_DEFAULT);
+  easy_init(easy);
+  easy_setopt(easy, CURLOPT_URL, URL);
+  easy_setopt(easy, CURLOPT_VERBOSE, 1L);
+  easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
+  /* ignores any content */
+  easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
 
-  easy = curl_easy_init();
-  if(easy) {
-    CURLcode res;
-    curl_easy_setopt(easy, CURLOPT_URL, URL);
-    curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
-    curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
-    /* ignores any content */
-    curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
+  /* if there's a proxy set, use it */
+  if(libtest_arg2 && *libtest_arg2) {
+    easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
+    easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
+  }
+  res = curl_easy_perform(easy);
+  if(res)
+    goto test_cleanup;
 
-    /* if there's a proxy set, use it */
-    if(libtest_arg2 && *libtest_arg2) {
-      curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
-      curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
-    }
-    res = curl_easy_perform(easy);
-    if(res) {
-      printf("badness: %d\n", (int)res);
-    }
-    showem(easy, CURLH_HEADER);
-    if(libtest_arg2 && *libtest_arg2) {
-      /* now show connect headers only */
-      showem(easy, CURLH_CONNECT);
-    }
-    showem(easy, CURLH_1XX);
-    showem(easy, CURLH_TRAILER);
-    curl_easy_cleanup(easy);
+  showem(easy, CURLH_HEADER);
+  if(libtest_arg2 && *libtest_arg2) {
+    /* now show connect headers only */
+    showem(easy, CURLH_CONNECT);
   }
+  showem(easy, CURLH_1XX);
+  showem(easy, CURLH_TRAILER);
+
+test_cleanup:
+  curl_easy_cleanup(easy);
   curl_global_cleanup();
-  return 0;
+  return (int)res;
 }
index 1b658b09161dfa781ba81f7ff9283a7e6da6bb21..2483402f41f4fd4a2c59caf031f0319f3cf45c1b 100644 (file)
@@ -52,30 +52,30 @@ static size_t write_cb(char *data, size_t n, size_t l, void *userp)
 int test(char *URL)
 {
   CURL *easy;
+  CURLcode res = CURLE_OK;
 
-  curl_global_init(CURL_GLOBAL_DEFAULT);
+  global_init(CURL_GLOBAL_DEFAULT);
 
-  easy = curl_easy_init();
-  if(easy) {
-    CURLcode res;
-    curl_easy_setopt(easy, CURLOPT_URL, URL);
-    curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
-    curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
-    /* ignores any content */
-    curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
+  easy_init(easy);
+  curl_easy_setopt(easy, CURLOPT_URL, URL);
+  curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
+  curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
+  /* ignores any content */
+  curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
 
-    /* if there's a proxy set, use it */
-    if(libtest_arg2 && *libtest_arg2) {
-      curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
-      curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
-    }
-    res = curl_easy_perform(easy);
-    if(res) {
-      printf("badness: %d\n", (int)res);
-    }
-    showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX);
-    curl_easy_cleanup(easy);
+  /* if there's a proxy set, use it */
+  if(libtest_arg2 && *libtest_arg2) {
+    curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
+    curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
   }
+  res = curl_easy_perform(easy);
+  if(res) {
+    printf("badness: %d\n", (int)res);
+  }
+  showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX);
+
+test_cleanup:
+  curl_easy_cleanup(easy);
   curl_global_cleanup();
-  return 0;
+  return (int)res;
 }
index b9b40079e33860554c9d01c73f7be3e927d385be..b7a013127a17d383acc603f66a5c51a511f1b96b 100644 (file)
@@ -36,54 +36,57 @@ static size_t writecb(char *data, size_t n, size_t l, void *userp)
 int test(char *URL)
 {
   CURL *curl;
-  CURLcode res;
+  CURLcode res = CURLE_OK;
+  struct curl_header *h;
+  int count = 0;
+  int origins;
 
-  curl_global_init(CURL_GLOBAL_DEFAULT);
+  global_init(CURL_GLOBAL_DEFAULT);
 
-  curl = curl_easy_init();
-  if(curl) {
-    struct curl_header *h;
-    int count = 0;
-    int origins;
+  easy_init(curl);
 
-    /* perform a request that involves redirection */
-    curl_easy_setopt(curl, CURLOPT_URL, URL);
-    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
-    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
-    res = curl_easy_perform(curl);
-    if(res)
-      fprintf(stderr, "curl_easy_perform() failed: %s\n",
-              curl_easy_strerror(res));
-
-    /* count the number of requests by reading the first header of each
-       request. */
-    origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT|
-               CURLH_1XX|CURLH_PSEUDO);
-    do {
-      h = curl_easy_nextheader(curl, origins, count, NULL);
-      if(h)
-        count++;
-    } while(h);
-    printf("count = %u\n", count);
+  /* perform a request that involves redirection */
+  easy_setopt(curl, CURLOPT_URL, URL);
+  easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
+  easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+  res = curl_easy_perform(curl);
+  if(res) {
+    fprintf(stderr, "curl_easy_perform() failed: %s\n",
+            curl_easy_strerror(res));
+    goto test_cleanup;
+  }
 
-    /* perform another request - without redirect */
-    curl_easy_setopt(curl, CURLOPT_URL, libtest_arg2);
-    res = curl_easy_perform(curl);
-    if(res)
-      fprintf(stderr, "curl_easy_perform() failed: %s\n",
-              curl_easy_strerror(res));
+  /* count the number of requests by reading the first header of each
+     request. */
+  origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT|
+             CURLH_1XX|CURLH_PSEUDO);
+  do {
+    h = curl_easy_nextheader(curl, origins, count, NULL);
+    if(h)
+      count++;
+  } while(h);
+  printf("count = %u\n", count);
 
-    /* count the number of requests again. */
-    count = 0;
-    do {
-      h = curl_easy_nextheader(curl, origins, count, NULL);
-      if(h)
-        count++;
-    } while(h);
-    printf("count = %u\n", count);
-    curl_easy_cleanup(curl);
+  /* perform another request - without redirect */
+  easy_setopt(curl, CURLOPT_URL, libtest_arg2);
+  res = curl_easy_perform(curl);
+  if(res) {
+    fprintf(stderr, "curl_easy_perform() failed: %s\n",
+            curl_easy_strerror(res));
+    goto test_cleanup;
   }
 
+  /* count the number of requests again. */
+  count = 0;
+  do {
+    h = curl_easy_nextheader(curl, origins, count, NULL);
+    if(h)
+      count++;
+  } while(h);
+  printf("count = %u\n", count);
+
+test_cleanup:
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
-  return 0;
+  return (int)res;
 }
index 4ee565e29df7e7706c580eefbec0cccbac52d5d2..a30244c27e04ba85669492995bd9f8211e658ae6 100644 (file)
@@ -44,36 +44,35 @@ static size_t put_callback(char *ptr, size_t size, size_t nmemb, void *stream)
 int test(char *URL)
 {
   CURL *curl;
-  CURLcode res = CURLE_OUT_OF_MEMORY;
+  CURLcode res = CURLE_OK;
+  const char *testput = "This is test PUT data\n";
+  put_buffer pbuf;
 
   curl_global_init(CURL_GLOBAL_DEFAULT);
 
-  curl = curl_easy_init();
-  if(curl) {
-    const char *testput = "This is test PUT data\n";
-    put_buffer pbuf;
+  easy_init(curl);
 
-    /* PUT */
-    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
-    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
-    curl_easy_setopt(curl, CURLOPT_READFUNCTION, put_callback);
-    pbuf.buf = (char *)testput;
-    pbuf.len = strlen(testput);
-    curl_easy_setopt(curl, CURLOPT_READDATA, &pbuf);
-    curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput));
-    res = curl_easy_setopt(curl, CURLOPT_URL, URL);
-    if(!res)
-      res = curl_easy_perform(curl);
-    if(!res) {
-      /* POST */
-      curl_easy_setopt(curl, CURLOPT_POST, 1L);
-      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, testput);
-      curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput));
-      res = curl_easy_perform(curl);
-    }
-    curl_easy_cleanup(curl);
-  }
+  /* PUT */
+  easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+  easy_setopt(curl, CURLOPT_HEADER, 1L);
+  easy_setopt(curl, CURLOPT_READFUNCTION, put_callback);
+  pbuf.buf = (char *)testput;
+  pbuf.len = strlen(testput);
+  easy_setopt(curl, CURLOPT_READDATA, &pbuf);
+  easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput));
+  easy_setopt(curl, CURLOPT_URL, URL);
+  res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
+  /* POST */
+  easy_setopt(curl, CURLOPT_POST, 1L);
+  easy_setopt(curl, CURLOPT_POSTFIELDS, testput);
+  easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput));
+  res = curl_easy_perform(curl);
+
+test_cleanup:
+  curl_easy_cleanup(curl);
   curl_global_cleanup();
   return (int)res;
 }
index 1831b331c43710bfe055bea22cf2ef0c50549943..839bdcc0a6d43a6c770f6a90ed47893013f3c771 100644 (file)
@@ -33,18 +33,22 @@ int test(char *URL)
 {
   /* first a fine GET response, then a bad one */
   CURL *cl;
-  int res = 0;
+  CURLcode res = CURLE_OK;
 
   global_init(CURL_GLOBAL_ALL);
 
-  cl = curl_easy_init();
-  curl_easy_setopt(cl, CURLOPT_URL, URL);
-  curl_easy_setopt(cl, CURLOPT_VERBOSE, 1L);
-  curl_easy_perform(cl);
+  easy_init(cl);
+  easy_setopt(cl, CURLOPT_URL, URL);
+  easy_setopt(cl, CURLOPT_VERBOSE, 1L);
+  res = curl_easy_perform(cl);
+  if(res)
+    goto test_cleanup;
 
   /* reuse handle, do a second transfer */
-  curl_easy_setopt(cl, CURLOPT_URL, URL2);
-  curl_easy_perform(cl);
+  easy_setopt(cl, CURLOPT_URL, URL2);
+  res = curl_easy_perform(cl);
+
+test_cleanup:
   curl_easy_cleanup(cl);
   curl_global_cleanup();
   return res;
index a4abba08077600d89cdb2f641fc307ba287f6ac0..bf950bd456304706775824a15b1a63fb7a5eeee0 100644 (file)
@@ -49,6 +49,8 @@ int test(char *URL)
 
   /* get first page */
   res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
   test_setopt(curl, CURLOPT_USERPWD, "anothermonster:inwardrobe");
 
index fdddae2c75a062ae10842d34825389eedeeee030..75c74fbff836ad28413ba53bbfc4c75420b31c1e 100644 (file)
@@ -99,7 +99,9 @@ int test(char *URL)
   test_setopt(curl, CURLOPT_READDATA, hd_src);
 
   /* Now run off and do what you've been told! */
-  curl_easy_perform(curl);
+  res = curl_easy_perform(curl);
+  if(res)
+    goto test_cleanup;
 
   /* and now upload the exact same again, but without rewinding so it already
      is at end of file */
index 8b70231b76c13aaee0731be39aa93121ad6abeda..13726c6b4820a683713e1a2c14af108776f44ce8 100644 (file)
@@ -213,7 +213,6 @@ int test(char *URL)
   test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
 
   res = curl_easy_perform(curl);
-  fprintf(stderr, "curl_easy_perform = %d\n", (int)res);
 
 test_cleanup:
 
index 90d180070d4242559ef43ea157fc4733a7a49689..f6e60773777d202d388c86d758a23f7e4d65e4c7 100644 (file)
@@ -131,7 +131,7 @@ static void *fire(void *ptr)
 /* test function */
 int test(char *URL)
 {
-  int res;
+  CURLcode res = CURLE_OK;
   CURLSHcode scode = CURLSHE_OK;
   char *url;
   struct Tdata tdata;
@@ -184,8 +184,6 @@ int test(char *URL)
   }
 
 
-  res = 0;
-
   /* start treads */
   for(i = 1; i <= THREADS; i++) {
 
@@ -215,7 +213,7 @@ int test(char *URL)
   test_setopt(curl, CURLOPT_SHARE, share);
 
   printf("PERFORM\n");
-  curl_easy_perform(curl);
+  res = curl_easy_perform(curl);
 
   /* try to free share, expect to fail because share is in use */
   printf("try SHARE_CLEANUP...\n");
index 5fe56dbba89efd03530d4d5249f62b0538cc3d77..3a17e31c6ba0cf2f2dcd1768fced68d91185abf8 100644 (file)
@@ -56,6 +56,8 @@ int test(char *URL)
     test_setopt(curl, CURLOPT_MIMEPOST, mime);
     res = curl_easy_perform(curl);
     curl_mime_free(mime);
+    if(res)
+      goto test_cleanup;
   }
 #endif
 
index b4ca93e1afbade87898d9c725fc0d531587ab0a0..6dc7e8e1779198a026793474a32b03b2dba2e7ba 100644 (file)
@@ -39,27 +39,22 @@ int test(char *URL)
   time_t start = time(NULL);
   int state = 0;
   ssize_t pos = 0;
+  int res = 0;
 
-  curl_global_init(CURL_GLOBAL_DEFAULT);
-  mcurl = curl_multi_init();
-  if(!mcurl)
-    goto fail;
-  curl = curl_easy_init();
-  if(!curl)
-    goto fail;
+  global_init(CURL_GLOBAL_DEFAULT);
+  multi_init(mcurl);
+  easy_init(curl);
 
-  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-  if(curl_easy_setopt(curl, CURLOPT_URL, URL))
-    goto fail;
-  curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+  easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+  easy_setopt(curl, CURLOPT_URL, URL);
+  easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
   if(curl_multi_add_handle(mcurl, curl))
-    goto fail;
+    goto test_cleanup;
 
   while(time(NULL) - start < 5) {
     struct curl_waitfd waitfd;
 
-    if(curl_multi_perform(mcurl, &mrun))
-      goto fail;
+    multi_perform(mcurl, &mrun);
     for(;;) {
       int i;
       struct CURLMsg *m = curl_multi_info_read(mcurl, &i);
@@ -69,7 +64,7 @@ int test(char *URL)
       if(m->msg == CURLMSG_DONE && m->easy_handle == curl) {
         curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sock);
         if(sock == CURL_SOCKET_BAD)
-          goto fail;
+          goto test_cleanup;
         printf("Connected fine, extracted socket. Moving on\n");
       }
     }
@@ -86,7 +81,14 @@ int test(char *URL)
       size_t len = 0;
 
       if(!state) {
-        curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len);
+        CURLcode ec;
+        ec = curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len);
+        if(ec != CURLE_OK) {
+          fprintf(stderr, "curl_easy_send() failed, with code %d (%s)\n",
+                  (int)ec, curl_easy_strerror(ec));
+          res = ec;
+          goto test_cleanup;
+        }
         if(len > 0)
           pos += len;
         else
@@ -97,7 +99,14 @@ int test(char *URL)
         }
       }
       else if(pos < (ssize_t)sizeof(buf)) {
-        curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len);
+        CURLcode ec;
+        ec = curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len);
+        if(ec != CURLE_OK) {
+          fprintf(stderr, "curl_easy_recv() failed, with code %d (%s)\n",
+                  (int)ec, curl_easy_strerror(ec));
+          res = ec;
+          goto test_cleanup;
+        }
         if(len > 0)
           pos += len;
       }
@@ -112,10 +121,10 @@ int test(char *URL)
   }
 
   curl_multi_remove_handle(mcurl, curl);
-fail:
+test_cleanup:
   curl_easy_cleanup(curl);
   curl_multi_cleanup(mcurl);
 
   curl_global_cleanup();
-  return 0;
+  return res;
 }