Skip to content

Commit

Permalink
PR bin/50574 - make the tests conform to what parsedate() actually
Browse files Browse the repository at this point in the history
does, so they should no longer fail.   This needs parsedate.y 1.28
in order to work properly.

OK christos@
  • Loading branch information
kre committed May 3, 2016
1 parent 1b13ecb commit 0972a34
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions tests/lib/libutil/t_parsedate.c
@@ -1,4 +1,4 @@
/* $NetBSD: t_parsedate.c,v 1.21 2016/05/03 18:10:38 kre Exp $ */
/* $NetBSD: t_parsedate.c,v 1.22 2016/05/03 18:18:15 kre Exp $ */
/*-
* Copyright (c) 2010, 2015 The NetBSD Foundation, Inc.
* All rights reserved.
Expand Down Expand Up @@ -29,7 +29,7 @@
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD: t_parsedate.c,v 1.21 2016/05/03 18:10:38 kre Exp $");
__RCSID("$NetBSD: t_parsedate.c,v 1.22 2016/05/03 18:18:15 kre Exp $");

#include <atf-c.h>
#include <errno.h>
Expand Down Expand Up @@ -244,15 +244,19 @@ ATF_TC_BODY(relative, tc)

#define REL_CHECK(s, now, tm) do { \
time_t p, q; \
char pb[30], qb[30]; \
char nb[30], pb[30], qb[30]; \
p = parsedate(s, &now, NULL); \
q = mktime(&tm); \
ATF_CHECK_EQ_MSG(p, q, \
"From \"%s\", obtained %jd (%24.24s); expected %jd (%24.24s)", \
"From %jd (%24.24s) using \"%s\", obtained %jd (%24.24s); expected %jd (%24.24s)", \
now, ctime_r(&now, nb), \
s, (uintmax_t)p, ctime_r(&p, pb), (uintmax_t)q, \
ctime_r(&q, qb)); \
} while (/*CONSTCOND*/0)

#define isleap(yr) (((yr) & 3) == 0 && (((yr) % 100) != 0 || \
((1900+(yr)) % 400) == 0))

ATF_CHECK(parsedate("-1 month", NULL, NULL) != -1);
ATF_CHECK(parsedate("last friday", NULL, NULL) != -1);
ATF_CHECK(parsedate("one week ago", NULL, NULL) != -1);
Expand Down Expand Up @@ -328,27 +332,55 @@ ATF_TC_BODY(relative, tc)

ATF_CHECK(localtime_r(&now, &tm) != NULL);
tm.tm_mon++;
if (tm.tm_mon == 1 &&
tm.tm_mday > 28 + isleap(tm.tm_year))
tm.tm_mday = 28 + isleap(tm.tm_year);
else if ((tm.tm_mon == 3 || tm.tm_mon == 5 ||
tm.tm_mon == 8 || tm.tm_mon == 10) && tm.tm_mday == 31)
tm.tm_mday = 30;
tm.tm_isdst = -1;
REL_CHECK("month", now, tm);

ATF_CHECK(localtime_r(&now, &tm) != NULL);
tm.tm_mon += 2; /* "next" means add 2 ... */
if (tm.tm_mon == 13 &&
tm.tm_mday > 28 + isleap(tm.tm_year + 1))
tm.tm_mday = 28 + isleap(tm.tm_year + 1);
else if (tm.tm_mon == 8 && tm.tm_mday == 31)
tm.tm_mday = 30;
tm.tm_isdst = -1;
REL_CHECK("next month", now, tm);

ATF_CHECK(localtime_r(&now, &tm) != NULL);
tm.tm_mon--;
if (tm.tm_mon == 1 &&
tm.tm_mday > 28 + isleap(tm.tm_year))
tm.tm_mday = 28 + isleap(tm.tm_year);
else if ((tm.tm_mon == 3 || tm.tm_mon == 5 ||
tm.tm_mon == 8 || tm.tm_mon == 10) && tm.tm_mday == 31)
tm.tm_mday = 30;
tm.tm_isdst = -1;
REL_CHECK("last month", now, tm);

ATF_CHECK(localtime_r(&now, &tm) != NULL);
tm.tm_mon += 6;
if (tm.tm_mon == 13 &&
tm.tm_mday > 28 + isleap(tm.tm_year + 1))
tm.tm_mday = 28 + isleap(tm.tm_year + 1);
else if ((tm.tm_mon == 15 || tm.tm_mon == 17 ||
tm.tm_mon == 8 || tm.tm_mon == 10) && tm.tm_mday == 31)
tm.tm_mday = 30;
tm.tm_mday += 2;
tm.tm_isdst = -1;
REL_CHECK("+6 months 2 days", now, tm);

ATF_CHECK(localtime_r(&now, &tm) != NULL);
tm.tm_mon -= 9;
if (tm.tm_mon == 1 && tm.tm_mday > 28 + isleap(tm.tm_year))
tm.tm_mday = tm.tm_mday > 28 + isleap(tm.tm_year);
else if ((tm.tm_mon == -9 || tm.tm_mon == -7 ||
tm.tm_mon == -2) && tm.tm_mday == 31)
tm.tm_mday = 30;
tm.tm_isdst = -1;
REL_CHECK("9 months ago", now, tm);

Expand Down

0 comments on commit 0972a34

Please sign in to comment.