]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
adding new unity test files, changes to Makefile.am
authorDamir Tomic <viperus@ntp.org>
Sat, 6 Jun 2015 08:38:18 +0000 (08:38 +0000)
committerDamir Tomic <viperus@ntp.org>
Sat, 6 Jun 2015 08:38:18 +0000 (08:38 +0000)
bk: 5572b17aJAdfJizAZO2yj_gdfIPi0Q

21 files changed:
tests/libntp/Makefile.am
tests/libntp/atoint.c [new file with mode: 0644]
tests/libntp/g_atoint.cpp [moved from tests/libntp/atoint.cpp with 100% similarity]
tests/libntp/g_hextoint.cpp [moved from tests/libntp/hextoint.cpp with 100% similarity]
tests/libntp/g_numtoa.cpp [moved from tests/libntp/numtoa.cpp with 100% similarity]
tests/libntp/g_numtohost.cpp [moved from tests/libntp/numtohost.cpp with 100% similarity]
tests/libntp/g_statestr.cpp [moved from tests/libntp/statestr.cpp with 99% similarity]
tests/libntp/g_ymd2yd.cpp [moved from tests/libntp/ymd2yd.cpp with 100% similarity]
tests/libntp/hextoint.c [new file with mode: 0644]
tests/libntp/modetoa.c
tests/libntp/numtoa.c [new file with mode: 0644]
tests/libntp/numtohost.c [new file with mode: 0644]
tests/libntp/run-test-atoint.c [new file with mode: 0644]
tests/libntp/run-test-hextoint.c [new file with mode: 0644]
tests/libntp/run-test-modetoa.c
tests/libntp/run-test-numtoa.c [new file with mode: 0644]
tests/libntp/run-test-numtohost.c [new file with mode: 0644]
tests/libntp/run-test-statestr.c [new file with mode: 0644]
tests/libntp/run-test-ymd2yd.c [new file with mode: 0644]
tests/libntp/statestr.c [new file with mode: 0644]
tests/libntp/ymd2yd.c [new file with mode: 0644]

index 97b9b9fb4719d147a8ca3b5329831591978a9323..f6d80a6f6e800134adb771075821121aa1d95d4f 100644 (file)
@@ -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 (file)
index 0000000..3217fb1
--- /dev/null
@@ -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));
+}
+
+
similarity index 99%
rename from tests/libntp/statestr.cpp
rename to tests/libntp/g_statestr.cpp
index 506b079aa4786ddbf26fb98b8a9faf6f7bc6bd8f..bfd437865417581d52b4d74ef252d9e55287e640 100644 (file)
@@ -25,3 +25,4 @@ TEST_F(statestrTest, ClockCodeExists) {
 TEST_F(statestrTest, ClockCodeUnknown) {
        EXPECT_STREQ("clk_-1", ceventstr(-1));
 }
+
diff --git a/tests/libntp/hextoint.c b/tests/libntp/hextoint.c
new file mode 100644 (file)
index 0000000..2744ca5
--- /dev/null
@@ -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));
+}
+
index 811eef626c8f94839f197415627a6b23c7b5ff52..21015348c6143f0430083a9cf0ef7cb125f23475 100644 (file)
@@ -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 (file)
index 0000000..5d21afa
--- /dev/null
@@ -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 (file)
index 0000000..cb13ac1
--- /dev/null
@@ -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 (file)
index 0000000..b91a69d
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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 (file)
index 0000000..a892b9d
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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());
+}
index ab49f716e75409690ed46f45c05c75079cba9d1f..3008310e558f4d960149b223a369e8f9e9841dd2 100644 (file)
@@ -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 (file)
index 0000000..e755c20
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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 (file)
index 0000000..d05dbc9
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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 (file)
index 0000000..44937a5
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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 (file)
index 0000000..ee2fcb0
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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 (file)
index 0000000..52a32d9
--- /dev/null
@@ -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 (file)
index 0000000..f5a601c
--- /dev/null
@@ -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));
+}
+