test-atoint \
test-atouint \
test-authkeys \
+ test-buftvtots \
test-calendar \
test-caljulian \
test-caltontp \
test-recvbuff \
test-refnumtoa \
test-sfptostr \
- test-ssl_init \
test-socktoa \
+ test-ssl_init \
test-statestr \
test-strtolfp \
test-timespecops \
g_statestr.cpp \
g_strtolfp.cpp \
g_timespecops.cpp \
- g_timestructs.cpp \
+ g_timestructs.cpp \
g_timevalops.cpp \
g_tstotv.cpp \
g_tvtots.cpp \
$(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 \
$(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 \
$(srcdir)/run-uglydate.c \
$(srcdir)/run-vi64ops.c \
$(srcdir)/run-ymd2yd.c \
- $(srcdir)/run-calendar.c \
$(NULL)
noinst_HEADERS = \
$(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 \
run-sfptostr.c \
$(NULL)
-test_humandate_SOURCES = \
+test_humandate_SOURCES = \
humandate.c \
run-humandate.c \
$(NULL)
run-msyslog.c \
$(NULL)
-test_prettydate_SOURCES = \
+test_prettydate_SOURCES = \
prettydate.c \
- run-prettydate.c \
+ run-prettydate.c \
$(NULL)
test_recvbuff_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
$(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 =
--- /dev/null
+#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
+}
+
--- /dev/null
+/* 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());
+}