lib1536.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_SCHEME */
27 
28 int test(char *URL)
29 {
30  CURL *curl, *dupe = NULL;
31  char *scheme;
32  int res = CURLE_OK;
33 
35 
36  easy_init(curl);
37 
38  /* Test that scheme is properly initialized on curl_easy_init.
39  */
40 
41  res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
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(scheme != NULL) {
48  fprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
49  __FILE__, __LINE__);
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 scheme is properly set after receiving an HTTP resource.
64  */
65 
66  res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
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(memcmp(scheme, "HTTP", 5) != 0) {
73  fprintf(stderr, "%s:%d scheme of http resource is incorrect; "
74  "expected 'HTTP' but is %s\n",
75  __FILE__, __LINE__, CURLPROTO_HTTP,
76  (scheme == NULL ? "NULL" : "invalid"));
78  goto test_cleanup;
79  }
80 
81  /* Test that a scheme is properly initialized on curl_easy_duphandle.
82  */
83 
84  dupe = curl_easy_duphandle(curl);
85  if(!dupe) {
86  fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n",
87  __FILE__, __LINE__);
88  res = CURLE_FAILED_INIT;
89  goto test_cleanup;
90  }
91 
92  res = curl_easy_getinfo(dupe, CURLINFO_SCHEME, &scheme);
93  if(res) {
94  fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
95  __FILE__, __LINE__, res, curl_easy_strerror(res));
96  goto test_cleanup;
97  }
98  if(scheme != 0) {
99  fprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
100  __FILE__, __LINE__);
101  res = CURLE_FAILED_INIT;
102  goto test_cleanup;
103  }
104 
105 
106  /* Test that a scheme is properly initialized on curl_easy_reset.
107  */
108 
109  curl_easy_reset(curl);
110 
111  res = curl_easy_getinfo(curl, CURLINFO_SCHEME, &scheme);
112  if(res) {
113  fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n",
114  __FILE__, __LINE__, res, curl_easy_strerror(res));
115  goto test_cleanup;
116  }
117  if(scheme != 0) {
118  fprintf(stderr, "%s:%d scheme init failed; expected NULL\n",
119  __FILE__, __LINE__);
120  res = CURLE_FAILED_INIT;
121  goto test_cleanup;
122  }
123 
124 test_cleanup:
125  curl_easy_cleanup(curl);
126  curl_easy_cleanup(dupe);
128  return res;
129 }
#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
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
int test(char *URL)
Definition: lib1536.c:28
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