lib1535.c
Go to the documentation of this file.
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_PROTOCOL */
27 
28 int test(char *URL)
29 {
30  CURL *curl, *dupe = NULL;
31  long protocol;
32  int res = CURLE_OK;
33 
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 %ld but is %ld\n",
75  __FILE__, __LINE__, CURLPROTO_HTTP, protocol);
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);
127  return res;
128 }
#define CURLPROTO_HTTP
Definition: curl.h:844
CURL_EXTERN void curl_easy_reset(CURL *curl)
#define global_init(A)
Definition: test.h:431
#define easy_setopt(A, B, C)
Definition: test.h:190
static int res
int test(char *URL)
Definition: lib1535.c:28
CURL_EXTERN CURL * curl_easy_duphandle(CURL *curl)
#define curl_easy_getinfo(handle, info, arg)
#define easy_init(A)
Definition: test.h:145
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN const char * curl_easy_strerror(CURLcode)
Definition: strerror.c:57
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15