From: Harlan Stenn Date: Sat, 20 Jun 2015 04:00:43 +0000 (+0000) Subject: tests/libntp cleanup for Unity X-Git-Tag: NTP_4_3_43~2^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f85b8472228b254f84f0002c6bd24fbbf37ab15e;p=thirdparty%2Fntp.git tests/libntp cleanup for Unity bk: 5584e56bMTvWZhhDx9cy4fZQrl0_0w --- diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 0f7874284..656351c56 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -81,12 +81,12 @@ AM_LDFLAGS = $(LDFLAGS_NTP) tests_SOURCES = \ $(top_srcdir)/sntp/tests_main.cpp \ - libntptest.cpp \ + g_libntptest.cpp \ g_a_md5encrypt.cpp \ g_atoint.cpp \ g_atouint.cpp \ g_authkeys.cpp \ - buftvtots.cpp \ + g_buftvtots.cpp \ g_calendar.cpp \ g_caljulian.cpp \ g_caltontp.cpp \ @@ -113,7 +113,7 @@ tests_SOURCES = \ g_statestr.cpp \ g_strtolfp.cpp \ g_timespecops.cpp \ - timestructs.cpp \ + g_timestructs.cpp \ g_timevalops.cpp \ g_tstotv.cpp \ g_tvtots.cpp \ @@ -162,12 +162,12 @@ BUILT_SOURCES += \ $(NULL) noinst_HEADERS = \ + g_lfptest.h \ lfptest.h \ - c_lfptest.h \ - libntptest.h \ + g_libntptest.h \ + g_sockaddrtest.h \ sockaddrtest.h \ - c_sockaddrtest.h\ - timestructs.h \ + g_timestructs.h \ test-libntp.h \ $(NULL) diff --git a/tests/libntp/c_lfptest.h b/tests/libntp/c_lfptest.h deleted file mode 100644 index 7949821a2..000000000 --- a/tests/libntp/c_lfptest.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef NTP_TESTS_LFPTEST_H -#define NTP_TESTS_LFPTEST_H - -#include "ntp_fp.h" - -int IsEqual(const l_fp expected, const l_fp actual) { - if (L_ISEQU(&expected, &actual)) { - return TRUE; - } else { - //printf(" expected: ..."); - /* - << " expected: " << lfptoa(&expected, FRACTION_PREC) - << " (" << expected.l_ui << "." << expected.l_uf << ")" - << " but was: " << lfptoa(&actual, FRACTION_PREC) - << " (" << actual.l_ui << "." << actual.l_uf << ")"; - */ - return FALSE; - } - -} - -static const int32 HALF = -2147483647L - 1L; -static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005 -static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005 -static const int32 QUARTER = 1073741824L; -static const int32 QUARTER_PROMILLE_APPRX = 1073742L; - -#endif - - diff --git a/tests/libntp/c_sockaddrtest.h b/tests/libntp/c_sockaddrtest.h deleted file mode 100644 index f9a9fde41..000000000 --- a/tests/libntp/c_sockaddrtest.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef TESTS_SOCKADDRTEST_H -#define TESTS_SOCKADDRTEST_H - -#include "ntp.h" -#include "ntp_stdlib.h" - -sockaddr_u CreateSockaddr4(const char* address, unsigned int port) { - sockaddr_u s; - s.sa4.sin_family = AF_INET; - s.sa4.sin_addr.s_addr = inet_addr(address); - SET_PORT(&s, port); - - return s; -} - -int IsEqual(const sockaddr_u expected, const sockaddr_u actual) { - struct in_addr in; - struct in6_addr in6; - - if (expected.sa.sa_family != actual.sa.sa_family) { - //<< "Expected sa_family: " << expected.sa.sa_family - //<< " but got: " << actual.sa.sa_family; - return FALSE; - } - - if (actual.sa.sa_family == AF_INET) { // IPv4 - if (expected.sa4.sin_port == actual.sa4.sin_port && - memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr, - sizeof( in )) == 0) { - return TRUE; - } else { - //<< "IPv4 comparision failed, expected: " - //<< expected.sa4.sin_addr.s_addr - //<< "(" << socktoa(&expected) << ") but was: " - //<< actual.sa4.sin_addr.s_addr "(" << socktoa(&actual) << ")"; - return FALSE; - } - } else if (actual.sa.sa_family == AF_INET6) { //IPv6 - if (expected.sa6.sin6_port == actual.sa6.sin6_port && - memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr, - sizeof(in6)) == 0) { - return TRUE; - } else { - printf("IPv6 comparision failed"); - return FALSE; - } - } else { // Unknown family - printf("Unknown sa_family: ");// << actual.sa.sa_family; - return FALSE; - } -} - - -#endif // TESTS_SOCKADDRTEST_H - - - diff --git a/tests/libntp/clocktime.c b/tests/libntp/clocktime.c index 3281975ec..a9c0fec82 100644 --- a/tests/libntp/clocktime.c +++ b/tests/libntp/clocktime.c @@ -1,16 +1,12 @@ #include "config.h" -#include - #include "ntp_calendar.h" -#include "unity.h" #include "ntp_stdlib.h" - +#include "unity.h" #include "test-libntp.h" - // --------------------------------------------------------------------- // test fixture // diff --git a/tests/libntp/decodenetnum.c b/tests/libntp/decodenetnum.c index 8d29eb64c..681b7125a 100644 --- a/tests/libntp/decodenetnum.c +++ b/tests/libntp/decodenetnum.c @@ -3,7 +3,7 @@ #include "ntp_calendar.h" #include "unity.h" -#include "c_sockaddrtest.h" +#include "sockaddrtest.h" void test_IPv4AddressOnly(void) { diff --git a/tests/libntp/g_a_md5encrypt.cpp b/tests/libntp/g_a_md5encrypt.cpp index f4cea7e54..691bf78e2 100644 --- a/tests/libntp/g_a_md5encrypt.cpp +++ b/tests/libntp/g_a_md5encrypt.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #ifdef OPENSSL diff --git a/tests/libntp/g_atoint.cpp b/tests/libntp/g_atoint.cpp index 371f3fe0a..9a8283fd2 100644 --- a/tests/libntp/g_atoint.cpp +++ b/tests/libntp/g_atoint.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class atointTest : public libntptest { }; diff --git a/tests/libntp/g_atouint.cpp b/tests/libntp/g_atouint.cpp index cc8cc394b..ba261dbb1 100644 --- a/tests/libntp/g_atouint.cpp +++ b/tests/libntp/g_atouint.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class atouintTest : public libntptest { }; diff --git a/tests/libntp/g_authkeys.cpp b/tests/libntp/g_authkeys.cpp index 8dd33a9ac..773112e52 100644 --- a/tests/libntp/g_authkeys.cpp +++ b/tests/libntp/g_authkeys.cpp @@ -1,6 +1,6 @@ /* This file contains test for both libntp/authkeys.c and libntp/authusekey.c */ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #ifdef OPENSSL diff --git a/tests/libntp/buftvtots.cpp b/tests/libntp/g_buftvtots.cpp similarity index 100% rename from tests/libntp/buftvtots.cpp rename to tests/libntp/g_buftvtots.cpp diff --git a/tests/libntp/g_calendar.cpp b/tests/libntp/g_calendar.cpp index 35b39c7e5..2db9ff78f 100644 --- a/tests/libntp/g_calendar.cpp +++ b/tests/libntp/g_calendar.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_calendar.h" diff --git a/tests/libntp/g_caljulian.cpp b/tests/libntp/g_caljulian.cpp index d9cc95293..7ed38c43b 100644 --- a/tests/libntp/g_caljulian.cpp +++ b/tests/libntp/g_caljulian.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_calendar.h" diff --git a/tests/libntp/g_caltontp.cpp b/tests/libntp/g_caltontp.cpp index b9732db32..7dafec0ab 100644 --- a/tests/libntp/g_caltontp.cpp +++ b/tests/libntp/g_caltontp.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_calendar.h" diff --git a/tests/libntp/g_calyearstart.cpp b/tests/libntp/g_calyearstart.cpp index 774edf3ea..59859be61 100644 --- a/tests/libntp/g_calyearstart.cpp +++ b/tests/libntp/g_calyearstart.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class calyearstartTest : public libntptest { protected: diff --git a/tests/libntp/g_clocktime.cpp b/tests/libntp/g_clocktime.cpp index a24df1af4..ee496d252 100644 --- a/tests/libntp/g_clocktime.cpp +++ b/tests/libntp/g_clocktime.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" // --------------------------------------------------------------------- // test fixture diff --git a/tests/libntp/g_hextoint.cpp b/tests/libntp/g_hextoint.cpp index 54c9a67aa..c20821a9b 100644 --- a/tests/libntp/g_hextoint.cpp +++ b/tests/libntp/g_hextoint.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class hextointTest : public libntptest { }; diff --git a/tests/libntp/g_humandate.cpp b/tests/libntp/g_humandate.cpp index 742aa2872..a50ae5340 100644 --- a/tests/libntp/g_humandate.cpp +++ b/tests/libntp/g_humandate.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" #include #include diff --git a/tests/libntp/g_lfpfunc.cpp b/tests/libntp/g_lfpfunc.cpp index 275918cdc..c9aaf9f23 100644 --- a/tests/libntp/g_lfpfunc.cpp +++ b/tests/libntp/g_lfpfunc.cpp @@ -1,5 +1,5 @@ -#include "libntptest.h" -#include "timestructs.h" +#include "g_libntptest.h" +#include "g_timestructs.h" extern "C" { #include "ntp_fp.h" diff --git a/tests/libntp/g_lfptest.h b/tests/libntp/g_lfptest.h new file mode 100644 index 000000000..1daffef94 --- /dev/null +++ b/tests/libntp/g_lfptest.h @@ -0,0 +1,32 @@ +#ifndef NTP_TESTS_LFPTEST_H +#define NTP_TESTS_LFPTEST_H + +#include "g_libntptest.h" + +extern "C" { +#include "ntp_fp.h" +}; + +class lfptest : public libntptest { +protected: + ::testing::AssertionResult IsEqual(const l_fp &expected, const l_fp &actual) { + if (L_ISEQU(&expected, &actual)) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() + << " expected: " << lfptoa(&expected, FRACTION_PREC) + << " (" << expected.l_ui << "." << expected.l_uf << ")" + << " but was: " << lfptoa(&actual, FRACTION_PREC) + << " (" << actual.l_ui << "." << actual.l_uf << ")"; + } + } + + static const int32 HALF = -2147483647L - 1L; + static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005 + static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005 + static const int32 QUARTER = 1073741824L; + static const int32 QUARTER_PROMILLE_APPRX = 1073742L; +}; + +#endif +/* NTP_TESTS_LFPTEST_H */ diff --git a/tests/libntp/g_lfptostr.cpp b/tests/libntp/g_lfptostr.cpp index aa5f5112d..ae594a67c 100644 --- a/tests/libntp/g_lfptostr.cpp +++ b/tests/libntp/g_lfptostr.cpp @@ -4,7 +4,7 @@ * a macro. */ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_fp.h" diff --git a/tests/libntp/libntptest.cpp b/tests/libntp/g_libntptest.cpp similarity index 95% rename from tests/libntp/libntptest.cpp rename to tests/libntp/g_libntptest.cpp index c3363b008..8897b5c09 100644 --- a/tests/libntp/libntptest.cpp +++ b/tests/libntp/g_libntptest.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" /* This file contains various constants that libntp needs to be set * and that is normally defined in ntpd/ntpq/... diff --git a/tests/libntp/libntptest.h b/tests/libntp/g_libntptest.h similarity index 100% rename from tests/libntp/libntptest.h rename to tests/libntp/g_libntptest.h diff --git a/tests/libntp/g_modetoa.cpp b/tests/libntp/g_modetoa.cpp index cb7404d03..96bf3ce59 100644 --- a/tests/libntp/g_modetoa.cpp +++ b/tests/libntp/g_modetoa.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class modetoaTest : public libntptest { }; diff --git a/tests/libntp/g_msyslog.cpp b/tests/libntp/g_msyslog.cpp index 5b00703e6..273600d3a 100644 --- a/tests/libntp/g_msyslog.cpp +++ b/tests/libntp/g_msyslog.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include diff --git a/tests/libntp/g_numtoa.cpp b/tests/libntp/g_numtoa.cpp index 58e00c4c2..a68e80dbd 100644 --- a/tests/libntp/g_numtoa.cpp +++ b/tests/libntp/g_numtoa.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class numtoaTest : public libntptest { }; diff --git a/tests/libntp/g_numtohost.cpp b/tests/libntp/g_numtohost.cpp index ffc574ee8..e04cad8a6 100644 --- a/tests/libntp/g_numtohost.cpp +++ b/tests/libntp/g_numtohost.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class numtohostTest : public libntptest { }; diff --git a/tests/libntp/g_octtoint.cpp b/tests/libntp/g_octtoint.cpp index 14a993e03..8731eed63 100644 --- a/tests/libntp/g_octtoint.cpp +++ b/tests/libntp/g_octtoint.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class octtointTest : public libntptest { }; diff --git a/tests/libntp/g_prettydate.cpp b/tests/libntp/g_prettydate.cpp index 391ac29a8..45741b5a9 100644 --- a/tests/libntp/g_prettydate.cpp +++ b/tests/libntp/g_prettydate.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_fp.h" diff --git a/tests/libntp/g_recvbuff.cpp b/tests/libntp/g_recvbuff.cpp index e9505bd7c..799802d8b 100644 --- a/tests/libntp/g_recvbuff.cpp +++ b/tests/libntp/g_recvbuff.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "recvbuff.h" diff --git a/tests/libntp/g_refnumtoa.cpp b/tests/libntp/g_refnumtoa.cpp index 75460c0b5..91648aa02 100644 --- a/tests/libntp/g_refnumtoa.cpp +++ b/tests/libntp/g_refnumtoa.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" #include "ntp_net.h" #include "ntp_refclock.h" diff --git a/tests/libntp/g_sfptostr.cpp b/tests/libntp/g_sfptostr.cpp index 5cef47e3c..c31b30c90 100644 --- a/tests/libntp/g_sfptostr.cpp +++ b/tests/libntp/g_sfptostr.cpp @@ -3,7 +3,7 @@ * since all these functions are very similar. */ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_fp.h" diff --git a/tests/libntp/g_sockaddrtest.h b/tests/libntp/g_sockaddrtest.h new file mode 100644 index 000000000..819a54f71 --- /dev/null +++ b/tests/libntp/g_sockaddrtest.h @@ -0,0 +1,59 @@ +#ifndef TESTS_SOCKADDRTEST_H +#define TESTS_SOCKADDRTEST_H + +#include "g_libntptest.h" + +extern "C" { +#include "ntp.h" +}; + +class sockaddrtest : public libntptest { +protected: + ::testing::AssertionResult IsEqual(const sockaddr_u &expected, const sockaddr_u &actual) { + if (expected.sa.sa_family != actual.sa.sa_family) { + return ::testing::AssertionFailure() + << "Expected sa_family: " << expected.sa.sa_family + << " but got: " << actual.sa.sa_family; + } + + if (actual.sa.sa_family == AF_INET) { // IPv4 + if (expected.sa4.sin_port == actual.sa4.sin_port && + memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr, + sizeof(in_addr)) == 0) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() + << "IPv4 comparision failed, expected: " + << expected.sa4.sin_addr.s_addr + << "(" << socktoa(&expected) << ")" + << " but was: " + << actual.sa4.sin_addr.s_addr + << "(" << socktoa(&actual) << ")"; + } + } else if (actual.sa.sa_family == AF_INET6) { //IPv6 + if (expected.sa6.sin6_port == actual.sa6.sin6_port && + memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr, + sizeof(in6_addr)) == 0) { + return ::testing::AssertionSuccess(); + } else { + return ::testing::AssertionFailure() + << "IPv6 comparision failed"; + } + } else { // Unknown family + return ::testing::AssertionFailure() + << "Unknown sa_family: " << actual.sa.sa_family; + } + } + + sockaddr_u CreateSockaddr4(const char* address, unsigned int port) { + sockaddr_u s; + s.sa4.sin_family = AF_INET; + s.sa4.sin_addr.s_addr = inet_addr(address); + SET_PORT(&s, port); + + return s; + } +}; + +#endif // TESTS_SOCKADDRTEST_H + diff --git a/tests/libntp/g_ssl_init.cpp b/tests/libntp/g_ssl_init.cpp index 8812656c3..16b2f4d43 100644 --- a/tests/libntp/g_ssl_init.cpp +++ b/tests/libntp/g_ssl_init.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #ifdef OPENSSL diff --git a/tests/libntp/g_statestr.cpp b/tests/libntp/g_statestr.cpp index bfd437865..dedbf5b00 100644 --- a/tests/libntp/g_statestr.cpp +++ b/tests/libntp/g_statestr.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp.h" // Needed for MAX_MAC_LEN used in ntp_control.h diff --git a/tests/libntp/g_timespecops.cpp b/tests/libntp/g_timespecops.cpp index 392d27102..0cc573ff4 100644 --- a/tests/libntp/g_timespecops.cpp +++ b/tests/libntp/g_timespecops.cpp @@ -1,5 +1,5 @@ -#include "libntptest.h" -#include "timestructs.h" +#include "g_libntptest.h" +#include "g_timestructs.h" extern "C" { #include diff --git a/tests/libntp/timestructs.cpp b/tests/libntp/g_timestructs.cpp similarity index 98% rename from tests/libntp/timestructs.cpp rename to tests/libntp/g_timestructs.cpp index 3cd0c543f..15b5ec164 100644 --- a/tests/libntp/timestructs.cpp +++ b/tests/libntp/g_timestructs.cpp @@ -4,8 +4,8 @@ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. * The contents of 'html/copyright.html' apply. */ -#include "libntptest.h" -#include "timestructs.h" +#include "g_libntptest.h" +#include "g_timestructs.h" extern "C" { #include "timetoa.h" diff --git a/tests/libntp/c_timestructs.h b/tests/libntp/g_timestructs.h similarity index 83% rename from tests/libntp/c_timestructs.h rename to tests/libntp/g_timestructs.h index 8cd59270d..7bc4ffdcf 100644 --- a/tests/libntp/c_timestructs.h +++ b/tests/libntp/g_timestructs.h @@ -13,69 +13,41 @@ * HRVs (human readable values) but we might also be interested in the * machine representation for diagnostic purposes. */ - - -//#ifndef TESTCALSHIMS_H -#include "testcalshims.h" -//#endif - - #ifndef TIMESTRUCTS_H #define TIMESTRUCTS_H +extern "C" { #include "ntp_fp.h" +} - -l_fp test ; -//namespace timeStruct { +namespace timeStruct { // wrap a l_fp struct with common operations -struct l_fp_wrap { - +class l_fp_wrap { + public: l_fp V; - - //bool operator == (const l_fp_wrap& rhs) const - // { return L_ISEQU(&V, &rhs.V); } - -//---------------THIS HAS TO BE MANUALLY CONVERTED IN CODE!!! - //operator l_fp* () - // { return &V; } - //operator l_fp& () - // { return V; } -//----------------------------------------- -/* + l_fp_wrap() + { ZERO(V); } + l_fp_wrap(u_int32 hi, u_int32 lo) + { V.l_ui = hi; V.l_uf = lo; } + l_fp_wrap(const l_fp &rhs) + { V = rhs; } + bool operator == (const l_fp_wrap& rhs) const + { return L_ISEQU(&V, &rhs.V); } + operator l_fp* () + { return &V; } + operator l_fp& () + { return V; } l_fp_wrap & operator = (const l_fp_wrap& rhs) { V = rhs.V; return *this; } l_fp_wrap& operator = (const l_fp& rhs) { V = rhs; return *this; } -*/ -}; - -l_fp_wrap(l_fp V){ - ZERO(V); } -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){ - V = rhs; } - -l_fp_wrap_equals(const l_fp_wrap& current, 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){ - V = rhs.V; - return current//*this; -} -l_fp_wrap_and(const l_fp& current, const l_fp& rhs){ - V = rhs; - return current//*this; -} - + }; - // wrap a 'struct timeval' with common operations -struct timeval_wrap { - +class timeval_wrap { +public: struct timeval V; timeval_wrap() @@ -102,8 +74,8 @@ struct timeval_wrap { }; // wrap a 'struct timespec' with common operations -struct timespec_wrap { - +class timespec_wrap { +public: struct timespec V; timespec_wrap() @@ -208,6 +180,6 @@ extern std::ostream& operator << (std::ostream& os, extern std::ostream& operator << (std::ostream& os, const timeStruct::timespec_wrap& val); -//} // namespace timeStruct +} // namespace timeStruct #endif // TIMESTRUCTS_H diff --git a/tests/libntp/g_timevalops.cpp b/tests/libntp/g_timevalops.cpp index 7232615b9..8c171fca0 100644 --- a/tests/libntp/g_timevalops.cpp +++ b/tests/libntp/g_timevalops.cpp @@ -1,5 +1,5 @@ -#include "libntptest.h" -#include "timestructs.h" +#include "g_libntptest.h" +#include "g_timestructs.h" extern "C" { #include diff --git a/tests/libntp/g_tstotv.cpp b/tests/libntp/g_tstotv.cpp index 41f44d70e..30f4ca6a7 100644 --- a/tests/libntp/g_tstotv.cpp +++ b/tests/libntp/g_tstotv.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_fp.h" diff --git a/tests/libntp/g_uglydate.cpp b/tests/libntp/g_uglydate.cpp index 6d9e6c6ac..12aa0025c 100644 --- a/tests/libntp/g_uglydate.cpp +++ b/tests/libntp/g_uglydate.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "ntp_fp.h" diff --git a/tests/libntp/g_vi64ops.cpp b/tests/libntp/g_vi64ops.cpp index 7b839ab37..29f7932b3 100644 --- a/tests/libntp/g_vi64ops.cpp +++ b/tests/libntp/g_vi64ops.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" extern "C" { #include "vint64ops.h" diff --git a/tests/libntp/g_ymd2yd.cpp b/tests/libntp/g_ymd2yd.cpp index e6f46f8c0..7e2599960 100644 --- a/tests/libntp/g_ymd2yd.cpp +++ b/tests/libntp/g_ymd2yd.cpp @@ -1,4 +1,4 @@ -#include "libntptest.h" +#include "g_libntptest.h" class ymd2ydTest : public libntptest { }; diff --git a/tests/libntp/hextolfp.c b/tests/libntp/hextolfp.c index 0a4a6f9cf..a2f548f56 100644 --- a/tests/libntp/hextolfp.c +++ b/tests/libntp/hextolfp.c @@ -1,8 +1,10 @@ #include "config.h" + #include "ntp_stdlib.h" #include "ntp_calendar.h" + #include "unity.h" -#include "c_lfptest.h" +#include "lfptest.h" void test_PositiveInteger(void) { diff --git a/tests/libntp/humandate.c b/tests/libntp/humandate.c index 36cbe2b9c..071fa4159 100644 --- a/tests/libntp/humandate.c +++ b/tests/libntp/humandate.c @@ -1,8 +1,9 @@ #include "config.h" -#include "unity.h" + #include "ntp_calendar.h" #include "ntp_stdlib.h" -#include + +#include "unity.h" void test_RegularTime(void) { diff --git a/tests/libntp/lfpfunc.c b/tests/libntp/lfpfunc.c index e38104f8f..72c564026 100644 --- a/tests/libntp/lfpfunc.c +++ b/tests/libntp/lfpfunc.c @@ -9,8 +9,6 @@ #include #include -#include - typedef struct { uint32_t h, l; diff --git a/tests/libntp/lfptest.h b/tests/libntp/lfptest.h index 85179b811..7949821a2 100644 --- a/tests/libntp/lfptest.h +++ b/tests/libntp/lfptest.h @@ -1,32 +1,30 @@ #ifndef NTP_TESTS_LFPTEST_H #define NTP_TESTS_LFPTEST_H -#include "libntptest.h" - -extern "C" { #include "ntp_fp.h" -}; -class lfptest : public libntptest { -protected: - ::testing::AssertionResult IsEqual(const l_fp &expected, const l_fp &actual) { - if (L_ISEQU(&expected, &actual)) { - return ::testing::AssertionSuccess(); - } else { - return ::testing::AssertionFailure() - << " expected: " << lfptoa(&expected, FRACTION_PREC) +int IsEqual(const l_fp expected, const l_fp actual) { + if (L_ISEQU(&expected, &actual)) { + return TRUE; + } else { + //printf(" expected: ..."); + /* + << " expected: " << lfptoa(&expected, FRACTION_PREC) << " (" << expected.l_ui << "." << expected.l_uf << ")" << " but was: " << lfptoa(&actual, FRACTION_PREC) << " (" << actual.l_ui << "." << actual.l_uf << ")"; - } + */ + return FALSE; } - static const int32 HALF = -2147483647L - 1L; - static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005 - static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005 - static const int32 QUARTER = 1073741824L; - static const int32 QUARTER_PROMILLE_APPRX = 1073742L; -}; +} + +static const int32 HALF = -2147483647L - 1L; +static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005 +static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005 +static const int32 QUARTER = 1073741824L; +static const int32 QUARTER_PROMILLE_APPRX = 1073742L; #endif -/* NTP_TESTS_LFPTEST_H */ + + diff --git a/tests/libntp/lfptostr.c b/tests/libntp/lfptostr.c index a5f67fb8c..c76e07fb0 100644 --- a/tests/libntp/lfptostr.c +++ b/tests/libntp/lfptostr.c @@ -7,9 +7,10 @@ #include "config.h" #include "ntp_stdlib.h" #include "ntp_calendar.h" -#include "unity.h" #include "ntp_fp.h" +#include "unity.h" + static const int LFP_MAX_PRECISION = 10; static const int LFP_MAX_PRECISION_MS = 7; diff --git a/tests/libntp/msyslog.c b/tests/libntp/msyslog.c index 5e2a1f82e..c9d6d2daf 100644 --- a/tests/libntp/msyslog.c +++ b/tests/libntp/msyslog.c @@ -1,8 +1,7 @@ #include "config.h" + #include "ntp_stdlib.h" -#include -#include -#include + #include "unity.h" #ifndef VSNPRINTF_PERCENT_M diff --git a/tests/libntp/netof.c b/tests/libntp/netof.c index c6434448d..010b16429 100644 --- a/tests/libntp/netof.c +++ b/tests/libntp/netof.c @@ -1,11 +1,11 @@ #include "config.h" + #include "ntp_stdlib.h" #include "ntp_calendar.h" + #include "unity.h" -//#include "ntp.h" -//#include "ntp_net.h" -#include "c_sockaddrtest.h" +#include "sockaddrtest.h" void test_ClassBAddress(void) { sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT); diff --git a/tests/libntp/octtoint.c b/tests/libntp/octtoint.c index 3541b2106..4b0f94cea 100644 --- a/tests/libntp/octtoint.c +++ b/tests/libntp/octtoint.c @@ -1,8 +1,7 @@ #include "config.h" #include "ntp_stdlib.h" -//#include "ntp_calendar.h" -//#include "ntp_fp.h" + #include "unity.h" void test_SingleDigit(void) { @@ -11,7 +10,6 @@ void test_SingleDigit(void) { TEST_ASSERT_TRUE(octtoint(str, &actual) ); TEST_ASSERT_EQUAL(5, actual); - } void test_MultipleDigits(void){ diff --git a/tests/libntp/prettydate.c b/tests/libntp/prettydate.c index c68dda0ed..9a331e828 100644 --- a/tests/libntp/prettydate.c +++ b/tests/libntp/prettydate.c @@ -3,6 +3,7 @@ #include "ntp_stdlib.h" #include "ntp_calendar.h" #include "ntp_fp.h" + #include "unity.h" void @@ -13,4 +14,4 @@ test_ConstantDate(void) { TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 Wed, Jun 9 2010 14:00:00.500", gmprettydate(&time)); -} \ No newline at end of file +} diff --git a/tests/libntp/recvbuff.c b/tests/libntp/recvbuff.c index 6fb96fb2c..e9c14da88 100644 --- a/tests/libntp/recvbuff.c +++ b/tests/libntp/recvbuff.c @@ -1,10 +1,9 @@ -//#include "testcalshims.h" #include "config.h" + #include "recvbuff.h" + #include "unity.h" -//#include "ntp_stdlib.h" -//#include "libntptest.h" void setUp(void) @@ -40,4 +39,4 @@ test_GetAndFill(void) { TEST_ASSERT_EQUAL_UINT(1, full_recvbuffs()); TEST_ASSERT_TRUE(has_full_recv_buffer()); TEST_ASSERT_EQUAL_PTR(buf, get_full_recv_buffer()); -} \ No newline at end of file +} diff --git a/tests/libntp/refnumtoa.c b/tests/libntp/refnumtoa.c index 164b22470..8a37690ce 100644 --- a/tests/libntp/refnumtoa.c +++ b/tests/libntp/refnumtoa.c @@ -1,4 +1,5 @@ #include "config.h" + #include "ntp_net.h" #include "ntp_refclock.h" diff --git a/tests/libntp/run-clocktime.c b/tests/libntp/run-clocktime.c index 6229933dc..f21de83ea 100644 --- a/tests/libntp/run-clocktime.c +++ b/tests/libntp/run-clocktime.c @@ -52,14 +52,14 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "clocktime.c"; UnityBegin("clocktime.c"); - RUN_TEST(test_CurrentYear, 36); - RUN_TEST(test_CurrentYearFuzz, 51); - RUN_TEST(test_TimeZoneOffset, 73); - RUN_TEST(test_WrongYearStart, 93); - RUN_TEST(test_PreviousYear, 112); - RUN_TEST(test_NextYear, 131); - RUN_TEST(test_NoReasonableConversion, 149); - RUN_TEST(test_AlwaysInLimit, 171); + RUN_TEST(test_CurrentYear, 32); + RUN_TEST(test_CurrentYearFuzz, 47); + RUN_TEST(test_TimeZoneOffset, 69); + RUN_TEST(test_WrongYearStart, 89); + RUN_TEST(test_PreviousYear, 108); + RUN_TEST(test_NextYear, 127); + RUN_TEST(test_NoReasonableConversion, 145); + RUN_TEST(test_AlwaysInLimit, 167); return (UnityEnd()); } diff --git a/tests/libntp/run-hextolfp.c b/tests/libntp/run-hextolfp.c index 9cc331e23..33a8b94d9 100644 --- a/tests/libntp/run-hextolfp.c +++ b/tests/libntp/run-hextolfp.c @@ -50,12 +50,12 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "hextolfp.c"; UnityBegin("hextolfp.c"); - RUN_TEST(test_PositiveInteger, 8); - RUN_TEST(test_NegativeInteger, 18); - RUN_TEST(test_PositiveFraction, 28); - RUN_TEST(test_NegativeFraction, 38); - RUN_TEST(test_IllegalNumberOfInteger, 48); - RUN_TEST(test_IllegalChar, 55); + RUN_TEST(test_PositiveInteger, 10); + RUN_TEST(test_NegativeInteger, 20); + RUN_TEST(test_PositiveFraction, 30); + RUN_TEST(test_NegativeFraction, 40); + RUN_TEST(test_IllegalNumberOfInteger, 50); + RUN_TEST(test_IllegalChar, 57); return (UnityEnd()); } diff --git a/tests/libntp/run-humandate.c b/tests/libntp/run-humandate.c index be3930d60..291415f53 100644 --- a/tests/libntp/run-humandate.c +++ b/tests/libntp/run-humandate.c @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "humandate.c"; UnityBegin("humandate.c"); - RUN_TEST(test_RegularTime, 7); - RUN_TEST(test_CurrentTime, 21); + RUN_TEST(test_RegularTime, 8); + RUN_TEST(test_CurrentTime, 22); return (UnityEnd()); } diff --git a/tests/libntp/run-lfpfunc.c b/tests/libntp/run-lfpfunc.c index 84f99f508..72b616b73 100644 --- a/tests/libntp/run-lfpfunc.c +++ b/tests/libntp/run-lfpfunc.c @@ -53,15 +53,15 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "lfpfunc.c"; UnityBegin("lfpfunc.c"); - RUN_TEST(test_AdditionLR, 317); - RUN_TEST(test_AdditionRL, 335); - RUN_TEST(test_SubtractionLR, 353); - RUN_TEST(test_SubtractionRL, 367); - RUN_TEST(test_Negation, 384); - RUN_TEST(test_Absolute, 403); - RUN_TEST(test_FDF_RoundTrip, 434); - RUN_TEST(test_SignedRelOps, 465); - RUN_TEST(test_UnsignedRelOps, 508); + RUN_TEST(test_AdditionLR, 315); + RUN_TEST(test_AdditionRL, 333); + RUN_TEST(test_SubtractionLR, 351); + RUN_TEST(test_SubtractionRL, 365); + RUN_TEST(test_Negation, 382); + RUN_TEST(test_Absolute, 401); + RUN_TEST(test_FDF_RoundTrip, 432); + RUN_TEST(test_SignedRelOps, 463); + RUN_TEST(test_UnsignedRelOps, 506); return (UnityEnd()); } diff --git a/tests/libntp/run-lfptostr.c b/tests/libntp/run-lfptostr.c index 491f7c0dc..7e54a4f0c 100644 --- a/tests/libntp/run-lfptostr.c +++ b/tests/libntp/run-lfptostr.c @@ -55,17 +55,17 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "lfptostr.c"; UnityBegin("lfptostr.c"); - RUN_TEST(test_PositiveInteger, 22); - RUN_TEST(test_NegativeInteger, 29); - RUN_TEST(test_PositiveIntegerWithFraction, 36); - RUN_TEST(test_NegativeIntegerWithFraction, 43); - RUN_TEST(test_RoundingDownToInteger, 50); - RUN_TEST(test_RoundingMiddleToInteger, 57); - RUN_TEST(test_RoundingUpToInteger, 64); - RUN_TEST(test_SingleDecimal, 71); - RUN_TEST(test_MillisecondsRoundingUp, 78); - RUN_TEST(test_MillisecondsRoundingDown, 87); - RUN_TEST(test_UnsignedInteger, 96); + 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); return (UnityEnd()); } diff --git a/tests/libntp/run-msyslog.c b/tests/libntp/run-msyslog.c index 8ec7c24c6..3da1b78f7 100644 --- a/tests/libntp/run-msyslog.c +++ b/tests/libntp/run-msyslog.c @@ -52,14 +52,14 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "msyslog.c"; UnityBegin("msyslog.c"); - RUN_TEST(test_msnprintf, 15); - RUN_TEST(test_msnprintfLiteralPercentm, 31); - RUN_TEST(test_msnprintfBackslashLiteralPercentm, 46); - RUN_TEST(test_msnprintfBackslashPercent, 60); - RUN_TEST(test_msnprintfHangingPercent, 75); - RUN_TEST(test_format_errmsgHangingPercent, 92); - RUN_TEST(test_msnprintfNullTarget, 107); - RUN_TEST(test_msnprintfTruncate, 118); + RUN_TEST(test_msnprintf, 14); + RUN_TEST(test_msnprintfLiteralPercentm, 30); + RUN_TEST(test_msnprintfBackslashLiteralPercentm, 45); + RUN_TEST(test_msnprintfBackslashPercent, 59); + RUN_TEST(test_msnprintfHangingPercent, 74); + RUN_TEST(test_format_errmsgHangingPercent, 91); + RUN_TEST(test_msnprintfNullTarget, 106); + RUN_TEST(test_msnprintfTruncate, 117); return (UnityEnd()); } diff --git a/tests/libntp/run-octtoint.c b/tests/libntp/run-octtoint.c index 4dd84a0b7..dc2bed566 100644 --- a/tests/libntp/run-octtoint.c +++ b/tests/libntp/run-octtoint.c @@ -51,13 +51,13 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "octtoint.c"; UnityBegin("octtoint.c"); - RUN_TEST(test_SingleDigit, 8); - RUN_TEST(test_MultipleDigits, 17); - RUN_TEST(test_Zero, 26); - RUN_TEST(test_MaximumUnsigned32bit, 35); - RUN_TEST(test_Overflow, 44); - RUN_TEST(test_IllegalCharacter, 52); - RUN_TEST(test_IllegalDigit, 60); + RUN_TEST(test_SingleDigit, 7); + RUN_TEST(test_MultipleDigits, 15); + RUN_TEST(test_Zero, 24); + RUN_TEST(test_MaximumUnsigned32bit, 33); + RUN_TEST(test_Overflow, 42); + RUN_TEST(test_IllegalCharacter, 50); + RUN_TEST(test_IllegalDigit, 58); return (UnityEnd()); } diff --git a/tests/libntp/run-prettydate.c b/tests/libntp/run-prettydate.c index cafdad41f..2067b13c5 100644 --- a/tests/libntp/run-prettydate.c +++ b/tests/libntp/run-prettydate.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "prettydate.c"; UnityBegin("prettydate.c"); - RUN_TEST(test_ConstantDate, 9); + RUN_TEST(test_ConstantDate, 10); return (UnityEnd()); } diff --git a/tests/libntp/run-recvbuff.c b/tests/libntp/run-recvbuff.c index 75adc6b4c..8060105e3 100644 --- a/tests/libntp/run-recvbuff.c +++ b/tests/libntp/run-recvbuff.c @@ -47,9 +47,9 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "recvbuff.c"; UnityBegin("recvbuff.c"); - RUN_TEST(test_Initialization, 16); - RUN_TEST(test_GetAndFree, 24); - RUN_TEST(test_GetAndFill, 35); + RUN_TEST(test_Initialization, 15); + RUN_TEST(test_GetAndFree, 23); + RUN_TEST(test_GetAndFill, 34); return (UnityEnd()); } diff --git a/tests/libntp/run-refnumtoa.c b/tests/libntp/run-refnumtoa.c index 3354da8cf..60981ca5a 100644 --- a/tests/libntp/run-refnumtoa.c +++ b/tests/libntp/run-refnumtoa.c @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "refnumtoa.c"; UnityBegin("refnumtoa.c"); - RUN_TEST(test_LocalClock, 12); - RUN_TEST(test_UnknownId, 40); + RUN_TEST(test_LocalClock, 13); + RUN_TEST(test_UnknownId, 41); return (UnityEnd()); } diff --git a/tests/libntp/run-socktoa.c b/tests/libntp/run-socktoa.c index 81e4717d0..a6fa77834 100644 --- a/tests/libntp/run-socktoa.c +++ b/tests/libntp/run-socktoa.c @@ -50,12 +50,12 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "socktoa.c"; UnityBegin("socktoa.c"); - RUN_TEST(test_IPv4AddressWithPort, 9); - RUN_TEST(test_IPv6AddressWithPort, 16); - RUN_TEST(test_ScopedIPv6AddressWithPort, 40); - RUN_TEST(test_HashEqual, 65); - RUN_TEST(test_HashNotEqual, 73); - RUN_TEST(test_IgnoreIPv6Fields, 86); + RUN_TEST(test_IPv4AddressWithPort, 11); + RUN_TEST(test_IPv6AddressWithPort, 18); + RUN_TEST(test_ScopedIPv6AddressWithPort, 42); + RUN_TEST(test_HashEqual, 67); + RUN_TEST(test_HashNotEqual, 75); + RUN_TEST(test_IgnoreIPv6Fields, 88); return (UnityEnd()); } diff --git a/tests/libntp/run-ssl_init.c b/tests/libntp/run-ssl_init.c index 565470a30..452a60a9a 100644 --- a/tests/libntp/run-ssl_init.c +++ b/tests/libntp/run-ssl_init.c @@ -49,11 +49,11 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "ssl_init.c"; UnityBegin("ssl_init.c"); - RUN_TEST(test_MD5KeyTypeWithoutDigestLength, 18); - RUN_TEST(test_MD5KeyTypeWithDigestLength, 22); - RUN_TEST(test_SHA1KeyTypeWithDigestLength, 31); - RUN_TEST(test_MD5KeyName, 46); - RUN_TEST(test_SHA1KeyName, 50); + RUN_TEST(test_MD5KeyTypeWithoutDigestLength, 19); + RUN_TEST(test_MD5KeyTypeWithDigestLength, 23); + RUN_TEST(test_SHA1KeyTypeWithDigestLength, 32); + RUN_TEST(test_MD5KeyName, 47); + RUN_TEST(test_SHA1KeyName, 51); return (UnityEnd()); } diff --git a/tests/libntp/run-strtolfp.c b/tests/libntp/run-strtolfp.c index c69880026..0a2912bee 100644 --- a/tests/libntp/run-strtolfp.c +++ b/tests/libntp/run-strtolfp.c @@ -51,13 +51,13 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "strtolfp.c"; UnityBegin("strtolfp.c"); - RUN_TEST(test_PositiveInteger, 9); - RUN_TEST(test_NegativeInteger, 23); - RUN_TEST(test_PositiveFraction, 40); - RUN_TEST(test_NegativeFraction, 54); - RUN_TEST(test_PositiveMsFraction, 71); - RUN_TEST(test_NegativeMsFraction, 87); - RUN_TEST(test_InvalidChars, 105); + RUN_TEST(test_PositiveInteger, 11); + RUN_TEST(test_NegativeInteger, 25); + RUN_TEST(test_PositiveFraction, 42); + RUN_TEST(test_NegativeFraction, 56); + RUN_TEST(test_PositiveMsFraction, 73); + RUN_TEST(test_NegativeMsFraction, 89); + RUN_TEST(test_InvalidChars, 107); return (UnityEnd()); } diff --git a/tests/libntp/run-timespecops.c b/tests/libntp/run-timespecops.c index ee291ab52..b56e7560f 100644 --- a/tests/libntp/run-timespecops.c +++ b/tests/libntp/run-timespecops.c @@ -72,34 +72,34 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "timespecops.c"; UnityBegin("timespecops.c"); - RUN_TEST(test_Helpers1, 156); - RUN_TEST(test_Normalise, 176); - RUN_TEST(test_SignNoFrac, 190); - RUN_TEST(test_SignWithFrac, 202); - RUN_TEST(test_CmpFracEQ, 216); - RUN_TEST(test_CmpFracGT, 229); - RUN_TEST(test_CmpFracLT, 242); - RUN_TEST(test_AddFullNorm, 259); - RUN_TEST(test_AddFullOflow1, 273); - RUN_TEST(test_AddNsecNorm, 287); - RUN_TEST(test_AddNsecOflow1, 299); - RUN_TEST(test_SubFullNorm, 315); - RUN_TEST(test_SubFullOflow, 329); - RUN_TEST(test_SubNsecNorm, 343); - RUN_TEST(test_SubNsecOflow, 355); - RUN_TEST(test_Neg, 371); - RUN_TEST(test_AbsNoFrac, 388); - RUN_TEST(test_AbsWithFrac, 399); - RUN_TEST(test_Helpers2, 414); - RUN_TEST(test_ToLFPbittest, 446); - RUN_TEST(test_ToLFPrelPos, 459); - RUN_TEST(test_ToLFPrelNeg, 471); - RUN_TEST(test_ToLFPabs, 483); - RUN_TEST(test_FromLFPbittest, 498); - RUN_TEST(test_FromLFPrelPos, 517); - RUN_TEST(test_FromLFPrelNeg, 530); - RUN_TEST(test_LFProundtrip, 545); - RUN_TEST(test_ToString, 564); + RUN_TEST(test_Helpers1, 155); + RUN_TEST(test_Normalise, 175); + RUN_TEST(test_SignNoFrac, 189); + RUN_TEST(test_SignWithFrac, 201); + RUN_TEST(test_CmpFracEQ, 215); + RUN_TEST(test_CmpFracGT, 228); + RUN_TEST(test_CmpFracLT, 241); + RUN_TEST(test_AddFullNorm, 258); + RUN_TEST(test_AddFullOflow1, 272); + RUN_TEST(test_AddNsecNorm, 286); + RUN_TEST(test_AddNsecOflow1, 298); + RUN_TEST(test_SubFullNorm, 314); + RUN_TEST(test_SubFullOflow, 328); + RUN_TEST(test_SubNsecNorm, 342); + RUN_TEST(test_SubNsecOflow, 354); + RUN_TEST(test_Neg, 370); + RUN_TEST(test_AbsNoFrac, 387); + RUN_TEST(test_AbsWithFrac, 398); + RUN_TEST(test_Helpers2, 413); + RUN_TEST(test_ToLFPbittest, 445); + RUN_TEST(test_ToLFPrelPos, 458); + RUN_TEST(test_ToLFPrelNeg, 470); + RUN_TEST(test_ToLFPabs, 482); + RUN_TEST(test_FromLFPbittest, 497); + RUN_TEST(test_FromLFPrelPos, 516); + RUN_TEST(test_FromLFPrelNeg, 529); + RUN_TEST(test_LFProundtrip, 544); + RUN_TEST(test_ToString, 563); return (UnityEnd()); } diff --git a/tests/libntp/run-timevalops.c b/tests/libntp/run-timevalops.c index 03ab64e87..013aae1f2 100644 --- a/tests/libntp/run-timevalops.c +++ b/tests/libntp/run-timevalops.c @@ -72,34 +72,34 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "timevalops.c"; UnityBegin("timevalops.c"); - RUN_TEST(test_Helpers1, 155); - RUN_TEST(test_Normalise, 175); - RUN_TEST(test_SignNoFrac, 189); - RUN_TEST(test_SignWithFrac, 201); - RUN_TEST(test_CmpFracEQ, 216); - RUN_TEST(test_CmpFracGT, 230); - RUN_TEST(test_CmpFracLT, 244); - RUN_TEST(test_AddFullNorm, 262); - RUN_TEST(test_AddFullOflow1, 276); - RUN_TEST(test_AddUsecNorm, 290); - RUN_TEST(test_AddUsecOflow1, 302); - RUN_TEST(test_SubFullNorm, 318); - RUN_TEST(test_SubFullOflow, 332); - RUN_TEST(test_SubUsecNorm, 346); - RUN_TEST(test_SubUsecOflow, 358); - RUN_TEST(test_Neg, 374); - RUN_TEST(test_AbsNoFrac, 391); - RUN_TEST(test_AbsWithFrac, 402); - RUN_TEST(test_Helpers2, 418); - RUN_TEST(test_ToLFPbittest, 451); - RUN_TEST(test_ToLFPrelPos, 466); - RUN_TEST(test_ToLFPrelNeg, 480); - RUN_TEST(test_ToLFPabs, 493); - RUN_TEST(test_FromLFPbittest, 511); - RUN_TEST(test_FromLFPrelPos, 529); - RUN_TEST(test_FromLFPrelNeg, 542); - RUN_TEST(test_LFProundtrip, 556); - RUN_TEST(test_ToString, 575); + RUN_TEST(test_Helpers1, 153); + RUN_TEST(test_Normalise, 173); + RUN_TEST(test_SignNoFrac, 187); + RUN_TEST(test_SignWithFrac, 199); + RUN_TEST(test_CmpFracEQ, 214); + RUN_TEST(test_CmpFracGT, 228); + RUN_TEST(test_CmpFracLT, 242); + RUN_TEST(test_AddFullNorm, 260); + RUN_TEST(test_AddFullOflow1, 274); + RUN_TEST(test_AddUsecNorm, 288); + RUN_TEST(test_AddUsecOflow1, 300); + RUN_TEST(test_SubFullNorm, 316); + RUN_TEST(test_SubFullOflow, 330); + RUN_TEST(test_SubUsecNorm, 344); + RUN_TEST(test_SubUsecOflow, 356); + RUN_TEST(test_Neg, 372); + RUN_TEST(test_AbsNoFrac, 389); + RUN_TEST(test_AbsWithFrac, 400); + RUN_TEST(test_Helpers2, 416); + RUN_TEST(test_ToLFPbittest, 449); + RUN_TEST(test_ToLFPrelPos, 464); + RUN_TEST(test_ToLFPrelNeg, 478); + RUN_TEST(test_ToLFPabs, 491); + RUN_TEST(test_FromLFPbittest, 509); + RUN_TEST(test_FromLFPrelPos, 527); + RUN_TEST(test_FromLFPrelNeg, 540); + RUN_TEST(test_LFProundtrip, 554); + RUN_TEST(test_ToString, 573); return (UnityEnd()); } diff --git a/tests/libntp/run-tstotv.c b/tests/libntp/run-tstotv.c index 34807b319..cf7dd1794 100644 --- a/tests/libntp/run-tstotv.c +++ b/tests/libntp/run-tstotv.c @@ -47,9 +47,9 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "tstotv.c"; UnityBegin("tstotv.c"); - RUN_TEST(test_Seconds, 7); - RUN_TEST(test_MicrosecondsExact, 19); - RUN_TEST(test_MicrosecondsRounding, 33); + RUN_TEST(test_Seconds, 9); + RUN_TEST(test_MicrosecondsExact, 21); + RUN_TEST(test_MicrosecondsRounding, 35); return (UnityEnd()); } diff --git a/tests/libntp/run-tvtots.c b/tests/libntp/run-tvtots.c index 0aa987afc..468aae5e0 100644 --- a/tests/libntp/run-tvtots.c +++ b/tests/libntp/run-tvtots.c @@ -47,9 +47,9 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "tvtots.c"; UnityBegin("tvtots.c"); - RUN_TEST(test_Seconds, 9); - RUN_TEST(test_MicrosecondsRounded, 20); - RUN_TEST(test_MicrosecondsExact, 35); + RUN_TEST(test_Seconds, 10); + RUN_TEST(test_MicrosecondsRounded, 21); + RUN_TEST(test_MicrosecondsExact, 36); return (UnityEnd()); } diff --git a/tests/libntp/run-uglydate.c b/tests/libntp/run-uglydate.c index aef5216d8..4e6771363 100644 --- a/tests/libntp/run-uglydate.c +++ b/tests/libntp/run-uglydate.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) progname = argv[0]; Unity.TestFile = "uglydate.c"; UnityBegin("uglydate.c"); - RUN_TEST(test_ConstantDateTime, 10); + RUN_TEST(test_ConstantDateTime, 11); return (UnityEnd()); } diff --git a/tests/libntp/sockaddrtest.h b/tests/libntp/sockaddrtest.h index fd3e4af82..f9a9fde41 100644 --- a/tests/libntp/sockaddrtest.h +++ b/tests/libntp/sockaddrtest.h @@ -1,59 +1,57 @@ #ifndef TESTS_SOCKADDRTEST_H #define TESTS_SOCKADDRTEST_H -#include "libntptest.h" - -extern "C" { #include "ntp.h" -}; - -class sockaddrtest : public libntptest { -protected: - ::testing::AssertionResult IsEqual(const sockaddr_u &expected, const sockaddr_u &actual) { - if (expected.sa.sa_family != actual.sa.sa_family) { - return ::testing::AssertionFailure() - << "Expected sa_family: " << expected.sa.sa_family - << " but got: " << actual.sa.sa_family; - } +#include "ntp_stdlib.h" - if (actual.sa.sa_family == AF_INET) { // IPv4 - if (expected.sa4.sin_port == actual.sa4.sin_port && - memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr, - sizeof(in_addr)) == 0) { - return ::testing::AssertionSuccess(); - } else { - return ::testing::AssertionFailure() - << "IPv4 comparision failed, expected: " - << expected.sa4.sin_addr.s_addr - << "(" << socktoa(&expected) << ")" - << " but was: " - << actual.sa4.sin_addr.s_addr - << "(" << socktoa(&actual) << ")"; - } - } else if (actual.sa.sa_family == AF_INET6) { //IPv6 - if (expected.sa6.sin6_port == actual.sa6.sin6_port && - memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr, - sizeof(in6_addr)) == 0) { - return ::testing::AssertionSuccess(); - } else { - return ::testing::AssertionFailure() - << "IPv6 comparision failed"; - } - } else { // Unknown family - return ::testing::AssertionFailure() - << "Unknown sa_family: " << actual.sa.sa_family; - } - } +sockaddr_u CreateSockaddr4(const char* address, unsigned int port) { + sockaddr_u s; + s.sa4.sin_family = AF_INET; + s.sa4.sin_addr.s_addr = inet_addr(address); + SET_PORT(&s, port); + + return s; +} + +int IsEqual(const sockaddr_u expected, const sockaddr_u actual) { + struct in_addr in; + struct in6_addr in6; - sockaddr_u CreateSockaddr4(const char* address, unsigned int port) { - sockaddr_u s; - s.sa4.sin_family = AF_INET; - s.sa4.sin_addr.s_addr = inet_addr(address); - SET_PORT(&s, port); + if (expected.sa.sa_family != actual.sa.sa_family) { + //<< "Expected sa_family: " << expected.sa.sa_family + //<< " but got: " << actual.sa.sa_family; + return FALSE; + } - return s; + if (actual.sa.sa_family == AF_INET) { // IPv4 + if (expected.sa4.sin_port == actual.sa4.sin_port && + memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr, + sizeof( in )) == 0) { + return TRUE; + } else { + //<< "IPv4 comparision failed, expected: " + //<< expected.sa4.sin_addr.s_addr + //<< "(" << socktoa(&expected) << ") but was: " + //<< actual.sa4.sin_addr.s_addr "(" << socktoa(&actual) << ")"; + return FALSE; + } + } else if (actual.sa.sa_family == AF_INET6) { //IPv6 + if (expected.sa6.sin6_port == actual.sa6.sin6_port && + memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr, + sizeof(in6)) == 0) { + return TRUE; + } else { + printf("IPv6 comparision failed"); + return FALSE; + } + } else { // Unknown family + printf("Unknown sa_family: ");// << actual.sa.sa_family; + return FALSE; } -}; +} + #endif // TESTS_SOCKADDRTEST_H + + diff --git a/tests/libntp/socktoa.c b/tests/libntp/socktoa.c index e6f76a5f5..537df1e44 100644 --- a/tests/libntp/socktoa.c +++ b/tests/libntp/socktoa.c @@ -1,9 +1,11 @@ #include "config.h" + #include "ntp_stdlib.h" #include "ntp_calendar.h" + #include "unity.h" -#include "c_sockaddrtest.h" +#include "sockaddrtest.h" void test_IPv4AddressWithPort(void) { diff --git a/tests/libntp/ssl_init.c b/tests/libntp/ssl_init.c index e8c37f588..fe22414e3 100644 --- a/tests/libntp/ssl_init.c +++ b/tests/libntp/ssl_init.c @@ -1,11 +1,12 @@ #include "config.h" +#include "ntp.h" + #ifdef OPENSSL # include "openssl/err.h" # include "openssl/rand.h" # include "openssl/evp.h" #endif -#include "ntp.h" #include "unity.h" diff --git a/tests/libntp/strtolfp.c b/tests/libntp/strtolfp.c index d328244cf..de9f1119c 100644 --- a/tests/libntp/strtolfp.c +++ b/tests/libntp/strtolfp.c @@ -1,8 +1,10 @@ #include "config.h" + #include "ntp_stdlib.h" #include "ntp_calendar.h" + #include "unity.h" -#include "c_lfptest.h" +#include "lfptest.h" /* This file tests both atolfp and mstolfp */ diff --git a/tests/libntp/test-libntp.c b/tests/libntp/test-libntp.c index 3e50e8e8f..e489f673f 100644 --- a/tests/libntp/test-libntp.c +++ b/tests/libntp/test-libntp.c @@ -2,6 +2,7 @@ #include "ntp_stdlib.h" #include "ntp_calendar.h" + #include "test-libntp.h" //const char *progname = "test-libntp"; diff --git a/tests/libntp/testcalshims.h b/tests/libntp/testcalshims.h index bd4c681ac..c4aeef28b 100644 --- a/tests/libntp/testcalshims.h +++ b/tests/libntp/testcalshims.h @@ -1,11 +1,8 @@ -//#include "tests_main.h" #include "config.h" #include "ntp_stdlib.h" #include "ntp_calendar.h" -//u_long current_time = 4; // needed by authkeys. Used only in to calculate lifetime. -//const char *progname = "libntptest"; static time_t timefunc(time_t*); static time_t nowtime; diff --git a/tests/libntp/timespecops.c b/tests/libntp/timespecops.c index 3590733d0..bb2619a07 100644 --- a/tests/libntp/timespecops.c +++ b/tests/libntp/timespecops.c @@ -1,5 +1,4 @@ #include "config.h" -//#include "c_timestructs.h" #include "ntp_types.h" #include "ntp_fp.h" diff --git a/tests/libntp/c_timestructs.c b/tests/libntp/timestructs.c similarity index 100% rename from tests/libntp/c_timestructs.c rename to tests/libntp/timestructs.c diff --git a/tests/libntp/timestructs.h b/tests/libntp/timestructs.h index 7bc4ffdcf..8cd59270d 100644 --- a/tests/libntp/timestructs.h +++ b/tests/libntp/timestructs.h @@ -13,41 +13,69 @@ * HRVs (human readable values) but we might also be interested in the * machine representation for diagnostic purposes. */ + + +//#ifndef TESTCALSHIMS_H +#include "testcalshims.h" +//#endif + + #ifndef TIMESTRUCTS_H #define TIMESTRUCTS_H -extern "C" { #include "ntp_fp.h" -} -namespace timeStruct { + +l_fp test ; +//namespace timeStruct { // wrap a l_fp struct with common operations -class l_fp_wrap { - public: +struct l_fp_wrap { + l_fp V; - l_fp_wrap() - { ZERO(V); } - l_fp_wrap(u_int32 hi, u_int32 lo) - { V.l_ui = hi; V.l_uf = lo; } - l_fp_wrap(const l_fp &rhs) - { V = rhs; } - bool operator == (const l_fp_wrap& rhs) const - { return L_ISEQU(&V, &rhs.V); } - operator l_fp* () - { return &V; } - operator l_fp& () - { return V; } + + //bool operator == (const l_fp_wrap& rhs) const + // { return L_ISEQU(&V, &rhs.V); } + +//---------------THIS HAS TO BE MANUALLY CONVERTED IN CODE!!! + //operator l_fp* () + // { return &V; } + //operator l_fp& () + // { return V; } +//----------------------------------------- +/* l_fp_wrap & operator = (const l_fp_wrap& rhs) { V = rhs.V; return *this; } l_fp_wrap& operator = (const l_fp& rhs) { V = rhs; return *this; } - }; +*/ +}; + +l_fp_wrap(l_fp V){ + ZERO(V); } +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){ + V = rhs; } + +l_fp_wrap_equals(const l_fp_wrap& current, 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){ + V = rhs.V; + return current//*this; +} +l_fp_wrap_and(const l_fp& current, const l_fp& rhs){ + V = rhs; + return current//*this; +} + + // wrap a 'struct timeval' with common operations -class timeval_wrap { -public: +struct timeval_wrap { + struct timeval V; timeval_wrap() @@ -74,8 +102,8 @@ public: }; // wrap a 'struct timespec' with common operations -class timespec_wrap { -public: +struct timespec_wrap { + struct timespec V; timespec_wrap() @@ -180,6 +208,6 @@ extern std::ostream& operator << (std::ostream& os, extern std::ostream& operator << (std::ostream& os, const timeStruct::timespec_wrap& val); -} // namespace timeStruct +//} // namespace timeStruct #endif // TIMESTRUCTS_H diff --git a/tests/libntp/timevalops.c b/tests/libntp/timevalops.c index e8e167ea2..080dfb737 100644 --- a/tests/libntp/timevalops.c +++ b/tests/libntp/timevalops.c @@ -1,17 +1,15 @@ #include "config.h" -//#include "c_timestructs.h" //functions removed from the wrapper and placed directly here! //some unused features are still in the wrapper, unconverted -#include "unity.h" - #include "ntp_types.h" #include "ntp_fp.h" #include #include "timevalops.h" -#include +#include "unity.h" + //in unity_helper.h : #define TEST_ASSERT_EQUAL_timeval(a, b) { \ diff --git a/tests/libntp/tstotv.c b/tests/libntp/tstotv.c index 87f6ad7b8..080172752 100644 --- a/tests/libntp/tstotv.c +++ b/tests/libntp/tstotv.c @@ -1,6 +1,8 @@ #include "config.h" + #include "ntp_fp.h" #include "timevalops.h" + #include "unity.h" void @@ -39,4 +41,4 @@ test_MicrosecondsRounding(void) { TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec); TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec); -} \ No newline at end of file +} diff --git a/tests/libntp/tvtots.c b/tests/libntp/tvtots.c index 2f311f55b..6c8345aaa 100644 --- a/tests/libntp/tvtots.c +++ b/tests/libntp/tvtots.c @@ -1,11 +1,12 @@ #include "config.h" -#include "c_lfptest.h" + +#include "lfptest.h" #include "timevalops.h" + #include "unity.h" #include // Required on Solaris for ldexp. - void test_Seconds(void) { struct timeval input = {500, 0}; // 500.0 s diff --git a/tests/libntp/uglydate.c b/tests/libntp/uglydate.c index a087da601..a8d02d15b 100644 --- a/tests/libntp/uglydate.c +++ b/tests/libntp/uglydate.c @@ -3,6 +3,7 @@ #include "ntp_stdlib.h" #include "ntp_calendar.h" #include "ntp_fp.h" + #include "unity.h" diff --git a/tests/libntp/vi64ops.c b/tests/libntp/vi64ops.c index ff5e57820..af7dd1b7b 100644 --- a/tests/libntp/vi64ops.c +++ b/tests/libntp/vi64ops.c @@ -1,11 +1,11 @@ #include "config.h" #include "ntp_stdlib.h" -//#include "ntp_calendar.h" -#include "vint64ops.h" #include "unity.h" +#include "vint64ops.h" + //technically bool //int IsEqual(const vint64 &expected, const vint64 &actual) { int IsEqual(const vint64 expected, const vint64 actual) {