]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
converted a bunch of test from GTest to Unity in test/libntp/
authorTomek Mrugalski <tomasz@isc.org>
Sun, 14 Jun 2015 22:42:12 +0000 (00:42 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Sun, 14 Jun 2015 22:42:12 +0000 (00:42 +0200)
bk: 557e0344F1CQ4Ig24xMjfGms9T03eg

18 files changed:
tests/libntp/caltontp.c [new file with mode: 0644]
tests/libntp/g_caltontp.cpp [moved from tests/libntp/caltontp.cpp with 100% similarity]
tests/libntp/g_msyslog.cpp [moved from tests/libntp/msyslog.cpp with 100% similarity]
tests/libntp/g_prettydate.cpp [moved from tests/libntp/prettydate.cpp with 100% similarity]
tests/libntp/g_recvbuff.cpp [moved from tests/libntp/recvbuff.cpp with 100% similarity]
tests/libntp/g_tstotv.cpp [moved from tests/libntp/tstotv.cpp with 100% similarity]
tests/libntp/g_vi64ops.cpp [moved from tests/libntp/vi64ops.cpp with 100% similarity]
tests/libntp/msyslog.c [new file with mode: 0644]
tests/libntp/prettydate.c [new file with mode: 0644]
tests/libntp/recvbuff.c [new file with mode: 0644]
tests/libntp/run-test-caltontp.c [new file with mode: 0644]
tests/libntp/run-test-msyslog.c [new file with mode: 0644]
tests/libntp/run-test-prettydate.c [new file with mode: 0644]
tests/libntp/run-test-recvbuff.c [new file with mode: 0644]
tests/libntp/run-test-tstotv.c [new file with mode: 0644]
tests/libntp/run-test-vi64ops.c [new file with mode: 0644]
tests/libntp/tstotv.c [new file with mode: 0644]
tests/libntp/vi64ops.c [new file with mode: 0644]

diff --git a/tests/libntp/caltontp.c b/tests/libntp/caltontp.c
new file mode 100644 (file)
index 0000000..9ce4854
--- /dev/null
@@ -0,0 +1,48 @@
+#include "config.h"
+#include "unity.h"
+#include "ntp_calendar.h"
+
+void
+test_DateGivenMonthDay(void) {
+       // 2010-06-24 12:50:00
+       struct calendar input = {2010, 0, 6, 24, 12, 50, 0};
+
+       u_long expected = 3486372600UL; // This is the timestamp above.
+
+       TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input));
+}
+
+void
+test_DateGivenYearDay(void) {
+       // 2010-06-24 12:50:00
+       // This is the 175th day of 2010.
+       struct calendar input = {2010, 175, 0, 0, 12, 50, 0};
+
+       u_long expected = 3486372600UL; // This is the timestamp above.
+
+       TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input));
+}
+
+void
+test_DateLeapYear(void) {
+       // 2012-06-24 12:00:00
+       // This is the 176th day of 2012 (since 2012 is a leap year).
+       struct calendar inputYd = {2012, 176, 0, 0, 12, 00, 00};
+       struct calendar inputMd = {2012, 0, 6, 24, 12, 00, 00};
+
+       u_long expected = 3549528000UL;
+
+       TEST_ASSERT_EQUAL_UINT(expected, caltontp(&inputYd));
+       TEST_ASSERT_EQUAL_UINT(expected, caltontp(&inputMd));
+}
+
+void
+test_WraparoundDateIn2036(void) {
+       // 2036-02-07 06:28:16
+       // This is (one) wrapping boundary where we go from ULONG_MAX to 0.
+       struct calendar input = {2036, 0, 2, 7, 6, 28, 16};
+
+       u_long expected = 0UL;
+
+       TEST_ASSERT_EQUAL_UINT(expected, caltontp(&input));
+}
diff --git a/tests/libntp/msyslog.c b/tests/libntp/msyslog.c
new file mode 100644 (file)
index 0000000..5e2a1f8
--- /dev/null
@@ -0,0 +1,137 @@
+#include "config.h"
+#include "ntp_stdlib.h"
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include "unity.h"
+
+#ifndef VSNPRINTF_PERCENT_M
+// format_errmsg() is normally private to msyslog.c
+void   format_errmsg   (char *, size_t, const char *, int);
+#endif
+
+
+
+void test_msnprintf(void) {
+#define FMT_PREFIX "msyslog.cpp ENOENT: "
+       char    exp_buf[512];
+       char    act_buf[512];
+       int     exp_cnt;
+       int     act_cnt;
+
+       exp_cnt = snprintf(exp_buf, sizeof(exp_buf), FMT_PREFIX "%s",
+                          strerror(ENOENT));
+       errno = ENOENT;
+       act_cnt = msnprintf(act_buf, sizeof(act_buf), FMT_PREFIX "%m");
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+       TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
+}
+
+void
+test_msnprintfLiteralPercentm(void)
+{
+       char    exp_buf[32];
+       char    act_buf[32];
+       int     exp_cnt;
+       int     act_cnt;
+
+       exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "%%m");
+       errno = ENOENT;
+       act_cnt = msnprintf(act_buf, sizeof(act_buf), "%%m");
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+       TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
+}
+
+void
+test_msnprintfBackslashLiteralPercentm(void) {
+       char    exp_buf[32];
+       char    act_buf[32];
+       int     exp_cnt;
+       int     act_cnt;
+
+       exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "\%%m");
+       errno = ENOENT;
+       act_cnt = msnprintf(act_buf, sizeof(act_buf), "\%%m");
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+       TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
+}
+
+void
+test_msnprintfBackslashPercent(void) {
+       char    exp_buf[32];
+       char    act_buf[32];
+       int     exp_cnt;
+       int     act_cnt;
+
+       exp_cnt = snprintf(exp_buf, sizeof(exp_buf), "\%s",
+                          strerror(ENOENT));
+       errno = ENOENT;
+       act_cnt = msnprintf(act_buf, sizeof(act_buf), "\%m");
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+       TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
+}
+
+void
+test_msnprintfHangingPercent(void) {
+       static char fmt[] = "percent then nul term then non-nul %\0oops!";
+       char exp_buf[64];
+       char act_buf[64];
+       int     exp_cnt;
+       int     act_cnt;
+
+       ZERO(exp_buf);
+       ZERO(act_buf);
+       exp_cnt = snprintf(exp_buf, sizeof(exp_buf), fmt);
+       act_cnt = msnprintf(act_buf, sizeof(act_buf), fmt);
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+       TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
+       TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf));
+}
+
+void
+test_format_errmsgHangingPercent(void) {
+#ifndef VSNPRINTF_PERCENT_M
+       static char fmt[] = "percent then nul term then non-nul %\0oops!";
+       char act_buf[64];
+
+       ZERO(act_buf);
+       format_errmsg(act_buf, sizeof(act_buf), fmt, ENOENT);
+       TEST_ASSERT_EQUAL_STRING(fmt, act_buf);
+       TEST_ASSERT_EQUAL_STRING("", act_buf + 1 + strlen(act_buf));
+#else
+       TEST_IGNORE_MESSAGE("VSNPRINTF_PERCENT_M is defined")
+#endif
+}
+
+void
+test_msnprintfNullTarget(void) {
+       int     exp_cnt;
+       int     act_cnt;
+
+       exp_cnt = snprintf(NULL, 0, "%d", 123);
+       errno = ENOENT;
+       act_cnt = msnprintf(NULL, 0, "%d", 123);
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+}
+
+void
+test_msnprintfTruncate(void) {
+       char    undist[] = "undisturbed";
+       char    exp_buf[512];
+       char    act_buf[512];
+       int     exp_cnt;
+       int     act_cnt;
+
+       memcpy(exp_buf + 3, undist, sizeof(undist));
+       memcpy(act_buf + 3, undist, sizeof(undist));
+       exp_cnt = snprintf(exp_buf, 3, "%s", strerror(ENOENT));
+       errno = ENOENT;
+       act_cnt = msnprintf(act_buf, 3, "%m");
+       TEST_ASSERT_EQUAL('\0', exp_buf[2]);
+       TEST_ASSERT_EQUAL('\0', act_buf[2]);
+       TEST_ASSERT_TRUE(act_cnt > 0);
+       TEST_ASSERT_EQUAL(exp_cnt, act_cnt);
+       TEST_ASSERT_EQUAL_STRING(exp_buf, act_buf);
+       TEST_ASSERT_EQUAL_STRING(exp_buf + 3, undist);
+       TEST_ASSERT_EQUAL_STRING(act_buf + 3, undist);
+}
diff --git a/tests/libntp/prettydate.c b/tests/libntp/prettydate.c
new file mode 100644 (file)
index 0000000..c68dda0
--- /dev/null
@@ -0,0 +1,16 @@
+#include "config.h"
+
+#include "ntp_stdlib.h"
+#include "ntp_calendar.h"
+#include "ntp_fp.h"
+#include "unity.h"
+
+void
+test_ConstantDate(void) {
+       const u_int32 HALF = 2147483648UL;
+
+       l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5
+
+       TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000  Wed, Jun  9 2010 14:00:00.500",
+               gmprettydate(&time));
+}
\ No newline at end of file
diff --git a/tests/libntp/recvbuff.c b/tests/libntp/recvbuff.c
new file mode 100644 (file)
index 0000000..b4bbe2f
--- /dev/null
@@ -0,0 +1,43 @@
+//#include "config.h"
+#include "testcalshims.h"
+#include "recvbuff.h"
+#include "unity.h"
+
+//#include "ntp_stdlib.h"
+//#include "libntptest.h"
+
+void
+setUp(void)
+{
+       init_recvbuff(RECV_INIT);
+}
+
+void
+test_Initialization(void) {
+       TEST_ASSERT_EQUAL_UINT(RECV_INIT, free_recvbuffs());
+       TEST_ASSERT_EQUAL_UINT(0, full_recvbuffs());
+       TEST_ASSERT_FALSE(has_full_recv_buffer());
+       TEST_ASSERT_TRUE(get_full_recv_buffer() == NULL);
+}
+
+void
+test_GetAndFree(void) {
+       u_long initial = free_recvbuffs();
+       recvbuf_t* buf = get_free_recv_buffer();
+
+       TEST_ASSERT_EQUAL_UINT(initial-1, free_recvbuffs());
+       freerecvbuf(buf);
+       TEST_ASSERT_EQUAL_UINT(initial, free_recvbuffs());
+}
+
+
+void
+test_GetAndFill(void) {
+       int initial = free_recvbuffs();
+       recvbuf_t* buf = get_free_recv_buffer();
+
+       add_full_recv_buffer(buf);
+       TEST_ASSERT_EQUAL_UINT(1, full_recvbuffs());
+       TEST_ASSERT_TRUE(has_full_recv_buffer());
+       TEST_ASSERT_EQUAL_PTR(buf, get_full_recv_buffer());
+}
\ No newline at end of file
diff --git a/tests/libntp/run-test-caltontp.c b/tests/libntp/run-test-caltontp.c
new file mode 100644 (file)
index 0000000..b7b6626
--- /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_DateGivenMonthDay(void);
+extern void test_DateGivenYearDay(void);
+extern void test_DateLeapYear(void);
+extern void test_WraparoundDateIn2036(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "caltontp.c";
+  UnityBegin("caltontp.c");
+  RUN_TEST(test_DateGivenMonthDay, 6);
+  RUN_TEST(test_DateGivenYearDay, 16);
+  RUN_TEST(test_DateLeapYear, 27);
+  RUN_TEST(test_WraparoundDateIn2036, 40);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-msyslog.c b/tests/libntp/run-test-msyslog.c
new file mode 100644 (file)
index 0000000..8ec7c24
--- /dev/null
@@ -0,0 +1,65 @@
+/* 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_msnprintf(void);
+extern void test_msnprintfLiteralPercentm(void);
+extern void test_msnprintfBackslashLiteralPercentm(void);
+extern void test_msnprintfBackslashPercent(void);
+extern void test_msnprintfHangingPercent(void);
+extern void test_format_errmsgHangingPercent(void);
+extern void test_msnprintfNullTarget(void);
+extern void test_msnprintfTruncate(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "msyslog.c";
+  UnityBegin("msyslog.c");
+  RUN_TEST(test_msnprintf, 15);
+  RUN_TEST(test_msnprintfLiteralPercentm, 31);
+  RUN_TEST(test_msnprintfBackslashLiteralPercentm, 46);
+  RUN_TEST(test_msnprintfBackslashPercent, 60);
+  RUN_TEST(test_msnprintfHangingPercent, 75);
+  RUN_TEST(test_format_errmsgHangingPercent, 92);
+  RUN_TEST(test_msnprintfNullTarget, 107);
+  RUN_TEST(test_msnprintfTruncate, 118);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-prettydate.c b/tests/libntp/run-test-prettydate.c
new file mode 100644 (file)
index 0000000..cafdad4
--- /dev/null
@@ -0,0 +1,51 @@
+/* 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_ConstantDate(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "prettydate.c";
+  UnityBegin("prettydate.c");
+  RUN_TEST(test_ConstantDate, 9);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-recvbuff.c b/tests/libntp/run-test-recvbuff.c
new file mode 100644 (file)
index 0000000..75adc6b
--- /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_Initialization(void);
+extern void test_GetAndFree(void);
+extern void test_GetAndFill(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "recvbuff.c";
+  UnityBegin("recvbuff.c");
+  RUN_TEST(test_Initialization, 16);
+  RUN_TEST(test_GetAndFree, 24);
+  RUN_TEST(test_GetAndFill, 35);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-tstotv.c b/tests/libntp/run-test-tstotv.c
new file mode 100644 (file)
index 0000000..34807b3
--- /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_Seconds(void);
+extern void test_MicrosecondsExact(void);
+extern void test_MicrosecondsRounding(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "tstotv.c";
+  UnityBegin("tstotv.c");
+  RUN_TEST(test_Seconds, 7);
+  RUN_TEST(test_MicrosecondsExact, 19);
+  RUN_TEST(test_MicrosecondsRounding, 33);
+
+  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..2deae5c
--- /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(void);
+extern void test_ParseVUI64_neg(void);
+extern void test_ParseVUI64_case(void);
+
+
+//=======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, 7);
+  RUN_TEST(test_ParseVUI64_neg, 23);
+  RUN_TEST(test_ParseVUI64_case, 39);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/tstotv.c b/tests/libntp/tstotv.c
new file mode 100644 (file)
index 0000000..87f6ad7
--- /dev/null
@@ -0,0 +1,42 @@
+#include "config.h"
+#include "ntp_fp.h"
+#include "timevalops.h"
+#include "unity.h"
+
+void
+test_Seconds(void) {
+       const l_fp input = {50, 0}; // 50.0 s
+       const struct timeval expected = {50, 0};
+       struct timeval actual;
+
+       TSTOTV(&input, &actual);
+
+       TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
+       TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
+}
+
+void
+test_MicrosecondsExact(void) {
+       const u_long HALF = 2147483648UL;
+       const l_fp input = {50, HALF}; // 50.5 s
+       const struct timeval expected = {50, 500000};
+       struct timeval actual;
+
+       TSTOTV(&input, &actual);
+
+       TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
+       TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
+
+}
+
+void
+test_MicrosecondsRounding(void) {
+       const l_fp input = {50, 3865471UL}; // Should round to 50.0009
+       const struct timeval expected = {50, 900};
+       struct timeval actual;
+
+       TSTOTV(&input, &actual);
+
+       TEST_ASSERT_EQUAL(expected.tv_sec, actual.tv_sec);
+       TEST_ASSERT_EQUAL(expected.tv_usec, actual.tv_usec);
+}
\ No newline at end of file
diff --git a/tests/libntp/vi64ops.c b/tests/libntp/vi64ops.c
new file mode 100644 (file)
index 0000000..f1b492b
--- /dev/null
@@ -0,0 +1,52 @@
+#include "config.h"
+#include "ntp_stdlib.h"
+#include "vint64ops.h"
+#include "unity.h"
+
+void
+test_ParseVUI64_pos(void) {
+       vint64 act, exp;
+       const char *sp;
+       char       *ep;
+
+       sp         = "1234x";
+       exp.D_s.hi = 0;
+       exp.D_s.lo = 1234;
+       act        = strtouv64(sp, &ep, 0);
+
+       TEST_ASSERT_EQUAL_HEX(exp.D_s.hi, act.D_s.hi);
+       TEST_ASSERT_EQUAL_HEX(exp.D_s.lo, act.D_s.lo);
+       TEST_ASSERT_EQUAL(*ep, 'x');
+}
+
+void
+test_ParseVUI64_neg(void) {
+       vint64 act, exp;
+       const char *sp;
+       char       *ep;
+
+       sp         = "-1234x";
+       exp.D_s.hi = ~0;
+       exp.D_s.lo = -1234;
+       act        = strtouv64(sp, &ep, 0);
+
+       TEST_ASSERT_EQUAL_HEX(exp.D_s.hi, act.D_s.hi);
+       TEST_ASSERT_EQUAL_HEX(exp.D_s.lo, act.D_s.lo);
+       TEST_ASSERT_EQUAL(*ep, 'x');
+}
+
+void
+test_ParseVUI64_case(void) {
+       vint64 act, exp;
+       const char *sp;
+       char       *ep;
+
+       sp         = "0123456789AbCdEf";
+       exp.D_s.hi = 0x01234567;
+       exp.D_s.lo = 0x89ABCDEF;
+       act        = strtouv64(sp, &ep, 16);
+
+       TEST_ASSERT_EQUAL_HEX(exp.D_s.hi, act.D_s.hi);
+       TEST_ASSERT_EQUAL_HEX(exp.D_s.lo, act.D_s.lo);
+       TEST_ASSERT_EQUAL(*ep, '\0');
+}