Module Name: src Committed By: christos Date: Thu Oct 29 17:48:21 UTC 2015
Modified Files: src/tests/lib/libc/time: t_strptime.c Log Message: Add tests for %z To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/time/t_strptime.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/libc/time/t_strptime.c diff -u src/tests/lib/libc/time/t_strptime.c:1.6 src/tests/lib/libc/time/t_strptime.c:1.7 --- src/tests/lib/libc/time/t_strptime.c:1.6 Sat Jul 4 09:36:25 2015 +++ src/tests/lib/libc/time/t_strptime.c Thu Oct 29 13:48:20 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: t_strptime.c,v 1.6 2015/07/04 13:36:25 christos Exp $ */ +/* $NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include <sys/cdefs.h> __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_strptime.c,v 1.6 2015/07/04 13:36:25 christos Exp $"); +__RCSID("$NetBSD: t_strptime.c,v 1.7 2015/10/29 17:48:20 christos Exp $"); #include <time.h> @@ -291,6 +291,97 @@ ATF_TC_BODY(year, tc) h_pass("1980", "%EY", 4, -1, -1, -1, -1, -1, 80, -1, -1); } +ATF_TC(zone); + +ATF_TC_HEAD(zone, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Checks strptime(3) timezone conversion [z]"); +} + +static struct { + const char *name; + long offs; +} zt[] = { + { "Z", 0 }, + { "UT", 0 }, + { "UTC", 0 }, + { "GMT", 0 }, + { "EST", -18000 }, + { "EDT", -14400 }, + { "CST", -21600 }, + { "CDT", -18000 }, + { "MST", -25200 }, + { "MDT", -21600 }, + { "PST", -28800 }, + { "PDT", -25200 }, + + { "VST", -1 }, + { "VDT", -1 }, + + { "+03", 10800 }, + { "-03", -10800 }, + { "+0403", 14580 }, + { "-0403", -14580 }, + { "+04:03", 14580 }, + { "-04:03", -14580 }, + + { "1", -1 }, + { "03", -1 }, + { "0304", -1 }, + { "+1", -1 }, + { "-203", -1 }, + { "+12345", -1 }, + { "+12:345", -1 }, + { "+123:45", -1 }, + + { "A", -3600 }, + { "B", -7200 }, + { "C", -10800 }, + { "D", -14400 }, + { "E", -18000 }, + { "F", -21600 }, + { "G", -25200 }, + { "H", -28800 }, + { "I", -32400 }, + { "L", -39600 }, + { "M", -43200 }, + { "N", 3600 }, + { "O", 7200 }, + { "P", 10800 }, + { "Q", 14400 }, + { "R", 18000 }, + { "T", 25200 }, + { "U", 28800 }, + { "V", 32400 }, + { "W", 36000 }, + { "X", 39600 }, + { "Y", 43200 }, + + { "J", -1 }, + + { "America/Los_Angeles", -28800 }, + { "America/New_York", -18000 }, + { "EST4EDT", -14400 }, + + { "Bogus", -1 }, +}; + +ATF_TC_BODY(zone, tc) +{ + struct tm tm; + + for (size_t i = 0; i < __arraycount(zt); i++) { + if (strptime(zt[i].name, "%z", &tm) == NULL) + tm.tm_gmtoff = -1; + ATF_REQUIRE_MSG(tm.tm_gmtoff == zt[i].offs, + "strptime(\"%s\", \"%%z\", &tm): " + "expected: tm.tm_gmtoff=%ld, got: tm.tm_gmtoff=%ld", + zt[i].name, zt[i].offs, tm.tm_gmtoff); + } +} + ATF_TP_ADD_TCS(tp) { @@ -300,6 +391,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, month); ATF_TP_ADD_TC(tp, seconds); ATF_TP_ADD_TC(tp, year); + ATF_TP_ADD_TC(tp, zone); return atf_no_error(); }