]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
run-buftvtots.c, buftvtots.c:
authorDamir Tomic <viperus@ntp.org>
Sat, 20 Jun 2015 07:19:13 +0000 (09:19 +0200)
committerDamir Tomic <viperus@ntp.org>
Sat, 20 Jun 2015 07:19:13 +0000 (09:19 +0200)
  new file
Makefile.am:
  minor fix to the alphabetic list
  added buftvtots

bk: 558513f15OMFHkaDi8yN4KGMIT3lDQ

tests/libntp/Makefile.am
tests/libntp/buftvtots.c [new file with mode: 0644]
tests/libntp/run-buftvtots.c [new file with mode: 0644]

index 656351c56cc8c72e0e5449b3649af3f52de21559..c7d1b9e147357618cf0768922dd45a7c69036888 100644 (file)
@@ -10,6 +10,7 @@ check_PROGRAMS =              \
        test-atoint             \
        test-atouint            \
        test-authkeys           \
+       test-buftvtots          \
        test-calendar           \
        test-caljulian          \
        test-caltontp           \
@@ -31,8 +32,8 @@ check_PROGRAMS =              \
        test-recvbuff           \
        test-refnumtoa          \
        test-sfptostr           \
-       test-ssl_init           \
        test-socktoa            \
+       test-ssl_init           \
        test-statestr           \
        test-strtolfp           \
        test-timespecops        \
@@ -113,7 +114,7 @@ tests_SOURCES =                                     \
        g_statestr.cpp          \
        g_strtolfp.cpp          \
        g_timespecops.cpp       \
-       g_timestructs.cpp               \
+       g_timestructs.cpp       \
        g_timevalops.cpp        \
        g_tstotv.cpp            \
        g_tvtots.cpp            \
@@ -127,8 +128,10 @@ BUILT_SOURCES +=                   \
        $(srcdir)/run-atoint.c          \
        $(srcdir)/run-atouint.c         \
        $(srcdir)/run-authkeys.c        \
+       $(srcdir)/run-buftvtots.c       \
+       $(srcdir)/run-calendar.c        \
        $(srcdir)/run-caljulian.c       \
-       $(srcdir)/run-caltontp.c
+       $(srcdir)/run-caltontp.c        \
        $(srcdir)/run-calyearstart.c    \
        $(srcdir)/run-clocktime.c       \
        $(srcdir)/run-decodenetnum.c    \
@@ -147,8 +150,8 @@ BUILT_SOURCES +=                    \
        $(srcdir)/run-recvbuff.c        \
        $(srcdir)/run-refnumtoa.c       \
        $(srcdir)/run-sfptostr.c        \
-       $(srcdir)/run-ssl_init.c        \
        $(srcdir)/run-socktoa.c         \
+       $(srcdir)/run-ssl_init.c        \
        $(srcdir)/run-statestr.c        \
        $(srcdir)/run-strtolfp.c        \
        $(srcdir)/run-timevalops.c      \
@@ -158,7 +161,6 @@ BUILT_SOURCES +=                    \
        $(srcdir)/run-uglydate.c        \
        $(srcdir)/run-vi64ops.c         \
        $(srcdir)/run-ymd2yd.c          \
-       $(srcdir)/run-calendar.c        \
        $(NULL)
 
 noinst_HEADERS =       \
@@ -498,6 +500,16 @@ test_tstotv_LDADD =                        \
        $(top_builddir)/sntp/unity/libunity.a   \
        $(NULL)
 
+test_buftvtots_CFLAGS =                        \
+       -I$(top_srcdir)/sntp/unity      \
+       -DUNITY_INCLUDE_DOUBLE          \
+       $(NULL)
+
+test_buftvtots_LDADD =                         \
+       $(LDADD)                                \
+       $(top_builddir)/sntp/unity/libunity.a   \
+       $(NULL)
+
 
 test_modetoa_SOURCES =                 \
        modetoa.c                       \
@@ -653,7 +665,7 @@ test_sfptostr_SOURCES =                     \
        run-sfptostr.c                  \
        $(NULL)
 
-test_humandate_SOURCES =                       \
+test_humandate_SOURCES =               \
        humandate.c                     \
        run-humandate.c                 \
        $(NULL)
@@ -668,9 +680,9 @@ test_msyslog_SOURCES =                      \
        run-msyslog.c                   \
        $(NULL)
 
-test_prettydate_SOURCES =                      \
+test_prettydate_SOURCES =              \
        prettydate.c                    \
-       run-prettydate.c                        \
+       run-prettydate.c                \
        $(NULL)
 
 test_recvbuff_SOURCES =                        \
@@ -683,6 +695,12 @@ test_tstotv_SOURCES =                      \
        run-tstotv.c                    \
        $(NULL)
 
+test_buftvtots_SOURCES =               \
+       buftvtots.c                     \
+       run-buftvtots.c                 \
+       $(NULL)
+
+
 $(srcdir)/run-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list)
        $(run_unity) modetoa.c run-modetoa.c
 
@@ -791,6 +809,8 @@ $(srcdir)/run-recvbuff.c: $(srcdir)/recvbuff.c $(std_unity_list)
 $(srcdir)/run-tstotv.c: $(srcdir)/tstotv.c $(std_unity_list)
        $(run_unity) tstotv.c run-tstotv.c
 
+$(srcdir)/run-buftvtots.c: $(srcdir)/buftvtots.c $(std_unity_list)
+       $(run_unity) buftvtots.c run-buftvtots.c
 
 TESTS =
 
diff --git a/tests/libntp/buftvtots.c b/tests/libntp/buftvtots.c
new file mode 100644 (file)
index 0000000..edeedf6
--- /dev/null
@@ -0,0 +1,78 @@
+#include "config.h"
+#include "ntp_types.h"
+#include "ntp_stdlib.h"
+
+#include "lfptest.h"
+
+#include "ntp_unixtime.h"
+
+#include "unity.h"
+
+// Required for Solaris.
+#include <math.h>
+
+
+
+void test_ZeroBuffer() {
+#ifndef SYS_WINNT
+       const struct timeval input = {0, 0};
+       const l_fp expected = {0 + JAN_1970, 0};
+
+       l_fp actual;
+
+       TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
+       TEST_ASSERT_TRUE(IsEqual(expected, actual));
+#else
+       TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
+#endif
+}
+
+void test_IntegerAndFractionalBuffer() {
+#ifndef SYS_WINNT
+       const struct timeval input = {5, 500000}; // 5.5
+       const l_fp expected = {5 + JAN_1970, HALF};
+
+       l_fp actual;
+
+       TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
+
+       // Compare the fractional part with an absolute error given.
+       TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);
+
+       double expectedDouble, actualDouble;
+       M_LFPTOD(0, expected.l_uf, expectedDouble);
+       M_LFPTOD(0, actual.l_uf, actualDouble);
+
+       // The error should be less than 0.5 us
+       TEST_ASSERT_DOUBLE_WITHIN(0.0000005,expectedDouble,actualDouble);  //delta,epected,actual //_EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
+#else
+       TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
+#endif
+}
+
+void test_IllegalMicroseconds() {
+#ifndef SYS_WINNT
+       const struct timeval input = {0, 1100000}; // > 999 999 microseconds.
+       
+       l_fp actual;
+
+       TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual));
+#else
+       TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
+#endif
+}
+
+
+void test_AlwaysFalseOnWindows() {
+#ifdef SYS_WINNT
+       /*
+        * Under Windows, buftvtots will just return
+        * 0 (false).
+        */
+       l_fp actual;
+       TEST_ASSERT_FALSE(buftvtots("", &actual));
+#else
+       TEST_IGNORE_MESSAGE("Non-Windows test, skipping...");
+#endif
+}
+
diff --git a/tests/libntp/run-buftvtots.c b/tests/libntp/run-buftvtots.c
new file mode 100644 (file)
index 0000000..c54c339
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_ZeroBuffer();
+extern void test_IntegerAndFractionalBuffer();
+extern void test_IllegalMicroseconds();
+extern void test_AlwaysFalseOnWindows();
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "buftvtots.c";
+  UnityBegin("buftvtots.c");
+  RUN_TEST(test_ZeroBuffer, 16);
+  RUN_TEST(test_IntegerAndFractionalBuffer, 30);
+  RUN_TEST(test_IllegalMicroseconds, 53);
+  RUN_TEST(test_AlwaysFalseOnWindows, 66);
+
+  return (UnityEnd());
+}