From: Damir Tomic Date: Mon, 15 Jun 2015 22:54:42 +0000 (+0200) Subject: c_sockaddrtest.h: X-Git-Tag: NTP_4_3_42~2^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=918317b70ea32d4e133800f074fdc6aacbd3ac17;p=thirdparty%2Fntp.git c_sockaddrtest.h: removed stuff like 1==1 with TRUE. Also added cin cout stuff, should be replaced b Many files: new file Makefile.am: fixes to Lokesh-Damir merge, added new .h to noinst_SOURCES c_lfptest.h: put the static vars back in here, removed them from hextolfp.c, because more files will need them. hextolfp.c: removed static consts, placed them in c_lpftest.h octtoint.c: removed outdates testcalshims.h, replaced with required includes bk: 557f57b2AUMb_7zs3jaMY7oj3giHSg --- diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 0daef1778..bfa346c47 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -28,8 +28,8 @@ check_PROGRAMS = \ test-hextolfp \ test-netof \ test-socktoa \ + test-decodenetnum \ $(NULL) -#test-decodenetnum if GTEST_AVAILABLE check_PROGRAMS += tests @@ -111,8 +111,10 @@ tests_SOURCES = \ noinst_HEADERS = \ lfptest.h \ + c_lfptest.h \ libntptest.h \ sockaddrtest.h \ + c_sockaddrtest.h \ timestructs.h \ test-libntp.h \ $(NULL) @@ -197,42 +199,48 @@ test_atoint_LDADD = \ $(unity_tests_LDADD) $(NULL) -test_octtoint_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_octtoint_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_octtoint_LDADD = \ - $(unity_tests_LDADD) +test_octtoint_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_hextolfp_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_hextolfp_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_hextolfp_LDADD = \ - $(unity_tests_LDADD) +test_hextolfp_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -test_netof_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_netof_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) -test_netof_LDADD = \ - $(unity_tests_LDADD) +test_netof_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) -#test_decodenetnum_CFLAGS = \ -# -I$(top_srcdir)/sntp/unity \ -# $(NULL) -# -#test_decodenetnum_LDADD = \ -# $(unity_tests_LDADD) -# $(NULL) +test_decodenetnum_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_decodenetnum_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) + +test_socktoa_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) -test_socktoa_CFLAGS = \ - -I$(top_srcdir)/sntp/unity \ +test_socktoa_LDADD = \ + $(unity_tests_LDADD) \ $(NULL) +test_a_md5encrypt_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ $(NULL) test_a_md5encrypt_LDADD = \ @@ -319,7 +327,6 @@ test_calendar_LDADD = \ $(NULL) - test_modetoa_SOURCES = \ modetoa.c \ run-test-modetoa.c \ @@ -360,29 +367,34 @@ test_atoint_SOURCES = \ run-test-atoint.c \ $(NULL) -test_octtoint_SOURCES = \ - octtoint.c \ - run-test-octtoint.c \ +test_a_md5encrypt_SOURCES = \ + a_md5encrypt.c \ + run-test-a_md5encrypt.c \ $(NULL) -test_hextolfp_SOURCES = \ - hextolfp.c \ - run-test-hextolfp.c \ +test_octtoint_SOURCES = \ + octtoint.c \ + run-test-octtoint.c \ $(NULL) -test_netof_SOURCES = \ - netof.c \ - run-test-netof.c \ +test_hextolfp_SOURCES = \ + hextolfp.c \ + run-test-hextolfp.c \ $(NULL) -#test_decodenetnum_SOURCES = \ -# decodenetnum.c \ -# run-test-decodenetnum.c \ -# $(NULL) +test_netof_SOURCES = \ + netof.c \ + run-test-netof.c \ + $(NULL) -test_socktoa_SOURCES = \ - socktoa.c \ - run-test-socktoa.c \ +test_decodenetnum_SOURCES = \ + decodenetnum.c \ + run-test-decodenetnum.c \ + $(NULL) + +test_socktoa_SOURCES = \ + socktoa.c \ + run-test-socktoa.c \ $(NULL) test_atouint_SOURCES = \ @@ -428,10 +440,10 @@ test_caljulian_SOURCES = \ test-libntp.c \ $(NULL) -test_calendar_SOURCES = \ - calendar.c \ - run-test-calendar.c \ - test-libntp.c \ +test_calendar_SOURCES = \ + calendar.c \ + run-test-calendar.c \ + test-libntp.c \ $(NULL) @@ -443,12 +455,17 @@ BUILT_SOURCES += \ $(srcdir)/run-test-caljulian.c \ $(srcdir)/run-test-calyearstart.c \ $(srcdir)/run-test-clocktime.c \ + $(srcdir)/run-test-decodenetnum.c \ $(srcdir)/run-test-hextoint.c \ + $(srcdir)/run-test-hextolfp.c \ $(srcdir)/run-test-lfpfunc.c \ $(srcdir)/run-test-modetoa.c \ + $(srcdir)/run-test-netof.c \ $(srcdir)/run-test-numtoa.c \ $(srcdir)/run-test-numtohost.c \ + $(srcdir)/run-test-octtoint.c \ $(srcdir)/run-test-refnumtoa.c \ + $(srcdir)/run-test-socktoa.c \ $(srcdir)/run-test-statestr.c \ $(srcdir)/run-test-uglydate.c \ $(srcdir)/run-test-vi64ops.c \ @@ -489,8 +506,8 @@ $(srcdir)/run-test-hextolfp.c: $(srcdir)/hextolfp.c $(std_unity_list) $(srcdir)/run-test-netof.c: $(srcdir)/netof.c $(std_unity_list) $(run_unity) netof.c run-test-netof.c -#$(srcdir)/run-test-decodenetnum.c: $(srcdir)/decodenetnum.c $(std_unity_list) -# $(run_unity) decodenetnum.c run-test-decodenetnum.c +$(srcdir)/run-test-decodenetnum.c: $(srcdir)/decodenetnum.c $(std_unity_list) + $(run_unity) decodenetnum.c run-test-decodenetnum.c $(srcdir)/run-test-socktoa.c: $(srcdir)/socktoa.c $(std_unity_list) $(run_unity) socktoa.c run-test-socktoa.c diff --git a/tests/libntp/c_lfptest.h b/tests/libntp/c_lfptest.h index a6e3627e9..7949821a2 100644 --- a/tests/libntp/c_lfptest.h +++ b/tests/libntp/c_lfptest.h @@ -5,13 +5,26 @@ int IsEqual(const l_fp expected, const l_fp actual) { if (L_ISEQU(&expected, &actual)) { - return 1==1; + return TRUE; } else { - return 1==2; + //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 index f5cd6b398..f9a9fde41 100644 --- a/tests/libntp/c_sockaddrtest.h +++ b/tests/libntp/c_sockaddrtest.h @@ -18,27 +18,35 @@ int IsEqual(const sockaddr_u expected, const sockaddr_u actual) { struct in6_addr in6; if (expected.sa.sa_family != actual.sa.sa_family) { - return 1==2; + //<< "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 1==1; + return TRUE; } else { - return 1==2; + //<< "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 1==1; + return TRUE; } else { - return 1==2; + printf("IPv6 comparision failed"); + return FALSE; } } else { // Unknown family - return 1==2; + printf("Unknown sa_family: ");// << actual.sa.sa_family; + return FALSE; } } diff --git a/tests/libntp/hextolfp.c b/tests/libntp/hextolfp.c index f17642ef3..0a4a6f9cf 100644 --- a/tests/libntp/hextolfp.c +++ b/tests/libntp/hextolfp.c @@ -4,13 +4,6 @@ #include "unity.h" #include "c_lfptest.h" -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; - - void test_PositiveInteger(void) { const char *str = "00001000.00000000"; diff --git a/tests/libntp/octtoint.c b/tests/libntp/octtoint.c index b2ceeed09..3541b2106 100644 --- a/tests/libntp/octtoint.c +++ b/tests/libntp/octtoint.c @@ -1,4 +1,7 @@ -#include "testcalshims.h" +#include "config.h" + +#include "ntp_stdlib.h" +//#include "ntp_calendar.h" //#include "ntp_fp.h" #include "unity.h" diff --git a/tests/libntp/run-test-decodenetnum.c b/tests/libntp/run-test-decodenetnum.c new file mode 100644 index 000000000..5c82a39d1 --- /dev/null +++ b/tests/libntp/run-test-decodenetnum.c @@ -0,0 +1,61 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +extern void test_IPv4AddressOnly(void); +extern void test_IPv4AddressWithPort(void); +extern void test_IPv6AddressOnly(void); +extern void test_IPv6AddressWithPort(void); +extern void test_IllegalAddress(void); +extern void test_IllegalCharInPort(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + +char *progname; + + +//=======MAIN===== +int main(int argc, char *argv[]) +{ + progname = argv[0]; + Unity.TestFile = "decodenetnum.c"; + UnityBegin("decodenetnum.c"); + RUN_TEST(test_IPv4AddressOnly, 9); + RUN_TEST(test_IPv4AddressWithPort, 22); + RUN_TEST(test_IPv6AddressOnly, 35); + RUN_TEST(test_IPv6AddressWithPort, 55); + RUN_TEST(test_IllegalAddress, 75); + RUN_TEST(test_IllegalCharInPort, 82); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-hextolfp.c b/tests/libntp/run-test-hextolfp.c new file mode 100644 index 000000000..9cc331e23 --- /dev/null +++ b/tests/libntp/run-test-hextolfp.c @@ -0,0 +1,61 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +extern void test_PositiveInteger(void); +extern void test_NegativeInteger(void); +extern void test_PositiveFraction(void); +extern void test_NegativeFraction(void); +extern void test_IllegalNumberOfInteger(void); +extern void test_IllegalChar(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + +char *progname; + + +//=======MAIN===== +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); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-netof.c b/tests/libntp/run-test-netof.c new file mode 100644 index 000000000..b39c9ee41 --- /dev/null +++ b/tests/libntp/run-test-netof.c @@ -0,0 +1,57 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +extern void test_ClassBAddress(void); +extern void test_ClassCAddress(void); +extern void test_ClassAAddress(void); +extern void test_IPv6Address(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + +char *progname; + + +//=======MAIN===== +int main(int argc, char *argv[]) +{ + progname = argv[0]; + Unity.TestFile = "netof.c"; + UnityBegin("netof.c"); + RUN_TEST(test_ClassBAddress, 10); + RUN_TEST(test_ClassCAddress, 20); + RUN_TEST(test_ClassAAddress, 30); + RUN_TEST(test_IPv6Address, 43); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-octtoint.c b/tests/libntp/run-test-octtoint.c index be9d09b11..4dd84a0b7 100644 --- a/tests/libntp/run-test-octtoint.c +++ b/tests/libntp/run-test-octtoint.c @@ -42,19 +42,22 @@ void resetTest() setUp(); } +char *progname; + //=======MAIN===== -int main(void) +int main(int argc, char *argv[]) { + progname = argv[0]; Unity.TestFile = "octtoint.c"; UnityBegin("octtoint.c"); - RUN_TEST(test_SingleDigit, 5); - RUN_TEST(test_MultipleDigits, 14); - RUN_TEST(test_Zero, 23); - RUN_TEST(test_MaximumUnsigned32bit, 32); - RUN_TEST(test_Overflow, 41); - RUN_TEST(test_IllegalCharacter, 49); - RUN_TEST(test_IllegalDigit, 57); + 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); return (UnityEnd()); } diff --git a/tests/libntp/run-test-socktoa.c b/tests/libntp/run-test-socktoa.c new file mode 100644 index 000000000..894404a8f --- /dev/null +++ b/tests/libntp/run-test-socktoa.c @@ -0,0 +1,61 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +extern void test_IPv4AddressWithPort(void); +extern void test_IPv6AddressWithPort(void); +extern void test_ScopedIPv6AddressWithPort(void); +extern void test_HashEqual(void); +extern void test_HashNotEqual(void); +extern void test_IgnoreIPv6Fields(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + +char *progname; + + +//=======MAIN===== +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, 82); + + return (UnityEnd()); +}