2
0

lib1535.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "test.h"
  25. #include "memdebug.h"
  26. /* Test CURLINFO_PROTOCOL */
  27. int test(char *URL)
  28. {
  29. CURL *curl, *dupe = NULL;
  30. long protocol;
  31. CURLcode res = CURLE_OK;
  32. global_init(CURL_GLOBAL_ALL);
  33. easy_init(curl);
  34. /* Test that protocol is properly initialized on curl_easy_init.
  35. */
  36. CURL_IGNORE_DEPRECATION(
  37. res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
  38. )
  39. if(res) {
  40. fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
  41. __FILE__, __LINE__, res, curl_easy_strerror(res));
  42. goto test_cleanup;
  43. }
  44. if(protocol) {
  45. fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
  46. __FILE__, __LINE__, protocol);
  47. res = CURLE_FAILED_INIT;
  48. goto test_cleanup;
  49. }
  50. easy_setopt(curl, CURLOPT_URL, URL);
  51. res = curl_easy_perform(curl);
  52. if(res) {
  53. fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
  54. __FILE__, __LINE__, res, curl_easy_strerror(res));
  55. goto test_cleanup;
  56. }
  57. /* Test that a protocol is properly set after receiving an HTTP resource.
  58. */
  59. CURL_IGNORE_DEPRECATION(
  60. res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
  61. )
  62. if(res) {
  63. fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
  64. __FILE__, __LINE__, res, curl_easy_strerror(res));
  65. goto test_cleanup;
  66. }
  67. if(protocol != CURLPROTO_HTTP) {
  68. fprintf(stderr, "%s:%d protocol of http resource is incorrect; "
  69. "expected %d but is %ld\n",
  70. __FILE__, __LINE__, CURLPROTO_HTTP, protocol);
  71. res = CURLE_HTTP_RETURNED_ERROR;
  72. goto test_cleanup;
  73. }
  74. /* Test that a protocol is properly initialized on curl_easy_duphandle.
  75. */
  76. dupe = curl_easy_duphandle(curl);
  77. if(!dupe) {
  78. fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
  79. __FILE__, __LINE__);
  80. res = CURLE_FAILED_INIT;
  81. goto test_cleanup;
  82. }
  83. CURL_IGNORE_DEPRECATION(
  84. res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
  85. )
  86. if(res) {
  87. fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
  88. __FILE__, __LINE__, res, curl_easy_strerror(res));
  89. goto test_cleanup;
  90. }
  91. if(protocol) {
  92. fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
  93. __FILE__, __LINE__, protocol);
  94. res = CURLE_FAILED_INIT;
  95. goto test_cleanup;
  96. }
  97. /* Test that a protocol is properly initialized on curl_easy_reset.
  98. */
  99. curl_easy_reset(curl);
  100. CURL_IGNORE_DEPRECATION(
  101. res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
  102. )
  103. if(res) {
  104. fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
  105. __FILE__, __LINE__, res, curl_easy_strerror(res));
  106. goto test_cleanup;
  107. }
  108. if(protocol) {
  109. fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
  110. __FILE__, __LINE__, protocol);
  111. res = CURLE_FAILED_INIT;
  112. goto test_cleanup;
  113. }
  114. test_cleanup:
  115. curl_easy_cleanup(curl);
  116. curl_easy_cleanup(dupe);
  117. curl_global_cleanup();
  118. return (int)res;
  119. }