lib1536.c 3.8 KB

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