2
#include "curl_config.h"
8
#include "memdebug.h" /* LAST include file */
10
static struct SessionHandle *data;
12
static CURLcode unit_setup( void )
14
data = curl_easy_init();
16
return CURLE_OUT_OF_MEMORY;
20
static void unit_stop( void )
22
curl_easy_cleanup(data);
25
/* BASE is just a define to make us fool around with decently large number so
26
that we aren't zero-based */
29
/* macro to set the pretended current time */
30
#define NOW(x,y) now.tv_sec = x; now.tv_usec = y
31
/* macro to set the millisecond based timeouts to use */
32
#define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
37
* 00/10/01/11 timeouts set
39
* T various values on the timeouts
40
* N various values of now
47
int connecttimeout_ms;
59
const struct timetest run[] = {
60
/* both timeouts set, not connecting */
61
{BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
62
{BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
63
{BASE + 10, 0, 10000, 8000, FALSE, -1, "timeout is -1, expired"},
64
{BASE + 12, 0, 10000, 8000, FALSE, -2000, "-2000, overdue 2 seconds"},
66
/* both timeouts set, connecting */
67
{BASE + 4, 0, 10000, 8000, TRUE, 4000, "4 seconds should be left"},
68
{BASE + 4, 990000, 10000, 8000, TRUE, 3010, "3010 ms should be left"},
69
{BASE + 8, 0, 10000, 8000, TRUE, -1, "timeout is -1, expired"},
70
{BASE + 10, 0, 10000, 8000, TRUE, -2000, "-2000, overdue 2 seconds"},
72
/* no connect timeout set, not connecting */
73
{BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
74
{BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
75
{BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
76
{BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
78
/* no connect timeout set, connecting */
79
{BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
80
{BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
81
{BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
82
{BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
84
/* only connect timeout set, not connecting */
85
{BASE + 4, 0, 0, 10000, FALSE, 0, "no timeout active"},
86
{BASE + 4, 990000, 0, 10000, FALSE, 0, "no timeout active"},
87
{BASE + 10, 0, 0, 10000, FALSE, 0, "no timeout active"},
88
{BASE + 12, 0, 0, 10000, FALSE, 0, "no timeout active"},
90
/* only connect timeout set, connecting */
91
{BASE + 4, 0, 0, 10000, TRUE, 6000, "6 seconds should be left"},
92
{BASE + 4, 990000, 0, 10000, TRUE, 5010, "5010 ms should be left"},
93
{BASE + 10, 0, 0, 10000, TRUE, -1, "timeout is -1, expired"},
94
{BASE + 12, 0, 0, 10000, TRUE, -2000, "-2000, overdue 2 seconds"},
96
/* no timeout set, not connecting */
97
{BASE + 4, 0, 0, 0, FALSE, 0, "no timeout active"},
98
{BASE + 4, 990000, 0, 0, FALSE, 0, "no timeout active"},
99
{BASE + 10, 0, 0, 0, FALSE, 0, "no timeout active"},
100
{BASE + 12, 0, 0, 0, FALSE, 0, "no timeout active"},
102
/* no timeout set, connecting */
103
{BASE + 4, 0, 0, 0, TRUE, 296000, "no timeout active"},
104
{BASE + 4, 990000, 0, 0, TRUE, 295010, "no timeout active"},
105
{BASE + 10, 0, 0, 0, TRUE, 290000, "no timeout active"},
106
{BASE + 12, 0, 0, 0, TRUE, 288000, "no timeout active"},
108
/* both timeouts set, connecting, connect timeout the longer one */
109
{BASE + 4, 0, 10000, 12000, TRUE, 6000, "6 seconds should be left"},
113
/* this is the pretended start time of the transfer */
114
data->progress.t_startsingle.tv_sec = BASE;
115
data->progress.t_startsingle.tv_usec = 0;
117
for(i=0; i < sizeof(run)/sizeof(run[0]); i++) {
118
NOW(run[i].now_s, run[i].now_us);
119
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
120
timeout = Curl_timeleft(data, &now, run[i].connecting);
121
if(timeout != run[i].result)
122
fail(run[i].comment);