00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023
00024 #include "urldata.h"
00025 #include "connect.h"
00026 #include "memdebug.h"
00027
00028 static struct Curl_easy *data;
00029
00030 static CURLcode unit_setup(void)
00031 {
00032 data = curl_easy_init();
00033 if(!data)
00034 return CURLE_OUT_OF_MEMORY;
00035 return CURLE_OK;
00036 }
00037
00038 static void unit_stop(void)
00039 {
00040 curl_easy_cleanup(data);
00041 }
00042
00043
00044
00045 #define BASE 1000000
00046
00047
00048 #define NOW(x,y) now.tv_sec = x; now.tv_usec = y
00049
00050 #define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 struct timetest {
00062 int now_s;
00063 int now_us;
00064 int timeout_ms;
00065 int connecttimeout_ms;
00066 bool connecting;
00067 long result;
00068 const char *comment;
00069 };
00070
00071 UNITTEST_START
00072 {
00073 struct timeval now;
00074 long timeout;
00075 unsigned int i;
00076
00077 const struct timetest run[] = {
00078
00079 {BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
00080 {BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
00081 {BASE + 10, 0, 10000, 8000, FALSE, -1, "timeout is -1, expired"},
00082 {BASE + 12, 0, 10000, 8000, FALSE, -2000, "-2000, overdue 2 seconds"},
00083
00084
00085 {BASE + 4, 0, 10000, 8000, TRUE, 4000, "4 seconds should be left"},
00086 {BASE + 4, 990000, 10000, 8000, TRUE, 3010, "3010 ms should be left"},
00087 {BASE + 8, 0, 10000, 8000, TRUE, -1, "timeout is -1, expired"},
00088 {BASE + 10, 0, 10000, 8000, TRUE, -2000, "-2000, overdue 2 seconds"},
00089
00090
00091 {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
00092 {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
00093 {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
00094 {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
00095
00096
00097 {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
00098 {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
00099 {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
00100 {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
00101
00102
00103 {BASE + 4, 0, 0, 10000, FALSE, 0, "no timeout active"},
00104 {BASE + 4, 990000, 0, 10000, FALSE, 0, "no timeout active"},
00105 {BASE + 10, 0, 0, 10000, FALSE, 0, "no timeout active"},
00106 {BASE + 12, 0, 0, 10000, FALSE, 0, "no timeout active"},
00107
00108
00109 {BASE + 4, 0, 0, 10000, TRUE, 6000, "6 seconds should be left"},
00110 {BASE + 4, 990000, 0, 10000, TRUE, 5010, "5010 ms should be left"},
00111 {BASE + 10, 0, 0, 10000, TRUE, -1, "timeout is -1, expired"},
00112 {BASE + 12, 0, 0, 10000, TRUE, -2000, "-2000, overdue 2 seconds"},
00113
00114
00115 {BASE + 4, 0, 0, 0, FALSE, 0, "no timeout active"},
00116 {BASE + 4, 990000, 0, 0, FALSE, 0, "no timeout active"},
00117 {BASE + 10, 0, 0, 0, FALSE, 0, "no timeout active"},
00118 {BASE + 12, 0, 0, 0, FALSE, 0, "no timeout active"},
00119
00120
00121 {BASE + 4, 0, 0, 0, TRUE, 296000, "no timeout active"},
00122 {BASE + 4, 990000, 0, 0, TRUE, 295010, "no timeout active"},
00123 {BASE + 10, 0, 0, 0, TRUE, 290000, "no timeout active"},
00124 {BASE + 12, 0, 0, 0, TRUE, 288000, "no timeout active"},
00125
00126
00127 {BASE + 4, 0, 10000, 12000, TRUE, 6000, "6 seconds should be left"},
00128
00129 };
00130
00131
00132 data->progress.t_startsingle.tv_sec = BASE;
00133 data->progress.t_startsingle.tv_usec = 0;
00134 data->progress.t_startop.tv_sec = BASE;
00135 data->progress.t_startop.tv_usec = 0;
00136
00137 for(i=0; i < sizeof(run)/sizeof(run[0]); i++) {
00138 NOW(run[i].now_s, run[i].now_us);
00139 TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
00140 timeout = Curl_timeleft(data, &now, run[i].connecting);
00141 if(timeout != run[i].result)
00142 fail(run[i].comment);
00143 }
00144 }
00145 UNITTEST_STOP