[Git][NTPsec/ntpsec][working] 16 commits: Added test for ntpcal_ntp_to_ntp.

Ian Bruene gitlab at mg.gitlab.com
Tue Jul 10 18:37:01 UTC 2018


Ian Bruene pushed to branch working at NTPsec / ntpsec


Commits:
c88bb159 by Ian Bruene at 2018-06-29T15:23:47Z
Added test for ntpcal_ntp_to_ntp.

- - - - -
90a3bec8 by Ian Bruene at 2018-06-29T19:25:46Z
Added test for ntpcal_daysec_to_date.

- - - - -
c1d02f36 by Ian Bruene at 2018-06-29T21:12:06Z
Added test for ntpcal_split_eradays.

- - - - -
295fcad5 by Ian Bruene at 2018-06-29T22:32:33Z
Added test for ntpcal_time_to_date.

- - - - -
c0a6ee36 by Ian Bruene at 2018-06-29T23:47:01Z
Added test for ntpcal_days_in_years.

- - - - -
80fe704e by Ian Bruene at 2018-06-30T00:09:43Z
Added test for ntpcal_edate_to_eradays.

- - - - -
dcd3c46b by Ian Bruene at 2018-06-30T00:17:50Z
Added test for ntpcal_etime_to_seconds.

- - - - -
638a2331 by Ian Bruene at 2018-06-30T15:15:23Z
Added test for ntpcal_tm_to_rd.

- - - - -
cd688b7c by Ian Bruene at 2018-06-30T15:29:13Z
Added tests for ntpcal_date_to_daysec and ntpcal_tm_to_daysec.

- - - - -
6f982e53 by Ian Bruene at 2018-06-30T15:36:02Z
Added test for ntpcal_date_to_time.

- - - - -
14be487b by Ian Bruene at 2018-06-30T20:33:45Z
Added tests for ntpcal_ntp64_to_date, ntpcal_ntp_to_date.

- - - - -
2e0da1b9 by Ian Bruene at 2018-06-30T21:30:19Z
Added test for ntpcal_periodic_event.

- - - - -
7347d728 by Ian Bruene at 2018-06-30T21:42:04Z
Fix for 32-bit error in ntpcal_date_to_time test.

- - - - -
065e9e48 by Ian Bruene at 2018-07-01T00:46:14Z
Added tests for functions in prettydate.c

- - - - -
929c5008 by Ian Bruene at 2018-07-10T18:26:20Z
Whitespace fixes.

- - - - -
f736a3d7 by Ian Bruene at 2018-07-10T18:36:27Z
Merge branch 'working' of gitlab.com:NTPsec/ntpsec into working

- - - - -


2 changed files:

- tests/libntp/ntp_calendar.c
- tests/libntp/prettydate.c


Changes:

=====================================
tests/libntp/ntp_calendar.c
=====================================
@@ -36,8 +36,8 @@ static bool IsEqualDate(const struct calendar *expected,
 			return true;
 	} else {
 		printf("Expected: %s but was %s\n",
-						DateToString(str, expected),
-						DateToString(str1, actual));
+                       DateToString(str, expected),
+                       DateToString(str1, actual));
 		return false;
 	}
 }
@@ -62,7 +62,7 @@ static const unsigned short real_month_days[2][14] = {
 };
 
 TEST(calendar, is_leapyear) {
-		/* check is_leapyear() */
+        /* check is_leapyear() */
 	TEST_ASSERT_EQUAL(false, is_leapyear(1900));
 	TEST_ASSERT_EQUAL(false, is_leapyear(1970));
 	TEST_ASSERT_EQUAL(false, is_leapyear(1999));
@@ -73,7 +73,7 @@ TEST(calendar, is_leapyear) {
 }
 
 TEST(calendar, julian0) {
-		/* check julian0() */
+        /* check julian0() */
 	TEST_ASSERT_EQUAL(693961, julian0(1900));
 	TEST_ASSERT_EQUAL(719528, julian0(1970));
 	TEST_ASSERT_EQUAL(730120, julian0(1999));
@@ -83,7 +83,7 @@ TEST(calendar, julian0) {
 }
 
 TEST(calendar, days_per_year) {
-		/* check is_leapyear() */
+        /* check is_leapyear() */
 	TEST_ASSERT_EQUAL(365, days_per_year(1900));
 	TEST_ASSERT_EQUAL(365, days_per_year(1970));
 	TEST_ASSERT_EQUAL(365, days_per_year(1999));
@@ -95,57 +95,58 @@ TEST(calendar, days_per_year) {
 
 #ifdef CLOCK_GENERIC
 TEST(calendar, parse_to_unixtime) {
-		/* check is_leapyear() */
-	clocktime_t  	ct;
-	time_t       	result;
-	unsigned long       Flag;
-
-	ct.day = 1;
-	ct.month = 1;
-	ct.year = 1970;
-	ct.hour = ct.minute = ct.second = ct.usecond = 0;
-	ct.utcoffset = 0;
-	ct.utctime = 0;
-	ct.flags = 0;
-
-	Flag = 0;
-	result = parse_to_unixtime( &ct, &Flag );
+        /* check is_leapyear() */
+        clocktime_t  	ct;
+        time_t       	result;
+        unsigned long       Flag;
+
+        ct.day = 1;
+        ct.month = 1;
+        ct.year = 1970;
+        ct.hour = ct.minute = ct.second = ct.usecond = 0;
+        ct.utcoffset = 0;
+        ct.utctime = 0;
+        ct.flags = 0;
+
+        Flag = 0;
+        result = parse_to_unixtime( &ct, &Flag );
 
 	TEST_ASSERT_EQUAL(0, result);
 
-	ct.year = 2000;
-	ct.hour = 2;
-	ct.utctime = 0;
-	result = parse_to_unixtime( &ct, &Flag );
+        ct.year = 2000;
+        ct.hour = 2;
+        ct.utctime = 0;
+        result = parse_to_unixtime( &ct, &Flag );
 	TEST_ASSERT_EQUAL(946692000L, result);
 
-	ct.year = 2037;
-	ct.minute = 2;
-	ct.second = 3;
-	ct.utctime = 0;
-	result = parse_to_unixtime( &ct, &Flag );
+        ct.year = 2037;
+        ct.minute = 2;
+        ct.second = 3;
+        ct.utctime = 0;
+        result = parse_to_unixtime( &ct, &Flag );
 	TEST_ASSERT_EQUAL(2114388123L, result);
 }
 #endif
+
 TEST(calendar, PeriodicExtend1) {
-	// Test positive cycle, pivot > value
-	TEST_ASSERT_EQUAL(1001, ntpcal_periodic_extend(1000, 5, 2));
-	// Test positive cycle, pivot < value
-	TEST_ASSERT_EQUAL(6, ntpcal_periodic_extend(5, 1000, 2));
-	// Test negative cycle, pivot > value
-	TEST_ASSERT_EQUAL(999, ntpcal_periodic_extend(1000, 5, -2));
-	// Test negative cycle, pivot < value
-	TEST_ASSERT_EQUAL(4, ntpcal_periodic_extend(5, 1000, -2));
+    // Test positive cycle, pivot > value
+    TEST_ASSERT_EQUAL(1001, ntpcal_periodic_extend(1000, 5, 2));
+    // Test positive cycle, pivot < value
+    TEST_ASSERT_EQUAL(6, ntpcal_periodic_extend(5, 1000, 2));
+    // Test negative cycle, pivot > value
+    TEST_ASSERT_EQUAL(999, ntpcal_periodic_extend(1000, 5, -2));
+    // Test negative cycle, pivot < value
+    TEST_ASSERT_EQUAL(4, ntpcal_periodic_extend(5, 1000, -2));
 }
 
 // test the NTP to 64-bit Unix scale time conversion
 TEST(calendar, NtpToTime1) {
-	TEST_ASSERT_EQUAL(2085978538, ntpcal_ntp_to_time(42, 23));
+    TEST_ASSERT_EQUAL(2085978538, ntpcal_ntp_to_time(42, 23));
 }
 
 // test the NTP to 64-bit NTP scale time conversion
 TEST(calendar, NtpToNtp1) {
-	TEST_ASSERT_EQUAL(4294967338, ntpcal_ntp_to_ntp(42, 23));
+    TEST_ASSERT_EQUAL(4294967338, ntpcal_ntp_to_ntp(42, 23));
 }
 
 // test the day/sec join & split ops, making sure that 32bit
@@ -178,34 +179,34 @@ TEST(calendar, DaySplitMerge) {
 }
 
 TEST(calendar, SplitEraDays1) {
-	ntpcal_split res;
-	int32_t isleapyear = 42;
-
-	// Test no flag, no-leap, positive
-	res = ntpcal_split_eradays(4, NULL);
-	TEST_ASSERT_EQUAL(0, res.hi);
-	TEST_ASSERT_EQUAL(4, res.lo);
-	TEST_ASSERT_EQUAL(42, isleapyear);
-
-	// Test flag, no-leap, positive
-	res = ntpcal_split_eradays(4, &isleapyear);
-	TEST_ASSERT_EQUAL(0, res.hi);
-	TEST_ASSERT_EQUAL(4, res.lo);
-	TEST_ASSERT_EQUAL(0, isleapyear);
-
-	// Test flag, leap, positive
-	res = ntpcal_split_eradays(1400, &isleapyear);
-	TEST_ASSERT_EQUAL(3, res.hi);
-	TEST_ASSERT_EQUAL(305, res.lo);
-	TEST_ASSERT_EQUAL(1, isleapyear);
-
-	isleapyear = 0;
-
-	// Test flag, leap, negative
-	res = ntpcal_split_eradays(-100, &isleapyear);
-	TEST_ASSERT_EQUAL(-1, res.hi);
-	TEST_ASSERT_EQUAL(266, res.lo);
-	TEST_ASSERT_EQUAL(1, isleapyear);
+    ntpcal_split res;
+    int32_t isleapyear = 42;
+
+    // Test no flag, no-leap, positive
+    res = ntpcal_split_eradays(4, NULL);
+    EST_ASSERT_EQUAL(0, res.hi);
+    TEST_ASSERT_EQUAL(4, res.lo);
+    TEST_ASSERT_EQUAL(42, isleapyear);
+
+    // Test flag, no-leap, positive
+    res = ntpcal_split_eradays(4, &isleapyear);
+    TEST_ASSERT_EQUAL(0, res.hi);
+    TEST_ASSERT_EQUAL(4, res.lo);
+    TEST_ASSERT_EQUAL(0, isleapyear);
+
+    // Test flag, leap, positive
+    res = ntpcal_split_eradays(1400, &isleapyear);
+    TEST_ASSERT_EQUAL(3, res.hi);
+    TEST_ASSERT_EQUAL(305, res.lo);
+    TEST_ASSERT_EQUAL(1, isleapyear);
+
+    isleapyear = 0;
+
+    // Test flag, leap, negative
+    res = ntpcal_split_eradays(-100, &isleapyear);
+    TEST_ASSERT_EQUAL(-1, res.hi);
+    TEST_ASSERT_EQUAL(266, res.lo);
+    TEST_ASSERT_EQUAL(1, isleapyear);
 }
 
 TEST(calendar, SplitYearDays1) {
@@ -248,81 +249,81 @@ TEST(calendar, RataDie1) {
 }
 
 TEST(calendar, DaysecToDate1) {
-	struct calendar cal;
-	int32_t days;
-
-	// Test normal date
-	days = ntpcal_daysec_to_date(&cal, 100000);
-	TEST_ASSERT_EQUAL(days, 1);
-	TEST_ASSERT_EQUAL(cal.hour, 3);
-	TEST_ASSERT_EQUAL(cal.minute, 46);
-	TEST_ASSERT_EQUAL(cal.second, 40);
-
-	// Test negative date
-	days = ntpcal_daysec_to_date(&cal, -100000);
-	TEST_ASSERT_EQUAL(-2, days);
-	TEST_ASSERT_EQUAL(20, cal.hour);
-	TEST_ASSERT_EQUAL(13, cal.minute);
-	TEST_ASSERT_EQUAL(20, cal.second);
+    struct calendar cal;
+    int32_t days;
+
+    // Test normal date
+    days = ntpcal_daysec_to_date(&cal, 100000);
+    TEST_ASSERT_EQUAL(days, 1);
+    TEST_ASSERT_EQUAL(cal.hour, 3);
+    TEST_ASSERT_EQUAL(cal.minute, 46);
+    TEST_ASSERT_EQUAL(cal.second, 40);
+
+    // Test negative date
+    days = ntpcal_daysec_to_date(&cal, -100000);
+    TEST_ASSERT_EQUAL(-2, days);
+    TEST_ASSERT_EQUAL(20, cal.hour);
+    TEST_ASSERT_EQUAL(13, cal.minute);
+    TEST_ASSERT_EQUAL(20, cal.second);
 }
 
 TEST(calendar, TimeToDate1) {
-	struct calendar jd = {0, 0, 0, 0, 0, 0, 0, 0};
-	int res;
-
-	res = ntpcal_time_to_date(&jd, 1000000);
-	TEST_ASSERT_EQUAL(0, res);
-	TEST_ASSERT_EQUAL(1970, jd.year);
-	TEST_ASSERT_EQUAL(12, jd.yearday);
-	TEST_ASSERT_EQUAL(1, jd.month);
-	TEST_ASSERT_EQUAL(12, jd.monthday);
-	TEST_ASSERT_EQUAL(13, jd.hour);
-	TEST_ASSERT_EQUAL(46, jd.minute);
-	TEST_ASSERT_EQUAL(40, jd.second);
-	TEST_ASSERT_EQUAL(1, jd.weekday);
+    struct calendar jd = {0, 0, 0, 0, 0, 0, 0, 0};
+    int res;
+
+    res = ntpcal_time_to_date(&jd, 1000000);
+    TEST_ASSERT_EQUAL(0, res);
+    TEST_ASSERT_EQUAL(1970, jd.year);
+    TEST_ASSERT_EQUAL(12, jd.yearday);
+    TEST_ASSERT_EQUAL(1, jd.month);
+    TEST_ASSERT_EQUAL(12, jd.monthday);
+    TEST_ASSERT_EQUAL(13, jd.hour);
+    TEST_ASSERT_EQUAL(46, jd.minute);
+    TEST_ASSERT_EQUAL(40, jd.second);
+    TEST_ASSERT_EQUAL(1, jd.weekday);
 }
 
 TEST(calendar, DayJoin1) {
-	TEST_ASSERT_EQUAL(4323600, ntpcal_dayjoin(50, 3600));
+    TEST_ASSERT_EQUAL(4323600, ntpcal_dayjoin(50, 3600));
 }
 
 TEST(calendar, DaysInYears1) {
-	// Test positive less than one gregorian cycle of years
-	TEST_ASSERT_EQUAL(109572, ntpcal_days_in_years(300));
-	// Test positive one gregorian cycle of years
-	TEST_ASSERT_EQUAL(146097, ntpcal_days_in_years(400));
-	// Test positive greater than one gregorian cycle of years
-	TEST_ASSERT_EQUAL(182621, ntpcal_days_in_years(500));
-	// Test negative less than one gregorian cycle of years
-	TEST_ASSERT_EQUAL(-109573, ntpcal_days_in_years(-300));
-	// Test negative one gregorian cycle of years
-	TEST_ASSERT_EQUAL(-146097, ntpcal_days_in_years(-400));
-	// Test negative greater than one gregorian cycle of years
-	TEST_ASSERT_EQUAL(-182622, ntpcal_days_in_years(-500));
+    // Test positive less than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(109572, ntpcal_days_in_years(300));
+    // Test positive one gregorian cycle of years
+    TEST_ASSERT_EQUAL(146097, ntpcal_days_in_years(400));
+    // Test positive greater than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(182621, ntpcal_days_in_years(500));
+    // Test negative less than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-109573, ntpcal_days_in_years(-300));
+    // Test negative one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-146097, ntpcal_days_in_years(-400));
+    // Test negative greater than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-182622, ntpcal_days_in_years(-500));
 }
 
 TEST(calendar, EdateToEradays1) {
-	// Test positive, no months
-	TEST_ASSERT_EQUAL(1827, ntpcal_edate_to_eradays(5, 0, 1));
-	// Test positive, with months
-	TEST_ASSERT_EQUAL(1917, ntpcal_edate_to_eradays(5, 3, 1));
-	// Test negative, no months
-	TEST_ASSERT_EQUAL(-1828, ntpcal_edate_to_eradays(-5, 0, -1));
-	// Test negative, with months
-	TEST_ASSERT_EQUAL(-1920, ntpcal_edate_to_eradays(-5, -3, -1));
+    // Test positive, no months
+    TEST_ASSERT_EQUAL(1827, ntpcal_edate_to_eradays(5, 0, 1));
+    // Test positive, with months
+    TEST_ASSERT_EQUAL(1917, ntpcal_edate_to_eradays(5, 3, 1));
+    // Test negative, no months
+    TEST_ASSERT_EQUAL(-1828, ntpcal_edate_to_eradays(-5, 0, -1));
+    // Test negative, with months
+    TEST_ASSERT_EQUAL(-1920, ntpcal_edate_to_eradays(-5, -3, -1));
 }
 
 TEST(calendar, EtimeToSeconds1) {
-	TEST_ASSERT_EQUAL(18181, ntpcal_etime_to_seconds(5, 3, 1));
+    TEST_ASSERT_EQUAL(18181, ntpcal_etime_to_seconds(5, 3, 1));
 }
 
 TEST(calendar, TmToRd1) {
-	struct tm utm;
+    struct tm utm;
 
-	utm.tm_year = 10;
-	utm.tm_mon = 5;
-	utm.tm_mday = 1;
-	TEST_ASSERT_EQUAL(697399, ntpcal_tm_to_rd(&utm));
+    utm.tm_year = 10;
+    utm.tm_mon = 5;
+    utm.tm_mday = 1;
+    TEST_ASSERT_EQUAL(697399, ntpcal_tm_to_rd(&utm));
 }
 
 // check last day of february for first 10000 years
@@ -388,57 +389,57 @@ TEST(calendar, RoundTripDate) {
 }
 
 TEST(calendar, DateToDaysec1) {
-	struct calendar jd;
+    struct calendar jd;
 
-	jd.hour = 18;
-	jd.minute = 45;
-	jd.second = 15;
-	TEST_ASSERT_EQUAL(67515, ntpcal_date_to_daysec(&jd));
+    jd.hour = 18;
+    jd.minute = 45;
+    jd.second = 15;
+    TEST_ASSERT_EQUAL(67515, ntpcal_date_to_daysec(&jd));
 }
 
 TEST(calendar, TmToDaysec1) {
-	struct tm utm;
+    struct tm utm;
 
-	utm.tm_hour = 18;
-	utm.tm_min = 45;
-	utm.tm_sec = 15;
-	TEST_ASSERT_EQUAL(67515, ntpcal_tm_to_daysec(&utm));
+    utm.tm_hour = 18;
+    utm.tm_min = 45;
+    utm.tm_sec = 15;
+    TEST_ASSERT_EQUAL(67515, ntpcal_tm_to_daysec(&utm));
 }
 
 TEST(calendar, DateToTime1) {
-	struct calendar jd;
-
-	jd.year = 2000;
-	jd.month = 2;
-	jd.monthday = 4;
-	jd.hour = 8;
-	jd.minute = 16;
-	jd.second = 32;
-	TEST_ASSERT_EQUAL(949652192, ntpcal_date_to_time(&jd));
+    struct calendar jd;
+
+    jd.year = 2000;
+    jd.month = 2;
+    jd.monthday = 4;
+    jd.hour = 8;
+    jd.minute = 16;
+    jd.second = 32;
+    TEST_ASSERT_EQUAL(949652192, ntpcal_date_to_time(&jd));
 }
 
 TEST(calendar, Ntp64ToDate1) {
-	struct calendar jd;
-
-	TEST_ASSERT_EQUAL(0, ntpcal_ntp64_to_date(&jd, 10000000));
-	TEST_ASSERT_EQUAL(1900, jd.year);
-	TEST_ASSERT_EQUAL(4, jd.month);
-	TEST_ASSERT_EQUAL(26, jd.monthday);
-	TEST_ASSERT_EQUAL(17, jd.hour);
-	TEST_ASSERT_EQUAL(46, jd.minute);
-	TEST_ASSERT_EQUAL(40, jd.second);
+    struct calendar jd;
+
+    TEST_ASSERT_EQUAL(0, ntpcal_ntp64_to_date(&jd, 10000000));
+    TEST_ASSERT_EQUAL(1900, jd.year);
+    TEST_ASSERT_EQUAL(4, jd.month);
+    TEST_ASSERT_EQUAL(26, jd.monthday);
+    TEST_ASSERT_EQUAL(17, jd.hour);
+    TEST_ASSERT_EQUAL(46, jd.minute);
+    TEST_ASSERT_EQUAL(40, jd.second);
 }
 
 TEST(calendar, NtpToDate1) {
-	struct calendar jd;
-
-	TEST_ASSERT_EQUAL(1, ntpcal_ntp_to_date(&jd, 86400, 1000000));
-	TEST_ASSERT_EQUAL(2036, jd.year);
-	TEST_ASSERT_EQUAL(2, jd.month);
-	TEST_ASSERT_EQUAL(8, jd.monthday);
-	TEST_ASSERT_EQUAL(6, jd.hour);
-	TEST_ASSERT_EQUAL(28, jd.minute);
-	TEST_ASSERT_EQUAL(16, jd.second);
+    struct calendar jd;
+
+    TEST_ASSERT_EQUAL(1, ntpcal_ntp_to_date(&jd, 86400, 1000000));
+    TEST_ASSERT_EQUAL(2036, jd.year);
+    TEST_ASSERT_EQUAL(2, jd.month);
+    TEST_ASSERT_EQUAL(8, jd.monthday);
+    TEST_ASSERT_EQUAL(6, jd.hour);
+    TEST_ASSERT_EQUAL(28, jd.minute);
+    TEST_ASSERT_EQUAL(16, jd.second);
 }
 
 


=====================================
tests/libntp/prettydate.c
=====================================
@@ -20,11 +20,11 @@ TEST_TEAR_DOWN(prettydate) {}
 static const uint32_t HALF = 2147483648UL;
 
 TEST(prettydate, Rfc3339Date1) {
-  TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
+    TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
 }
 
 TEST(prettydate, Rfc3339Time1) {
-  TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
+    TEST_ASSERT_EQUAL_STRING("2036-02-07T06:28:16.000Z", rfc3339date(0));
 }
 
 TEST(prettydate, ConstantDate) {



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/e20581d5e2e5f191924c21304c62edf2ffede8e3...f736a3d7043e99c132d964854ed7ae5fb0ff5a2d

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/e20581d5e2e5f191924c21304c62edf2ffede8e3...f736a3d7043e99c132d964854ed7ae5fb0ff5a2d
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180710/52f463c0/attachment.html>


More information about the vc mailing list