unit1654.c 3.7 KB

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