Separate two tests. Mention the platforms in canonical order.
[gnulib.git] / tests / test-getdate.c
index adbcf3a..7dfb09e 100644 (file)
@@ -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 <stdlib.h>
 #include <string.h>
 
+#include "progname.h"
+
 #include "getdate.h"
 
 #define ASSERT(expr)                                                   \
   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
 
 int
 main (int argc, char **argv)
 {
-  bool ret;
   struct timespec result;
   struct timespec result2;
   struct timespec now;
   const char *p;
 
+  set_program_name (argv[0]);
+
   now.tv_sec = 4711;
   now.tv_nsec = 1267;
   p = "now";
@@ -160,5 +163,53 @@ main (int argc, char **argv)
   p = "UTC+25:00";
   ASSERT (!get_date (&result, p, &now));
 
+       /* Check for several invalid countable dayshifts */
+  now.tv_sec = 4711;
+  now.tv_nsec = 1267;
+  p = "UTC+4:00 +40 yesterday";
+  ASSERT (!get_date (&result, p, &now));
+  p = "UTC+4:00 next yesterday";
+  ASSERT (!get_date (&result, p, &now));
+  p = "UTC+4:00 tomorrow ago";
+  ASSERT (!get_date (&result, p, &now));
+  p = "UTC+4:00 40 now ago";
+  ASSERT (!get_date (&result, p, &now));
+  p = "UTC+4:00 last tomorrow";
+  ASSERT (!get_date (&result, p, &now));
+  p = "UTC+4:00 -4 today";
+  ASSERT (!get_date (&result, p, &now));
+
+  /* And check correct usage of dayshifts */
+  now.tv_sec = 4711;
+  now.tv_nsec = 1267;
+  p = "UTC+400 tomorrow";
+  ASSERT (get_date (&result, p, &now));
+  LOG (p, now, result);
+  p = "UTC+400 +1 day";
+  ASSERT (get_date (&result2, p, &now));
+  LOG (p, now, result2);
+  ASSERT (result.tv_sec == result2.tv_sec
+         && result.tv_nsec == result2.tv_nsec);
+  now.tv_sec = 4711;
+  now.tv_nsec = 1267;
+  p = "UTC+400 yesterday";
+  ASSERT (get_date (&result, p, &now));
+  LOG (p, now, result);
+  p = "UTC+400 1 day ago";
+  ASSERT (get_date (&result2, p, &now));
+  LOG (p, now, result2);
+  ASSERT (result.tv_sec == result2.tv_sec
+         && result.tv_nsec == result2.tv_nsec);
+  now.tv_sec = 4711;
+  now.tv_nsec = 1267;
+  p = "UTC+400 now";
+  ASSERT (get_date (&result, p, &now));
+  LOG (p, now, result);
+  p = "UTC+400 +0 minutes"; /* silly, but simple "UTC+400" is different*/
+  ASSERT (get_date (&result2, p, &now));
+  LOG (p, now, result2);
+  ASSERT (result.tv_sec == result2.tv_sec
+         && result.tv_nsec == result2.tv_nsec);
+
   return 0;
 }