lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * _ _ ____ _ |
| 3 | * Project ___| | | | _ \| | |
| 4 | * / __| | | | |_) | | |
| 5 | * | (__| |_| | _ <| |___ |
| 6 | * \___|\___/|_| \_\_____| |
| 7 | * |
| 8 | * Copyright (C) 1998 - 2016, 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 | |
| 24 | #include "memdebug.h" |
| 25 | |
| 26 | /* Test CURLINFO_SCHEME */ |
| 27 | |
| 28 | int test(char *URL) |
| 29 | { |
| 30 | CURL *curl, *dupe = NULL; |
| 31 | char *scheme; |
| 32 | int res = CURLE_OK; |
| 33 | |
| 34 | global_init(CURL_GLOBAL_ALL); |
| 35 | |
| 36 | easy_init(curl); |
| 37 | |
| 38 | /* Test that scheme is properly initialized on curl_easy_init. |
| 39 | */ |
| 40 | |
| 41 | res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme); |
| 42 | if(res) { |
| 43 | fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", |
| 44 | __FILE__, __LINE__, res, curl_easy_strerror(res)); |
| 45 | goto test_cleanup; |
| 46 | } |
| 47 | if(scheme != NULL) { |
| 48 | fprintf(stderr, "%s:%d scheme init failed; expected NULL\n", |
| 49 | __FILE__, __LINE__); |
| 50 | res = CURLE_FAILED_INIT; |
| 51 | goto test_cleanup; |
| 52 | } |
| 53 | |
| 54 | easy_setopt(curl, CURLOPT_URL, URL); |
| 55 | |
| 56 | res = curl_easy_perform(curl); |
| 57 | if(res) { |
| 58 | fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n", |
| 59 | __FILE__, __LINE__, res, curl_easy_strerror(res)); |
| 60 | goto test_cleanup; |
| 61 | } |
| 62 | |
| 63 | /* Test that a scheme is properly set after receiving an HTTP resource. |
| 64 | */ |
| 65 | |
| 66 | res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme); |
| 67 | if(res) { |
| 68 | fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", |
| 69 | __FILE__, __LINE__, res, curl_easy_strerror(res)); |
| 70 | goto test_cleanup; |
| 71 | } |
| 72 | if(memcmp(scheme, "HTTP", 5) != 0) { |
| 73 | fprintf(stderr, "%s:%d scheme of http resource is incorrect; " |
| 74 | "expected 'HTTP' but is %s\n", |
| 75 | __FILE__, __LINE__, CURLPROTO_HTTP, |
| 76 | (scheme == NULL ? "NULL" : "invalid")); |
| 77 | res = CURLE_HTTP_RETURNED_ERROR; |
| 78 | goto test_cleanup; |
| 79 | } |
| 80 | |
| 81 | /* Test that a scheme is properly initialized on curl_easy_duphandle. |
| 82 | */ |
| 83 | |
| 84 | dupe = curl_easy_duphandle(curl); |
| 85 | if(!dupe) { |
| 86 | fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n", |
| 87 | __FILE__, __LINE__); |
| 88 | res = CURLE_FAILED_INIT; |
| 89 | goto test_cleanup; |
| 90 | } |
| 91 | |
| 92 | res = curl_easy_getinfo(dupe, CURLINFO_SCHEME, &scheme); |
| 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(scheme != 0) { |
| 99 | fprintf(stderr, "%s:%d scheme init failed; expected NULL\n", |
| 100 | __FILE__, __LINE__); |
| 101 | res = CURLE_FAILED_INIT; |
| 102 | goto test_cleanup; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /* Test that a scheme is properly initialized on curl_easy_reset. |
| 107 | */ |
| 108 | |
| 109 | curl_easy_reset(curl); |
| 110 | |
| 111 | res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme); |
| 112 | if(res) { |
| 113 | fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", |
| 114 | __FILE__, __LINE__, res, curl_easy_strerror(res)); |
| 115 | goto test_cleanup; |
| 116 | } |
| 117 | if(scheme != 0) { |
| 118 | fprintf(stderr, "%s:%d scheme init failed; expected NULL\n", |
| 119 | __FILE__, __LINE__); |
| 120 | res = CURLE_FAILED_INIT; |
| 121 | goto test_cleanup; |
| 122 | } |
| 123 | |
| 124 | test_cleanup: |
| 125 | curl_easy_cleanup(curl); |
| 126 | curl_easy_cleanup(dupe); |
| 127 | curl_global_cleanup(); |
| 128 | return res; |
| 129 | } |