2
0

lib1536.c 3.8 KB

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