--- /dev/null
+#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));
+}
--- /dev/null
+#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);
+}
--- /dev/null
+#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
--- /dev/null
+//#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
--- /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_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());
+}
--- /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_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());
+}
--- /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_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());
+}
--- /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_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());
+}
--- /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_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());
+}
--- /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_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());
+}
--- /dev/null
+#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
--- /dev/null
+#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');
+}