From: Damir Tomic Date: Sat, 6 Jun 2015 08:38:18 +0000 (+0000) Subject: adding new unity test files, changes to Makefile.am X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06988a3e5770354ed9f7f0ac32e37e84512cddc5;p=thirdparty%2Fntp.git adding new unity test files, changes to Makefile.am bk: 5572b17aJAdfJizAZO2yj_gdfIPi0Q --- diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 97b9b9fb4..f6d80a6f6 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -5,7 +5,9 @@ CLEANFILES = run_unity = cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb #removed test-libntp -check_PROGRAMS = test-modetoa test-uglydate +check_PROGRAMS = test-modetoa test-uglydate test-ymd2yd test-statestr test-numtoa test-numtohost \ +test-hextoint test-atoint + if GTEST_AVAILABLE check_PROGRAMS += tests else @@ -25,6 +27,11 @@ tests_LDADD = \ $(GTEST_LIBS) \ $(NULL) +unity_tests_LDADD = \ + $(LDADD) \ + $(top_builddir)/sntp/unity/libunity.a \ + $(NULL) + AM_CFLAGS = $(CFLAGS_NTP) AM_CXXFLAGS = $(GTEST_CXXFLAGS) @@ -38,7 +45,7 @@ AM_LDFLAGS = $(LDFLAGS_NTP) tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \ libntptest.cpp \ a_md5encrypt.cpp \ - atoint.cpp \ + g_atoint.cpp \ atouint.cpp \ authkeys.cpp \ buftvtots.cpp \ @@ -48,7 +55,7 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \ calyearstart.cpp \ clocktime.cpp \ decodenetnum.cpp \ - hextoint.cpp \ + g_hextoint.cpp \ hextolfp.cpp \ humandate.cpp \ lfpfunc.cpp \ @@ -56,8 +63,8 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \ g_modetoa.cpp \ msyslog.cpp \ netof.cpp \ - numtoa.cpp \ - numtohost.cpp \ + g_numtoa.cpp \ + g_numtohost.cpp \ octtoint.cpp \ prettydate.cpp \ recvbuff.cpp \ @@ -65,7 +72,7 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \ sfptostr.cpp \ socktoa.cpp \ ssl_init.cpp \ - statestr.cpp \ + g_statestr.cpp \ strtolfp.cpp \ timespecops.cpp \ timestructs.cpp \ @@ -74,7 +81,7 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \ tvtots.cpp \ g_uglydate.cpp \ vi64ops.cpp \ - ymd2yd.cpp \ + g_ymd2yd.cpp \ $(NULL) noinst_HEADERS = \ @@ -100,7 +107,6 @@ test_modetoa_CFLAGS = \ -I$(top_srcdir)/sntp/unity \ $(NULL) - test_modetoa_LDADD = \ $(LDADD) \ $(top_builddir)/sntp/unity/libunity.a \ @@ -115,15 +121,65 @@ test_uglydate_LDADD = \ $(top_builddir)/sntp/unity/libunity.a \ $(NULL) -#removed one combined test, because unity devs suggested we use one program per test -test_libntp_SOURCES = \ - modetoa.c \ - uglydate.c \ - test-libntp.c \ - test-libntp.h \ - run-test-libntp.c \ +test_ymd2yd_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_ymd2yd_LDADD = \ + $(LDADD) \ + $(top_builddir)/sntp/unity/libunity.a \ + $(NULL) + +test_statestr_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_statestr_LDADD = \ + $(LDADD) \ + $(top_builddir)/sntp/unity/libunity.a \ + $(NULL) + +test_numtoa_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_numtoa_LDADD = \ + $(unity_tests_LDADD) + +test_numtohost_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_numtohost_LDADD = \ + $(unity_tests_LDADD) \ + $(NULL) + +test_hextoint_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_hextoint_LDADD = \ + $(unity_tests_LDADD) + $(NULL) + +test_atoint_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_atoint_LDADD = \ + $(unity_tests_LDADD) $(NULL) + +#removed one combined test, because unity devs suggested we use one program per test +#test_libntp_SOURCES = \ +# modetoa.c \ +# uglydate.c \ +# test-libntp.c \ +# test-libntp.h \ +# run-test-libntp.c \ +# $(NULL) + test_modetoa_SOURCES = \ modetoa.c \ run-test-modetoa.c \ @@ -134,12 +190,60 @@ test_uglydate_SOURCES = \ run-test-uglydate.c \ $(NULL) +test_ymd2yd_SOURCES = \ + ymd2yd.c \ + run-test-ymd2yd.c \ + $(NULL) + +test_statestr_SOURCES = \ + statestr.c \ + run-test-statestr.c \ + $(NULL) + +test_numtoa_SOURCES = \ + numtoa.c \ + run-test-numtoa.c \ + $(NULL) + +test_numtohost_SOURCES = \ + numtohost.c \ + run-test-numtohost.c \ + $(NULL) + +test_hextoint_SOURCES = \ + hextoint.c \ + run-test-hextoint.c \ + $(NULL) + +test_atoint_SOURCES = \ + atoint.c \ + run-test-atoint.c \ + $(NULL) + + $(srcdir)/run-test-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list) $(run_unity) modetoa.c run-test-modetoa.c $(srcdir)/run-test-uglydate.c: $(srcdir)/uglydate.c $(std_unity_list) $(run_unity) uglydate.c run-test-uglydate.c +$(srcdir)/run-test-ymd2yd.c: $(srcdir)/ymd2yd.c $(std_unity_list) + $(run_unity) ymd2yd.c run-test-ymd2yd.c + +$(srcdir)/run-test-statestr.c: $(srcdir)/statestr.c $(std_unity_list) + $(run_unity) statestr.c run-test-statestr.c + +$(srcdir)/run-test-numtoa.c: $(srcdir)/numtoa.c $(std_unity_list) + $(run_unity) numtoa.c run-test-numtoa.c + +$(srcdir)/run-test-numtohost.c: $(srcdir)/numtohost.c $(std_unity_list) + $(run_unity) numtohost.c run-test-numtohost.c + +$(srcdir)/run-test-hextoint.c: $(srcdir)/hextoint.c $(std_unity_list) + $(run_unity) hextoint.c run-test-hextoint.c + +$(srcdir)/run-test-atoint.c: $(srcdir)/atoint.c $(std_unity_list) + $(run_unity) atoint.c run-test-atoint.c TESTS = diff --git a/tests/libntp/atoint.c b/tests/libntp/atoint.c new file mode 100644 index 000000000..3217fb155 --- /dev/null +++ b/tests/libntp/atoint.c @@ -0,0 +1,47 @@ +#include "unity.h" + +void test_RegularPositive(void) { + const char *str = "17"; + long val; + + TEST_ASSERT_TRUE(atoint(str, &val)); + TEST_ASSERT_EQUAL(17, val); +} + +void test_RegularNegative(void) { + const char *str = "-20"; + long val; + + TEST_ASSERT_TRUE(atoint(str, &val)); + TEST_ASSERT_EQUAL(-20, val); +} + +void test_PositiveOverflowBoundary(void) { + const char *str = "2147483648"; + long val; + + TEST_ASSERT_FALSE(atoint(str, &val)); +} + +void test_NegativeOverflowBoundary(void) { + const char *str = "-2147483649"; + long val; + + TEST_ASSERT_FALSE(atoint(str, &val)); +} + +void test_PositiveOverflowBig(void) { + const char *str = "2300000000"; + long val; + + TEST_ASSERT_FALSE(atoint(str, &val)); +} + +void test_IllegalCharacter(void) { + const char *str = "4500l"; + long val; + + TEST_ASSERT_FALSE(atoint(str, &val)); +} + + diff --git a/tests/libntp/atoint.cpp b/tests/libntp/g_atoint.cpp similarity index 100% rename from tests/libntp/atoint.cpp rename to tests/libntp/g_atoint.cpp diff --git a/tests/libntp/hextoint.cpp b/tests/libntp/g_hextoint.cpp similarity index 100% rename from tests/libntp/hextoint.cpp rename to tests/libntp/g_hextoint.cpp diff --git a/tests/libntp/numtoa.cpp b/tests/libntp/g_numtoa.cpp similarity index 100% rename from tests/libntp/numtoa.cpp rename to tests/libntp/g_numtoa.cpp diff --git a/tests/libntp/numtohost.cpp b/tests/libntp/g_numtohost.cpp similarity index 100% rename from tests/libntp/numtohost.cpp rename to tests/libntp/g_numtohost.cpp diff --git a/tests/libntp/statestr.cpp b/tests/libntp/g_statestr.cpp similarity index 99% rename from tests/libntp/statestr.cpp rename to tests/libntp/g_statestr.cpp index 506b079aa..bfd437865 100644 --- a/tests/libntp/statestr.cpp +++ b/tests/libntp/g_statestr.cpp @@ -25,3 +25,4 @@ TEST_F(statestrTest, ClockCodeExists) { TEST_F(statestrTest, ClockCodeUnknown) { EXPECT_STREQ("clk_-1", ceventstr(-1)); } + diff --git a/tests/libntp/ymd2yd.cpp b/tests/libntp/g_ymd2yd.cpp similarity index 100% rename from tests/libntp/ymd2yd.cpp rename to tests/libntp/g_ymd2yd.cpp diff --git a/tests/libntp/hextoint.c b/tests/libntp/hextoint.c new file mode 100644 index 000000000..2744ca505 --- /dev/null +++ b/tests/libntp/hextoint.c @@ -0,0 +1,44 @@ +#include "config.h" +#include "ntp_fp.h" +#include "unity.h" +//#include "libntptest.h" + + +void test_SingleDigit(void) { + const char *str = "a"; // 10 decimal + u_long actual; + + TEST_ASSERT_TRUE(hextoint(str, &actual)); + TEST_ASSERT_EQUAL(10, actual); +} + +void test_MultipleDigits(void) { + const char *str = "8F3"; // 2291 decimal + u_long actual; + + TEST_ASSERT_TRUE(hextoint(str, &actual)); + TEST_ASSERT_EQUAL(2291, actual); +} + +void test_MaxUnsigned(void) { + const char *str = "ffffffff"; // 4294967295 decimal + u_long actual; + + TEST_ASSERT_TRUE(hextoint(str, &actual)); + TEST_ASSERT_EQUAL(4294967295UL, actual); +} + +void test_Overflow(void) { + const char *str = "100000000"; // Overflow by 1 + u_long actual; + + TEST_ASSERT_FALSE(hextoint(str, &actual)); +} + +void test_IllegalChar(void) { + const char *str = "5gb"; // Illegal character g + u_long actual; + + TEST_ASSERT_FALSE(hextoint(str, &actual)); +} + diff --git a/tests/libntp/modetoa.c b/tests/libntp/modetoa.c index 811eef626..21015348c 100644 --- a/tests/libntp/modetoa.c +++ b/tests/libntp/modetoa.c @@ -1,5 +1,5 @@ //#include "config.h" -//#include "libntptest.h" +//#include "libntptest.h" //used for google test framework, not needed #include "unity.h" //#include "ntp_stdlib.h" @@ -9,12 +9,11 @@ void test_KnownMode(void) { const int MODE = 3; // Should be "client" TEST_ASSERT_EQUAL_STRING("client", modetoa(MODE)); -// EXPECT_STREQ("client", modetoa(MODE)); } void test_UnknownMode(void) { const int MODE = 100; - TEST_ASSERT_EQUAL_STRING("mode#1001", modetoa(MODE)); + TEST_ASSERT_EQUAL_STRING("mode#100", modetoa(MODE)); // EXPECT_STREQ("mode#100", modetoa(MODE)); } diff --git a/tests/libntp/numtoa.c b/tests/libntp/numtoa.c new file mode 100644 index 000000000..5d21afa87 --- /dev/null +++ b/tests/libntp/numtoa.c @@ -0,0 +1,27 @@ +#include "config.h" +#include "ntp_fp.h" +#include "unity.h" + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_Address(void) { + u_int32 input = htonl(3221225472UL+512UL+1UL); // 192.0.2.1 + + TEST_ASSERT_EQUAL_STRING("192.0.2.1", 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 new file mode 100644 index 000000000..cb13ac17a --- /dev/null +++ b/tests/libntp/numtohost.c @@ -0,0 +1,16 @@ +#include "config.h" +#include "ntp_fp.h" + +#include "unity.h" + +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 + + TEST_ASSERT_EQUAL_STRING("127.0.1.1", numtohost(htonl(input))); +} + diff --git a/tests/libntp/run-test-atoint.c b/tests/libntp/run-test-atoint.c new file mode 100644 index 000000000..b91a69d71 --- /dev/null +++ b/tests/libntp/run-test-atoint.c @@ -0,0 +1,58 @@ +/* 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_RegularPositive(void); +extern void test_RegularNegative(void); +extern void test_PositiveOverflowBoundary(void); +extern void test_NegativeOverflowBoundary(void); +extern void test_PositiveOverflowBig(void); +extern void test_IllegalCharacter(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + + +//=======MAIN===== +int main(void) +{ + Unity.TestFile = "atoint.c"; + UnityBegin("atoint.c"); + RUN_TEST(test_RegularPositive, 3); + RUN_TEST(test_RegularNegative, 11); + RUN_TEST(test_PositiveOverflowBoundary, 19); + RUN_TEST(test_NegativeOverflowBoundary, 26); + RUN_TEST(test_PositiveOverflowBig, 33); + RUN_TEST(test_IllegalCharacter, 40); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-hextoint.c b/tests/libntp/run-test-hextoint.c new file mode 100644 index 000000000..a892b9dde --- /dev/null +++ b/tests/libntp/run-test-hextoint.c @@ -0,0 +1,56 @@ +/* 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_SingleDigit(void); +extern void test_MultipleDigits(void); +extern void test_MaxUnsigned(void); +extern void test_Overflow(void); +extern void test_IllegalChar(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + + +//=======MAIN===== +int main(void) +{ + Unity.TestFile = "hextoint.c"; + UnityBegin("hextoint.c"); + RUN_TEST(test_SingleDigit, 7); + RUN_TEST(test_MultipleDigits, 15); + RUN_TEST(test_MaxUnsigned, 23); + RUN_TEST(test_Overflow, 31); + RUN_TEST(test_IllegalChar, 38); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-modetoa.c b/tests/libntp/run-test-modetoa.c index ab49f716e..3008310e5 100644 --- a/tests/libntp/run-test-modetoa.c +++ b/tests/libntp/run-test-modetoa.c @@ -44,7 +44,7 @@ int main(void) Unity.TestFile = "modetoa.c"; UnityBegin("modetoa.c"); RUN_TEST(test_KnownMode, 8); - RUN_TEST(test_UnknownMode, 15); + RUN_TEST(test_UnknownMode, 14); return (UnityEnd()); } diff --git a/tests/libntp/run-test-numtoa.c b/tests/libntp/run-test-numtoa.c new file mode 100644 index 000000000..e755c2056 --- /dev/null +++ b/tests/libntp/run-test-numtoa.c @@ -0,0 +1,50 @@ +/* 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_Address(void); +extern void test_Netmask(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + + +//=======MAIN===== +int main(void) +{ + Unity.TestFile = "numtoa.c"; + UnityBegin("numtoa.c"); + RUN_TEST(test_Address, 14); + RUN_TEST(test_Netmask, 20); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-numtohost.c b/tests/libntp/run-test-numtohost.c new file mode 100644 index 000000000..d05dbc9bc --- /dev/null +++ b/tests/libntp/run-test-numtohost.c @@ -0,0 +1,48 @@ +/* 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_LoopbackNetNonResolve(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + + +//=======MAIN===== +int main(void) +{ + Unity.TestFile = "numtohost.c"; + UnityBegin("numtohost.c"); + RUN_TEST(test_LoopbackNetNonResolve, 6); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-statestr.c b/tests/libntp/run-test-statestr.c new file mode 100644 index 000000000..44937a5a6 --- /dev/null +++ b/tests/libntp/run-test-statestr.c @@ -0,0 +1,54 @@ +/* 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_PeerRestart(void); +extern void test_SysUnspecified(void); +extern void test_ClockCodeExists(void); +extern void test_ClockCodeUnknown(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + + +//=======MAIN===== +int main(void) +{ + Unity.TestFile = "statestr.c"; + UnityBegin("statestr.c"); + RUN_TEST(test_PeerRestart, 18); + RUN_TEST(test_SysUnspecified, 22); + RUN_TEST(test_ClockCodeExists, 27); + RUN_TEST(test_ClockCodeUnknown, 31); + + return (UnityEnd()); +} diff --git a/tests/libntp/run-test-ymd2yd.c b/tests/libntp/run-test-ymd2yd.c new file mode 100644 index 000000000..ee2fcb094 --- /dev/null +++ b/tests/libntp/run-test-ymd2yd.c @@ -0,0 +1,54 @@ +/* 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_NonLeapYearFebruary(void); +extern void test_NonLeapYearJune(void); +extern void test_LeapYearFebruary(void); +extern void test_LeapYearDecember(void); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + + +//=======MAIN===== +int main(void) +{ + Unity.TestFile = "ymd2yd.c"; + UnityBegin("ymd2yd.c"); + RUN_TEST(test_NonLeapYearFebruary, 12); + RUN_TEST(test_NonLeapYearJune, 16); + RUN_TEST(test_LeapYearFebruary, 21); + RUN_TEST(test_LeapYearDecember, 25); + + return (UnityEnd()); +} diff --git a/tests/libntp/statestr.c b/tests/libntp/statestr.c new file mode 100644 index 000000000..52a32d927 --- /dev/null +++ b/tests/libntp/statestr.c @@ -0,0 +1,34 @@ +#include "config.h" +//#include "libntptest.h" + +#include "unity.h" +#include "ntp.h" // Needed for MAX_MAC_LEN used in ntp_control.h +#include "ntp_control.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + + +// eventstr() +void test_PeerRestart(void) { + TEST_ASSERT_EQUAL_STRING("restart", eventstr(PEVNT_RESTART)); +} + +void test_SysUnspecified(void) { + TEST_ASSERT_EQUAL_STRING("unspecified", eventstr(EVNT_UNSPEC)); +} + +// ceventstr() +void test_ClockCodeExists(void) { + TEST_ASSERT_EQUAL_STRING("clk_unspec", ceventstr(CTL_CLK_OKAY)); +} + +void test_ClockCodeUnknown(void) { + TEST_ASSERT_EQUAL_STRING("clk_-1", ceventstr(-1)); +} + diff --git a/tests/libntp/ymd2yd.c b/tests/libntp/ymd2yd.c new file mode 100644 index 000000000..f5a601c03 --- /dev/null +++ b/tests/libntp/ymd2yd.c @@ -0,0 +1,30 @@ +#include "unity.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + + +void test_NonLeapYearFebruary (void) { + TEST_ASSERT_EQUAL(31+20, ymd2yd(2010,2,20)); //2010-02-20 +} + +void test_NonLeapYearJune (void) { + int expected = 31+28+31+30+31+18; // 18 June non-leap year + TEST_ASSERT_EQUAL(expected, ymd2yd(2011,6,18)); +} + +void test_LeapYearFebruary (void) { + TEST_ASSERT_EQUAL(31+20, ymd2yd(2012,2,20)); //2012-02-20 (leap year) +} + +void test_LeapYearDecember (void) { + // 2012-12-31 + int expected = 31+29+31+30+31+30+31+31+30+31+30+31; + TEST_ASSERT_EQUAL(expected, ymd2yd(2012,12,31)); +} +