2
0

lib1906.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "testutil.h"
  26. #include "warnless.h"
  27. #include "memdebug.h"
  28. CURLcode test(char *URL)
  29. {
  30. CURLcode res = CURLE_OK;
  31. char *url_after = NULL;
  32. CURLU *curlu = curl_url();
  33. char error_buffer[CURL_ERROR_SIZE] = "";
  34. CURL *curl;
  35. easy_init(curl);
  36. curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME);
  37. easy_setopt(curl, CURLOPT_CURLU, curlu);
  38. easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
  39. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  40. /* msys2 times out instead of CURLE_COULDNT_CONNECT, so make it faster */
  41. easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000L);
  42. /* set a port number that makes this request fail */
  43. easy_setopt(curl, CURLOPT_PORT, 1L);
  44. res = curl_easy_perform(curl);
  45. if(res != CURLE_COULDNT_CONNECT && res != CURLE_OPERATION_TIMEDOUT) {
  46. fprintf(stderr, "failure expected, "
  47. "curl_easy_perform returned %d: <%s>, <%s>\n",
  48. res, curl_easy_strerror(res), error_buffer);
  49. if(res == CURLE_OK)
  50. res = TEST_ERR_MAJOR_BAD; /* force an error return */
  51. goto test_cleanup;
  52. }
  53. res = CURLE_OK; /* reset for next use */
  54. /* print the used url */
  55. curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
  56. fprintf(stderr, "curlu now: <%s>\n", url_after);
  57. curl_free(url_after);
  58. url_after = NULL;
  59. /* now reset CURLOP_PORT to go back to originally set port number */
  60. easy_setopt(curl, CURLOPT_PORT, 0L);
  61. res = curl_easy_perform(curl);
  62. if(res)
  63. fprintf(stderr, "success expected, "
  64. "curl_easy_perform returned %d: <%s>, <%s>\n",
  65. res, curl_easy_strerror(res), error_buffer);
  66. /* print url */
  67. curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
  68. fprintf(stderr, "curlu now: <%s>\n", url_after);
  69. test_cleanup:
  70. curl_free(url_after);
  71. curl_easy_cleanup(curl);
  72. curl_url_cleanup(curlu);
  73. curl_global_cleanup();
  74. return res;
  75. }