cache_flags = 0;
cache_secret = NULL;
cache_secretsize = 0;
+
+ return;
}
void
tearDown(void)
{
-
+ return;
}
static const int KEYTYPE = KEY_TYPE_MD5;
void
-AddTrustedKey(keyid_t keyno) {
+AddTrustedKey(keyid_t keyno)
+{
/*
* We need to add a MD5-key in addition to setting the
* trust, because authhavekey() requires type != 0.
MD5auth_setkey(keyno, KEYTYPE, NULL, 0);
authtrust(keyno, TRUE);
+
+ return;
}
void
-AddUntrustedKey(keyid_t keyno) {
+AddUntrustedKey(keyid_t keyno)
+{
authtrust(keyno, FALSE);
+
+ return;
}
void
-test_AddTrustedKeys(void) {
+test_AddTrustedKeys(void)
+{
const keyid_t KEYNO1 = 5;
const keyid_t KEYNO2 = 8;
TEST_ASSERT_TRUE(authistrusted(KEYNO1));
TEST_ASSERT_TRUE(authistrusted(KEYNO2));
+
+ return;
}
void
-test_AddUntrustedKey(void) {
+test_AddUntrustedKey(void)
+{
const keyid_t KEYNO = 3;
AddUntrustedKey(KEYNO);
TEST_ASSERT_FALSE(authistrusted(KEYNO));
+
+ return;
}
void
-test_HaveKeyCorrect(void) {
+test_HaveKeyCorrect(void)
+{
const keyid_t KEYNO = 3;
AddTrustedKey(KEYNO);
TEST_ASSERT_TRUE(auth_havekey(KEYNO));
TEST_ASSERT_TRUE(authhavekey(KEYNO));
+
+ return;
}
void
-test_HaveKeyIncorrect(void) {
+test_HaveKeyIncorrect(void)
+{
const keyid_t KEYNO = 2;
TEST_ASSERT_FALSE(auth_havekey(KEYNO));
TEST_ASSERT_FALSE(authhavekey(KEYNO));
+
+ return;
}
void
-test_AddWithAuthUseKey(void) {
+test_AddWithAuthUseKey(void)
+{
const keyid_t KEYNO = 5;
const char* KEY = "52a";
- TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (const u_char*)KEY));
+ TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (const u_char*)KEY));
+
+ return;
}
void
-test_EmptyKey(void) {
+test_EmptyKey(void)
+{
const keyid_t KEYNO = 3;
const char* KEY = "";
TEST_ASSERT_FALSE(authusekey(KEYNO, KEYTYPE, (const u_char*)KEY));
+
+ return;
}
void
-test_ZeroBuffer(void) {
+test_ZeroBuffer(void)
+{
#ifndef SYS_WINNT
const struct timeval input = {0, 0};
const l_fp expected = {{0 + JAN_1970}, 0};
#else
TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
#endif
+
+ return;
}
+
void
-test_IntegerAndFractionalBuffer(void) {
+test_IntegerAndFractionalBuffer(void)
+{
#ifndef SYS_WINNT
const struct timeval input = {5, 500000}; /* 5.5 */
const l_fp expected = {{5 + JAN_1970}, HALF};
#else
TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
#endif
+
+ return;
}
void
-test_IllegalMicroseconds(void) {
+test_IllegalMicroseconds(void)
+{
#ifndef SYS_WINNT
const struct timeval input = {0, 1100000}; /* > 999 999 microseconds. */
-
+
l_fp actual;
TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual));
#else
TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
#endif
+
+ return;
}
void
-test_AlwaysFalseOnWindows(void) {
+test_AlwaysFalseOnWindows(void)
+{
#ifdef SYS_WINNT
/*
* Under Windows, buftvtots will just return
#else
TEST_IGNORE_MESSAGE("Non-Windows test, skipping...");
#endif
-}
+ return;
+}
static int leapdays(int year);
-int isGT(int first, int second);
-int leapdays(int year);
-char * CalendarFromCalToString(const struct calendar *cal);
-char * CalendarFromIsoToString(const struct isodate *iso);
-int IsEqualCal(const struct calendar *expected, const struct calendar *actual);
-int IsEqualIso(const struct isodate *expected, const struct isodate *actual);
-char * DateFromCalToString(const struct calendar *cal);
-char * DateFromIsoToString(const struct isodate *iso);
-int IsEqualDateCal(const struct calendar *expected, const struct calendar *actual);
-int IsEqualDateIso(const struct isodate *expected, const struct isodate *actual);
-void test_DaySplitMerge(void);
-void test_SplitYearDays1(void);
-void test_SplitYearDays2(void);
-void test_RataDie1(void);
-void test_LeapYears1(void);
-void test_LeapYears2(void);
-void test_RoundTripDate(void);
-void test_RoundTripYearStart(void);
-void test_RoundTripMonthStart(void);
-void test_RoundTripWeekStart(void);
-void test_RoundTripDayStart(void);
-void test_IsoCalYearsToWeeks(void);
-void test_IsoCalWeeksToYearStart(void);
-void test_IsoCalWeeksToYearEnd(void);
-void test_DaySecToDate(void);
+int isGT(int first, int second);
+int leapdays(int year);
+char * CalendarFromCalToString(const struct calendar *cal);
+char * CalendarFromIsoToString(const struct isodate *iso);
+int IsEqualCal(const struct calendar *expected, const struct calendar *actual);
+int IsEqualIso(const struct isodate *expected, const struct isodate *actual);
+char * DateFromCalToString(const struct calendar *cal);
+char * DateFromIsoToString(const struct isodate *iso);
+int IsEqualDateCal(const struct calendar *expected, const struct calendar *actual);
+int IsEqualDateIso(const struct isodate *expected, const struct isodate *actual);
+void test_DaySplitMerge(void);
+void test_SplitYearDays1(void);
+void test_SplitYearDays2(void);
+void test_RataDie1(void);
+void test_LeapYears1(void);
+void test_LeapYears2(void);
+void test_RoundTripDate(void);
+void test_RoundTripYearStart(void);
+void test_RoundTripMonthStart(void);
+void test_RoundTripWeekStart(void);
+void test_RoundTripDayStart(void);
+void test_IsoCalYearsToWeeks(void);
+void test_IsoCalWeeksToYearStart(void);
+void test_IsoCalWeeksToYearEnd(void);
+void test_DaySecToDate(void);
/*
* ---------------------------------------------------------------------
int
isGT(int first, int second)
{
- if(first > second) {
+ if(first > second) {
return TRUE;
} else {
return FALSE;
* the 'vint64' is definitely needed.
*/
void
-test_DaySplitMerge(void) {
+test_DaySplitMerge(void)
+{
int32 day,sec;
+
for (day = -1000000; day <= 1000000; day += 100) {
for (sec = -100000; sec <= 186400; sec += 10000) {
vint64 merge;
TEST_ASSERT_EQUAL(esec, split.lo);
}
}
+
+ return;
}
void
-test_SplitYearDays1(void) {
+test_SplitYearDays1(void)
+{
int32 eyd;
+
for (eyd = -1; eyd <= 365; eyd++) {
ntpcal_split split = ntpcal_split_yeardays(eyd, 0);
if (split.lo >= 0 && split.hi >= 0) {
} else
TEST_ASSERT_TRUE(eyd < 0 || eyd > 364);
}
+
+ return;
}
-
+
void
-test_SplitYearDays2(void) {
+test_SplitYearDays2(void)
+{
int32 eyd;
+
for (eyd = -1; eyd <= 366; eyd++) {
ntpcal_split split = ntpcal_split_yeardays(eyd, 1);
if (split.lo >= 0 && split.hi >= 0) {
} else
TEST_ASSERT_TRUE(eyd < 0 || eyd > 365);
}
+
+ return;
}
-
+
void
-test_RataDie1(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;
}
/* check last day of february for first 10000 years */
void
-test_LeapYears1(void) {
+test_LeapYears1(void)
+{
struct calendar dateIn, dateOut;
for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
TEST_ASSERT_TRUE(IsEqualDateCal(&dateIn, &dateOut));
}
+
+ return;
}
/* check first day of march for first 10000 years */
void
-test_LeapYears2(void) {
+test_LeapYears2(void)
+{
struct calendar dateIn, dateOut;
for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
ntpcal_rd_to_date(&dateOut, ntpcal_date_to_rd(&dateIn));
TEST_ASSERT_TRUE(IsEqualDateCal(&dateIn, &dateOut));
}
+
+ return;
}
/* Full roundtrip from 1601-01-01 to 2400-12-31
* invalid output can occur.)
*/
void
-test_RoundTripDate(void) {
+test_RoundTripDate(void)
+{
struct calendar truDate, expDate = { 1600, 0, 12, 31 };;
int leaps;
int32 truRdn, expRdn = ntpcal_date_to_rd(&expDate);
expDate.yearday = 0;
leaps = leapdays(expDate.year);
while (expDate.month < 12) {
- expDate.month++;
+ expDate.month++;
expDate.monthday = 0;
while (expDate.monthday < real_month_days[leaps][expDate.month]) {
expDate.monthday++;
}
}
}
+
+ return;
}
/* Roundtrip testing on calyearstart */
void
-test_RoundTripYearStart(void) {
+test_RoundTripYearStart(void)
+{
static const time_t pivot = 0;
u_int32 ntp, expys, truys;
struct calendar date;
expys = ntpcal_date_to_ntp(&date);
TEST_ASSERT_EQUAL(expys, truys);
}
-}
+
+ return;
+}
/* Roundtrip testing on calmonthstart */
void
-test_RoundTripMonthStart(void) {
+test_RoundTripMonthStart(void)
+{
static const time_t pivot = 0;
u_int32 ntp, expms, trums;
struct calendar date;
expms = ntpcal_date_to_ntp(&date);
TEST_ASSERT_EQUAL(expms, trums);
}
-}
+
+ return;
+}
/* Roundtrip testing on calweekstart */
void
-test_RoundTripWeekStart(void) {
+test_RoundTripWeekStart(void)
+{
static const time_t pivot = 0;
u_int32 ntp, expws, truws;
struct isodate date;
expws = isocal_date_to_ntp(&date);
TEST_ASSERT_EQUAL(expws, truws);
}
-}
+
+ return;
+}
/* Roundtrip testing on caldaystart */
void
-test_RoundTripDayStart(void) {
+test_RoundTripDayStart(void)
+{
static const time_t pivot = 0;
u_int32 ntp, expds, truds;
struct calendar date;
expds = ntpcal_date_to_ntp(&date);
TEST_ASSERT_EQUAL(expds, truds);
}
+
+ return;
}
/* ---------------------------------------------------------------------
int32_t years)
{
int32_t days, weeks;
+
days = ntpcal_weekday_close(
ntpcal_days_in_years(years) + 1,
CAL_MONDAY) - 1;
weeks = days / 7;
days = days % 7;
TEST_ASSERT_EQUAL(0, days); /* paranoia check... */
+
return weeks;
}
* they are not, the calendar needs a better implementation...
*/
void
-test_IsoCalYearsToWeeks(void) {
+test_IsoCalYearsToWeeks(void)
+{
int32_t years;
int32_t wref, wcal;
+
for (years = -1000; years < 4000; ++years) {
/* get number of weeks before years (reference) */
wref = refimpl_WeeksInIsoYears(years);
wcal = isocal_weeks_in_years(years);
TEST_ASSERT_EQUAL(wref, wcal);
}
+
+ return;
}
void
-test_IsoCalWeeksToYearStart(void) {
+test_IsoCalWeeksToYearStart(void)
+{
int32_t years;
int32_t wref;
ntpcal_split ysplit;
+
for (years = -1000; years < 4000; ++years) {
/* get number of weeks before years (reference) */
wref = refimpl_WeeksInIsoYears(years);
TEST_ASSERT_EQUAL(years, ysplit.hi);
TEST_ASSERT_EQUAL(0, ysplit.lo);
}
+
+ return;
}
void
-test_IsoCalWeeksToYearEnd(void) {
+test_IsoCalWeeksToYearEnd(void)
+{
int32_t years;
int32_t wref;
ntpcal_split ysplit;
+
for (years = -1000; years < 4000; ++years) {
/* get last week of previous year */
wref = refimpl_WeeksInIsoYears(years) - 1;
TEST_ASSERT_EQUAL(years-1, ysplit.hi);
TEST_ASSERT(ysplit.lo == 51 || ysplit.lo == 52);
}
+
+ return;
}
void
-test_DaySecToDate(void) {
+test_DaySecToDate(void)
+{
struct calendar cal;
int32_t days;
days = ntpcal_daysec_to_date(&cal, 86400);
TEST_ASSERT_MESSAGE((days==1 && cal.hour==0 && cal.minute==0 && cal.second==0),
"failed for 86400");
+
+ return;
}
char *
-CalendarToString(const struct calendar cal) {
+CalendarToString(const struct calendar cal)
+{
char * str = emalloc (sizeof (char) * 100);
-
+
char buffer[100] ="";
snprintf(buffer, 100, "%u", cal.year);
strcat(str, buffer);
}
int // technically boolean
-IsEqual(const struct calendar expected, const struct calendar actual) {
+IsEqual(const struct calendar expected, const struct calendar actual)
+{
if (expected.year == actual.year &&
(expected.yearday == actual.yearday ||
(expected.month == actual.month &&
expected.second == actual.second) {
return TRUE;
} else {
- printf("expected: %s but was %s", CalendarToString(expected) ,CalendarToString(actual));
+ printf("expected: %s but was %s", CalendarToString(expected),
+ CalendarToString(actual));
return FALSE;
-
}
}
{
ntpcal_set_timefunc(timefunc);
settime(1970, 1, 1, 0, 0, 0);
+
+ return;
}
void
tearDown()
{
ntpcal_set_timefunc(NULL);
+
+ return;
}
void
-test_RegularTime(void) {
+test_RegularTime(void)
+{
u_long testDate = 3485080800UL; // 2010-06-09 14:00:00
struct calendar expected = {2010,160,6,9,14,0,0};
caljulian(testDate, &actual);
TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+ return;
}
void
-test_LeapYear(void) {
+test_LeapYear(void)
+{
u_long input = 3549902400UL; // 2012-06-28 20:00:00Z
struct calendar expected = {2012, 179, 6, 28, 20, 0, 0};
caljulian(input, &actual);
TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+ return;
}
void
-test_uLongBoundary(void) {
+test_uLongBoundary(void)
+{
u_long enc_time = 4294967295UL; // 2036-02-07 6:28:15
struct calendar expected = {2036,0,2,7,6,28,15};
caljulian(enc_time, &actual);
TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+ return;
}
void
-test_uLongWrapped(void) {
+test_uLongWrapped(void)
+{
u_long enc_time = 0;
struct calendar expected = {2036,0,2,7,6,28,16};
caljulian(enc_time, &actual);
TEST_ASSERT_TRUE(IsEqual(expected, actual));
+
+ return;
}
void
setUp()
{
- ntpcal_set_timefunc(timefunc);
- settime(2000, 1, 1, 0, 0, 0);
+ ntpcal_set_timefunc(timefunc);
+ settime(2000, 1, 1, 0, 0, 0);
+
+ return;
}
void
tearDown()
{
- ntpcal_set_timefunc(NULL);
+ ntpcal_set_timefunc(NULL);
+
+ return;
}
/* ---------------------------------------------------------------------
*/
void
-test_CurrentYear(void) {
+test_CurrentYear(void)
+{
/* Timestamp: 2010-06-24 12:50:00Z */
const u_int32 timestamp = 3486372600UL;
const u_int32 expected = timestamp; /* exactly the same. */
const int yday=175, hour=12, minute=50, second=0, tzoff=0;
- u_long yearstart=0;
+ u_long yearstart = 0;
u_int32 actual;
- TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp,
- &yearstart, &actual));
+ TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff,
+ timestamp, &yearstart, &actual));
TEST_ASSERT_EQUAL(expected, actual);
+
+ return;
}
void
-test_CurrentYearFuzz(void) {
+test_CurrentYearFuzz(void)
+{
/*
* Timestamp (rec_ui) is: 2010-06-24 12:50:00
* Time sent into function is 12:00:00.
u_long yearstart=0;
u_int32 actual;
- TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp,
- &yearstart, &actual));
+ TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff,
+ timestamp, &yearstart, &actual));
TEST_ASSERT_EQUAL(expected, actual);
+
+ return;
}
void
-test_TimeZoneOffset(void) {
+test_TimeZoneOffset(void)
+{
/*
* Timestamp (rec_ui) is: 2010-06-24 12:00:00 +0800
* (which is 2010-06-24 04:00:00Z)
}
void
-test_WrongYearStart(void) {
+test_WrongYearStart(void)
+{
/*
* Timestamp (rec_ui) is: 2010-01-02 11:00:00Z
* Time sent into function is 11:00:00.
}
void
-test_PreviousYear(void) {
+test_PreviousYear(void)
+{
/*
* Timestamp is: 2010-01-01 01:00:00Z
* Time sent into function is 23:00:00
}
void
-test_NextYear(void) {
+test_NextYear(void)
+{
/*
* Timestamp is: 2009-12-31 23:00:00Z
* Time sent into function is 01:00:00
u_long yearstart = 0;
u_int32 actual;
- TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff, timestamp,
- &yearstart, &actual));
+ TEST_ASSERT_TRUE(clocktime(yday, hour, minute, second, tzoff,
+ timestamp, &yearstart, &actual));
TEST_ASSERT_EQUAL(expected, actual);
+
+ return;
}
void
-test_NoReasonableConversion(void) {
+test_NoReasonableConversion(void)
+{
/* Timestamp is: 2010-01-02 11:00:00Z */
const u_int32 timestamp = 3471418800UL;
-
+
const int yday=100, hour=12, minute=0, second=0, tzoff=0;
u_long yearstart = 0;
u_int32 actual;
- TEST_ASSERT_FALSE(clocktime(yday, hour, minute, second, tzoff, timestamp,
- &yearstart, &actual));
+ TEST_ASSERT_FALSE(clocktime(yday, hour, minute, second, tzoff,
+ timestamp, &yearstart, &actual));
+
+ return;
}
int/*BOOL*/
-isLE(u_int32 diff,u_int32 actual){
- if(diff <= actual){
+isLE(u_int32 diff,u_int32 actual)
+{
+
+ if (diff <= actual) {
return TRUE;
}
else return FALSE;
void
-test_AlwaysInLimit(void) {
+test_AlwaysInLimit(void)
+{
/* Timestamp is: 2010-01-02 11:00:00Z */
const u_int32 timestamp = 3471418800UL;
const u_short prime_incs[] = { 127, 151, 163, 179 };
for (hour = -204; hour < 204; hour += 2) {
for (minute = -60; minute < 60; minute++) {
clocktime(yday, hour, minute, 30, 0,
- timestamp, &yearstart, &actual);
+ timestamp, &yearstart,
+ &actual);
diff = actual - timestamp;
if (diff >= 0x80000000UL)
diff = ~diff + 1;
}
}
}
+ return;
}
struct tm* tm;
tm = localtime(&sample);
- TEST_ASSERT_TRUE(time != NULL);
+ TEST_ASSERT_TRUE(tm != NULL);
snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
+
+ return;
}
void
time(&sample);
tm = localtime(&sample);
- TEST_ASSERT_TRUE(time != NULL);
+ TEST_ASSERT_TRUE(tm != NULL);
snprintf(expected, 15, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
+
+ return;
}
#include <math.h>
-/* replaced TEST_ASSERT_EQUAL_MEMORY(&a, &b, sizeof(a)) with TEST_ASSERT_EQUAL_l_fp(a, b).
- It's safer this way, because structs can be compared even if they aren't initiated
- with memset (due to padding bytes).
+/*
+ replaced: TEST_ASSERT_EQUAL_MEMORY(&a, &b, sizeof(a))
+ with: TEST_ASSERT_EQUAL_l_fp(a, b).
+ It's safer this way, because structs can be compared even if they
+ aren't initiated with memset (due to padding bytes).
*/
-#define TEST_ASSERT_EQUAL_l_fp(a, b) { \
- TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \
- TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \
+#define TEST_ASSERT_EQUAL_l_fp(a, b) { \
+ TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \
+ TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \
}
-
typedef int bool; // typedef enum { FALSE, TRUE } boolean; -> can't use this because TRUE and FALSE are already defined
} lfp_hl;
-int l_fp_scmp(const l_fp first, const l_fp second);
-int l_fp_ucmp(const l_fp first, l_fp second );
-l_fp l_fp_init(int32 i, u_int32 f);
-l_fp l_fp_add(const l_fp first, const l_fp second);
-l_fp l_fp_subtract(const l_fp first, const l_fp second);
-l_fp l_fp_negate(const l_fp first);
-l_fp l_fp_abs(const l_fp first);
-int l_fp_signum(const l_fp first);
-double l_fp_convert_to_double(const l_fp first);
-l_fp l_fp_init_from_double( double rhs);
-void l_fp_swap(l_fp * first, l_fp *second);
-bool l_isgt(const l_fp first, const l_fp second);
-bool l_isgtu(const l_fp first, const l_fp second);
-bool l_ishis(const l_fp first, const l_fp second);
-bool l_isgeq(const l_fp first, const l_fp second);
-bool l_isequ(const l_fp first, const l_fp second);
-double eps(double d);
+int l_fp_scmp(const l_fp first, const l_fp second);
+int l_fp_ucmp(const l_fp first, l_fp second);
+l_fp l_fp_init(int32 i, u_int32 f);
+l_fp l_fp_add(const l_fp first, const l_fp second);
+l_fp l_fp_subtract(const l_fp first, const l_fp second);
+l_fp l_fp_negate(const l_fp first);
+l_fp l_fp_abs(const l_fp first);
+int l_fp_signum(const l_fp first);
+double l_fp_convert_to_double(const l_fp first);
+l_fp l_fp_init_from_double( double rhs);
+void l_fp_swap(l_fp * first, l_fp *second);
+bool l_isgt(const l_fp first, const l_fp second);
+bool l_isgtu(const l_fp first, const l_fp second);
+bool l_ishis(const l_fp first, const l_fp second);
+bool l_isgeq(const l_fp first, const l_fp second);
+bool l_isequ(const l_fp first, const l_fp second);
+double eps(double d);
void test_AdditionLR(void);
void test_UnsignedRelOps(void);
-
static int cmp_work(u_int32 a[3], u_int32 b[3]);
//----------------------------------------------------------------------
l_fp_scmp(const l_fp first, const l_fp second)
{
u_int32 a[3], b[3];
-
+
const l_fp op1 = first;
const l_fp op2 = second;
-
+
a[0] = op1.l_uf; a[1] = op1.l_ui; a[2] = 0;
b[0] = op2.l_uf; b[1] = op2.l_ui; b[2] = 0;
}
int
-l_fp_ucmp(const l_fp first, l_fp second )
+l_fp_ucmp(const l_fp first, l_fp second)
{
u_int32 a[3], b[3];
const l_fp op1 = first;
const l_fp op2 = second;
-
+
a[0] = op1.l_uf; a[1] = op1.l_ui; a[2] = 0;
b[0] = op2.l_uf; b[1] = op2.l_ui; b[2] = 0;
{
l_fp temp = first;
L_SUB(&temp, &second);
-
+
return temp;
}
{
l_fp temp = first;
L_NEG(&temp);
-
+
return temp;
}
}
void
-l_fp_swap(l_fp * first, l_fp *second){
+l_fp_swap(l_fp * first, l_fp *second)
+{
l_fp temp = *second;
*second = *first;
*first = temp;
+
+ return;
}
//----------------------------------------------------------------------
bool
-l_isgt (const l_fp first, const l_fp second) {
+l_isgt (const l_fp first, const l_fp second)
+{
+
return L_ISGT(&first, &second);
}
bool
-l_isgtu(const l_fp first, const l_fp second) {
+l_isgtu(const l_fp first, const l_fp second)
+{
+
return L_ISGTU(&first, &second);
}
bool
-l_ishis(const l_fp first, const l_fp second) {
+l_ishis(const l_fp first, const l_fp second)
+{
+
return L_ISHIS(&first, &second);
}
bool
-l_isgeq(const l_fp first, const l_fp second) {
+l_isgeq(const l_fp first, const l_fp second)
+{
+
return L_ISGEQ(&first, &second);
}
bool
-l_isequ(const l_fp first, const l_fp second) {
+l_isequ(const l_fp first, const l_fp second)
+{
+
return L_ISEQU(&first, &second);
}
double
eps(double d)
{
+
return fmax(ldexp(1.0, -31), ldexp(fabs(d), -53));
}
// test addition
//----------------------------------------------------------------------
void
-test_AdditionLR(void) {
+test_AdditionLR(void)
+{
size_t idx = 0;
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
l_fp op2 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l);
l_fp e_res = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l);
- l_fp res = l_fp_add(op1, op2);
+ l_fp res = l_fp_add(op1, op2);
TEST_ASSERT_EQUAL_l_fp(e_res, res);
- }
+ }
+ return;
}
void
-test_AdditionRL(void) {
+test_AdditionRL(void)
+{
size_t idx = 0;
+
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp op2 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
l_fp op1 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l);
l_fp res = l_fp_add(op1, op2);
TEST_ASSERT_EQUAL_l_fp(e_res, res);
- }
+ }
+ return;
}
-
//----------------------------------------------------------------------
// test subtraction
//----------------------------------------------------------------------
void
-test_SubtractionLR(void) {
+test_SubtractionLR(void)
+{
size_t idx = 0;
+
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp op2 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
l_fp e_res = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l);
l_fp op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l);
l_fp res = l_fp_subtract(op1, op2);
-
- TEST_ASSERT_EQUAL_l_fp(e_res, res);
- }
+
+ TEST_ASSERT_EQUAL_l_fp(e_res, res);
+ }
+ return;
}
void
-test_SubtractionRL(void) {
+test_SubtractionRL(void)
+{
size_t idx = 0;
+
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp e_res = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
l_fp op2 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l);
l_fp res = l_fp_subtract(op1, op2);
TEST_ASSERT_EQUAL_l_fp(e_res, res);
- }
+ }
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_Negation(void) {
-
+test_Negation(void)
+{
size_t idx = 0;
+
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
l_fp op2 = l_fp_negate(op1);
l_fp sum = l_fp_add(op1, op2);
-
+
l_fp zero = l_fp_init(0, 0);
TEST_ASSERT_EQUAL_l_fp(zero, sum);
- }
+ }
+ return;
}
// test absolute value
//----------------------------------------------------------------------
void
-test_Absolute(void) {
+test_Absolute(void)
+{
size_t idx = 0;
+
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
l_fp op2 = l_fp_abs(op1);
- TEST_ASSERT_TRUE(l_fp_signum(op2) >= 0);
+ TEST_ASSERT_TRUE(l_fp_signum(op2) >= 0);
if (l_fp_signum(op1) >= 0)
- op1 = l_fp_subtract(op1, op2);
+ op1 = l_fp_subtract(op1, op2);
else
op1 = l_fp_add(op1, op2);
-
+
l_fp zero = l_fp_init(0, 0);
-
+
TEST_ASSERT_EQUAL_l_fp(zero, op1);
}
TEST_ASSERT_EQUAL(-1, l_fp_signum(minVal));
TEST_ASSERT_EQUAL_l_fp(minVal, minAbs);
+
+ return;
}
// fp -> double -> fp rountrip test
//----------------------------------------------------------------------
void
-test_FDF_RoundTrip(void) {
+test_FDF_RoundTrip(void)
+{
+ size_t idx = 0;
+
// since a l_fp has 64 bits in it's mantissa and a double has
// only 54 bits available (including the hidden '1') we have to
// make a few concessions on the roundtrip precision. The 'eps()'
// function makes an educated guess about the avilable precision
// and checks the difference in the two 'l_fp' values against
// that limit.
- size_t idx = 0;
+
for (idx = 0; idx < addsub_cnt; ++idx) {
l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
double op2 = l_fp_convert_to_double(op1);
l_fp temp = l_fp_subtract(op1, op3);
double d = l_fp_convert_to_double(temp);
- TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d));
- }
+ TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d));
+ }
+
+ return;
}
// macros in 'ntp_fp.h' produce mathing results.
// ----------------------------------------------------------------------
void
-test_SignedRelOps(void) {
+test_SignedRelOps(void)
+{
const lfp_hl * tv = (&addsub_tab[0][0]);
size_t lc ;
+
for (lc = addsub_tot - 1; lc; --lc, ++tv) {
l_fp op1 = l_fp_init(tv[0].h, tv[0].l);
l_fp op2 = l_fp_init(tv[1].h, tv[1].l);
- int cmp = l_fp_scmp(op1, op2);
-
+ int cmp = l_fp_scmp(op1, op2);
+
switch (cmp) {
case -1:
//printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui);
TEST_ASSERT_TRUE (l_isequ(op2, op1));
break;
default:
- TEST_FAIL_MESSAGE("unexpected UCMP result: " );
+ TEST_FAIL_MESSAGE("unexpected UCMP result: ");
}
}
+
+ return;
}
void
-test_UnsignedRelOps(void) {
- const lfp_hl * tv =(&addsub_tab[0][0]);
+test_UnsignedRelOps(void)
+{
+ const lfp_hl * tv =(&addsub_tab[0][0]);
size_t lc;
+
for (lc = addsub_tot - 1; lc; --lc, ++tv) {
l_fp op1 = l_fp_init(tv[0].h, tv[0].l);
l_fp op2 = l_fp_init(tv[1].h, tv[1].l);
TEST_ASSERT_TRUE (l_ishis(op2, op1));
break;
default:
- TEST_FAIL_MESSAGE("unexpected UCMP result: " );
+ TEST_FAIL_MESSAGE("unexpected UCMP result: ");
}
}
+
+ return;
}
+
/*
*/
void test_IPv6Address(void);
-
-void test_ClassBAddress(void) {
+void
+test_ClassBAddress(void)
+{
sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT);
sockaddr_u expected = CreateSockaddr4("172.16.0.0", NTP_PORT);
TEST_ASSERT_TRUE(actual != NULL);
TEST_ASSERT_TRUE(IsEqual(expected, *actual));
+
+ return;
}
-void test_ClassCAddress(void) {
+void
+test_ClassCAddress(void)
+{
sockaddr_u input = CreateSockaddr4("192.0.2.255", NTP_PORT);
sockaddr_u expected = CreateSockaddr4("192.0.2.0", NTP_PORT);
TEST_ASSERT_TRUE(actual != NULL);
TEST_ASSERT_TRUE(IsEqual(expected, *actual));
+
+ return;
}
-void test_ClassAAddress(void) {
+
+void
+test_ClassAAddress(void)
+{
/* Class A addresses are assumed to be classless,
* thus the same address should be returned.
*/
TEST_ASSERT_TRUE(actual != NULL);
TEST_ASSERT_TRUE(IsEqual(expected, *actual));
+
+ return;
}
-void test_IPv6Address(void) {
+void
+test_IPv6Address(void)
+{
/* IPv6 addresses are assumed to have 64-bit host- and 64-bit network parts. */
const struct in6_addr input_address = { { {
0x20, 0x01, 0x0d, 0xb8,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
} } }; // 2001:0db8:85a3:08d3:0000:0000:0000:0000
-
+
sockaddr_u input;
input.sa6.sin6_family = AF_INET6;
input.sa6.sin6_addr = input_address;
TEST_ASSERT_TRUE(actual != NULL);
TEST_ASSERT_TRUE(IsEqual(expected, *actual));
-}
+ return;
+}
*/
const u_int32 input = 127*256*256*256 + 1*256 + 1; // 127.0.1.1
-
+
TEST_ASSERT_EQUAL_STRING("127.0.1.1", numtohost(htonl(input)));
}
void test_IllegalDigit(void);
-void test_SingleDigit(void) {
+void
+test_SingleDigit(void)
+{
const char* str = "5";
u_long actual;
- TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_TRUE(octtoint(str, &actual));
TEST_ASSERT_EQUAL(5, actual);
+
+ return;
}
-void test_MultipleDigits(void){
+void
+test_MultipleDigits(void)
+{
const char* str = "271";
u_long actual;
- TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_TRUE(octtoint(str, &actual));
TEST_ASSERT_EQUAL(185, actual);
+ return;
}
-void test_Zero(void){
+void
+test_Zero(void)
+{
const char* str = "0";
u_long actual;
- TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_TRUE(octtoint(str, &actual));
TEST_ASSERT_EQUAL(0, actual);
+ return;
}
-void test_MaximumUnsigned32bit(void){
+void
+test_MaximumUnsigned32bit(void)
+{
const char* str = "37777777777";
u_long actual;
- TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_TRUE(octtoint(str, &actual));
TEST_ASSERT_EQUAL(4294967295UL, actual);
+ return;
}
-void test_Overflow(void){
+void
+test_Overflow(void)
+{
const char* str = "40000000000";
u_long actual;
- TEST_ASSERT_FALSE(octtoint(str, &actual) );
+ TEST_ASSERT_FALSE(octtoint(str, &actual));
+ return;
}
-void test_IllegalCharacter(void){
+void
+test_IllegalCharacter(void)
+{
const char* str = "5ac2";
u_long actual;
- TEST_ASSERT_FALSE(octtoint(str, &actual) );
+ TEST_ASSERT_FALSE(octtoint(str, &actual));
+ return;
}
-void test_IllegalDigit(void){
+void
+test_IllegalDigit(void)
+{
const char* str = "5283";
u_long actual;
- TEST_ASSERT_FALSE(octtoint(str, &actual) );
+ TEST_ASSERT_FALSE(octtoint(str, &actual));
+ return;
}
*/
-
void rtol(uint32_t r, char *es);
void rtoltor(uint32_t er, char *es);
void ltor(l_fp l, char *er);
l = convertRefIDToLFP(htonl(r));
as = lfptoa(&l, 8);
-
+
//printf("refid %#x, smear %s\n", r, as);
TEST_ASSERT_NOT_NULL_MESSAGE(as, msg);
}
-
-
void
rtoltor(uint32_t er, char *es)
{
sockaddr_u address;
address.sa4.sin_family = AF_INET;
address.sa4.sin_addr.s_addr = htonl(addr);
-
+
char stringStart[100]= "";
strcat(stringStart, clockname(REFCLK_LOCALCLOCK));
char * expected = stringStart;
TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
-#else
+#else
TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
#endif /* REFCLOCK */
}
sockaddr_u address;
address.sa4.sin_family = AF_INET;
address.sa4.sin_addr.s_addr = htonl(addr);
-
+
char stringStart[100]= "REFCLK(";
- char value[100] ;
+ char value[100] ;
snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID);
strcat(stringStart,value);
strcat(stringStart,",4)");
char * expected = stringStart;
TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
-#else
+#else
TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
#endif /* REFCLOCK */
}
{
progname = argv[0];
UnityBegin("lfpfunc.c");
- RUN_TEST(test_AdditionLR, 50);
- RUN_TEST(test_AdditionRL, 51);
- RUN_TEST(test_SubtractionLR, 52);
- RUN_TEST(test_SubtractionRL, 53);
- RUN_TEST(test_Negation, 54);
- RUN_TEST(test_Absolute, 55);
- RUN_TEST(test_FDF_RoundTrip, 56);
- RUN_TEST(test_SignedRelOps, 57);
- RUN_TEST(test_UnsignedRelOps, 58);
+ RUN_TEST(test_AdditionLR, 51);
+ RUN_TEST(test_AdditionRL, 52);
+ RUN_TEST(test_SubtractionLR, 53);
+ RUN_TEST(test_SubtractionRL, 54);
+ RUN_TEST(test_Negation, 55);
+ RUN_TEST(test_Absolute, 56);
+ RUN_TEST(test_FDF_RoundTrip, 57);
+ RUN_TEST(test_SignedRelOps, 58);
+ RUN_TEST(test_UnsignedRelOps, 59);
return (UnityEnd());
}
{
progname = argv[0];
UnityBegin("refidsmear.c");
- RUN_TEST(test_refidsmear, 36);
+ RUN_TEST(test_refidsmear, 35);
return (UnityEnd());
}
#include <string.h>
-#define TEST_ASSERT_EQUAL_timespec(a, b) { \
- TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
+#define TEST_ASSERT_EQUAL_timespec(a, b) { \
+ TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
TEST_ASSERT_EQUAL_MESSAGE(a.tv_nsec, b.tv_nsec, "Field tv_nsec"); \
}
-#define TEST_ASSERT_EQUAL_l_fp(a, b) { \
- TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \
+#define TEST_ASSERT_EQUAL_l_fp(a, b) { \
+ TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \
TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \
}
typedef int bool;
-const bool timespec_isValid(struct timespec V);
+const bool timespec_isValid(struct timespec V);
struct timespec timespec_init(time_t hi, long lo);
-l_fp l_fp_init(int32 i, u_int32 f);
-bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit);
-bool AssertTimespecClose(const struct timespec m, const struct timespec n, const struct timespec limit);
+l_fp l_fp_init(int32 i, u_int32 f);
+bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit);
+bool AssertTimespecClose(const struct timespec m,
+ const struct timespec n,
+ const struct timespec limit);
-//******************************************MY CUSTOM FUNCTIONS*******************************
-
+//***************************MY CUSTOM FUNCTIONS***************************
const bool
-timespec_isValid(struct timespec V) {
+timespec_isValid(struct timespec V)
+{
+
return V.tv_nsec >= 0 && V.tv_nsec < 1000000000;
}
struct timespec
-timespec_init(time_t hi, long lo) {
- struct timespec V;
+timespec_init(time_t hi, long lo)
+{
+ struct timespec V;
+
V.tv_sec = hi;
V.tv_nsec = lo;
+
return V;
}
l_fp
-l_fp_init(int32 i, u_int32 f) {
+l_fp_init(int32 i, u_int32 f)
+{
l_fp temp;
+
temp.l_i = i;
temp.l_uf = f;
bool
-AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) {
+AssertFpClose(const l_fp m, const l_fp n, const l_fp limit)
+{
l_fp diff;
if (L_ISGEQ(&m, &n)) {
diff = n;
L_SUB(&diff, &m);
}
- if (L_ISGEQ(&limit, &diff)){
+ if (L_ISGEQ(&limit, &diff)) {
return TRUE;
}
else {
bool
-AssertTimespecClose(const struct timespec m, const struct timespec n, const struct timespec limit) {
+AssertTimespecClose(const struct timespec m, const struct timespec n,
+ const struct timespec limit)
+{
struct timespec diff;
diff = abs_tspec(sub_tspec(m, n));
u_int32
-my_tick_to_tsf(u_int32 ticks) {
+my_tick_to_tsf(u_int32 ticks)
+{
// convert nanoseconds to l_fp fractional units, using double
// precision float calculations or, if available, 64bit integer
// arithmetic. This should give the precise fraction, rounded to
// the nearest representation.
+
#ifdef HAVE_U_INT64
return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000000) / 1000000000);
#else
u_int32
-my_tsf_to_tick(u_int32 tsf) {
+my_tsf_to_tick(u_int32 tsf)
+{
+
// Inverse operation: converts fraction to microseconds.
#ifdef HAVE_U_INT64
return (u_int32)(( ((u_int64)(tsf)) * 1000000000 + 0x80000000) >> 32);
// ---------------------------------------------------------------------
void
-test_Helpers1(void) {
+test_Helpers1(void)
+{
struct timespec x;
for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
x.tv_nsec = 1000000000;
TEST_ASSERT_FALSE(timespec_isValid(x));
}
+
+ return;
}
//----------------------------------------------------------------------
void
-test_Normalise(void) {
+test_Normalise(void)
+{
long ns;
+
for ( ns = -2000000000; ns <= 2000000000; ns += 10000000) {
struct timespec x = timespec_init(0, ns);
x = normalize_tspec(x);
TEST_ASSERT_TRUE(timespec_isValid(x));
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_SignNoFrac(void) {
+test_SignNoFrac(void)
+{
// sign test, no fraction
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 0);
int E = (i > 0) - (i < 0);
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
void
-test_SignWithFrac(void) {
+test_SignWithFrac(void)
+{
// sign test, with fraction
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 10);
int E = (i >= 0) - (i < 0);
int r = test_tspec(a);
+
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
// test compare
//----------------------------------------------------------------------
void
-test_CmpFracEQ(void) {
+test_CmpFracEQ(void)
+{
// fractions are equal
int i, j;
for (i = -4; i <= 4; ++i)
struct timespec b = timespec_init( j , 200);
int E = (i > j) - (i < j);
int r = cmp_tspec_denorm(a, b);
+
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
void
-test_CmpFracGT(void) {
+test_CmpFracGT(void)
+{
// fraction a bigger fraction b
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 999999800);
struct timespec b = timespec_init(j, 200);
int E = (i >= j) - (i < j);
int r = cmp_tspec_denorm(a, b);
+
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
void
-test_CmpFracLT(void) {
+test_CmpFracLT(void)
+{
// fraction a less fraction b
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 200);
struct timespec b = timespec_init(j, 999999800);
int E = (i > j) - (i <= j);
int r = cmp_tspec_denorm(a, b);
+
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_AddFullNorm(void) {
+test_AddFullNorm(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 200);
c = add_tspec(a, b);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
void
-test_AddFullOflow1(void) {
+test_AddFullOflow1(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 200);
c = add_tspec(a, b);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
void
test_AddNsecNorm(void) {
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 200);
struct timespec E = timespec_init(i, 600);
c = add_tspec_ns(a, 600 - 200);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
void
-test_AddNsecOflow1(void) {
+test_AddNsecOflow1(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 200);
struct timespec E = timespec_init(i + 1, 100);
c = add_tspec_ns(a, NANOSECONDS - 100);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_SubFullNorm(void) {
+test_SubFullNorm(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init( i , 600);
c = sub_tspec(a, b);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
void
-test_SubFullOflow(void) {
+test_SubFullOflow(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 100);
c = sub_tspec(a, b);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
void
-test_SubNsecNorm(void) {
+test_SubNsecNorm(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 600);
struct timespec E = timespec_init(i, 200);
c = sub_tspec_ns(a, 600 - 200);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
void
-test_SubNsecOflow(void) {
+test_SubNsecOflow(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init( i , 100);
struct timespec E = timespec_init(i-1, 200);
c = sub_tspec_ns(a, NANOSECONDS - 100);
TEST_ASSERT_EQUAL_timespec(E, c);
}
+
+ return;
}
//----------------------------------------------------------------------
void
-test_Neg(void) {
+test_Neg(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 100);
struct timespec b;
c = add_tspec(a, b);
TEST_ASSERT_EQUAL(0, test_tspec(c));
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_AbsNoFrac(void) {
+test_AbsNoFrac(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i , 0);
struct timespec b;
b = abs_tspec(a);
TEST_ASSERT_EQUAL((i != 0), test_tspec(b));
}
+
+ return;
}
void
-test_AbsWithFrac(void) {
+test_AbsWithFrac(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 100);
struct timespec b;
b = abs_tspec(a);
TEST_ASSERT_EQUAL(1, test_tspec(b));
}
+
+ return;
}
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
void
-test_Helpers2(void) {
+test_Helpers2(void)
+{
struct timespec limit = timespec_init(0, 2);
-
struct timespec x, y;
long i;
for (i = -4; i < 5; ++i) {
y = x;
y.tv_nsec += i;
- if (i >= -2 && i <= 2){
+ if (i >= -2 && i <= 2) {
TEST_ASSERT_TRUE(AssertTimespecClose(x, y, limit));
}
else
}
}
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_ToLFPbittest(void) {
+test_ToLFPbittest(void)
+{
l_fp lfpClose = l_fp_init(0, 1);
u_int32 i;
+
for (i = 0; i < 1000000000; i+=1000) {
struct timespec a = timespec_init(1, i);
l_fp E= l_fp_init(1, my_tick_to_tsf(i));
r = tspec_intv_to_lfp(a);
TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
+
+ return;
}
void
-test_ToLFPrelPos(void) {
+test_ToLFPrelPos(void)
+{
int i;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(1, fdata[i].nsec);
l_fp E = l_fp_init(1, fdata[i].frac);
r = tspec_intv_to_lfp(a);
TEST_ASSERT_EQUAL_l_fp(E, r);
}
+
+ return;
}
void
-test_ToLFPrelNeg(void) {
+test_ToLFPrelNeg(void)
+{
int i;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(-1, fdata[i].nsec);
l_fp E = l_fp_init(~0, fdata[i].frac);
r = tspec_intv_to_lfp(a);
TEST_ASSERT_EQUAL_l_fp(E, r);
}
+
+ return;
}
void
-test_ToLFPabs(void) {
+test_ToLFPabs(void)
+{
int i;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(1, fdata[i].nsec);
l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
r = tspec_stamp_to_lfp(a);
TEST_ASSERT_EQUAL_l_fp(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_FromLFPbittest(void) {
+test_FromLFPbittest(void)
+{
struct timespec limit = timespec_init(0, 2);
// Not *exactly* a bittest, because 2**32 tests would take a
// comparing to calculated value.
TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit));
}
+
+ return;
}
void
-test_FromLFPrelPos(void) {
+test_FromLFPrelPos(void)
+{
struct timespec limit = timespec_init(0, 2);
int i;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(1, fdata[i].frac);
struct timespec E = timespec_init(1, fdata[i].nsec);
r = lfp_intv_to_tspec(a);
TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit));
}
+
+ return;
}
void
-test_FromLFPrelNeg(void) {
+test_FromLFPrelNeg(void)
+{
struct timespec limit = timespec_init(0, 2);
int i;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(~0, fdata[i].frac);
struct timespec E = timespec_init(-1, fdata[i].nsec);
r = lfp_intv_to_tspec(a);
TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit));
}
+
+ return;
}
// nsec -> frac -> nsec roundtrip, using a prime start and increment
void
-test_LFProundtrip(void) {
+test_LFProundtrip(void)
+{
int32_t t;
u_int32 i;
+
for (t = -1; t < 2; ++t)
for (i = 4999; i < 1000000000; i += 10007) {
struct timespec E = timespec_init(t, i);
r = lfp_intv_to_tspec(a);
TEST_ASSERT_EQUAL_timespec(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_ToString(void) {
+test_ToString(void)
+{
static const struct {
time_t sec;
long nsec;
{-1,-1, "-1.000000001" },
};
int i;
+
for (i = 0; i < COUNTOF(data); ++i) {
struct timespec a = timespec_init(data[i].sec, data[i].nsec);
const char * E = data[i].repr;
const char * r = tspectoa(a);
TEST_ASSERT_EQUAL_STRING(E, r);
}
+
+ return;
}
// -*- EOF -*-
l_fp V;
- //bool operator == (const l_fp_wrap& rhs) const
+ //bool operator == (const l_fp_wrap &rhs) const
// { return L_ISEQU(&V, &rhs.V); }
//---------------THIS HAS TO BE MANUALLY CONVERTED IN CODE!!!
// { return V; }
//-----------------------------------------
/*
- l_fp_wrap & operator = (const l_fp_wrap& rhs)
+ l_fp_wrap &operator = (const l_fp_wrap &rhs)
{ V = rhs.V; return *this; }
- l_fp_wrap& operator = (const l_fp& rhs)
+ l_fp_wrap &operator = (const l_fp &rhs)
{ V = rhs; return *this; }
*/
};
-l_fp_wrap(l_fp V){
+l_fp_wrap(l_fp V) {
ZERO(V); }
-l_fp_wrap(l_fp V, u_int32 hi, u_int32 lo){
+l_fp_wrap(l_fp V, u_int32 hi, u_int32 lo) {
V.l_ui = hi; V.l_uf = lo; }
-l_fp_wrap(l_fp V, const l_fp &rhs){
+l_fp_wrap(l_fp V, const l_fp &rhs) {
V = rhs; }
-l_fp_wrap_equals(const l_fp_wrap& current, const l_fp_wrap& rhs) const // operator ==
+l_fp_wrap_equals(const l_fp_wrap ¤t, const l_fp_wrap &rhs) const // operator ==
{ return L_ISEQU(¤t.V, &rhs.V); }
-l_fp_wrap_and(const l_fp_wrap& current, const l_fp_wrap& rhs){
+l_fp_wrap_and(const l_fp_wrap ¤t, const l_fp_wrap &rhs) {
V = rhs.V;
return current//*this;
}
-l_fp_wrap_and(const l_fp& current, const l_fp& rhs){
+l_fp_wrap_and(const l_fp ¤t, const l_fp &rhs) {
V = rhs;
return current//*this;
}
{ ZERO(V); }
timeval_wrap(time_t hi, long lo)
{ V.tv_sec = hi; V.tv_usec = lo; }
- timeval_wrap(const struct timeval & rhs)
+ timeval_wrap(const struct timeval &rhs)
{ V = rhs; }
- timeval_wrap(const timeval_wrap & rhs)
+ timeval_wrap(const timeval_wrap &rhs)
{ V = rhs.V; }
- bool operator == (const timeval_wrap& rhs) const
+ bool operator == (const timeval_wrap &rhs) const
{ return V.tv_sec == rhs.V.tv_sec &&
V.tv_usec == rhs.V.tv_usec ; }
bool valid() const
{ return &V; }
operator struct timeval& ()
{ return V; }
- timeval_wrap& operator = (const timeval_wrap& rhs)
+ timeval_wrap &operator = (const timeval_wrap &rhs)
{ V = rhs.V; return *this; }
- timeval_wrap& operator = (const struct timeval& rhs)
+ timeval_wrap &operator = (const struct timeval &rhs)
{ V = rhs; return *this; }
};
{ ZERO(V); }
timespec_wrap(time_t hi, long lo)
{ V.tv_sec = hi; V.tv_nsec = lo; }
- timespec_wrap(const struct timespec & rhs)
+ timespec_wrap(const struct timespec &rhs)
{ V = rhs; }
- timespec_wrap(const timespec_wrap & rhs)
+ timespec_wrap(const timespec_wrap &rhs)
{ V = rhs.V; }
- bool operator == (const timespec_wrap& rhs) const
+ bool operator == (const timespec_wrap &rhs) const
{ return V.tv_sec == rhs.V.tv_sec &&
V.tv_nsec == rhs.V.tv_nsec ; }
bool valid() const
{ return &V; }
operator struct timespec& ()
{ return V; }
- timespec_wrap& operator = (const timespec_wrap& rhs)
+ timespec_wrap &operator = (const timespec_wrap &rhs)
{ V = rhs.V; return *this; }
- timespec_wrap& operator = (const struct timespec& rhs)
+ timespec_wrap &operator = (const struct timespec &rhs)
{ V = rhs; return *this; }
};
::testing::AssertionResult
operator()(const char* m_expr, const char* n_expr,
- const l_fp & m, const l_fp & n);
+ const l_fp &m, const l_fp &n);
};
::testing::AssertionResult
operator()(const char* m_expr, const char* n_expr,
- const struct timeval & m, const struct timeval & n);
+ const struct timeval &m, const struct timeval &n);
};
::testing::AssertionResult
operator()(const char* m_expr, const char* n_expr,
- const struct timespec & m, const struct timespec & n);
+ const struct timespec &m, const struct timespec &n);
};
#include "unity.h"
-#define TEST_ASSERT_EQUAL_timeval(a, b) { \
- TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
+#define TEST_ASSERT_EQUAL_timeval(a, b) { \
+ TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
TEST_ASSERT_EQUAL_MESSAGE(a.tv_usec, b.tv_usec, "Field tv_usec"); \
}
void test_ToString(void);
-//******************************************MY CUSTOM FUNCTIONS*******************************
-
+//**********************************MY CUSTOM FUNCTIONS***********************
struct timeval
-timeval_init( time_t hi, long lo){
+timeval_init(time_t hi, long lo)
+{
struct timeval V;
+
V.tv_sec = hi;
V.tv_usec = lo;
+
return V;
}
const bool
-timeval_isValid(struct timeval V) {
+timeval_isValid(struct timeval V)
+{
+
return V.tv_usec >= 0 && V.tv_usec < 1000000;
}
l_fp
-l_fp_init(int32 i, u_int32 f) {
+l_fp_init(int32 i, u_int32 f)
+{
l_fp temp;
+
temp.l_i = i;
temp.l_uf = f;
bool
-AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit) {
+AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit)
+{
struct timeval diff;
diff = abs_tval(sub_tval(m, n));
if (cmp_tval(limit, diff) >= 0)
return TRUE;
-
else
{
printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%luusec\n", m.tv_sec, m.tv_usec, n.tv_sec, n.tv_usec, diff.tv_sec, diff.tv_usec);
//I don't have variables m_expr and n_expr in unity, those are command line arguments which only getst has!!!
-
+
return FALSE;
}
}
bool
-AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) {
+AssertFpClose(const l_fp m, const l_fp n, const l_fp limit)
+{
l_fp diff;
if (L_ISGEQ(&m, &n)) {
diff = n;
L_SUB(&diff, &m);
}
- if (L_ISGEQ(&limit, &diff)){
+ if (L_ISGEQ(&limit, &diff)) {
return TRUE;
}
else {
u_int32
-my_tick_to_tsf(u_int32 ticks) {
+my_tick_to_tsf(u_int32 ticks)
+{
// convert microseconds to l_fp fractional units, using double
// precision float calculations or, if available, 64bit integer
// arithmetic. This should give the precise fraction, rounded to
// the nearest representation.
+
#ifdef HAVE_U_INT64
return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000) / 1000000); //I put too much () when casting just to be safe
#else
u_int32
-my_tsf_to_tick(u_int32 tsf) {
+my_tsf_to_tick(u_int32 tsf)
+{
// Inverse operation: converts fraction to microseconds.
#ifdef HAVE_U_INT64
return (u_int32)( ((u_int64)(tsf) * 1000000 + 0x80000000) >> 32); //CHECK ME!!!
}
-//***************************************END OF CUSTOM FUNCTIONS*****************************
+//*******************************END OF CUSTOM FUNCTIONS*********************
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
void
-test_Helpers1(void) {
+test_Helpers1(void)
+{
struct timeval x;
for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
x.tv_usec = 1000000;
TEST_ASSERT_FALSE(timeval_isValid(x));
}
+
+ return;
}
//----------------------------------------------------------------------
void
-test_Normalise(void) {
+test_Normalise(void)
+{
long ns;
+
for (ns = -2000000000; ns <= 2000000000; ns += 10000000) {
struct timeval x = timeval_init(0, ns);
-
+
x = normalize_tval(x);
TEST_ASSERT_TRUE(timeval_isValid(x));
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_SignNoFrac(void) {
+test_SignNoFrac(void)
+{
int i;
+
// sign test, no fraction
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 0);
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
void
-test_SignWithFrac(void) {
+test_SignWithFrac(void)
+{
// sign test, with fraction
int i;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 10);
int E = (i >= 0) - (i < 0);
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
// test compare
//----------------------------------------------------------------------
void
-test_CmpFracEQ(void) {
+test_CmpFracEQ(void)
+{
int i, j;
+
// fractions are equal
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
void
-test_CmpFracGT(void) {
+test_CmpFracGT(void)
+{
// fraction a bigger fraction b
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init( i , 999800);
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
void
-test_CmpFracLT(void) {
+test_CmpFracLT(void)
+{
// fraction a less fraction b
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 200);
TEST_ASSERT_EQUAL(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_AddFullNorm(void) {
+test_AddFullNorm(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 200);
c = add_tval(a, b);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
void
-test_AddFullOflow1(void) {
+test_AddFullOflow1(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 200);
c = add_tval(a, b);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
void
-test_AddUsecNorm(void) {
+test_AddUsecNorm(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 200);
struct timeval E = timeval_init(i, 600);
c = add_tval_us(a, 600 - 200);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
void
-test_AddUsecOflow1(void) {
+test_AddUsecOflow1(void)
+{
int i;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 200);
struct timeval E = timeval_init(i + 1, 100);
c = add_tval_us(a, MICROSECONDS - 100);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_SubFullNorm(void) {
+test_SubFullNorm(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 600);
c = sub_tval(a, b);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
void
-test_SubFullOflow(void) {
+test_SubFullOflow(void)
+{
int i, j;
+
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 100);
c = sub_tval(a, b);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
void
-test_SubUsecNorm(void) {
+test_SubUsecNorm(void)
+{
int i = -4;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 600);
struct timeval E = timeval_init(i, 200);
c = sub_tval_us(a, 600 - 200);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
void
-test_SubUsecOflow(void) {
+test_SubUsecOflow(void)
+{
int i = -4;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 100);
struct timeval E = timeval_init(i - 1, 200);
c = sub_tval_us(a, MICROSECONDS - 100);
TEST_ASSERT_EQUAL_timeval(E, c);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_Neg(void) {
+test_Neg(void)
+{
int i = -4;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 100);
struct timeval b;
c = add_tval(a, b);
TEST_ASSERT_EQUAL(0, test_tval(c));
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_AbsNoFrac(void) {
+test_AbsNoFrac(void)
+{
int i = -4;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 0);
struct timeval b;
b = abs_tval(a);
TEST_ASSERT_EQUAL((i != 0), test_tval(b));
}
+
+ return;
}
void
-test_AbsWithFrac(void) {
+test_AbsWithFrac(void)
+{
int i = -4;
+
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 100);
struct timeval b;
b = abs_tval(a);
TEST_ASSERT_EQUAL(1, test_tval(b));
}
+
+ return;
}
// ---------------------------------------------------------------------
void
-test_Helpers2(void) {
-
+test_Helpers2(void)
+{
struct timeval limit = timeval_init(0, 2);
struct timeval x, y;
- long i;
+ long i;
- for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++){
+ for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
for (x.tv_usec = 1;
x.tv_usec < 1000000;
x.tv_usec += 499999) {
for (i = -4; i < 5; ++i) {
y = x;
y.tv_usec += i;
- if (i >= -2 && i <= 2){
+ if (i >= -2 && i <= 2) {
TEST_ASSERT_TRUE(AssertTimevalClose(x, y, limit));//ASSERT_PRED_FORMAT2(isClose, x, y);
}
else {
}
}
}
+
+ return;
}
// and the global predicate instances we're using here
//----------------------------------------------------------------------
void
-test_ToLFPbittest(void) {
- l_fp lfpClose = l_fp_init(0, 1);
+test_ToLFPbittest(void)
+{
+ l_fp lfpClose = l_fp_init(0, 1);
u_int32 i = 0;
for (i = 0; i < 1000000; ++i) {
r = tval_intv_to_lfp(a);
TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); //ASSERT_PRED_FORMAT2(FpClose, E, r);
}
+
+ return;
}
void
-test_ToLFPrelPos(void) {
+test_ToLFPrelPos(void)
+{
l_fp lfpClose = l_fp_init(0, 1);
-
int i = 0;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
struct timeval a = timeval_init(1, fdata[i].usec);
l_fp E = l_fp_init(1, fdata[i].frac);
r = tval_intv_to_lfp(a);
TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
+
+ return;
}
void
-test_ToLFPrelNeg(void) {
+test_ToLFPrelNeg(void)
+{
l_fp lfpClose = l_fp_init(0, 1);
int i = 0;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
struct timeval a = timeval_init(-1, fdata[i].usec);
l_fp E = l_fp_init(~0, fdata[i].frac);
r = tval_intv_to_lfp(a);
TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
+
+ return;
}
void
-test_ToLFPabs(void) {
+test_ToLFPabs(void)
+{
l_fp lfpClose = l_fp_init(0, 1);
-
int i = 0;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
struct timeval a = timeval_init(1, fdata[i].usec);
l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
r = tval_stamp_to_lfp(a);
TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_FromLFPbittest(void) {
+test_FromLFPbittest(void)
+{
struct timeval timevalClose = timeval_init(0, 1);
// Not *exactly* a bittest, because 2**32 tests would take a
// really long time even on very fast machines! So we do test
// every 1000 fractional units.
u_int32 tsf = 0;
+
for (tsf = 0; tsf < ~((u_int32)(1000)); tsf += 1000) {
struct timeval E = timeval_init(1, my_tsf_to_tick(tsf));
l_fp a = l_fp_init(1, tsf);
// comparing to calculated value.
TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
}
+
+ return;
}
void
-test_FromLFPrelPos(void) {
+test_FromLFPrelPos(void)
+{
struct timeval timevalClose = timeval_init(0, 1);
- int i = 0;
+ int i = 0;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(1, fdata[i].frac);
struct timeval E = timeval_init(1, fdata[i].usec);
r = lfp_intv_to_tval(a);
TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
}
+
+ return;
}
void
-test_FromLFPrelNeg(void) {
+test_FromLFPrelNeg(void)
+{
struct timeval timevalClose = timeval_init(0, 1);
int i = 0;
+
for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(~0, fdata[i].frac);
struct timeval E = timeval_init(-1, fdata[i].usec);
r = lfp_intv_to_tval(a);
TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
}
+
+ return;
}
// usec -> frac -> usec roundtrip, using a prime start and increment
void
-test_LFProundtrip(void) {
+test_LFProundtrip(void)
+{
int32_t t = -1;
u_int32 i = 5;
+
for (t = -1; t < 2; ++t)
for (i = 5; i < 1000000; i += 11) {
struct timeval E = timeval_init(t, i);
r = lfp_intv_to_tval(a);
TEST_ASSERT_EQUAL_timeval(E, r);
}
+
+ return;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void
-test_ToString(void) {
+test_ToString(void)
+{
static const struct {
time_t sec;
long usec;
{-1,-1, "-1.000001" },
};
int i;
+
for (i = 0; i < COUNTOF(data); ++i) {
struct timeval a = timeval_init(data[i].sec, data[i].usec);
const char * E = data[i].repr;
TEST_ASSERT_EQUAL_STRING(E, r);
}
+
+ return;
}
// -*- EOF -*-