unit1303.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, 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 "curlcheck.h"
23 
24 #include "urldata.h"
25 #include "connect.h"
26 #include "memdebug.h" /* LAST include file */
27 
28 static struct Curl_easy *data;
29 
30 static CURLcode unit_setup(void)
31 {
32  int res = CURLE_OK;
33 
35  data = curl_easy_init();
36  if(!data)
37  return CURLE_OUT_OF_MEMORY;
38  return res;
39 }
40 
41 static void unit_stop(void)
42 {
43  curl_easy_cleanup(data);
45 }
46 
47 /* BASE is just a define to make us fool around with decently large number so
48  that we aren't zero-based */
49 #define BASE 1000000
50 
51 /* macro to set the pretended current time */
52 #define NOW(x,y) now.tv_sec = x; now.tv_usec = y
53 /* macro to set the millisecond based timeouts to use */
54 #define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
55 
56 /*
57  * To test:
58  *
59  * 00/10/01/11 timeouts set
60  * 0/1 during connect
61  * T various values on the timeouts
62  * N various values of now
63  */
64 
65 struct timetest {
66  int now_s;
67  int now_us;
70  bool connecting;
71  time_t result;
72  const char *comment;
73 };
74 
76 {
77  struct curltime now;
78  time_t timeout;
79  unsigned int i;
80 
81  const struct timetest run[] = {
82  /* both timeouts set, not connecting */
83  {BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
84  {BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
85  {BASE + 10, 0, 10000, 8000, FALSE, -1, "timeout is -1, expired"},
86  {BASE + 12, 0, 10000, 8000, FALSE, -2000, "-2000, overdue 2 seconds"},
87 
88  /* both timeouts set, connecting */
89  {BASE + 4, 0, 10000, 8000, TRUE, 4000, "4 seconds should be left"},
90  {BASE + 4, 990000, 10000, 8000, TRUE, 3010, "3010 ms should be left"},
91  {BASE + 8, 0, 10000, 8000, TRUE, -1, "timeout is -1, expired"},
92  {BASE + 10, 0, 10000, 8000, TRUE, -2000, "-2000, overdue 2 seconds"},
93 
94  /* no connect timeout set, not connecting */
95  {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
96  {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
97  {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
98  {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
99 
100  /* no connect timeout set, connecting */
101  {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
102  {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
103  {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
104  {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
105 
106  /* only connect timeout set, not connecting */
107  {BASE + 4, 0, 0, 10000, FALSE, 0, "no timeout active"},
108  {BASE + 4, 990000, 0, 10000, FALSE, 0, "no timeout active"},
109  {BASE + 10, 0, 0, 10000, FALSE, 0, "no timeout active"},
110  {BASE + 12, 0, 0, 10000, FALSE, 0, "no timeout active"},
111 
112  /* only connect timeout set, connecting */
113  {BASE + 4, 0, 0, 10000, TRUE, 6000, "6 seconds should be left"},
114  {BASE + 4, 990000, 0, 10000, TRUE, 5010, "5010 ms should be left"},
115  {BASE + 10, 0, 0, 10000, TRUE, -1, "timeout is -1, expired"},
116  {BASE + 12, 0, 0, 10000, TRUE, -2000, "-2000, overdue 2 seconds"},
117 
118  /* no timeout set, not connecting */
119  {BASE + 4, 0, 0, 0, FALSE, 0, "no timeout active"},
120  {BASE + 4, 990000, 0, 0, FALSE, 0, "no timeout active"},
121  {BASE + 10, 0, 0, 0, FALSE, 0, "no timeout active"},
122  {BASE + 12, 0, 0, 0, FALSE, 0, "no timeout active"},
123 
124  /* no timeout set, connecting */
125  {BASE + 4, 0, 0, 0, TRUE, 296000, "no timeout active"},
126  {BASE + 4, 990000, 0, 0, TRUE, 295010, "no timeout active"},
127  {BASE + 10, 0, 0, 0, TRUE, 290000, "no timeout active"},
128  {BASE + 12, 0, 0, 0, TRUE, 288000, "no timeout active"},
129 
130  /* both timeouts set, connecting, connect timeout the longer one */
131  {BASE + 4, 0, 10000, 12000, TRUE, 6000, "6 seconds should be left"},
132 
133  };
134 
135  /* this is the pretended start time of the transfer */
138  data->progress.t_startop.tv_sec = BASE;
139  data->progress.t_startop.tv_usec = 0;
140 
141  for(i = 0; i < sizeof(run)/sizeof(run[0]); i++) {
142  NOW(run[i].now_s, run[i].now_us);
143  TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
144  timeout = Curl_timeleft(data, &now, run[i].connecting);
145  if(timeout != run[i].result)
146  fail(run[i].comment);
147  }
148 }
static CURLcode unit_setup(void)
Definition: unit1303.c:30
#define BASE
Definition: unit1303.c:49
static struct Curl_easy * data
Definition: unit1303.c:28
time_t tv_sec
Definition: timeval.h:33
#define global_init(A)
Definition: test.h:431
time_t timeout
Definition: unit1303.c:78
CURLcode
Definition: curl.h:454
const struct timetest run[]
Definition: unit1303.c:81
static int res
struct curltime t_startop
Definition: urldata.h:1120
unsigned int i
Definition: unit1303.c:79
int now_s
Definition: unit1303.c:66
static void unit_stop(void)
Definition: unit1303.c:41
#define FALSE
time_t Curl_timeleft(struct Curl_easy *data, struct curltime *nowp, bool duringconnect)
Definition: connect.c:182
int now_us
Definition: unit1303.c:67
#define fail(msg)
Definition: curlcheck.h:51
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
struct Progress progress
Definition: urldata.h:1768
Definition: curl.h:455
#define UNITTEST_STOP
Definition: curlcheck.h:95
bool connecting
Definition: unit1303.c:70
time_t result
Definition: unit1303.c:71
#define TIMEOUTS(x, y)
Definition: unit1303.c:54
int connecttimeout_ms
Definition: unit1303.c:69
struct curltime t_startsingle
Definition: urldata.h:1119
const char * comment
Definition: unit1303.c:72
#define NOW(x, y)
Definition: unit1303.c:52
int timeout_ms
Definition: unit1303.c:68
#define TRUE
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
UNITTEST_START
Definition: unit1303.c:76
unsigned int tv_usec
Definition: timeval.h:34


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