test-statestr \
test-timespecops \
test-timevalops \
+ test-tvtots \
test-uglydate \
test-vi64ops \
test-ymd2yd \
timestructs.cpp \
g_timevalops.cpp \
tstotv.cpp \
- tvtots.cpp \
+ g_tvtots.cpp \
g_uglydate.cpp \
g_vi64ops.cpp \
g_ymd2yd.cpp \
$(srcdir)/run-statestr.c \
$(srcdir)/run-timevalops.c \
$(srcdir)/run-timespecops.c \
+ $(srcdir)/run-tvtots.c \
$(srcdir)/run-uglydate.c \
$(srcdir)/run-vi64ops.c \
$(srcdir)/run-ymd2yd.c \
$(top_builddir)/sntp/unity/libunity.a \
$(NULL)
+test_tvtots_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ -DUNITY_INCLUDE_DOUBLE \
+ $(NULL)
+
+test_tvtots_LDADD = \
+ $(LDADD) \
+ $(top_builddir)/sntp/unity/libunity.a \
+ $(NULL)
+
+
test_modetoa_SOURCES = \
modetoa.c \
run-ssl_init.c \
$(NULL)
+test_tvtots_SOURCES = \
+ tvtots.c \
+ run-tvtots.c \
+ $(NULL)
$(srcdir)/run-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list)
$(run_unity) modetoa.c run-modetoa.c
$(srcdir)/run-ssl_init.c: $(srcdir)/ssl_init.c $(std_unity_list)
$(run_unity) ssl_init.c run-ssl_init.c
+$(srcdir)/run-tvtots.c: $(srcdir)/tvtots.c $(std_unity_list)
+ $(run_unity) tvtots.c run-tvtots.c
+
TESTS =
if !NTP_CROSSCOMPILE
--- /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_Seconds(void);
+extern void test_MicrosecondsRounded(void);
+extern void test_MicrosecondsExact(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+ progname = argv[0];
+ Unity.TestFile = "tvtots.c";
+ UnityBegin("tvtots.c");
+ RUN_TEST(test_Seconds, 9);
+ RUN_TEST(test_MicrosecondsRounded, 20);
+ RUN_TEST(test_MicrosecondsExact, 35);
+
+ return (UnityEnd());
+}
--- /dev/null
+#include "config.h"
+#include "c_lfptest.h"
+#include "timevalops.h"
+#include "unity.h"
+#include <math.h>// Required on Solaris for ldexp.
+
+
+
+void test_Seconds(void)
+{
+ struct timeval input = {500, 0}; // 500.0 s
+ l_fp expected = {500, 0};
+ l_fp actual;
+
+ TVTOTS(&input, &actual);
+
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+}
+
+void test_MicrosecondsRounded(void)
+{
+ /* 0.0005 can not be represented exact in a l_fp structure.
+ * It would equal to 2147483,648. This means that
+ * HALF_PROMILLE_UP (which is 2147484) should be
+ * the correct rounding. */
+
+ struct timeval input = {0, 500}; // 0.0005 exact
+ l_fp expected = {0, HALF_PROMILLE_UP};
+ l_fp actual;
+
+ TVTOTS(&input, &actual);
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+}
+
+void test_MicrosecondsExact(void)
+{
+ // 0.5 can be represented exact in both l_fp and timeval.
+ const struct timeval input = {10, 500000}; // 0.5 exact
+ const l_fp expected = {10, HALF}; // 0.5 exact
+ l_fp actual;
+
+ TVTOTS(&input, &actual);
+
+ // Compare the fractional part with an absolute error given.
+ TEST_ASSERT_EQUAL_UINT(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(0000005, expectedDouble, actualDouble);
+}