]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
fixes for regression test
authorJuergen Perlinger <perlinger@ntp.org>
Tue, 2 Nov 2010 19:21:30 +0000 (20:21 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Tue, 2 Nov 2010 19:21:30 +0000 (20:21 +0100)
bk: 4cd064ba_pNlUxLHy-8T0nIUIzN6cQ

libntp/prettydate.c
libntp/ymd2yd.c
scripts/checkChangeLog
tests/libntp/calyearstart.cpp

index 45f5b45514dfbfd7fc88ab9df063c87dc01ff3ad..c48ab8eb36bac06beb840cd63983a2d3f4843c65 100644 (file)
@@ -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);
index 5a9d4c3e35ff247e44b33816c646b03eac2ca1b1..c6b3a0cad7dcea5d21dcaa2d7a67ae91fec43057 100644 (file)
@@ -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 <config.h>
-#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;
 }
index 9ca17edd864cf5857262d7a071f087bd435a7a67..7a8ffbd32595054b476a970047a15feb44ce2243 100755 (executable)
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-. packageinfo.sh
+. ./packageinfo.sh
 
 cl1=`head -1 ChangeLog`
 
index 9642570f0f58c9916b362a60eaa29b2512b25ff7..59ac1f8e50db32d206f6d75acf6eaac55fb137a0 100644 (file)
@@ -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));
 }