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