Annotation of embedaddon/curl/tests/libtest/lib1535.c, revision 1.1.1.1
1.1 misho 1: /***************************************************************************
2: * _ _ ____ _
3: * Project ___| | | | _ \| |
4: * / __| | | | |_) | |
5: * | (__| |_| | _ <| |___
6: * \___|\___/|_| \_\_____|
7: *
8: * Copyright (C) 1998 - 2020, 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_PROTOCOL */
27:
28: int test(char *URL)
29: {
30: CURL *curl, *dupe = NULL;
31: long protocol;
32: int res = CURLE_OK;
33:
34: global_init(CURL_GLOBAL_ALL);
35:
36: easy_init(curl);
37:
38: /* Test that protocol is properly initialized on curl_easy_init.
39: */
40:
41: res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
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(protocol != 0) {
48: fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
49: __FILE__, __LINE__, protocol);
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 protocol is properly set after receiving an HTTP resource.
64: */
65:
66: res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
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(protocol != CURLPROTO_HTTP) {
73: fprintf(stderr, "%s:%d protocol of http resource is incorrect; "
74: "expected %d but is %ld\n",
75: __FILE__, __LINE__, CURLPROTO_HTTP, protocol);
76: res = CURLE_HTTP_RETURNED_ERROR;
77: goto test_cleanup;
78: }
79:
80: /* Test that a protocol is properly initialized on curl_easy_duphandle.
81: */
82:
83: dupe = curl_easy_duphandle(curl);
84: if(!dupe) {
85: fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
86: __FILE__, __LINE__);
87: res = CURLE_FAILED_INIT;
88: goto test_cleanup;
89: }
90:
91: res = curl_easy_getinfo(dupe, CURLINFO_PROTOCOL, &protocol);
92: if(res) {
93: fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
94: __FILE__, __LINE__, res, curl_easy_strerror(res));
95: goto test_cleanup;
96: }
97: if(protocol != 0) {
98: fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
99: __FILE__, __LINE__, protocol);
100: res = CURLE_FAILED_INIT;
101: goto test_cleanup;
102: }
103:
104:
105: /* Test that a protocol is properly initialized on curl_easy_reset.
106: */
107:
108: curl_easy_reset(curl);
109:
110: res = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
111: if(res) {
112: fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
113: __FILE__, __LINE__, res, curl_easy_strerror(res));
114: goto test_cleanup;
115: }
116: if(protocol != 0) {
117: fprintf(stderr, "%s:%d protocol init failed; expected 0 but is %ld\n",
118: __FILE__, __LINE__, protocol);
119: res = CURLE_FAILED_INIT;
120: goto test_cleanup;
121: }
122:
123: test_cleanup:
124: curl_easy_cleanup(curl);
125: curl_easy_cleanup(dupe);
126: curl_global_cleanup();
127: return res;
128: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>