CVS commit: [netbsd-7] src/tests/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:42:45 UTC 2014 Modified Files: src/tests/lib/libutil [netbsd-7]: t_parsedate.c Log Message: Pull up following revision(s) (requested by apb in ticket #135): tests/lib/libutil/t_parsedate.c: revision 1.8 Add local parsecheck() function and use it for several tests. Instead of just checking that parsedate(3) does not return an error, also pass the result through localtime_r(3) or gmtime_r(3) and check the year/month/day/hour/minute/second fields in the resulting struct tm. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.7.8.1 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.7 src/tests/lib/libutil/t_parsedate.c:1.7.8.1 --- src/tests/lib/libutil/t_parsedate.c:1.7 Sat Jan 19 15:21:43 2013 +++ src/tests/lib/libutil/t_parsedate.c Sat Oct 11 16:42:45 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.7 2013/01/19 15:21:43 apb Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.7.8.1 2014/10/11 16:42:45 snj Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.7 2013/01/19 15:21:43 apb Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.1 2014/10/11 16:42:45 snj Exp $"); #include #include @@ -37,6 +37,58 @@ __RCSID("$NetBSD: t_parsedate.c,v 1.7 20 #include #include +/* + * ANY is used as a placeholder for values that do not need to be + * checked. The actual value is arbitrary. We don't use -1 + * because some tests might want to use -1 as a literal value. + */ +#define ANY -30215 + +/* parsecheck -- + * call parsedate(), then call time_to_tm() on the result, + * and check that year/month/day/hour/minute/second are as expected. + * + * time_to_tm should usually be localtime_r or gmtime_r. + * + * Don't check values specified as ANY. + */ +static void +parsecheck(const char *datestr, const time_t *reftime, const int *zoff, + struct tm * time_to_tm(const time_t *, struct tm *), + int year, int month, int day, int hour, int minute, int second) +{ + time_t t; + struct tm tm; + + ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1, + "parsedate(\"%s\",,) returned -1\n", datestr); + ATF_CHECK(time_to_tm(&t, &tm) != NULL); + if (year != ANY) + ATF_CHECK_MSG(tm.tm_year + 1900 == year, + "parsedate(\"%s\",,) expected year %d got %d (+1900)\n", + datestr, year, (int)tm.tm_year); + if (month != ANY) + ATF_CHECK_MSG(tm.tm_mon + 1 == month, + "parsedate(\"%s\",,) expected month %d got %d (+1)\n", + datestr, month, (int)tm.tm_mon); + if (day != ANY) + ATF_CHECK_MSG(tm.tm_mday == day, + "parsedate(\"%s\",,) expected day %d got %d\n", + datestr, day, (int)tm.tm_mday); + if (hour != ANY) + ATF_CHECK_MSG(tm.tm_hour == hour, + "parsedate(\"%s\",,) expected hour %d got %d\n", + datestr, hour, (int)tm.tm_hour); + if (minute != ANY) + ATF_CHECK_MSG(tm.tm_min == minute, + "parsedate(\"%s\",,) expected minute %d got %d\n", + datestr, minute, (int)tm.tm_min); + if (second != ANY) + ATF_CHECK_MSG(tm.tm_sec == second, + "parsedate(\"%s\",,) expected second %d got %d\n", + datestr, second, (int)tm.tm_sec); +} + ATF_TC(dates); ATF_TC_HEAD(dates, tc) @@ -48,15 +100,24 @@ ATF_TC_HEAD(dates, tc) ATF_TC_BODY(dates, tc) { - ATF_CHECK(parsedate("69-09-10", NULL, NULL) != -1); - ATF_CHECK(parsedate("2006-11-17", NULL, NULL) != -1); - ATF_CHECK(parsedate("10/1/2000", NULL, NULL) != -1); - ATF_CHECK(parsedate("20 Jun 1994", NULL, NULL) != -1); - ATF_CHECK(parsedate("23jun2001", NULL, NULL) != -1); - ATF_CHECK(parsedate("1-sep-06", NULL, NULL) != -1); - ATF_CHECK(parsedate("1/11", NULL, NULL) != -1); - ATF_CHECK(parsedate("1500-01-02", NULL, NULL) != -1); - ATF_CHECK(parsedate("-12-21", NULL, NULL) != -1); + parsecheck("69-09-10", NULL, NULL, localtime_r, + 2069, 9, 10, 0, 0, 0); + parsecheck("2006-11-17", NULL, NULL, localtime_r, + 2006, 11, 17, 0, 0, 0); + parsecheck("10/1/2000", NULL, NULL, localtime_r, + 2000, 10, 1, 0, 0, 0); + parsecheck("20 Jun 1994", NULL, NULL, localtime_r, + 1994, 6, 20, 0, 0, 0); + parsecheck("23jun2001", NULL, NULL, localtime_r, + 2001, 6, 23, 0, 0, 0); + parsecheck("1-sep-06", NULL, NULL, localtime_r, + 2006, 9, 1, 0, 0, 0); + parsecheck("1/11", NULL, NULL, localtime_r, + ANY, 1, 11, 0, 0, 0); + parsecheck("1500-01-02", NULL, NULL, localtime_r, + 1500, 1, 2, 0, 0, 0); + parsecheck("-12-21", NULL, NULL, localtime_r, + , 12, 21, 0, 0, 0); } ATF_TC(times); @@ -70,10 +131,14 @@ ATF_TC_HEAD(times, tc) ATF_TC_BODY(times, tc) { - ATF_CHECK(parsedate("10:01", NULL, NULL) != -1); - ATF_CHECK(parsedate("10:12pm", NULL, NULL) != -1); - ATF_CHECK(parsedate("12:11:01.12", NULL, NULL) != -1); - ATF_CHECK(parseda
CVS commit: [netbsd-7] src/tests/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:43:46 UTC 2014 Modified Files: src/tests/lib/libutil [netbsd-7]: t_parsedate.c Log Message: Pull up following revision(s) (requested by apb in ticket #135): tests/lib/libutil/t_parsedate.c: revision 1.9 Add comments for some non-obvious cases. Also add a test with year=70, which is documented to be treated as 1970. To generate a diff of this commit: cvs rdiff -u -r1.7.8.1 -r1.7.8.2 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.7.8.1 src/tests/lib/libutil/t_parsedate.c:1.7.8.2 --- src/tests/lib/libutil/t_parsedate.c:1.7.8.1 Sat Oct 11 16:42:45 2014 +++ src/tests/lib/libutil/t_parsedate.c Sat Oct 11 16:43:46 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.7.8.1 2014/10/11 16:42:45 snj Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.7.8.2 2014/10/11 16:43:46 snj Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.1 2014/10/11 16:42:45 snj Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.2 2014/10/11 16:43:46 snj Exp $"); #include #include @@ -101,11 +101,13 @@ ATF_TC_BODY(dates, tc) { parsecheck("69-09-10", NULL, NULL, localtime_r, - 2069, 9, 10, 0, 0, 0); + 2069, 9, 10, 0, 0, 0); /* year < 70: add 2000 */ + parsecheck("70-09-10", NULL, NULL, localtime_r, + 1970, 9, 10, 0, 0, 0); /* 70 <= year < 100: add 1900 */ parsecheck("2006-11-17", NULL, NULL, localtime_r, 2006, 11, 17, 0, 0, 0); parsecheck("10/1/2000", NULL, NULL, localtime_r, - 2000, 10, 1, 0, 0, 0); + 2000, 10, 1, 0, 0, 0); /* month/day/year */ parsecheck("20 Jun 1994", NULL, NULL, localtime_r, 1994, 6, 20, 0, 0, 0); parsecheck("23jun2001", NULL, NULL, localtime_r, @@ -113,7 +115,7 @@ ATF_TC_BODY(dates, tc) parsecheck("1-sep-06", NULL, NULL, localtime_r, 2006, 9, 1, 0, 0, 0); parsecheck("1/11", NULL, NULL, localtime_r, - ANY, 1, 11, 0, 0, 0); + ANY, 1, 11, 0, 0, 0); /* month/day */ parsecheck("1500-01-02", NULL, NULL, localtime_r, 1500, 1, 2, 0, 0, 0); parsecheck("-12-21", NULL, NULL, localtime_r,
CVS commit: [netbsd-7] src/tests/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:45:24 UTC 2014 Modified Files: src/tests/lib/libutil [netbsd-7]: t_parsedate.c Log Message: Pull up following revision(s) (requested by apb in ticket #135): tests/lib/libutil/t_parsedate.c: revision 1.10 Adapt to a recent change in parsedate(). "9/10/69" still refers to 2069, and "9/10/70" still refers to 1970, but "69-09-10" and "70-09-10" now refer to the years 69 and 70. To generate a diff of this commit: cvs rdiff -u -r1.7.8.2 -r1.7.8.3 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.7.8.2 src/tests/lib/libutil/t_parsedate.c:1.7.8.3 --- src/tests/lib/libutil/t_parsedate.c:1.7.8.2 Sat Oct 11 16:43:46 2014 +++ src/tests/lib/libutil/t_parsedate.c Sat Oct 11 16:45:24 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.7.8.2 2014/10/11 16:43:46 snj Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.7.8.3 2014/10/11 16:45:24 snj Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.2 2014/10/11 16:43:46 snj Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.3 2014/10/11 16:45:24 snj Exp $"); #include #include @@ -100,10 +100,14 @@ ATF_TC_HEAD(dates, tc) ATF_TC_BODY(dates, tc) { - parsecheck("69-09-10", NULL, NULL, localtime_r, + parsecheck("9/10/69", NULL, NULL, localtime_r, 2069, 9, 10, 0, 0, 0); /* year < 70: add 2000 */ - parsecheck("70-09-10", NULL, NULL, localtime_r, + parsecheck("9/10/70", NULL, NULL, localtime_r, 1970, 9, 10, 0, 0, 0); /* 70 <= year < 100: add 1900 */ + parsecheck("69-09-10", NULL, NULL, localtime_r, + 69, 9, 10, 0, 0, 0); /* ISO8601 year remains unchanged */ + parsecheck("70-09-10", NULL, NULL, localtime_r, + 70, 9, 10, 0, 0, 0); /* ISO8601 year remains unchanged */ parsecheck("2006-11-17", NULL, NULL, localtime_r, 2006, 11, 17, 0, 0, 0); parsecheck("10/1/2000", NULL, NULL, localtime_r,
CVS commit: [netbsd-7] src/tests/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:47:00 UTC 2014 Modified Files: src/tests/lib/libutil [netbsd-7]: t_parsedate.c Log Message: Pull up following revision(s) (requested by apb in ticket #135): tests/lib/libutil/t_parsedate.c: revision 1.11 Add tests for PR lib/47916. Some of these fail. To generate a diff of this commit: cvs rdiff -u -r1.7.8.3 -r1.7.8.4 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.7.8.3 src/tests/lib/libutil/t_parsedate.c:1.7.8.4 --- src/tests/lib/libutil/t_parsedate.c:1.7.8.3 Sat Oct 11 16:45:24 2014 +++ src/tests/lib/libutil/t_parsedate.c Sat Oct 11 16:47:00 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.7.8.3 2014/10/11 16:45:24 snj Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.3 2014/10/11 16:45:24 snj Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $"); #include #include @@ -147,6 +147,49 @@ ATF_TC_BODY(times, tc) ANY, ANY, ANY, 12+5, 21, 0); } +ATF_TC(dsttimes); + +ATF_TC_HEAD(dsttimes, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test DST transition times" + " (PR lib/47916)"); +} + +ATF_TC_BODY(dsttimes, tc) +{ + struct tm tm; + time_t t; + int tzoff; + + putenv(__UNCONST("TZ=EST")); + tzset(); + parsecheck("12:0", NULL, NULL, localtime_r, + ANY, ANY, ANY, 12, 0, 0); + + putenv(__UNCONST("TZ=Japan")); + tzset(); + parsecheck("12:0", NULL, NULL, localtime_r, + ANY, ANY, ANY, 12, 0, 0); + + /* + * When the effective local time is Tue Jul 9 13:21:53 BST 2013, + * check mktime("14:00") + */ + putenv(__UNCONST("TZ=Europe/London")); + tzset(); + tm = (struct tm){ + .tm_year = 2013-1900, .tm_mon = 7-1, .tm_mday = 9, + .tm_hour = 13, .tm_min = 21, .tm_sec = 53, + .tm_isdst = 0 }; + t = mktime(&tm); + ATF_CHECK(t != (time_t)-1); + parsecheck("14:00", &t, NULL, localtime_r, + 2013, 7, 9, 14, 0, 0); + tzoff = 0; + parsecheck("14:00", &t, &tzoff, localtime_r, + 2013, 7, 9, 14, 0, 0); +} + ATF_TC(relative); ATF_TC_HEAD(relative, tc) @@ -206,6 +249,7 @@ ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, dates); ATF_TP_ADD_TC(tp, times); + ATF_TP_ADD_TC(tp, dsttimes); ATF_TP_ADD_TC(tp, relative); ATF_TP_ADD_TC(tp, atsecs);
CVS commit: [netbsd-7] src/tests/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:52:56 UTC 2014 Modified Files: src/tests/lib/libutil [netbsd-7]: t_parsedate.c Log Message: Pull up following revision(s) (requested by apb in ticket #135.10): tests/lib/libutil/t_parsedate.c: revision 1.12 When tests fail, print all args, notjust the date string. To generate a diff of this commit: cvs rdiff -u -r1.7.8.4 -r1.7.8.5 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.7.8.4 src/tests/lib/libutil/t_parsedate.c:1.7.8.5 --- src/tests/lib/libutil/t_parsedate.c:1.7.8.4 Sat Oct 11 16:47:00 2014 +++ src/tests/lib/libutil/t_parsedate.c Sat Oct 11 16:52:56 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,10 +29,11 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.4 2014/10/11 16:47:00 snj Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $"); #include #include +#include #include #include #include @@ -59,34 +60,55 @@ parsecheck(const char *datestr, const ti { time_t t; struct tm tm; + char argstr[128]; + + /* + * printable version of the args. + * + * Note that printf("%.*d", 0, 0)) prints nothing at all, + * while printf("%.*d", 1, val) prints the value as usual. + */ + snprintf(argstr, sizeof(argstr), "%s%s%s, %s%.*jd, %s%.*d", + /* NULL or \"\" */ + (datestr ? "\"" : ""), + (datestr ? datestr : "NULL"), + (datestr ? "\"" : ""), + /* NULL or *reftime */ + (reftime ? "" : "NULL"), + (reftime ? 1 : 0), + (reftime ? (intmax_t)*reftime : (intmax_t)0), + /* NULL or *zoff */ + (zoff ? "" : "NULL"), + (zoff ? 1 : 0), + (zoff ? *zoff : 0)); ATF_CHECK_MSG((t = parsedate(datestr, reftime, zoff)) != -1, - "parsedate(\"%s\",,) returned -1\n", datestr); + "parsedate(%s) returned -1\n", argstr); ATF_CHECK(time_to_tm(&t, &tm) != NULL); if (year != ANY) ATF_CHECK_MSG(tm.tm_year + 1900 == year, - "parsedate(\"%s\",,) expected year %d got %d (+1900)\n", - datestr, year, (int)tm.tm_year); + "parsedate(%s) expected year %d got %d (+1900)\n", + argstr, year, (int)tm.tm_year); if (month != ANY) ATF_CHECK_MSG(tm.tm_mon + 1 == month, - "parsedate(\"%s\",,) expected month %d got %d (+1)\n", - datestr, month, (int)tm.tm_mon); + "parsedate(%s) expected month %d got %d (+1)\n", + argstr, month, (int)tm.tm_mon); if (day != ANY) ATF_CHECK_MSG(tm.tm_mday == day, - "parsedate(\"%s\",,) expected day %d got %d\n", - datestr, day, (int)tm.tm_mday); + "parsedate(%s) expected day %d got %d\n", + argstr, day, (int)tm.tm_mday); if (hour != ANY) ATF_CHECK_MSG(tm.tm_hour == hour, - "parsedate(\"%s\",,) expected hour %d got %d\n", - datestr, hour, (int)tm.tm_hour); + "parsedate(%s) expected hour %d got %d\n", + argstr, hour, (int)tm.tm_hour); if (minute != ANY) ATF_CHECK_MSG(tm.tm_min == minute, - "parsedate(\"%s\",,) expected minute %d got %d\n", - datestr, minute, (int)tm.tm_min); + "parsedate(%s) expected minute %d got %d\n", + argstr, minute, (int)tm.tm_min); if (second != ANY) ATF_CHECK_MSG(tm.tm_sec == second, - "parsedate(\"%s\",,) expected second %d got %d\n", - datestr, second, (int)tm.tm_sec); + "parsedate(%s) expected second %d got %d\n", + argstr, second, (int)tm.tm_sec); } ATF_TC(dates);
CVS commit: [netbsd-7] src/tests/lib/libutil
Module Name:src Committed By: snj Date: Sat Oct 11 16:55:32 UTC 2014 Modified Files: src/tests/lib/libutil [netbsd-7]: t_parsedate.c Log Message: Pull up following revision(s) (requested by apb in ticket #135): tests/lib/libutil/t_parsedate.c: revision 1.13 2013-07-09 was in British Summer TIme, so use tzoff=-60, not 0. To generate a diff of this commit: cvs rdiff -u -r1.7.8.5 -r1.7.8.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.7.8.5 src/tests/lib/libutil/t_parsedate.c:1.7.8.6 --- src/tests/lib/libutil/t_parsedate.c:1.7.8.5 Sat Oct 11 16:52:56 2014 +++ src/tests/lib/libutil/t_parsedate.c Sat Oct 11 16:55:32 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $ */ +/* $NetBSD: t_parsedate.c,v 1.7.8.6 2014/10/11 16:55:32 snj Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.5 2014/10/11 16:52:56 snj Exp $"); +__RCSID("$NetBSD: t_parsedate.c,v 1.7.8.6 2014/10/11 16:55:32 snj Exp $"); #include #include @@ -207,7 +207,7 @@ ATF_TC_BODY(dsttimes, tc) ATF_CHECK(t != (time_t)-1); parsecheck("14:00", &t, NULL, localtime_r, 2013, 7, 9, 14, 0, 0); - tzoff = 0; + tzoff = -60; /* British Summer Time */ parsecheck("14:00", &t, &tzoff, localtime_r, 2013, 7, 9, 14, 0, 0); }