unit1654.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "curlcheck.h"
  25. #include "urldata.h"
  26. #include "altsvc.h"
  27. static CURLcode
  28. unit_setup(void)
  29. {
  30. return CURLE_OK;
  31. }
  32. static void
  33. unit_stop(void)
  34. {
  35. curl_global_cleanup();
  36. }
  37. UNITTEST_START
  38. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
  39. {
  40. char outname[256];
  41. CURL *curl;
  42. CURLcode result;
  43. struct altsvcinfo *asi = Curl_altsvc_init();
  44. abort_if(!asi, "Curl_altsvc_i");
  45. result = Curl_altsvc_load(asi, arg);
  46. if(result) {
  47. fail_if(result, "Curl_altsvc_load");
  48. goto fail;
  49. }
  50. curl_global_init(CURL_GLOBAL_ALL);
  51. curl = curl_easy_init();
  52. if(!curl) {
  53. fail_if(!curl, "curl_easy_init");
  54. goto fail;
  55. }
  56. fail_unless(Curl_llist_count(&asi->list) == 4, "wrong number of entries");
  57. msnprintf(outname, sizeof(outname), "%s-out", arg);
  58. result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"\r\n",
  59. ALPN_h1, "example.org", 8080);
  60. fail_if(result, "Curl_altsvc_parse() failed!");
  61. fail_unless(Curl_llist_count(&asi->list) == 5, "wrong number of entries");
  62. result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"\r\n",
  63. ALPN_h1, "2.example.org", 8080);
  64. fail_if(result, "Curl_altsvc_parse(2) failed!");
  65. fail_unless(Curl_llist_count(&asi->list) == 6, "wrong number of entries");
  66. result = Curl_altsvc_parse(curl, asi,
  67. "h2=\"example.com:8080\", h3=\"yesyes.com\"\r\n",
  68. ALPN_h1, "3.example.org", 8080);
  69. fail_if(result, "Curl_altsvc_parse(3) failed!");
  70. /* that one should make two entries */
  71. fail_unless(Curl_llist_count(&asi->list) == 8, "wrong number of entries");
  72. result = Curl_altsvc_parse(curl, asi,
  73. "h2=\"example.com:443\"; ma = 120;\r\n",
  74. ALPN_h2, "example.org", 80);
  75. fail_if(result, "Curl_altsvc_parse(4) failed!");
  76. fail_unless(Curl_llist_count(&asi->list) == 9, "wrong number of entries");
  77. /* quoted 'ma' value */
  78. result = Curl_altsvc_parse(curl, asi,
  79. "h2=\"example.net:443\"; ma=\"180\";\r\n",
  80. ALPN_h2, "example.net", 80);
  81. fail_if(result, "Curl_altsvc_parse(4) failed!");
  82. fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
  83. result =
  84. Curl_altsvc_parse(curl, asi,
  85. "h2=\":443\", h3=\":443\"; ma = 120; persist = 1\r\n",
  86. ALPN_h1, "curl.se", 80);
  87. fail_if(result, "Curl_altsvc_parse(5) failed!");
  88. fail_unless(Curl_llist_count(&asi->list) == 12, "wrong number of entries");
  89. /* clear that one again and decrease the counter */
  90. result = Curl_altsvc_parse(curl, asi, "clear;\r\n",
  91. ALPN_h1, "curl.se", 80);
  92. fail_if(result, "Curl_altsvc_parse(6) failed!");
  93. fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
  94. Curl_altsvc_save(curl, asi, outname);
  95. curl_easy_cleanup(curl);
  96. fail:
  97. Curl_altsvc_cleanup(&asi);
  98. }
  99. #endif
  100. UNITTEST_STOP