#include "unity.h"
-// Required for Solaris.
+/* Required for Solaris. */
#include <math.h>
void test_ZeroBuffer(void);
test_ZeroBuffer(void) {
#ifndef SYS_WINNT
const struct timeval input = {0, 0};
- const l_fp expected = {0 + JAN_1970, 0};
+ const l_fp expected = {{0 + JAN_1970}, 0};
l_fp actual;
void
test_IntegerAndFractionalBuffer(void) {
#ifndef SYS_WINNT
- const struct timeval input = {5, 500000}; // 5.5
- const l_fp expected = {5 + JAN_1970, HALF};
+ const struct timeval input = {5, 500000}; /* 5.5 */
+ const l_fp expected = {{5 + JAN_1970}, HALF};
double expectedDouble, actualDouble;
l_fp actual;
TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
- // Compare the fractional part with an absolute error given.
+ /* Compare the fractional part with an absolute error given. */
TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);
M_LFPTOD(0, expected.l_uf, expectedDouble);
M_LFPTOD(0, actual.l_uf, actualDouble);
- // The error should be less than 0.5 us
+ /* The error should be less than 0.5 us */
TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
#else
TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
void
test_IllegalMicroseconds(void) {
#ifndef SYS_WINNT
- const struct timeval input = {0, 1100000}; // > 999 999 microseconds.
+ const struct timeval input = {0, 1100000}; /* > 999 999 microseconds. */
l_fp actual;
#include "config.h"
-#include "ntp_stdlib.h" //test fail without this include, for some reason
+#include "ntp_stdlib.h" /* test fail without this include, for some reason */
#include "ntp_calendar.h"
#include "unity.h"
void test_IsoCalWeeksToYearEnd(void);
void test_DaySecToDate(void);
-// ---------------------------------------------------------------------
-// test support stuff
-// ---------------------------------------------------------------------
-
+/*
+ * ---------------------------------------------------------------------
+ * test support stuff
+ * ---------------------------------------------------------------------
+ */
int
isGT(int first, int second)
{
return str;
}
-// boolean
-int
+int/*BOOL*/
IsEqualDateCal(
const struct calendar *expected,
const struct calendar *actual)
}
}
-// boolean
-int
+int/*BOOL*/
IsEqualDateIso(
const struct isodate *expected,
const struct isodate *actual)
}
-// ---------------------------------------------------------------------
-// test cases
-// ---------------------------------------------------------------------
+/*
+ * ---------------------------------------------------------------------
+ * test cases
+ * ---------------------------------------------------------------------
+ */
+
+/* days before month, with a full-year pad at the upper end */
static const u_short real_month_table[2][13] = {
/* -*- table for regular years -*- */
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
};
-// days in month, with one month wrap-around at both ends
+/* days in month, with one month wrap-around at both ends */
static const u_short real_month_days[2][14] = {
/* -*- table for regular years -*- */
{ 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 },
{ 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 }
};
-// test the day/sec join & split ops, making sure that 32bit
-// intermediate results would definitely overflow and the hi DWORD of
-// the 'vint64' is definitely needed.
+/* test the day/sec join & split ops, making sure that 32bit
+ * intermediate results would definitely overflow and the hi DWORD of
+ * the 'vint64' is definitely needed.
+ */
void
test_DaySplitMerge(void) {
int32 day,sec;
for (eyd = -1; eyd <= 366; eyd++) {
ntpcal_split split = ntpcal_split_yeardays(eyd, 1);
if (split.lo >= 0 && split.hi >= 0) {
- //TEST_ASSERT_TRUE(12 > split.hi); //simpler version, works for basic types, doesn't work for complex structs
- TEST_ASSERT_TRUE(isGT(12,split.hi));//EXPECT_GT(12, split.hi);
- TEST_ASSERT_TRUE(isGT(real_month_days[1][split.hi+1], split.lo));//EXPECT_GT(real_month_days[1][split.hi+1], split.lo);
+ /* basic checks do not work on compunds :( */
+ /* would like: TEST_ASSERT_TRUE(12 > split.hi); */
+ TEST_ASSERT_TRUE(isGT(12,split.hi));
+ TEST_ASSERT_TRUE(isGT(real_month_days[1][split.hi+1], split.lo));
int32 tyd = real_month_table[1][split.hi] + split.lo;
TEST_ASSERT_EQUAL(eyd, tyd);
} else
void
test_RataDie1(void) {
- int32 testDate = 1; // 0001-01-01 (proleptic date)
+ int32 testDate = 1; /* 0001-01-01 (proleptic date) */
struct calendar expected = { 1, 1, 1, 1 };
struct calendar actual;
TEST_ASSERT_TRUE(IsEqualDateCal(&expected, &actual));
}
-// check last day of february for first 10000 years
+/* check last day of february for first 10000 years */
void
test_LeapYears1(void) {
struct calendar dateIn, dateOut;
}
}
-// check first day of march for first 10000 years
+/* check first day of march for first 10000 years */
void
test_LeapYears2(void) {
struct calendar dateIn, dateOut;
}
}
-// 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.)
+/* Full roundtrip from 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(void) {
struct calendar truDate, expDate = { 1600, 0, 12, 31 };;
}
}
-// Roundtrip testing on calyearstart
+/* Roundtrip testing on calyearstart */
void
test_RoundTripYearStart(void) {
static const time_t pivot = 0;
}
}
-// Roundtrip testing on calymonthstart
+/* Roundtrip testing on calmonthstart */
void
test_RoundTripMonthStart(void) {
static const time_t pivot = 0;
}
}
-// Roundtrip testing on calweekstart
+/* Roundtrip testing on calweekstart */
void
test_RoundTripWeekStart(void) {
static const time_t pivot = 0;
}
}
-// Roundtrip testing on caldaystart
+/* Roundtrip testing on caldaystart */
void
test_RoundTripDayStart(void) {
static const time_t pivot = 0;
/* The next tests loop over 5000yrs, but should still be very fast. If
* they are not, the calendar needs a better implementation...
*/
-void test_IsoCalYearsToWeeks(void) {
+void
+test_IsoCalYearsToWeeks(void) {
int32_t years;
int32_t wref, wcal;
for (years = -1000; years < 4000; ++years) {
}
}
-void test_IsoCalWeeksToYearStart(void) {
+void
+test_IsoCalWeeksToYearStart(void) {
int32_t years;
int32_t wref;
ntpcal_split ysplit;
}
}
-void test_IsoCalWeeksToYearEnd(void) {
+void
+test_IsoCalWeeksToYearEnd(void) {
int32_t years;
int32_t wref;
ntpcal_split ysplit;
}
}
-void test_DaySecToDate(void) {
+void
+test_DaySecToDate(void) {
struct calendar cal;
int32_t days;
void test_AlwaysInLimit(void);
-// ---------------------------------------------------------------------
-// test fixture
-//
-// The clocktimeTest uses the NTP calendar feature to use a mockup
-// function for getting the current system time, so the tests are not
-// dependent on the actual system time.
-
+/* ---------------------------------------------------------------------
+ * test fixture
+ *
+ * The clocktimeTest uses the NTP calendar feature to use a mockup
+ * function for getting the current system time, so the tests are not
+ * dependent on the actual system time.
+ */
void
setUp()
ntpcal_set_timefunc(NULL);
}
-// ---------------------------------------------------------------------
-// test cases
+/* ---------------------------------------------------------------------
+ * test cases
+ */
void
test_CurrentYear(void) {
- // Timestamp: 2010-06-24 12:50:00Z
+ /* Timestamp: 2010-06-24 12:50:00Z */
const u_int32 timestamp = 3486372600UL;
- const u_int32 expected = timestamp; // exactly the same.
+ const u_int32 expected = timestamp; /* exactly the same. */
const int yday=175, hour=12, minute=50, second=0, tzoff=0;
* timestamp for the 12:00:00 time.
*/
- const u_int32 timestamp = 3486372600UL; // 2010-06-24 12:50:00Z
- const u_int32 expected = 3486369600UL; // 2010-06-24 12:00:00Z
+ const u_int32 timestamp = 3486372600UL; /* 2010-06-24 12:50:00Z */
+ const u_int32 expected = 3486369600UL; /* 2010-06-24 12:00:00Z */
const int yday=175, hour=12, minute=0, second=0, tzoff=0;
const int yday=2, hour=11, minute=0, second=0, tzoff=0;
- u_long yearstart = 302024100UL; // Yearstart of 2009.
+ u_long yearstart = 302024100UL; /* Yearstart of 2009. */
u_int32 actual;
TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp,
}
-int // technically boolean
+int/*BOOL*/
isLE(u_int32 diff,u_int32 actual){
if(diff <= actual){
return TRUE;
u_short ydayinc;
int hour;
int minute;
- int second;
u_long yearstart;
u_int32 actual;
u_int32 diff;
const char *str = "00001000.00000000";
l_fp actual;
- l_fp expected = {4096, 0}; // 16^3, no fraction part.
+ l_fp expected = {{4096}, 0}; /* 16^3, no fraction part. */
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
void
test_NegativeInteger(void) {
- const char *str = "ffffffff.00000000"; // -1 decimal
+ const char *str = "ffffffff.00000000"; /* -1 decimal */
l_fp actual;
- l_fp expected = {-1, 0};
+ l_fp expected = {{-1}, 0};
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
void
test_PositiveFraction(void) {
- const char *str = "00002000.80000000"; // 8196.5 decimal
+ const char *str = "00002000.80000000"; /* 8196.5 decimal */
l_fp actual;
- l_fp expected = {8192, HALF};
+ l_fp expected = {{8192}, HALF};
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
void
test_NegativeFraction(void) {
- const char *str = "ffffffff.40000000"; // -1 + 0.25 decimal
+ const char *str = "ffffffff.40000000"; /* -1 + 0.25 decimal */
l_fp actual;
- l_fp expected = {-1, QUARTER}; //-1 + 0.25
+ l_fp expected = {{-1}, QUARTER}; /* -1 + 0.25 */
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
void
test_IllegalNumberOfInteger(void) {
- const char *str = "1000000.00000000"; // Missing one digit in integral part.
+ const char *str = "1000000.00000000"; /* Missing one digit in integral part. */
l_fp actual;
TEST_ASSERT_FALSE(hextolfp(str, &actual));
void
test_IllegalChar(void) {
- const char *str = "10000000.0000h000"; // Illegal character h.
+ const char *str = "10000000.0000h000"; /* Illegal character h. */
l_fp actual;
TEST_ASSERT_FALSE(hextolfp(str, &actual));
static const int LFP_MAX_PRECISION = 10;
static const int LFP_MAX_PRECISION_MS = 7;
-static const int ONE_FOURTH = 1073741824; // (1 << 30)
+static const int ONE_FOURTH = 1073741824; /* (1 << 30) */
static const int HALF = (1 << 31);
static const int THREE_FOURTH = -1073741824;
-static const int HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
-static const int HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
+static const int HALF_PROMILLE_UP = 2147484; /* slightly more than 0.0005 */
+static const int HALF_PROMILLE_DOWN = 2147483; /* slightly less than 0.0005 */
void test_PositiveInteger(void);
void
test_PositiveInteger(void) {
- l_fp test = {200, 0}; // exact 200.0000000000
+ l_fp test = {{200}, 0}; /* exact 200.0000000000 */
TEST_ASSERT_EQUAL_STRING("200.0000000000", mfptoa(test.l_ui, test.l_uf, LFP_MAX_PRECISION));
TEST_ASSERT_EQUAL_STRING("200000.0000000", mfptoms(test.l_ui, test.l_uf, LFP_MAX_PRECISION_MS));
void
test_NegativeInteger(void) {
- l_fp test = {-100, 0}; // -100
+ l_fp test = {{-100}, 0}; /* -100 */
TEST_ASSERT_EQUAL_STRING("-100.0000000000", lfptoa(&test, LFP_MAX_PRECISION));
TEST_ASSERT_EQUAL_STRING("-100000.0000000", lfptoms(&test, LFP_MAX_PRECISION_MS));
void
test_PositiveIntegerWithFraction(void) {
- l_fp test = {200, ONE_FOURTH}; // 200.25
+ l_fp test = {{200}, ONE_FOURTH}; /* 200.25 */
TEST_ASSERT_EQUAL_STRING("200.2500000000", lfptoa(&test, LFP_MAX_PRECISION));
TEST_ASSERT_EQUAL_STRING("200250.0000000", lfptoms(&test, LFP_MAX_PRECISION_MS));
void
test_NegativeIntegerWithFraction(void) {
- l_fp test = {-100, ONE_FOURTH}; // -99.75
+ l_fp test = {{-100}, ONE_FOURTH}; /* -99.75 */
TEST_ASSERT_EQUAL_STRING("-99.7500000000", lfptoa(&test, LFP_MAX_PRECISION));
TEST_ASSERT_EQUAL_STRING("-99750.0000000", lfptoms(&test, LFP_MAX_PRECISION_MS));
void
test_RoundingDownToInteger(void) {
- l_fp test = {10, ONE_FOURTH}; // 10.25
+ l_fp test = {{10}, ONE_FOURTH}; /* 10.25 */
TEST_ASSERT_EQUAL_STRING("10", lfptoa(&test, 0));
TEST_ASSERT_EQUAL_STRING("10250", lfptoms(&test, 0));
void
test_RoundingMiddleToInteger(void) {
- l_fp test = {10, HALF}; // 10.5
+ l_fp test = {{10}, HALF}; /* 10.5 */
TEST_ASSERT_EQUAL_STRING("11", lfptoa(&test, 0));
TEST_ASSERT_EQUAL_STRING("10500", lfptoms(&test, 0));
void
test_RoundingUpToInteger(void) {
- l_fp test = {5, THREE_FOURTH}; // 5.75
+ l_fp test = {{5}, THREE_FOURTH}; /* 5.75 */
TEST_ASSERT_EQUAL_STRING("6", lfptoa(&test, 0));
TEST_ASSERT_EQUAL_STRING("5750", lfptoms(&test, 0));
void
test_SingleDecimal(void) {
- l_fp test = {8, ONE_FOURTH}; // 8.25
+ l_fp test = {{8}, ONE_FOURTH}; /* 8.25 */
TEST_ASSERT_EQUAL_STRING("8.3", lfptoa(&test, 1));
TEST_ASSERT_EQUAL_STRING("8250.0", lfptoms(&test, 1));
void
test_MillisecondsRoundingUp(void) {
- l_fp test = {1, HALF_PROMILLE_UP}; //slightly more than 1.0005
+ l_fp test = {{1}, HALF_PROMILLE_UP}; /* slightly more than 1.0005 */
TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(&test, 1));
void
test_MillisecondsRoundingDown(void) {
- l_fp test = {1, HALF_PROMILLE_DOWN}; // slightly less than 1.0005
+ l_fp test = {{1}, HALF_PROMILLE_DOWN}; /* slightly less than 1.0005 */
TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(&test, 1));
}
void test_UnsignedInteger(void) {
- l_fp test = {3000000000UL, 0};
+ l_fp test = {{3000000000UL}, 0};
TEST_ASSERT_EQUAL_STRING("3000000000.0", ulfptoa(&test, 1));
}
test_ConstantDate(void) {
const u_int32 HALF = 2147483648UL;
- l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5
+ l_fp time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */
TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 Wed, Jun 9 2010 14:00:00.500",
gmprettydate(&time));
const char *str = "500";
const char *str_ms = "500000";
- l_fp expected = {500,0};
+ l_fp expected = {{500},0};
l_fp actual, actual_ms;
TEST_ASSERT_TRUE(atolfp(str, &actual));
const char *str = "+500.5";
const char *str_ms = "500500.0";
- l_fp expected = {500, HALF};
+ l_fp expected = {{500}, HALF};
l_fp actual, actual_ms;
TEST_ASSERT_TRUE(atolfp(str, &actual));
const char *str = "300.00025";
const char *str_ms = "300000.25";
- l_fp expected = {300, QUARTER_PROMILLE_APPRX};
+ l_fp expected = {{300}, QUARTER_PROMILLE_APPRX};
l_fp actual, actual_ms;
void
test_Seconds(void) {
- const l_fp input = {50, 0}; // 50.0 s
+ const l_fp input = {{50}, 0}; /* 50.0 s */
const struct timeval expected = {50, 0};
struct timeval actual;
void
test_MicrosecondsExact(void) {
const u_long HALF = 2147483648UL;
- const l_fp input = {50, HALF}; // 50.5 s
+ const l_fp input = {{50}, HALF}; /* 50.5 s */
const struct timeval expected = {50, 500000};
struct timeval actual;
void
test_MicrosecondsRounding(void) {
- const l_fp input = {50, 3865471UL}; // Should round to 50.0009
+ const l_fp input = {{50}, 3865471UL}; /* Should round to 50.0009 */
const struct timeval expected = {50, 900};
struct timeval actual;
#include "unity.h"
-#include <math.h> // Required on Solaris for ldexp.
+#include <math.h> /* Required on Solaris for ldexp. */
void test_Seconds(void);
void test_MicrosecondsRounded(void);
void
test_Seconds(void)
{
- struct timeval input = {500, 0}; // 500.0 s
- l_fp expected = {500, 0};
+ struct timeval input = {500, 0}; /* 500.0 s */
+ l_fp expected = {{500}, 0};
l_fp actual;
TVTOTS(&input, &actual);
* HALF_PROMILLE_UP (which is 2147484) should be
* the correct rounding. */
- struct timeval input = {0, 500}; // 0.0005 exact
- l_fp expected = {0, HALF_PROMILLE_UP};
+ struct timeval input = {0, 500}; /* 0.0005 exact */
+ l_fp expected = {{0}, HALF_PROMILLE_UP};
l_fp actual;
TVTOTS(&input, &actual);
void
test_MicrosecondsExact(void)
{
- // 0.5 can be represented exact in both l_fp and timeval.
- const struct timeval input = {10, 500000}; // 0.5 exact
- const l_fp expected = {10, HALF}; // 0.5 exact
+ /* 0.5 can be represented exact in both l_fp and timeval. */
+ const struct timeval input = {10, 500000}; /* 0.5 exact */
+ const l_fp expected = {{10}, HALF}; /* 0.5 exact */
l_fp actual;
TVTOTS(&input, &actual);
- // Compare the fractional part with an absolute error given.
+ /* Compare the fractional part with an absolute error given. */
TEST_ASSERT_EQUAL_UINT(expected.l_ui, actual.l_ui);
double expectedDouble, actualDouble;
M_LFPTOD(0, expected.l_uf, expectedDouble);
M_LFPTOD(0, actual.l_uf, actualDouble);
- // The error should be less than 0.5 us
+ /* The error should be less than 0.5 us */
TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
}
test_ConstantDateTime(void) {
const u_int32 HALF = 2147483648UL;
- l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5
+ l_fp time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */
TEST_ASSERT_EQUAL_STRING("3485080800.500000 10:159:14:00:00.500",
uglydate(&time));