File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / unit / unit1654.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 10:01:16 2020 UTC (5 years ago) by misho
Branches: curl, MAIN
CVS tags: v7_70_0p4, HEAD
curl

    1: /***************************************************************************
    2:  *                                  _   _ ____  _
    3:  *  Project                     ___| | | |  _ \| |
    4:  *                             / __| | | | |_) | |
    5:  *                            | (__| |_| |  _ <| |___
    6:  *                             \___|\___/|_| \_\_____|
    7:  *
    8:  * Copyright (C) 2019 - 2020, 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.haxx.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:  ***************************************************************************/
   22: #include "curlcheck.h"
   23: 
   24: #include "urldata.h"
   25: #include "altsvc.h"
   26: 
   27: static CURLcode
   28: unit_setup(void)
   29: {
   30:   return CURLE_OK;
   31: }
   32: 
   33: static void
   34: unit_stop(void)
   35: {
   36:   curl_global_cleanup();
   37: }
   38: 
   39: #if defined(CURL_DISABLE_HTTP) || !defined(USE_ALTSVC)
   40: UNITTEST_START
   41: {
   42:   return 0; /* nothing to do when HTTP is disabled or alt-svc support is
   43:                missing */
   44: }
   45: UNITTEST_STOP
   46: #else
   47: UNITTEST_START
   48: {
   49:   char outname[256];
   50:   CURL *curl;
   51:   CURLcode result;
   52:   struct altsvcinfo *asi = Curl_altsvc_init();
   53:   if(!asi)
   54:     return 1;
   55:   result = Curl_altsvc_load(asi, arg);
   56:   if(result) {
   57:     Curl_altsvc_cleanup(asi);
   58:     return result;
   59:   }
   60:   curl = curl_easy_init();
   61:   if(!curl)
   62:     goto fail;
   63:   fail_unless(asi->num == 4, "wrong number of entries");
   64:   msnprintf(outname, sizeof(outname), "%s-out", arg);
   65: 
   66:   result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"",
   67:                              ALPN_h1, "example.org", 8080);
   68:   if(result) {
   69:     fprintf(stderr, "Curl_altsvc_parse() failed!\n");
   70:     unitfail++;
   71:   }
   72:   fail_unless(asi->num == 5, "wrong number of entries");
   73: 
   74:   result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"",
   75:                              ALPN_h1, "2.example.org", 8080);
   76:   if(result) {
   77:     fprintf(stderr, "Curl_altsvc_parse(2) failed!\n");
   78:     unitfail++;
   79:   }
   80:   fail_unless(asi->num == 6, "wrong number of entries");
   81: 
   82:   result = Curl_altsvc_parse(curl, asi,
   83:                              "h2=\"example.com:8080\", h3=\"yesyes.com\"",
   84:                              ALPN_h1, "3.example.org", 8080);
   85:   if(result) {
   86:     fprintf(stderr, "Curl_altsvc_parse(3) failed!\n");
   87:     unitfail++;
   88:   }
   89:   /* that one should make two entries */
   90:   fail_unless(asi->num == 8, "wrong number of entries");
   91: 
   92:   result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:443\"; ma = 120;",
   93:                              ALPN_h2, "example.org", 80);
   94:   if(result) {
   95:     fprintf(stderr, "Curl_altsvc_parse(4) failed!\n");
   96:     unitfail++;
   97:   }
   98:   fail_unless(asi->num == 9, "wrong number of entries");
   99: 
  100:   /* quoted 'ma' value */
  101:   result = Curl_altsvc_parse(curl, asi, "h2=\"example.net:443\"; ma=\"180\";",
  102:                              ALPN_h2, "example.net", 80);
  103:   if(result) {
  104:     fprintf(stderr, "Curl_altsvc_parse(4) failed!\n");
  105:     unitfail++;
  106:   }
  107:   fail_unless(asi->num == 10, "wrong number of entries");
  108: 
  109:   result = Curl_altsvc_parse(curl, asi,
  110:                              "h2=\":443\", h3=\":443\"; ma = 120; persist = 1",
  111:                              ALPN_h1, "curl.haxx.se", 80);
  112:   if(result) {
  113:     fprintf(stderr, "Curl_altsvc_parse(5) failed!\n");
  114:     unitfail++;
  115:   }
  116:   fail_unless(asi->num == 12, "wrong number of entries");
  117: 
  118:   /* clear that one again and decrease the counter */
  119:   result = Curl_altsvc_parse(curl, asi, "clear;",
  120:                              ALPN_h1, "curl.haxx.se", 80);
  121:   if(result) {
  122:     fprintf(stderr, "Curl_altsvc_parse(6) failed!\n");
  123:     unitfail++;
  124:   }
  125:   fail_unless(asi->num == 10, "wrong number of entries");
  126: 
  127:   Curl_altsvc_save(curl, asi, outname);
  128: 
  129:   curl_easy_cleanup(curl);
  130:   fail:
  131:   Curl_altsvc_cleanup(asi);
  132:   return unitfail;
  133: }
  134: UNITTEST_STOP
  135: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>