quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib1906.c (2932B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at https://curl.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 #include "first.h"
     25 
     26 #include "memdebug.h"
     27 
     28 static CURLcode test_lib1906(char *URL)
     29 {
     30   CURLcode res = CURLE_OK;
     31   char *url_after = NULL;
     32   CURLU *curlu = curl_url();
     33   char error_buffer[CURL_ERROR_SIZE] = "";
     34   CURL *curl;
     35 
     36   easy_init(curl);
     37 
     38   curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME);
     39   easy_setopt(curl, CURLOPT_CURLU, curlu);
     40   easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
     41   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     42   /* msys2 times out instead of CURLE_COULDNT_CONNECT, so make it faster */
     43   easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000L);
     44   /* set a port number that makes this request fail */
     45   easy_setopt(curl, CURLOPT_PORT, 1L);
     46   res = curl_easy_perform(curl);
     47   if(res != CURLE_COULDNT_CONNECT && res != CURLE_OPERATION_TIMEDOUT) {
     48     curl_mfprintf(stderr, "failure expected, "
     49                   "curl_easy_perform returned %d: <%s>, <%s>\n",
     50                   res, curl_easy_strerror(res), error_buffer);
     51     if(res == CURLE_OK)
     52       res = TEST_ERR_MAJOR_BAD;  /* force an error return */
     53     goto test_cleanup;
     54   }
     55   res = CURLE_OK;  /* reset for next use */
     56 
     57   /* print the used url */
     58   curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
     59   curl_mfprintf(stderr, "curlu now: <%s>\n", url_after);
     60   curl_free(url_after);
     61   url_after = NULL;
     62 
     63   /* now reset CURLOP_PORT to go back to originally set port number */
     64   easy_setopt(curl, CURLOPT_PORT, 0L);
     65 
     66   res = curl_easy_perform(curl);
     67   if(res)
     68     curl_mfprintf(stderr, "success expected, "
     69                   "curl_easy_perform returned %d: <%s>, <%s>\n",
     70                   res, curl_easy_strerror(res), error_buffer);
     71 
     72   /* print url */
     73   curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
     74   curl_mfprintf(stderr, "curlu now: <%s>\n", url_after);
     75 
     76 test_cleanup:
     77   curl_free(url_after);
     78   curl_easy_cleanup(curl);
     79   curl_url_cleanup(curlu);
     80   curl_global_cleanup();
     81 
     82   return res;
     83 }