1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2014, 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 http://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 ***************************************************************************/
22 #include "curlcheck.h"
26 #include "memdebug.h" /* LAST include file */
28 static struct SessionHandle *data;
30 static CURLcode unit_setup( void )
32 data = curl_easy_init();
34 return CURLE_OUT_OF_MEMORY;
38 static void unit_stop( void )
40 curl_easy_cleanup(data);
43 /* BASE is just a define to make us fool around with decently large number so
44 that we aren't zero-based */
47 /* macro to set the pretended current time */
48 #define NOW(x,y) now.tv_sec = x; now.tv_usec = y
49 /* macro to set the millisecond based timeouts to use */
50 #define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
55 * 00/10/01/11 timeouts set
57 * T various values on the timeouts
58 * N various values of now
65 int connecttimeout_ms;
77 const struct timetest run[] = {
78 /* both timeouts set, not connecting */
79 {BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
80 {BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
81 {BASE + 10, 0, 10000, 8000, FALSE, -1, "timeout is -1, expired"},
82 {BASE + 12, 0, 10000, 8000, FALSE, -2000, "-2000, overdue 2 seconds"},
84 /* both timeouts set, connecting */
85 {BASE + 4, 0, 10000, 8000, TRUE, 4000, "4 seconds should be left"},
86 {BASE + 4, 990000, 10000, 8000, TRUE, 3010, "3010 ms should be left"},
87 {BASE + 8, 0, 10000, 8000, TRUE, -1, "timeout is -1, expired"},
88 {BASE + 10, 0, 10000, 8000, TRUE, -2000, "-2000, overdue 2 seconds"},
90 /* no connect timeout set, not connecting */
91 {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
92 {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
93 {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
94 {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
96 /* no connect timeout set, connecting */
97 {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
98 {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
99 {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
100 {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
102 /* only connect timeout set, not connecting */
103 {BASE + 4, 0, 0, 10000, FALSE, 0, "no timeout active"},
104 {BASE + 4, 990000, 0, 10000, FALSE, 0, "no timeout active"},
105 {BASE + 10, 0, 0, 10000, FALSE, 0, "no timeout active"},
106 {BASE + 12, 0, 0, 10000, FALSE, 0, "no timeout active"},
108 /* only connect timeout set, connecting */
109 {BASE + 4, 0, 0, 10000, TRUE, 6000, "6 seconds should be left"},
110 {BASE + 4, 990000, 0, 10000, TRUE, 5010, "5010 ms should be left"},
111 {BASE + 10, 0, 0, 10000, TRUE, -1, "timeout is -1, expired"},
112 {BASE + 12, 0, 0, 10000, TRUE, -2000, "-2000, overdue 2 seconds"},
114 /* no timeout set, not connecting */
115 {BASE + 4, 0, 0, 0, FALSE, 0, "no timeout active"},
116 {BASE + 4, 990000, 0, 0, FALSE, 0, "no timeout active"},
117 {BASE + 10, 0, 0, 0, FALSE, 0, "no timeout active"},
118 {BASE + 12, 0, 0, 0, FALSE, 0, "no timeout active"},
120 /* no timeout set, connecting */
121 {BASE + 4, 0, 0, 0, TRUE, 296000, "no timeout active"},
122 {BASE + 4, 990000, 0, 0, TRUE, 295010, "no timeout active"},
123 {BASE + 10, 0, 0, 0, TRUE, 290000, "no timeout active"},
124 {BASE + 12, 0, 0, 0, TRUE, 288000, "no timeout active"},
126 /* both timeouts set, connecting, connect timeout the longer one */
127 {BASE + 4, 0, 10000, 12000, TRUE, 6000, "6 seconds should be left"},
131 /* this is the pretended start time of the transfer */
132 data->progress.t_startsingle.tv_sec = BASE;
133 data->progress.t_startsingle.tv_usec = 0;
134 data->progress.t_startop.tv_sec = BASE;
135 data->progress.t_startop.tv_usec = 0;
137 for(i=0; i < sizeof(run)/sizeof(run[0]); i++) {
138 NOW(run[i].now_s, run[i].now_us);
139 TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
140 timeout = Curl_timeleft(data, &now, run[i].connecting);
141 if(timeout != run[i].result)
142 fail(run[i].comment);