X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-getdate.c;h=ea70527f9393f83d5daa42a1f392597f1d633b87;hb=7da6c6f9a62e4a00ad88beb04f492b28fe517699;hp=874d918e20e149f6adac9191d8802746b343ba87;hpb=929a85498c0c5657499db769f36c739d28467c8f;p=gnulib.git diff --git a/tests/test-getdate.c b/tests/test-getdate.c index 874d918e2..ea70527f9 100644 --- a/tests/test-getdate.c +++ b/tests/test-getdate.c @@ -1,5 +1,5 @@ /* Test of getdate() function. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ #include #include +#include "progname.h" + #include "getdate.h" #define ASSERT(expr) \ @@ -43,17 +45,31 @@ printf ("string `%s' diff %d %d\n", \ str, res.tv_sec - now.tv_sec, res.tv_nsec - now.tv_nsec); #else -#define LOG(str, now, res) 0 +#define LOG(str, now, res) (void) 0 #endif +static const char* const day_table[] = +{ + "SUNDAY", + "MONDAY", + "TUESDAY", + "WEDNESDAY", + "THURSDAY", + "FRIDAY", + "SATURDAY", + NULL +}; + int main (int argc, char **argv) { - bool ret; struct timespec result; struct timespec result2; struct timespec now; const char *p; + int i; + + set_program_name (argv[0]); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -208,5 +224,44 @@ main (int argc, char **argv) ASSERT (result.tv_sec == result2.tv_sec && result.tv_nsec == result2.tv_nsec); + /* Check that some "next Monday", "last Wednesday", etc. are correct. */ + putenv ("TZ=UTC0"); + for (i = 0; day_table[i]; i++) + { + unsigned int thur2 = 7 * 24 * 3600; /* 2nd thursday */ + char tmp[32]; + sprintf (tmp, "NEXT %s", day_table[i]); + now.tv_sec = thur2 + 4711; + now.tv_nsec = 1267; + ASSERT (get_date (&result, tmp, &now)); + LOG (tmp, now, result); + ASSERT (result.tv_nsec == 0); + ASSERT (result.tv_sec == thur2 + (i == 4 ? 7 : (i + 3) % 7) * 24 * 3600); + + sprintf (tmp, "LAST %s", day_table[i]); + now.tv_sec = thur2 + 4711; + now.tv_nsec = 1267; + ASSERT (get_date (&result, tmp, &now)); + LOG (tmp, now, result); + ASSERT (result.tv_nsec == 0); + ASSERT (result.tv_sec == thur2 + ((i + 3) % 7 - 7) * 24 * 3600); + } + + p = "THURSDAY UTC+00"; /* The epoch was on Thursday. */ + now.tv_sec = 0; + now.tv_nsec = 0; + ASSERT (get_date (&result, p, &now)); + LOG (p, now, result); + ASSERT (result.tv_sec == now.tv_sec + && result.tv_nsec == now.tv_nsec); + + p = "FRIDAY UTC+00"; + now.tv_sec = 0; + now.tv_nsec = 0; + ASSERT (get_date (&result, p, &now)); + LOG (p, now, result); + ASSERT (result.tv_sec == 24 * 3600 + && result.tv_nsec == now.tv_nsec); + return 0; }