Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libutil * Test that parsedate("@0", ...) returns (...



details:   https://anonhg.NetBSD.org/src/rev/1373aeb8a68d
branches:  trunk
changeset: 784132:1373aeb8a68d
user:      apb <apb%NetBSD.org@localhost>
date:      Sat Jan 19 14:03:08 2013 +0000

description:
* Test that parsedate("@0", ...) returns (time_t)0 regardless of timezone.
* Test that parsedate("@-1", NULL, NULL) returns (time_t)-1
  without setting errno.

diffstat:

 tests/lib/libutil/t_parsedate.c |  39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)

diffs (67 lines):

diff -r a0d7d2f0de79 -r 1373aeb8a68d tests/lib/libutil/t_parsedate.c
--- a/tests/lib/libutil/t_parsedate.c   Sat Jan 19 11:56:17 2013 +0000
+++ b/tests/lib/libutil/t_parsedate.c   Sat Jan 19 14:03:08 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_parsedate.c,v 1.5 2012/03/18 07:14:08 jruoho Exp $ */
+/* $NetBSD: t_parsedate.c,v 1.6 2013/01/19 14:03:08 apb Exp $ */
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,9 +29,12 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_parsedate.c,v 1.5 2012/03/18 07:14:08 jruoho Exp $");
+__RCSID("$NetBSD: t_parsedate.c,v 1.6 2013/01/19 14:03:08 apb Exp $");
 
 #include <atf-c.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
 #include <util.h>
 
 ATF_TC(dates);
@@ -92,11 +95,43 @@
        ATF_CHECK(parsedate("+2 years", NULL, NULL) != -1);
 }
 
+ATF_TC(atsecs);
+
+ATF_TC_HEAD(atsecs, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test seconds past the epoch");
+}
+
+ATF_TC_BODY(atsecs, tc)
+{
+       int tzoff;
+
+       /* "@0" -> (time_t)0, regardless of timezone */
+       ATF_CHECK(parsedate("@0", NULL, NULL) == (time_t)0);
+       putenv(__UNCONST("TZ=Europe/Berlin"));
+       tzset();
+       ATF_CHECK(parsedate("@0", NULL, NULL) == (time_t)0);
+       putenv(__UNCONST("TZ=America/New_York"));
+       tzset();
+       ATF_CHECK(parsedate("@0", NULL, NULL) == (time_t)0);
+       tzoff = 0;
+       ATF_CHECK(parsedate("@0", NULL, &tzoff) == (time_t)0);
+       tzoff = 3600;
+       ATF_CHECK(parsedate("@0", NULL, &tzoff) == (time_t)0);
+       tzoff = -3600;
+       ATF_CHECK(parsedate("@0", NULL, &tzoff) == (time_t)0);
+
+       /* -1 is not an error */
+       errno = 0;
+       ATF_CHECK(parsedate("@-1", NULL, &tzoff) == (time_t)-1 && errno == 0);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, dates);
        ATF_TP_ADD_TC(tp, times);
        ATF_TP_ADD_TC(tp, relative);
+       ATF_TP_ADD_TC(tp, atsecs);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index