Example #1
0
// Full roundtrip for 1601-01-01 to 2400-12-31
// checks sequence of rata die numbers and validates date output
// (since the input is all nominal days of the calendar in that range
// and the result of the inverse calculation must match the input no
// invalid output can occur.)
void test_RoundTripDate() {
    struct calendar truDate, expDate = { 1600, 0, 12, 31 };;
    int32	 truRdn, expRdn	= ntpcal_date_to_rd(&expDate);
    int	 leaps;

    while (expDate.year < 2400) {
        expDate.year++;
        expDate.month	= 0;
        expDate.yearday = 0;
        leaps = leapdays(expDate.year);
        while (expDate.month < 12) {
            expDate.month++;
            expDate.monthday = 0;
            while (expDate.monthday < real_month_days[leaps][expDate.month]) {
                expDate.monthday++;
                expDate.yearday++;
                expRdn++;

                truRdn = ntpcal_date_to_rd(&expDate);
                TEST_ASSERT_EQUAL(expRdn, truRdn);

                ntpcal_rd_to_date(&truDate, truRdn);
                TEST_ASSERT_TRUE(IsEqualDateCal(expDate, truDate));
            }
        }
    }
}
Example #2
0
void test_RataDie1() {
    int32	 testDate = 1; // 0001-01-01 (proleptic date)
    struct calendar expected = { 1, 1, 1, 1 };
    struct calendar actual;

    ntpcal_rd_to_date(&actual, testDate);
    TEST_ASSERT_TRUE(IsEqualDateCal(expected, actual));
}
Example #3
0
// check first day of march for first 10000 years
void test_LeapYears2() {
    struct calendar dateIn, dateOut;

    for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
        dateIn.month	= 3;
        dateIn.monthday = 1;
        dateIn.yearday	= 60 + leapdays(dateIn.year);

        ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn));
        TEST_ASSERT_TRUE(IsEqualDateCal(dateIn, dateOut));
    }
}
Example #4
0
void
test_RataDie1(void)
{
	int32	 testDate = 1; /* 0001-01-01 (proleptic date) */
	struct calendar expected = { 1, 1, 1, 1 };
	struct calendar actual;

	ntpcal_rd_to_date(&actual, testDate);
	TEST_ASSERT_TRUE(IsEqualDateCal(&expected, &actual));

	return;
}
Example #5
0
/* check last day of february for first 10000 years */
void
test_LeapYears1(void)
{
	struct calendar dateIn, dateOut;

	for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
		dateIn.month	= 2;
		dateIn.monthday = 28 + leapdays(dateIn.year);
		dateIn.yearday	= 31 + dateIn.monthday;

		ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn));

		TEST_ASSERT_TRUE(IsEqualDateCal(&dateIn, &dateOut));
	}

	return;
}