1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
26 /* Test CURLINFO_PROTOCOL */
30 CURL *curl, *dupe = NULL;
34 global_init(CURL_GLOBAL_ALL);
38 /* Test that protocol is properly initialized on curl_easy_init.
41 res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
43 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
44 __FILE__, __LINE__, res, curl_easy_strerror(res));
48 fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
49 __FILE__, __LINE__, protocol);
50 res = CURLE_FAILED_INIT;
54 easy_setopt(curl, CURLOPT_URL, URL);
56 res = curl_easy_perform(curl);
58 fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
59 __FILE__, __LINE__, res, curl_easy_strerror(res));
63 /* Test that a protocol is properly set after receiving an HTTP resource.
66 res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
68 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
69 __FILE__, __LINE__, res, curl_easy_strerror(res));
72 if(protocol != CURLPROTO_HTTP) {
73 fprintf(stderr, "%s:%d protocol of http resource is incorrect; "
74 "expected %ld but is %ld\n",
75 __FILE__, __LINE__, CURLPROTO_HTTP, protocol);
76 res = CURLE_HTTP_RETURNED_ERROR;
80 /* Test that a protocol is properly initialized on curl_easy_duphandle.
83 dupe = curl_easy_duphandle(curl);
85 fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
87 res = CURLE_FAILED_INIT;
91 res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
93 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
94 __FILE__, __LINE__, res, curl_easy_strerror(res));
98 fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
99 __FILE__, __LINE__, protocol);
100 res = CURLE_FAILED_INIT;
105 /* Test that a protocol is properly initialized on curl_easy_reset.
108 curl_easy_reset(curl);
110 res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
112 fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
113 __FILE__, __LINE__, res, curl_easy_strerror(res));
117 fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
118 __FILE__, __LINE__, protocol);
119 res = CURLE_FAILED_INIT;
124 curl_easy_cleanup(curl);
125 curl_easy_cleanup(dupe);
126 curl_global_cleanup();