quickjs-tart

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

lib1536.c (4179B)


      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 /* Test CURLINFO_SCHEME */
     29 
     30 static CURLcode test_lib1536(char *URL)
     31 {
     32   CURL *curl, *dupe = NULL;
     33   char *scheme;
     34   CURLcode res = CURLE_OK;
     35 
     36   global_init(CURL_GLOBAL_ALL);
     37 
     38   easy_init(curl);
     39 
     40   /* Test that scheme is properly initialized on curl_easy_init.
     41   */
     42 
     43   res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
     44   if(res) {
     45     curl_mfprintf(stderr,
     46                   "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
     47                   __FILE__, __LINE__, res, curl_easy_strerror(res));
     48     goto test_cleanup;
     49   }
     50   if(scheme) {
     51     curl_mfprintf(stderr,
     52                   "%s:%d scheme init failed; expected NULL\n",
     53                   __FILE__, __LINE__);
     54     res = CURLE_FAILED_INIT;
     55     goto test_cleanup;
     56   }
     57 
     58   easy_setopt(curl, CURLOPT_URL, URL);
     59 
     60   res = curl_easy_perform(curl);
     61   if(res) {
     62     curl_mfprintf(stderr,
     63                   "%s:%d curl_easy_perform() failed with code %d (%s)\n",
     64                   __FILE__, __LINE__, res, curl_easy_strerror(res));
     65     goto test_cleanup;
     66   }
     67 
     68   /* Test that a scheme is properly set after receiving an HTTP resource.
     69   */
     70 
     71   res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
     72   if(res) {
     73     curl_mfprintf(stderr,
     74                   "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
     75                   __FILE__, __LINE__, res, curl_easy_strerror(res));
     76     goto test_cleanup;
     77   }
     78   if(!scheme || memcmp(scheme, "http", 5) != 0) {
     79     curl_mfprintf(stderr, "%s:%d scheme of http resource is incorrect; "
     80                   "expected 'http' but is %s\n",
     81                   __FILE__, __LINE__,
     82                   (scheme == NULL ? "NULL" : "invalid"));
     83     res = CURLE_HTTP_RETURNED_ERROR;
     84     goto test_cleanup;
     85   }
     86 
     87   /* Test that a scheme is properly initialized on curl_easy_duphandle.
     88   */
     89 
     90   dupe = curl_easy_duphandle(curl);
     91   if(!dupe) {
     92     curl_mfprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
     93                   __FILE__, __LINE__);
     94     res = CURLE_FAILED_INIT;
     95     goto test_cleanup;
     96   }
     97 
     98   res = curl_easy_getinfo(dupe, CURLINFO_SCHEME, &scheme);
     99   if(res) {
    100     curl_mfprintf(stderr,
    101                   "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
    102                   __FILE__, __LINE__, res, curl_easy_strerror(res));
    103     goto test_cleanup;
    104   }
    105   if(scheme) {
    106     curl_mfprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
    107                   __FILE__, __LINE__);
    108     res = CURLE_FAILED_INIT;
    109     goto test_cleanup;
    110   }
    111 
    112   /* Test that a scheme is properly initialized on curl_easy_reset.
    113   */
    114 
    115   curl_easy_reset(curl);
    116 
    117   res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
    118   if(res) {
    119     curl_mfprintf(stderr,
    120                   "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
    121                   __FILE__, __LINE__, res, curl_easy_strerror(res));
    122     goto test_cleanup;
    123   }
    124   if(scheme) {
    125     curl_mfprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
    126                   __FILE__, __LINE__);
    127     res = CURLE_FAILED_INIT;
    128     goto test_cleanup;
    129   }
    130 
    131 test_cleanup:
    132   curl_easy_cleanup(curl);
    133   curl_easy_cleanup(dupe);
    134   curl_global_cleanup();
    135   return res;
    136 }