unit1303.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 #include "urldata.h"
00025 #include "connect.h"
00026 #include "memdebug.h" /* LAST include file */
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 /* BASE is just a define to make us fool around with decently large number so
00044    that we aren't zero-based */
00045 #define BASE 1000000
00046 
00047 /* macro to set the pretended current time */
00048 #define NOW(x,y) now.tv_sec = x; now.tv_usec = y
00049 /* macro to set the millisecond based timeouts to use */
00050 #define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
00051 
00052 /*
00053  * To test:
00054  *
00055  * 00/10/01/11 timeouts set
00056  * 0/1         during connect
00057  * T           various values on the timeouts
00058  * N           various values of now
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   /* both timeouts set, not connecting */
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   /* both timeouts set, connecting */
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   /* no connect timeout set, not connecting */
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   /* no connect timeout set, connecting */
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   /* only connect timeout set, not connecting */
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   /* only connect timeout set, connecting */
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   /* no timeout set, not connecting */
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   /* no timeout set, connecting */
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   /* both timeouts set, connecting, connect timeout the longer one */
00127   {BASE + 4, 0,      10000, 12000, TRUE, 6000, "6 seconds should be left"},
00128 
00129   };
00130 
00131   /* this is the pretended start time of the transfer */
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


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07