Module Name: src
Committed By: apb
Date: Sat Jan 19 14:03:08 UTC 2013
Modified Files:
src/tests/lib/libutil: t_parsedate.c
Log Message:
* Test that parsedate("@0", ...) returns (time_t)0 regardless of timezone.
* Test that parsedate("@-1", NULL, NULL) returns (time_t)-1
without setting errno.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libutil/t_parsedate.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libutil/t_parsedate.c
diff -u src/tests/lib/libutil/t_parsedate.c:1.5 src/tests/lib/libutil/t_parsedate.c:1.6
--- src/tests/lib/libutil/t_parsedate.c:1.5 Sun Mar 18 07:14:08 2012
+++ src/tests/lib/libutil/t_parsedate.c Sat Jan 19 14:03:08 2013
@@ -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_TC_BODY(relative, tc)
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();
}