From: Juergen Perlinger Date: Tue, 2 Nov 2010 19:21:30 +0000 (+0100) Subject: fixes for regression test X-Git-Tag: NTP_4_2_7P78~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52b732d351be9370527c4c125fe83f976ae45fa0;p=thirdparty%2Fntp.git fixes for regression test bk: 4cd064ba_pNlUxLHy-8T0nIUIzN6cQ --- diff --git a/libntp/prettydate.c b/libntp/prettydate.c index 45f5b4551..c48ab8eb3 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -158,7 +158,7 @@ common_prettydate( ) { static const char* pfmt[2] = { - "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u", + "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u", "%08lx.%08lx [%s, %s %2d %4d %2d:%02d:%02d.%03u UTC]" }; @@ -182,7 +182,7 @@ common_prettydate( if (!tm) { /* * get a replacement, but always in UTC, using - * caljulian() + * ntpcal_time_to_date() */ struct calendar jd; ntpcal_time_to_date(&jd, &sec); diff --git a/libntp/ymd2yd.c b/libntp/ymd2yd.c index 5a9d4c3e3..c6b3a0cad 100644 --- a/libntp/ymd2yd.c +++ b/libntp/ymd2yd.c @@ -1,38 +1,26 @@ /* * ymd2yd - compute the date in the year from y/m/d + * + * A thin wrapper around a more general calendar function. */ #include -#include "ntp_fp.h" -#include "ntp_unixtime.h" #include "ntp_stdlib.h" - -/* - * Tables to compute the day of year from yyyymmdd timecode. - * Viva la leap. - */ -static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +#include "ntp_calendar.h" int ymd2yd( int y, int m, - int d - ) + int d) { - int i, *t; - - if (m < 1 || m > 12 || d < 1) - return (-1); - - if (((y%4 == 0) && (y%100 != 0)) || (y%400 == 0)) - t = day2tab; /* leap year */ - else - t = day1tab; /* not a leap year */ - if (d > t[m - 1]) - return (-1); - for (i = 0; i < m - 1; i++) - d += t[i]; - return d; + /* + * convert y/m/d to elapsed calendar units, convert that to + * elapsed days since the start of the given year and convert + * back to unity-based day in year. + * + * This does no further error checking, since the underlying + * function is assumed to work out how to handle the data. + */ + return ntpcal_edate_to_yeardays(y-1, m-1, d-1) + 1; } diff --git a/scripts/checkChangeLog b/scripts/checkChangeLog index 9ca17edd8..7a8ffbd32 100755 --- a/scripts/checkChangeLog +++ b/scripts/checkChangeLog @@ -1,6 +1,6 @@ #! /bin/sh -. packageinfo.sh +. ./packageinfo.sh cl1=`head -1 ChangeLog` diff --git a/tests/libntp/calyearstart.cpp b/tests/libntp/calyearstart.cpp index 9642570f0..59ac1f8e5 100644 --- a/tests/libntp/calyearstart.cpp +++ b/tests/libntp/calyearstart.cpp @@ -1,34 +1,33 @@ #include "libntptest.h" /* - * Currently calyearstart() uses the caljulian() functions, which - * in turn uses the current system time to wrap a timestamp around - * the current year. - * - * Ideally, some sort of mock around caljulian() should be provided - * so that tests doesn't depend on the current system time. + * calyearstart uses a pivot time, which defaults to the current system + * time if not given. Since this is not a good idea in an regression + * test, we use 2020-01-01 for the pivot. */ +static const time_t hold = 1577836800; // 2020-01-01 00:00:00 + class calyearstartTest : public libntptest { }; TEST_F(calyearstartTest, NoWrapInDateRange) { - const u_long input = 3486372600UL; // 2010-06-24 12:50:00. - const u_long expected = 3471292800UL; // 2010-01-01 00:00:00 + const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00. + const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00 - EXPECT_EQ(expected, calyearstart(input)); + EXPECT_EQ(expected, calyearstart(input, &hold)); } TEST_F(calyearstartTest, NoWrapInDateRangeLeapYear) { - const u_long input = 3549528000UL; // 2012-06-24 12:00:00 - const u_long expected = 3534364800UL; // 2012-01-01 00:00:00 + const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00 + const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00 - EXPECT_EQ(expected, calyearstart(input)); + EXPECT_EQ(expected, calyearstart(input, &hold)); } TEST_F(calyearstartTest, WrapInDateRange) { - const u_long input = 19904UL; // 2036-02-07 12:00:00 - const u_long expected = 4291747200UL; // 2036-01-01 00:00:00 + const u_int32 input = 19904UL; // 2036-02-07 12:00:00 + const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00 - EXPECT_EQ(expected, calyearstart(input)); + EXPECT_EQ(expected, calyearstart(input, &hold)); }