quickjs-tart

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

lib1597.c (3148B)


      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 
     25 /* Testing CURLOPT_PROTOCOLS_STR */
     26 
     27 #include "first.h"
     28 
     29 #include "memdebug.h"
     30 
     31 struct pair {
     32   const char *in;
     33   CURLcode *exp;
     34 };
     35 
     36 static CURLcode test_lib1597(char *URL)
     37 {
     38   CURL *curl = NULL;
     39   CURLcode res = CURLE_OK;
     40   curl_version_info_data *curlinfo;
     41   const char *const *proto;
     42   int n;
     43   int i;
     44   static CURLcode ok = CURLE_OK;
     45   static CURLcode bad = CURLE_BAD_FUNCTION_ARGUMENT;
     46   static CURLcode unsup = CURLE_UNSUPPORTED_PROTOCOL;
     47   static CURLcode httpcode = CURLE_UNSUPPORTED_PROTOCOL;
     48   static CURLcode httpscode = CURLE_UNSUPPORTED_PROTOCOL;
     49   static char protolist[1024];
     50 
     51   static const struct pair prots[] = {
     52     {"goobar", &unsup},
     53     {"http ", &unsup},
     54     {" http", &unsup},
     55     {"http", &httpcode},
     56     {"http,", &httpcode},
     57     {"https,", &httpscode},
     58     {"https,http", &httpscode},
     59     {"http,http", &httpcode},
     60     {"HTTP,HTTP", &httpcode},
     61     {",HTTP,HTTP", &httpcode},
     62     {"http,http,ft", &unsup},
     63     {"", &bad},
     64     {",,", &bad},
     65     {protolist, &ok},
     66     {"all", &ok},
     67     {NULL, NULL},
     68   };
     69   (void)URL;
     70 
     71   global_init(CURL_GLOBAL_ALL);
     72 
     73   easy_init(curl);
     74 
     75   /* Get enabled protocols.*/
     76   curlinfo = curl_version_info(CURLVERSION_NOW);
     77   if(!curlinfo) {
     78     fputs("curl_version_info failed\n", stderr);
     79     res = TEST_ERR_FAILURE;
     80     goto test_cleanup;
     81   }
     82 
     83   n = 0;
     84   for(proto = curlinfo->protocols; *proto; proto++) {
     85     if((size_t) n >= sizeof(protolist)) {
     86       puts("protolist buffer too small\n");
     87       res = TEST_ERR_FAILURE;
     88       goto test_cleanup;
     89     }
     90     n += curl_msnprintf(protolist + n, sizeof(protolist) - n, ",%s", *proto);
     91     if(curl_strequal(*proto, "http"))
     92       httpcode = CURLE_OK;
     93     if(curl_strequal(*proto, "https"))
     94       httpscode = CURLE_OK;
     95   }
     96 
     97   /* Run the tests. */
     98   for(i = 0; prots[i].in; i++) {
     99     res = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in);
    100     if(res != *prots[i].exp) {
    101       curl_mprintf("unexpectedly '%s' returned %d\n", prots[i].in, res);
    102       break;
    103     }
    104   }
    105   curl_mprintf("Tested %u strings\n", i);
    106 
    107 test_cleanup:
    108   curl_easy_cleanup(curl);
    109   curl_global_cleanup();
    110 
    111   return res;
    112 }