X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-getdate.c;h=ea70527f9393f83d5daa42a1f392597f1d633b87;hb=f7b182c11bce2ba412f47a764dd7555a488dbfb1;hp=3433c09fb3c5af593a1a7b439d85a3363acf04da;hpb=47bf1430c04eb59f70e74f8b402a5ea23e5b891c;p=gnulib.git diff --git a/tests/test-getdate.c b/tests/test-getdate.c index 3433c09fb..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,9 +45,21 @@ 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) { @@ -53,6 +67,9 @@ main (int argc, char **argv) struct timespec result2; struct timespec now; const char *p; + int i; + + set_program_name (argv[0]); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -207,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; }