Home | History | Annotate | Download | only in libtest
      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel (at) 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 "test.h"
     23 
     24 #include "memdebug.h"
     25 
     26 struct dcheck {
     27   const char *input;
     28   time_t output;
     29 };
     30 
     31 static struct dcheck dates[] = {
     32   {"Sun, 06 Nov 1994 08:49:37 GMT", 784111777 },
     33   {"Sunday, 06-Nov-94 08:49:37 GMT", 784111777 },
     34   {"Sun Nov  6 08:49:37 1994", 784111777 },
     35   {"06 Nov 1994 08:49:37 GMT", 784111777 },
     36   {"06-Nov-94 08:49:37 GMT", 784111777 },
     37   {"Nov  6 08:49:37 1994", 784111777 },
     38   {"06 Nov 1994 08:49:37", 784111777 },
     39   {"06-Nov-94 08:49:37", 784111777 },
     40   {"1994 Nov 6 08:49:37", 784111777 },
     41   {"GMT 08:49:37 06-Nov-94 Sunday", 784111777 },
     42   {"94 6 Nov 08:49:37", 784111777 },
     43   {"1994 Nov 6", 784080000 },
     44   {"06-Nov-94", 784080000 },
     45   {"Sun Nov 6 94", 784080000 },
     46   {"1994.Nov.6", 784080000 },
     47   {"Sun/Nov/6/94/GMT", 784080000 },
     48   {"Sun, 06 Nov 1994 08:49:37 CET", 784108177 },
     49   {"06 Nov 1994 08:49:37 EST", 784129777 },
     50   {"Sun, 06 Nov 1994 08:49:37 UT", 784111777 },
     51   {"Sun, 12 Sep 2004 15:05:58 -0700", 1095026758 },
     52   {"Sat, 11 Sep 2004 21:32:11 +0200", 1094931131 },
     53   {"20040912 15:05:58 -0700", 1095026758 },
     54   {"20040911 +0200", 1094853600 },
     55   {"Thu, 01-Jan-1970 00:59:59 GMT", 3599 },
     56   {"Thu, 01-Jan-1970 01:00:00 GMT", 3600 },
     57   {"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 },
     58   {"Thu, 19-Apr-2007 16:00:00 GMT", 1176998400 },
     59   {"Wed, 25 Apr 2007 21:02:13 GMT", 1177534933 },
     60   {"Thu, 19/Apr\\2007 16:00:00 GMT", 1176998400 },
     61   {"Fri, 1 Jan 2010 01:01:50 GMT", 1262307710 },
     62   {"Wednesday, 1-Jan-2003 00:00:00 GMT", 1041379200 },
     63   {", 1-Jan-2003 00:00:00 GMT", 1041379200 },
     64   {"1-Jan-2003 00:00:00 GMT", 1041379200 },
     65   {"1-Jan-2003 00:00:00 GMT", 1041379200 },
     66   {"Wed,18-Apr-07 22:50:12 GMT", 1176936612 },
     67   {"WillyWonka  , 18-Apr-07 22:50:12 GMT", -1 },
     68   {"WillyWonka  , 18-Apr-07 22:50:12", -1 },
     69   {"WillyWonka  ,  18-apr-07   22:50:12", -1 },
     70   {"Mon, 18-Apr-1977 22:50:13 GMT", 230251813 },
     71   {"Mon, 18-Apr-77 22:50:13 GMT", 230251813 },
     72   {"Sat, 15-Apr-17\"21:01:22\"GMT", 1492290082 },
     73   {"Partyday, 18- April-07 22:50:12", -1 },
     74   {"Partyday, 18 - Apri-07 22:50:12", -1 },
     75   {"Wednes, 1-Januar-2003 00:00:00 GMT", -1 },
     76   {"Sat, 15-Apr-17 21:01:22", 1492290082 },
     77   {"Sat, 15-Apr-17 21:01:22 GMT-2", 1492290082 },
     78   {"Sat, 15-Apr-17 21:01:22 GMT BLAH", 1492290082 },
     79   {"Sat, 15-Apr-17 21:01:22 GMT-0400", 1492290082 },
     80   {"Sat, 15-Apr-17 21:01:22 GMT-0400 (EDT)", 1492290082 },
     81   {"Sat, 15-Apr-17 21:01:22 DST", -1 },
     82   {"Sat, 15-Apr-17 21:01:22 -0400", 1492304482 },
     83   {"Sat, 15-Apr-17 21:01:22 (hello there)", -1 },
     84   {"Sat, 15-Apr-17 21:01:22 11:22:33", -1 },
     85   {"Sat, 15-Apr-17 ::00 21:01:22", -1 },
     86   {"Sat, 15-Apr-17 boink:z 21:01:22", -1 },
     87   {"Sat, 15-Apr-17 91:22:33 21:01:22", -1 },
     88   {"Thu Apr 18 22:50:12 2007 GMT", 1176936612 },
     89   {"22:50:12 Thu Apr 18 2007 GMT", 1176936612 },
     90   {"Thu 22:50:12 Apr 18 2007 GMT", 1176936612 },
     91   {"Thu Apr 22:50:12 18 2007 GMT", 1176936612 },
     92   {"Thu Apr 18 22:50:12 2007 GMT", 1176936612 },
     93   {"Thu Apr 18 2007 22:50:12 GMT", 1176936612 },
     94   {"Thu Apr 18 2007 GMT 22:50:12", 1176936612 },
     95   {"Sat, 15-Apr-17 21:01:22 GMT", 1492290082 },
     96   {"15-Sat, Apr-17 21:01:22 GMT", 1492290082 },
     97   {"15-Sat, Apr 21:01:22 GMT 17", 1492290082 },
     98   {"15-Sat, Apr 21:01:22 GMT 2017", 1492290082 },
     99   {"15 Apr 21:01:22 2017", 1492290082 },
    100   {"15 17 Apr 21:01:22", 1492290082 },
    101   {"Apr 15 17 21:01:22", 1492290082 },
    102   {"Apr 15 21:01:22 17", 1492290082 },
    103   {"2017 April 15 21:01:22", -1 },
    104   {"15 April 2017 21:01:22", -1 },
    105   {"98 April 17 21:01:22", -1 },
    106   {"Thu, 012-Aug-2008 20:49:07 GMT", 1218574147 },
    107   {"Thu, 999999999999-Aug-2007 20:49:07 GMT", -1 },
    108   {"Thu, 12-Aug-2007 20:61:99999999999 GMT", -1 },
    109   {"IAintNoDateFool", -1 },
    110   {"Thu Apr 18 22:50 2007 GMT", 1176936600 },
    111   {"20110623 12:34:56", 1308832496 },
    112   {"20110632 12:34:56", -1 },
    113   {"20110623 56:34:56", -1 },
    114   {"20111323 12:34:56", -1 },
    115   {"20110623 12:34:79", -1 },
    116   {"Wed, 31 Dec 2008 23:59:60 GMT", 1230768000 },
    117   {"20110623 12:3", 1308830580 },
    118   {"20110623 1:3", 1308790980 },
    119   {"20110623 1:30", 1308792600 },
    120   {"20110623 12:12:3", 1308831123 },
    121   {"20110623 01:12:3", 1308791523 },
    122   {"20110623 01:99:30", -1 },
    123   {"Thu, 01-Jan-1970 00:00:00 GMT", 0 },
    124   {"Thu, 31-Dec-1969 23:59:58 GMT", -2 },
    125   {"Thu, 31-Dec-1969 23:59:59 GMT", 0 }, /* avoids -1 ! */
    126 #if SIZEOF_TIME_T > 4
    127   {"Sun, 06 Nov 2044 08:49:37 GMT", 2362034977 },
    128   {"Sun, 06 Nov 3144 08:49:37 GMT", 37074617377 },
    129 #ifndef HAVE_TIME_T_UNSIGNED
    130 #if 0
    131   /* causes warning on MSVC */
    132   {"Sun, 06 Nov 1900 08:49:37 GMT", -2182259423 },
    133 #endif
    134   {"Sun, 06 Nov 1800 08:49:37 GMT", -5337933023 },
    135   {"Thu, 01-Jan-1583 00:00:00 GMT", -12212553600 },
    136 #endif
    137   {"Thu, 01-Jan-1499 00:00:00 GMT", -1 },
    138 #else
    139   {"Sun, 06 Nov 2044 08:49:37 GMT", -1 },
    140 #endif
    141 #ifndef HAVE_TIME_T_UNSIGNED
    142   {"Sun, 06 Nov 1968 08:49:37 GMT", -36342623 },
    143 #endif
    144   { NULL, 0 }
    145 };
    146 
    147 int test(char *URL)
    148 {
    149   int i;
    150   int error = 0;
    151 
    152   (void)URL; /* not used */
    153 
    154   for(i = 0; dates[i].input; i++) {
    155     time_t out = curl_getdate(dates[i].input, NULL);
    156     if(out != dates[i].output) {
    157       printf("WRONGLY %s => %ld (instead of %ld)\n",
    158              dates[i].input, out, dates[i].output);
    159       error++;
    160     }
    161   }
    162 
    163   return error;
    164 }
    165