From: Tomek Mrugalski Date: Sun, 5 Jul 2015 16:41:36 +0000 (+0200) Subject: refnumtoa.c: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b18e5ceda036b9e9ba34a5c587a2fe3472a3cb1;p=thirdparty%2Fntp.git refnumtoa.c: fixed formatting numtoa.c: remove unnecessary empty functions, fix formatting lfpfunc.c: remove unnecessary include, remove old comments, fix formatting, cleanup numtohost.c: added const, fixed formatting lfptostr.c: fix formatting, delete an include lfpfunc.c: removed an endline ChangeLog: update with new changes to numtoa.c numtoa.c: added "const" ChangeLog: changes with numtohost.c added changes to lfpfunc.c add info about numtoa.c updated with modetoa.c changes add info about lfptostr.c msyslog.c, modetoa.c: fix formatting Many files: autogenerated ChangeLog: add info about msyslog.c lfpfunc.c: added spaces after the commas ChangeLog: updated info about refnumtoa.c bk: 55995e40P2FHK4-7Xs-woQBVOUHaVw --- diff --git a/ChangeLog b/ChangeLog index 9451b5df9..ae9da2617 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,16 @@ caltontp.c, clocktime.c, humandate.c, hextolfp.c, decodenetnum.c - fixed formatting; first declaration, then code (C90); deleted unnecessary comments; changed from sprintf to snprintf; fixed order of includes. Tomasz Flendrich +* tests/libntp/lfpfunc.c remove unnecessary include, remove old comments, + fix formatting, cleanup. Tomasz Flendrich +* tests/libntp/lfptostr.c remove unnecessary include, add consts, fix formatting. + Tomasz Flendrich +* tests/libntp/modetoa.c fixed formatting. Tomasz Flendrich +* tests/libntp/msyslog.c fixed formatting. Tomasz Flendrich +* tests/libntp/numtoa.c deleted unnecessary empty functions, fixed formatting. + Tomasz Flendrich +* tests/libntp/numtohost.c added const, fixed formatting. Tomasz Flendrich +* tests/libntp/refnumtoa.c fixed formatting. Tomasz Flendrich * sntp/unity/Makefile.am added a missing header. Tomasz Flendrich * sntp/unity/unity_config.h: Distribute it. Harlan Stenn. * sntp/libevent/evconfig-private.h: remove generated filefrom SCM. H.Stenn. diff --git a/tests/libntp/lfpfunc.c b/tests/libntp/lfpfunc.c index bb1720c22..1ddcd8ab1 100644 --- a/tests/libntp/lfpfunc.c +++ b/tests/libntp/lfpfunc.c @@ -1,7 +1,6 @@ #include "config.h" #include "ntp_stdlib.h" -#include "ntp_calendar.h" #include "ntp_fp.h" #include "unity.h" @@ -10,7 +9,10 @@ #include -//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"); \ @@ -23,69 +25,20 @@ typedef struct { static int cmp_work(u_int32 a[3], u_int32 b[3]); -/* -//---------------------------------------------------------------------- -// OO-wrapper for 'l_fp' -//---------------------------------------------------------------------- - - - ~LFP(); - LFP(); - LFP(const LFP& rhs); - LFP(int32 i, u_int32 f); - - LFP operator+ (const LFP &rhs) const; - LFP& operator+=(const LFP &rhs); - - LFP operator- (const LFP &rhs) const; - LFP& operator-=(const LFP &rhs); - - LFP& operator=(const LFP &rhs); - LFP operator-() const; - - bool operator==(const LFP &rhs) const; - - LFP neg() const; - LFP abs() const; - int signum() const; - - - - int ucmp(const LFP & rhs) const; - int scmp(const LFP & rhs) const; - - std::string toString() const; - std::ostream& toStream(std::ostream &oo) const; - - operator double() const; - explicit LFP(double); - - - LFP(const l_fp &rhs); - - static int cmp_work(u_int32 a[3], u_int32 b[3]); - - l_fp _v; - - -static std::ostream& operator<<(std::ostream &oo, const LFP& rhs) -{ - return rhs.toStream(oo); -} -*/ //---------------------------------------------------------------------- // reference comparision // This is implementad as a full signed MP-subtract in 3 limbs, where // the operands are zero or sign extended before the subtraction is // executed. //---------------------------------------------------------------------- -int l_fp_scmp(const l_fp first, const l_fp second) + +int +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; - //const l_fp &op1(_v), &op2(rhs._v); 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; @@ -96,7 +49,8 @@ int l_fp_scmp(const l_fp first, const l_fp second) return cmp_work(a,b); } -int l_fp_ucmp(const l_fp first, l_fp second ) +int +l_fp_ucmp(const l_fp first, l_fp second ) { u_int32 a[3], b[3]; const l_fp op1 = first; @@ -108,9 +62,9 @@ int l_fp_ucmp(const l_fp first, l_fp second ) return cmp_work(a,b); } - -//maybe rename it to lf_cmp_work ??? -int cmp_work(u_int32 a[3], u_int32 b[3]) +// maybe rename it to lf_cmp_work +int +cmp_work(u_int32 a[3], u_int32 b[3]) { u_int32 cy, idx, tmp; for (cy = idx = 0; idx < 3; ++idx) { @@ -128,9 +82,8 @@ int cmp_work(u_int32 a[3], u_int32 b[3]) // This should be easy enough... //---------------------------------------------------------------------- - - -l_fp l_fp_init(int32 i, u_int32 f) +l_fp +l_fp_init(int32 i, u_int32 f) { l_fp temp; temp.l_i = i; @@ -139,35 +92,35 @@ l_fp l_fp_init(int32 i, u_int32 f) return temp; } - - -l_fp l_fp_add(const l_fp first, const l_fp second) +l_fp +l_fp_add(const l_fp first, const l_fp second) { - l_fp temp; - temp = first; + l_fp temp = first; L_ADD(&temp, &second); + return temp; } -l_fp l_fp_subtract(const l_fp first, const l_fp second) +l_fp +l_fp_subtract(const l_fp first, const l_fp second) { - l_fp temp; - temp = first; + l_fp temp = first; L_SUB(&temp, &second); return temp; } -l_fp l_fp_negate(const l_fp first) +l_fp +l_fp_negate(const l_fp first) { - l_fp temp; - temp = first; //is this line really necessary? + l_fp temp = first; L_NEG(&temp); return temp; } -l_fp l_fp_abs(const l_fp first) +l_fp +l_fp_abs(const l_fp first) { l_fp temp = first; if (L_ISNEG(&temp)) @@ -175,94 +128,71 @@ l_fp l_fp_abs(const l_fp first) return temp; } -int l_fp_signum(const l_fp first) +int +l_fp_signum(const l_fp first) { if (first.l_ui & 0x80000000u) return -1; return (first.l_ui || first.l_uf); } -double l_fp_convert_to_double(const l_fp first) +double +l_fp_convert_to_double(const l_fp first) { double res; LFPTOD(&first, res); return res; } -l_fp l_fp_init_from_double( double rhs) +l_fp +l_fp_init_from_double( double rhs) { l_fp temp; DTOLFP(rhs, &temp); return temp; } - - -void l_fp_swap(l_fp * first, l_fp *second){ +void +l_fp_swap(l_fp * first, l_fp *second){ l_fp temp = *second; *second = *first; *first = temp; - } +//---------------------------------------------------------------------- +// testing the relational macros works better with proper predicate +// formatting functions; it slows down the tests a bit, but makes for +// readable failure messages. +//---------------------------------------------------------------------- -/* -LFP::LFP() -{ - _v.l_ui = 0; - _v.l_uf = 0; -} - +typedef int bool; // typedef enum { FALSE, TRUE } boolean; -> can't use this because TRUE and FALSE are already defined -std::string -LFP::toString() const -{ - std::ostringstream oss; - toStream(oss); - return oss.str(); +bool +l_isgt (const l_fp first, const l_fp second) { + return L_ISGT(&first, &second); } -std::ostream& -LFP::toStream(std::ostream &os) const -{ - return os - << mfptoa(_v.l_ui, _v.l_uf, 9) - << " [$" << std::setw(8) << std::setfill('0') << std::hex << _v.l_ui - << ':' << std::setw(8) << std::setfill('0') << std::hex << _v.l_uf - << ']'; +bool +l_isgtu(const l_fp first, const l_fp second) { + return L_ISGTU(&first, &second); } -bool LFP::operator==(const LFP &rhs) const -{ - return L_ISEQU(&_v, &rhs._v); +bool +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) { + return L_ISGEQ(&first, &second); +} - -*/ - -//---------------------------------------------------------------------- -// testing the relational macros works better with proper predicate -// formatting functions; it slows down the tests a bit, but makes for -// readable failure messages. -//---------------------------------------------------------------------- - - -typedef int bool; //typedef enum { FALSE, TRUE } boolean; -> can't use this because TRUE and FALSE are already defined - - -bool 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) - { return L_ISGTU(&first, &second); } -bool 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) - { return L_ISGEQ(&first, &second); } -bool l_isequ(const l_fp first, const l_fp second) - { return L_ISEQU(&first, &second); } +bool +l_isequ(const l_fp first, const l_fp second) { + return L_ISEQU(&first, &second); +} //---------------------------------------------------------------------- @@ -308,46 +238,39 @@ static const size_t addsub_tot = (sizeof(addsub_tab)/sizeof(addsub_tab[0][0])); // '1'-bit of the l_fp value, the roundtrip *will* create truncation // errors. This is an inherent property caused by the 54-bit mantissa of // the 'double' type. -double eps(double d) +double +eps(double d) { - return fmax(ldexp(1.0, -31), ldexp(fabs(d), -53)); //max + return fmax(ldexp(1.0, -31), ldexp(fabs(d), -53)); } - - //---------------------------------------------------------------------- // test addition //---------------------------------------------------------------------- -void test_AdditionLR(void) { +void +test_AdditionLR(void) { - size_t idx=0; - for (idx=0; idx < addsub_cnt; ++idx) { - - + 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); - //LFP op1(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); - //LFP exp(addsub_tab[idx][2].h, addsub_tab[idx][2].l); l_fp exp = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); - //LFP res(op1 + op2); - l_fp res = l_fp_add(op1,op2); + l_fp res = l_fp_add(op1, op2); - TEST_ASSERT_EQUAL_l_fp(exp,res); - //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp, res); } } -void test_AdditionRL(void) { - - size_t idx=0; - for (idx=0; idx < addsub_cnt; ++idx) { +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 exp = 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(exp,res); - //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp, res); } } @@ -356,32 +279,29 @@ void test_AdditionRL(void) { //---------------------------------------------------------------------- // test subtraction //---------------------------------------------------------------------- -void test_SubtractionLR(void) { - - size_t idx=0; - for (idx=0; idx < addsub_cnt; ++idx) { +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 exp = 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); - //LFP res(op1 - op2); + l_fp res = l_fp_subtract(op1, op2); - TEST_ASSERT_EQUAL_l_fp(exp,res); - //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp, res); } } -void test_SubtractionRL(void) { - - size_t idx=0; - for (idx=0; idx < addsub_cnt; ++idx) { +void +test_SubtractionRL(void) { + size_t idx = 0; + for (idx = 0; idx < addsub_cnt; ++idx) { l_fp exp = 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 op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l); - l_fp res = l_fp_subtract(op1,op2); + l_fp res = l_fp_subtract(op1, op2); - TEST_ASSERT_EQUAL_l_fp(exp,res); - //TEST_ASSERT_EQUAL_MEMORY(&exp, &res,sizeof(exp)); + TEST_ASSERT_EQUAL_l_fp(exp, res); } } @@ -389,19 +309,18 @@ void test_SubtractionRL(void) { // test negation //---------------------------------------------------------------------- -void test_Negation(void) { +void +test_Negation(void) { - size_t idx=0; - for (idx=0; idx < addsub_cnt; ++idx) { + 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); + l_fp zero = l_fp_init(0, 0); - TEST_ASSERT_EQUAL_l_fp(zero,sum); - //TEST_ASSERT_EQUAL_MEMORY(&zero, &sum,sizeof(sum)); - + TEST_ASSERT_EQUAL_l_fp(zero, sum); } } @@ -410,24 +329,23 @@ void test_Negation(void) { //---------------------------------------------------------------------- // test absolute value //---------------------------------------------------------------------- -void test_Absolute(void) { - size_t idx=0; - for (idx=0; idx < addsub_cnt; ++idx) { +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); if (l_fp_signum(op1) >= 0) - op1 = l_fp_subtract(op1,op2); //op1 -= op2; - + op1 = l_fp_subtract(op1, op2); else - op1 = l_fp_add(op1,op2); + op1 = l_fp_add(op1, op2); - l_fp zero = l_fp_init(0,0); + l_fp zero = l_fp_init(0, 0); - TEST_ASSERT_EQUAL_l_fp(zero,op1); - //TEST_ASSERT_EQUAL_MEMORY(&zero, &op1,sizeof(op1)); + TEST_ASSERT_EQUAL_l_fp(zero, op1); } // There is one special case we have to check: the minimum @@ -437,36 +355,30 @@ void test_Absolute(void) { l_fp minAbs = l_fp_abs(minVal); TEST_ASSERT_EQUAL(-1, l_fp_signum(minVal)); - TEST_ASSERT_EQUAL_l_fp(minVal,minAbs); - //TEST_ASSERT_EQUAL_MEMORY(&minVal, &minAbs,sizeof(minAbs)); + TEST_ASSERT_EQUAL_l_fp(minVal, minAbs); } //---------------------------------------------------------------------- // fp -> double -> fp rountrip test //---------------------------------------------------------------------- -void test_FDF_RoundTrip(void) { +void +test_FDF_RoundTrip(void) { // 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) { + 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 op3 = l_fp_init_from_double(op2); - // for manual checks only: - // std::cout << std::setprecision(16) << op2 << std::endl; - - l_fp temp = l_fp_subtract(op1,op3); + 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)); //delta,epected,actual - - //ASSERT_LE(fabs(op1-op3), eps(op2)); //unity has no equivalent of LE!!! - //you could use TEST_ASSERT_TRUE(IsLE(fabs(op1-op3), eps(op2))); + TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d)); } } @@ -477,55 +389,54 @@ void test_FDF_RoundTrip(void) { // This uses the local compare and checks if the operations using the // macros in 'ntp_fp.h' produce mathing results. // ---------------------------------------------------------------------- -void test_SignedRelOps(void) { +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(op1.scmp(op2)); - int cmp = l_fp_scmp(op1,op2); + 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); switch (cmp) { case -1: //printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui); - //std::swap(op1, op2); - l_fp_swap(&op1,&op2); + l_fp_swap(&op1, &op2); //printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui); case 1: - TEST_ASSERT_TRUE (l_isgt(op1,op2)); - TEST_ASSERT_FALSE(l_isgt(op2,op1)); + TEST_ASSERT_TRUE (l_isgt(op1, op2)); + TEST_ASSERT_FALSE(l_isgt(op2, op1)); - TEST_ASSERT_TRUE (l_isgeq(op1,op2)); - TEST_ASSERT_FALSE(l_isgeq(op2,op1)); + TEST_ASSERT_TRUE (l_isgeq(op1, op2)); + TEST_ASSERT_FALSE(l_isgeq(op2, op1)); - TEST_ASSERT_FALSE(l_isequ(op1,op2)); - TEST_ASSERT_FALSE(l_isequ(op2,op1)); + TEST_ASSERT_FALSE(l_isequ(op1, op2)); + TEST_ASSERT_FALSE(l_isequ(op2, op1)); break; case 0: - TEST_ASSERT_FALSE(l_isgt(op1,op2)); - TEST_ASSERT_FALSE(l_isgt(op2,op1)); + TEST_ASSERT_FALSE(l_isgt(op1, op2)); + TEST_ASSERT_FALSE(l_isgt(op2, op1)); - TEST_ASSERT_TRUE (l_isgeq(op1,op2)); - TEST_ASSERT_TRUE (l_isgeq(op2,op1)); + TEST_ASSERT_TRUE (l_isgeq(op1, op2)); + TEST_ASSERT_TRUE (l_isgeq(op2, op1)); - TEST_ASSERT_TRUE (l_isequ(op1,op2)); - TEST_ASSERT_TRUE (l_isequ(op2,op1)); + TEST_ASSERT_TRUE (l_isequ(op1, op2)); + TEST_ASSERT_TRUE (l_isequ(op2, op1)); break; default: TEST_FAIL_MESSAGE("unexpected UCMP result: " ); - //TEST_ASSERT_FAIL() << "unexpected SCMP result: " << cmp; } } } -void test_UnsignedRelOps(void) { +void +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); - int cmp = l_fp_ucmp(op1,op2); + 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_ucmp(op1, op2); switch (cmp) { case -1: @@ -533,22 +444,21 @@ void test_UnsignedRelOps(void) { l_fp_swap(&op1, &op2); //printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui); case 1: - TEST_ASSERT_TRUE (l_isgtu(op1,op2)); - TEST_ASSERT_FALSE(l_isgtu(op2,op1)); + TEST_ASSERT_TRUE (l_isgtu(op1, op2)); + TEST_ASSERT_FALSE(l_isgtu(op2, op1)); - TEST_ASSERT_TRUE (l_ishis(op1,op2)); - TEST_ASSERT_FALSE(l_ishis(op2,op1)); + TEST_ASSERT_TRUE (l_ishis(op1, op2)); + TEST_ASSERT_FALSE(l_ishis(op2, op1)); break; case 0: - TEST_ASSERT_FALSE(l_isgtu(op1,op2)); - TEST_ASSERT_FALSE(l_isgtu(op2,op1)); + TEST_ASSERT_FALSE(l_isgtu(op1, op2)); + TEST_ASSERT_FALSE(l_isgtu(op2, op1)); - TEST_ASSERT_TRUE (l_ishis(op1,op2)); - TEST_ASSERT_TRUE (l_ishis(op2,op1)); + TEST_ASSERT_TRUE (l_ishis(op1, op2)); + TEST_ASSERT_TRUE (l_ishis(op2, op1)); break; default: TEST_FAIL_MESSAGE("unexpected UCMP result: " ); - //FAIL() << "unexpected UCMP result: " << cmp; } } } diff --git a/tests/libntp/lfptostr.c b/tests/libntp/lfptostr.c index c76e07fb0..338e20a25 100644 --- a/tests/libntp/lfptostr.c +++ b/tests/libntp/lfptostr.c @@ -6,7 +6,6 @@ #include "config.h" #include "ntp_stdlib.h" -#include "ntp_calendar.h" #include "ntp_fp.h" #include "unity.h" @@ -20,63 +19,72 @@ 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 -void test_PositiveInteger(void) { +void +test_PositiveInteger(void) { 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) { +void +test_NegativeInteger(void) { 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) { +void +test_PositiveIntegerWithFraction(void) { 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) { +void +test_NegativeIntegerWithFraction(void) { 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) { +void +test_RoundingDownToInteger(void) { 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) { +void +test_RoundingMiddleToInteger(void) { 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) { +void +test_RoundingUpToInteger(void) { 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) { +void +test_SingleDecimal(void) { 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) { +void +test_MillisecondsRoundingUp(void) { l_fp test = {1, HALF_PROMILLE_UP}; //slightly more than 1.0005 TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(&test, 1)); @@ -85,7 +93,8 @@ void test_MillisecondsRoundingUp(void) { TEST_ASSERT_EQUAL_STRING("1001", lfptoms(&test, 0)); } -void test_MillisecondsRoundingDown(void) { +void +test_MillisecondsRoundingDown(void) { l_fp test = {1, HALF_PROMILLE_DOWN}; // slightly less than 1.0005 TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(&test, 1)); @@ -99,5 +108,3 @@ void test_UnsignedInteger(void) { TEST_ASSERT_EQUAL_STRING("3000000000.0", ulfptoa(&test, 1)); } - - diff --git a/tests/libntp/modetoa.c b/tests/libntp/modetoa.c index 19a76d585..5ad3f7bf7 100644 --- a/tests/libntp/modetoa.c +++ b/tests/libntp/modetoa.c @@ -1,20 +1,20 @@ #include "config.h" #include "ntp_stdlib.h" -#include "ntp_calendar.h" #include "unity.h" -void test_KnownMode(void) { +void +test_KnownMode(void) { const int MODE = 3; // Should be "client" - TEST_ASSERT_EQUAL_STRING("client", modetoa(MODE)); + TEST_ASSERT_EQUAL_STRING("client", modetoa(MODE)); } -void test_UnknownMode(void) { +void +test_UnknownMode(void) { const int MODE = 100; TEST_ASSERT_EQUAL_STRING("mode#100", modetoa(MODE)); -// EXPECT_STREQ("mode#100", modetoa(MODE)); } diff --git a/tests/libntp/msyslog.c b/tests/libntp/msyslog.c index bad0e90a9..1c94bb3fe 100644 --- a/tests/libntp/msyslog.c +++ b/tests/libntp/msyslog.c @@ -6,11 +6,12 @@ #ifndef VSNPRINTF_PERCENT_M // format_errmsg() is normally private to msyslog.c -void format_errmsg (char *, size_t, const char *, int); +void format_errmsg(char *, size_t, const char *, int); #endif -void test_msnprintf(void) { +void +test_msnprintf(void) { #define FMT_PREFIX "msyslog.cpp ENOENT: " char exp_buf[512]; char act_buf[512]; @@ -21,6 +22,7 @@ void test_msnprintf(void) { strerror(ENOENT)); errno = ENOENT; act_cnt = msnprintf(act_buf, sizeof(act_buf), FMT_PREFIX "%m"); + TEST_ASSERT_EQUAL(exp_cnt, act_cnt); TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf); } @@ -36,6 +38,7 @@ test_msnprintfLiteralPercentm(void) exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "%%m"); errno = ENOENT; act_cnt = msnprintf(act_buf, sizeof(act_buf), "%%m"); + TEST_ASSERT_EQUAL(exp_cnt, act_cnt); TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf); } @@ -50,6 +53,7 @@ test_msnprintfBackslashLiteralPercentm(void) { exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "\%%m"); errno = ENOENT; act_cnt = msnprintf(act_buf, sizeof(act_buf), "\%%m"); + TEST_ASSERT_EQUAL(exp_cnt, act_cnt); TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf); } @@ -65,6 +69,7 @@ test_msnprintfBackslashPercent(void) { strerror(ENOENT)); errno = ENOENT; act_cnt = msnprintf(act_buf, sizeof(act_buf), "\%m"); + TEST_ASSERT_EQUAL(exp_cnt, act_cnt); TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf); } @@ -81,6 +86,7 @@ test_msnprintfHangingPercent(void) { ZERO(act_buf); exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "%s", fmt); act_cnt = msnprintf(act_buf, sizeof(act_buf), "%s", fmt); + TEST_ASSERT_EQUAL(exp_cnt, act_cnt); TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf); TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf)); @@ -94,6 +100,7 @@ test_format_errmsgHangingPercent(void) { ZERO(act_buf); format_errmsg(act_buf, sizeof(act_buf), fmt, ENOENT); + TEST_ASSERT_EQUAL_STRING(fmt, act_buf); TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf)); #else @@ -109,6 +116,7 @@ test_msnprintfNullTarget(void) { exp_cnt = snprintf(NULL, 0, "%d", 123); errno = ENOENT; act_cnt = msnprintf(NULL, 0, "%d", 123); + TEST_ASSERT_EQUAL(exp_cnt, act_cnt); } @@ -125,6 +133,7 @@ test_msnprintfTruncate(void) { exp_cnt = snprintf(exp_buf, 3, "%s", strerror(ENOENT)); errno = ENOENT; act_cnt = msnprintf(act_buf, 3, "%m"); + TEST_ASSERT_EQUAL('\0', exp_buf[2]); TEST_ASSERT_EQUAL('\0', act_buf[2]); TEST_ASSERT_TRUE(act_cnt > 0); diff --git a/tests/libntp/numtoa.c b/tests/libntp/numtoa.c index 1d01c7843..fc79c3812 100644 --- a/tests/libntp/numtoa.c +++ b/tests/libntp/numtoa.c @@ -1,31 +1,23 @@ #include "config.h" #include "ntp_stdlib.h" -#include "ntp_calendar.h" #include "ntp_fp.h" #include "unity.h" -void setUp(void) -{ -} +void +test_Address(void) { + const u_int32 input = htonl(3221225472UL + 512UL + 1UL); // 192.0.2.1 -void tearDown(void) -{ + TEST_ASSERT_EQUAL_STRING("192.0.2.1", numtoa(input)); } -void test_Address(void) { - u_int32 input = htonl(3221225472UL+512UL+1UL); // 192.0.2.1 +void +test_Netmask(void) { + // 255.255.255.0 + const u_int32 hostOrder = 255UL*256UL*256UL*256UL + 255UL*256UL*256UL + 255UL*256UL; + const u_int32 input = htonl(hostOrder); - TEST_ASSERT_EQUAL_STRING("192.0.2.1", numtoa(input)); + TEST_ASSERT_EQUAL_STRING("255.255.255.0", numtoa(input)); } - -void test_Netmask(void) { - // 255.255.255.0 - u_int32 hostOrder = 255UL*256UL*256UL*256UL + 255UL*256UL*256UL + 255UL*256UL; - u_int32 input = htonl(hostOrder); - - TEST_ASSERT_EQUAL_STRING("255.255.255.0", numtoa(input)); -} - diff --git a/tests/libntp/numtohost.c b/tests/libntp/numtohost.c index 7472f46f6..c1597c48b 100644 --- a/tests/libntp/numtohost.c +++ b/tests/libntp/numtohost.c @@ -1,19 +1,18 @@ #include "config.h" #include "ntp_stdlib.h" -#include "ntp_calendar.h" #include "ntp_fp.h" #include "unity.h" -void test_LoopbackNetNonResolve(void) { +void +test_LoopbackNetNonResolve(void) { /* A loopback address in 127.0.0.0/8 is chosen, and * numtohost() should not try to resolve it unless * it is 127.0.0.1 */ - u_int32 input = 127*256*256*256 + 1*256 + 1; // 127.0.1.1 + 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))); } - diff --git a/tests/libntp/refnumtoa.c b/tests/libntp/refnumtoa.c index 037ed4c18..6b7ae65ec 100644 --- a/tests/libntp/refnumtoa.c +++ b/tests/libntp/refnumtoa.c @@ -9,8 +9,8 @@ /* Might need to be updated if a new refclock gets this id. */ static const int UNUSED_REFCLOCK_ID = 250; - -void test_LocalClock(void) { +void +test_LocalClock(void) { #ifdef REFCLOCK /* clockname() is useless otherwise */ /* We test with a refclock address of type LOCALCLOCK. * with id 8 @@ -23,10 +23,10 @@ void test_LocalClock(void) { address.sa4.sin_family = AF_INET; address.sa4.sin_addr.s_addr = htonl(addr); - char stringStart [100]= ""; + char stringStart[100]= ""; - strcat(stringStart,clockname(REFCLK_LOCALCLOCK)); - strcat(stringStart,"(8)"); + strcat(stringStart, clockname(REFCLK_LOCALCLOCK)); + strcat(stringStart, "(8)"); char * expected = stringStart; @@ -36,9 +36,8 @@ void test_LocalClock(void) { #endif /* REFCLOCK */ } - - -void test_UnknownId(void) { +void +test_UnknownId(void) { #ifdef REFCLOCK /* refnumtoa() is useless otherwise */ /* We test with a currently unused refclock ID */ u_int32 addr = REFCLOCK_ADDR; @@ -49,8 +48,8 @@ void test_UnknownId(void) { address.sa4.sin_family = AF_INET; address.sa4.sin_addr.s_addr = htonl(addr); - char stringStart [100]= "REFCLK("; - char value [100] ; + char stringStart[100]= "REFCLK("; + char value[100] ; snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID); strcat(stringStart,value); strcat(stringStart,",4)"); @@ -61,4 +60,3 @@ void test_UnknownId(void) { TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST"); #endif /* REFCLOCK */ } - diff --git a/tests/libntp/run-lfpfunc.c b/tests/libntp/run-lfpfunc.c index 0f78f9418..0953d674b 100644 --- a/tests/libntp/run-lfpfunc.c +++ b/tests/libntp/run-lfpfunc.c @@ -54,15 +54,15 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "lfpfunc.c"; UnityBegin("lfpfunc.c"); - RUN_TEST(test_AdditionLR, 321); - RUN_TEST(test_AdditionRL, 340); - RUN_TEST(test_SubtractionLR, 359); - RUN_TEST(test_SubtractionRL, 374); - RUN_TEST(test_Negation, 392); - RUN_TEST(test_Absolute, 413); - RUN_TEST(test_FDF_RoundTrip, 448); - RUN_TEST(test_SignedRelOps, 480); - RUN_TEST(test_UnsignedRelOps, 522); + RUN_TEST(test_AdditionLR, 253); + RUN_TEST(test_AdditionRL, 267); + RUN_TEST(test_SubtractionLR, 285); + RUN_TEST(test_SubtractionRL, 298); + RUN_TEST(test_Negation, 315); + RUN_TEST(test_Absolute, 335); + RUN_TEST(test_FDF_RoundTrip, 368); + RUN_TEST(test_SignedRelOps, 395); + RUN_TEST(test_UnsignedRelOps, 435); return (UnityEnd()); } diff --git a/tests/libntp/run-lfptostr.c b/tests/libntp/run-lfptostr.c index 7e54a4f0c..8a541711b 100644 --- a/tests/libntp/run-lfptostr.c +++ b/tests/libntp/run-lfptostr.c @@ -26,6 +26,7 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); +void resetTest(void); extern void test_PositiveInteger(void); extern void test_NegativeInteger(void); extern void test_PositiveIntegerWithFraction(void); @@ -56,16 +57,16 @@ int main(int argc, char *argv[]) Unity.TestFile = "lfptostr.c"; UnityBegin("lfptostr.c"); RUN_TEST(test_PositiveInteger, 23); - RUN_TEST(test_NegativeInteger, 30); - RUN_TEST(test_PositiveIntegerWithFraction, 37); - RUN_TEST(test_NegativeIntegerWithFraction, 44); - RUN_TEST(test_RoundingDownToInteger, 51); - RUN_TEST(test_RoundingMiddleToInteger, 58); - RUN_TEST(test_RoundingUpToInteger, 65); - RUN_TEST(test_SingleDecimal, 72); - RUN_TEST(test_MillisecondsRoundingUp, 79); - RUN_TEST(test_MillisecondsRoundingDown, 88); - RUN_TEST(test_UnsignedInteger, 97); + RUN_TEST(test_NegativeInteger, 31); + RUN_TEST(test_PositiveIntegerWithFraction, 39); + RUN_TEST(test_NegativeIntegerWithFraction, 47); + RUN_TEST(test_RoundingDownToInteger, 55); + RUN_TEST(test_RoundingMiddleToInteger, 63); + RUN_TEST(test_RoundingUpToInteger, 71); + RUN_TEST(test_SingleDecimal, 79); + RUN_TEST(test_MillisecondsRoundingUp, 87); + RUN_TEST(test_MillisecondsRoundingDown, 97); + RUN_TEST(test_UnsignedInteger, 106); return (UnityEnd()); } diff --git a/tests/libntp/run-modetoa.c b/tests/libntp/run-modetoa.c index 334e08d63..0fdef7a26 100644 --- a/tests/libntp/run-modetoa.c +++ b/tests/libntp/run-modetoa.c @@ -26,6 +26,7 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); +void resetTest(void); extern void test_KnownMode(void); extern void test_UnknownMode(void); @@ -47,7 +48,7 @@ int main(int argc, char *argv[]) Unity.TestFile = "modetoa.c"; UnityBegin("modetoa.c"); RUN_TEST(test_KnownMode, 9); - RUN_TEST(test_UnknownMode, 15); + RUN_TEST(test_UnknownMode, 16); return (UnityEnd()); } diff --git a/tests/libntp/run-msyslog.c b/tests/libntp/run-msyslog.c index 3e4fac926..e21e76080 100644 --- a/tests/libntp/run-msyslog.c +++ b/tests/libntp/run-msyslog.c @@ -53,14 +53,14 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "msyslog.c"; UnityBegin("msyslog.c"); - RUN_TEST(test_msnprintf, 13); - RUN_TEST(test_msnprintfLiteralPercentm, 29); - RUN_TEST(test_msnprintfBackslashLiteralPercentm, 44); - RUN_TEST(test_msnprintfBackslashPercent, 58); - RUN_TEST(test_msnprintfHangingPercent, 73); - RUN_TEST(test_format_errmsgHangingPercent, 90); - RUN_TEST(test_msnprintfNullTarget, 105); - RUN_TEST(test_msnprintfTruncate, 116); + RUN_TEST(test_msnprintf, 14); + RUN_TEST(test_msnprintfLiteralPercentm, 31); + RUN_TEST(test_msnprintfBackslashLiteralPercentm, 47); + RUN_TEST(test_msnprintfBackslashPercent, 62); + RUN_TEST(test_msnprintfHangingPercent, 78); + RUN_TEST(test_format_errmsgHangingPercent, 96); + RUN_TEST(test_msnprintfNullTarget, 112); + RUN_TEST(test_msnprintfTruncate, 124); return (UnityEnd()); } diff --git a/tests/libntp/run-numtoa.c b/tests/libntp/run-numtoa.c index 5468b72e9..4f71aa1f4 100644 --- a/tests/libntp/run-numtoa.c +++ b/tests/libntp/run-numtoa.c @@ -26,6 +26,7 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); +void resetTest(void); extern void test_Address(void); extern void test_Netmask(void); @@ -46,8 +47,8 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "numtoa.c"; UnityBegin("numtoa.c"); - RUN_TEST(test_Address, 18); - RUN_TEST(test_Netmask, 24); + RUN_TEST(test_Address, 10); + RUN_TEST(test_Netmask, 17); return (UnityEnd()); } diff --git a/tests/libntp/run-numtohost.c b/tests/libntp/run-numtohost.c index 3ec4fdff0..8b92408a8 100644 --- a/tests/libntp/run-numtohost.c +++ b/tests/libntp/run-numtohost.c @@ -26,6 +26,7 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); +void resetTest(void); extern void test_LoopbackNetNonResolve(void); diff --git a/tests/libntp/run-refnumtoa.c b/tests/libntp/run-refnumtoa.c index ccdc8cf59..8aad9239d 100644 --- a/tests/libntp/run-refnumtoa.c +++ b/tests/libntp/run-refnumtoa.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) Unity.TestFile = "refnumtoa.c"; UnityBegin("refnumtoa.c"); RUN_TEST(test_LocalClock, 13); - RUN_TEST(test_UnknownId, 41); + RUN_TEST(test_UnknownId, 40); return (UnityEnd()); }