lib1535.c 3.9 KB

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