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