]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Makefile.am:
authorDamir Tomic <viperus@ntp.org>
Sat, 13 Jun 2015 22:20:14 +0000 (00:20 +0200)
committerDamir Tomic <viperus@ntp.org>
Sat, 13 Jun 2015 22:20:14 +0000 (00:20 +0200)
  added refnumtoa.c
run-test-vi64ops.c, refnumtoa.c, run-test-refnumtoa.c:
  new file
g_refnumtoa.cpp:
  Rename: tests/libntp/refnumtoa.cpp -> tests/libntp/g_refnumtoa.cpp

bk: 557cac9ekqtxJLDN6fVt22aq15MxkA

tests/libntp/Makefile.am
tests/libntp/g_refnumtoa.cpp [moved from tests/libntp/refnumtoa.cpp with 100% similarity]
tests/libntp/refnumtoa.c [new file with mode: 0644]
tests/libntp/run-test-refnumtoa.c [new file with mode: 0644]
tests/libntp/run-test-vi64ops.c [new file with mode: 0644]

index 4e5e67d019a58165333a6a871ce69ed06e2946df..9bb33fd56189f93d7c7ea662884f62467eadaa9a 100644 (file)
@@ -6,7 +6,8 @@ run_unity =     cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb
 
 #removed test-libntp
 check_PROGRAMS = test-modetoa test-uglydate test-ymd2yd test-statestr test-numtoa test-numtohost \
-test-hextoint test-atoint test-atouint test-authkeys test-a_md5encrypt test-lfpfunc test-vi64ops
+test-hextoint test-atoint test-atouint test-authkeys test-a_md5encrypt test-lfpfunc test-vi64ops \
+test-refnumtoa
 
 if GTEST_AVAILABLE
 check_PROGRAMS += tests
@@ -69,7 +70,7 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp     \
                octtoint.cpp            \
                prettydate.cpp          \
                recvbuff.cpp            \
-               refnumtoa.cpp           \
+               g_refnumtoa.cpp         \
                sfptostr.cpp            \
                socktoa.cpp             \
                ssl_init.cpp            \
@@ -221,6 +222,15 @@ test_vi64ops_LDADD =                       \
        $(unity_tests_LDADD)            \
        $(NULL)
 
+test_refnumtoa_CFLAGS =                  \
+       -I$(top_srcdir)/sntp/unity      \
+       $(NULL)
+
+test_refnumtoa_LDADD =                           \
+       $(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 =                         \
@@ -296,6 +306,10 @@ test_vi64ops_SOURCES =                             \
        run-test-vi64ops.c                      \
        $(NULL)
 
+test_refnumtoa_SOURCES =               \
+       refnumtoa.c                     \
+       run-test-refnumtoa.c                    \
+       $(NULL)
 
 $(srcdir)/run-test-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list)
        $(run_unity) modetoa.c run-test-modetoa.c
@@ -336,6 +350,9 @@ $(srcdir)/run-test-lfpfunc.c: $(srcdir)/lfpfunc.c $(std_unity_list)
 $(srcdir)/run-test-vi64ops.c: $(srcdir)/vi64ops.c $(std_unity_list)
        $(run_unity) vi64ops.c run-test-vi64ops.c
 
+$(srcdir)/run-test-refnumtoa.c: $(srcdir)/refnumtoa.c $(std_unity_list)
+       $(run_unity) refnumtoa.c run-test-refnumtoa.c
+
 
 TESTS =
 
diff --git a/tests/libntp/refnumtoa.c b/tests/libntp/refnumtoa.c
new file mode 100644 (file)
index 0000000..164b224
--- /dev/null
@@ -0,0 +1,63 @@
+#include "config.h"
+#include "ntp_net.h"
+#include "ntp_refclock.h"
+
+#include "unity.h"
+
+
+/* Might need to be updated if a new refclock gets this id. */
+static const int UNUSED_REFCLOCK_ID = 250;
+
+
+void test_LocalClock() {
+#ifdef REFCLOCK                /* clockname() is useless otherwise */
+       /* We test with a refclock address of type LOCALCLOCK.
+        * with id 8
+        */
+       u_int32 addr = REFCLOCK_ADDR;
+       addr |= REFCLK_LOCALCLOCK << 8;
+       addr |= 0x8;
+
+       sockaddr_u address;
+       address.sa4.sin_family = AF_INET;
+       address.sa4.sin_addr.s_addr = htonl(addr);
+       
+       char stringStart [100]= "";
+
+       strcat(stringStart,clockname(REFCLK_LOCALCLOCK));
+       strcat(stringStart,"(8)");
+
+       char * expected = stringStart;
+
+       TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
+#else  
+       TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
+#endif /* REFCLOCK */
+}
+
+
+
+void test_UnknownId() {
+#ifdef REFCLOCK                /* refnumtoa() is useless otherwise */
+       /* We test with a currently unused refclock ID */
+       u_int32 addr = REFCLOCK_ADDR;
+       addr |= UNUSED_REFCLOCK_ID << 8;
+       addr |= 0x4;
+
+       sockaddr_u address;
+       address.sa4.sin_family = AF_INET;
+       address.sa4.sin_addr.s_addr = htonl(addr);
+       
+       char stringStart [100]= "REFCLK(";
+       char value [100] ;      
+       snprintf(value, sizeof(value), "%d", UNUSED_REFCLOCK_ID);
+       strcat(stringStart,value);
+       strcat(stringStart,",4)");
+       char * expected = stringStart;
+
+       TEST_ASSERT_EQUAL_STRING(expected, refnumtoa(&address));
+#else  
+       TEST_IGNORE_MESSAGE("REFCLOCK NOT DEFINED, SKIPPING TEST");
+#endif /* REFCLOCK */
+}
+
diff --git a/tests/libntp/run-test-refnumtoa.c b/tests/libntp/run-test-refnumtoa.c
new file mode 100644 (file)
index 0000000..3354da8
--- /dev/null
@@ -0,0 +1,53 @@
+/* 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_LocalClock();
+extern void test_UnknownId();
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+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);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-vi64ops.c b/tests/libntp/run-test-vi64ops.c
new file mode 100644 (file)
index 0000000..c11e47f
--- /dev/null
@@ -0,0 +1,55 @@
+/* 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_ParseVUI64_pos();
+extern void test_ParseVUI64_neg();
+extern void test_ParseVUI64_case();
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "vi64ops.c";
+  UnityBegin("vi64ops.c");
+  RUN_TEST(test_ParseVUI64_pos, 33);
+  RUN_TEST(test_ParseVUI64_neg, 47);
+  RUN_TEST(test_ParseVUI64_case, 60);
+
+  return (UnityEnd());
+}