numtoa.cpp \
numtohost.cpp \
octtoint.cpp \
+ prettydate.cpp \
+ refnumtoa.cpp \
sfptostr.cpp \
socktoa.cpp \
ssl_init.cpp \
strtolfp.cpp \
- uinttoa.cpp
+ uglydate.cpp \
+ uinttoa.cpp \
+ ymd2yd.cpp
+
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \
-I$(top_srcdir)/lib/isc/nothreads/include \
--- /dev/null
+#include "libntptest.h"
+
+extern "C" {
+#include "ntp_fp.h"
+};
+
+class prettydateTest : public libntptest {
+protected:
+ static const int HALF = -2147483648L;
+};
+
+TEST_F(prettydateTest, ConstantDate) {
+ l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5
+
+ ASSERT_STREQ("cfba1ce0.80000000 Wed, Jun 9 2010 14:00:00.500", gmprettydate(&time));
+}
+
+TEST_F(prettydateTest, ) {
+
+}
--- /dev/null
+#include "libntptest.h"
+
+#include "ntp_net.h"
+#include "ntp_refclock.h"
+
+#include <sstream>
+
+class refnumtoaTest : public libntptest {
+protected:
+ /* Might need to be updated if a new refclock gets this id. */
+ static const int UNUSED_REFCLOCK_ID = 250;
+};
+
+TEST_F(refnumtoaTest, LocalClock) {
+ /* We test with a refclock address of type LOCALCLOCK.
+ * with id 8
+ */
+ u_int32 addr = REFCLOCK_ADDR;
+ addr |= REFCLK_LOCALCLOCK << 8;
+ addr |= 0x8;
+
+ sockaddr_u address;
+ address.sa4.sin_family = AF_INET;
+ address.sa4.sin_addr.s_addr = htonl(addr);
+
+ std::ostringstream expected;
+ expected << clockname(REFCLK_LOCALCLOCK)
+ << "(8)";
+
+ EXPECT_STREQ(expected.str().c_str(), refnumtoa(&address));
+}
+
+TEST_F(refnumtoaTest, UnknownId) {
+ /* We test with a currently unused refclock ID */
+ u_int32 addr = REFCLOCK_ADDR;
+ addr |= UNUSED_REFCLOCK_ID << 8;
+ addr |= 0x4;
+
+ sockaddr_u address;
+ address.sa4.sin_family = AF_INET;
+ address.sa4.sin_addr.s_addr = htonl(addr);
+
+ std::ostringstream expected;
+ expected << "REFCLK(" << UNUSED_REFCLOCK_ID
+ << ",4)";
+
+ EXPECT_STREQ(expected.str().c_str(), refnumtoa(&address));
+}
--- /dev/null
+#include "libntptest.h"
+
+extern "C" {
+#include "ntp_fp.h"
+};
+
+class uglydateTest : public libntptest {
+protected:
+ static const int HALF = -2147483648L;
+};
+
+TEST_F(uglydateTest, ConstantDateTime) {
+ l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5
+
+ EXPECT_STREQ("3485080800.500000 10:159:14:00:00.500",
+ uglydate(&time));
+}
+
--- /dev/null
+#include "libntptest.h"
+
+class ymd2ydTest : public libntptest {
+};
+
+TEST_F(ymd2ydTest, NonLeapYearFebruary) {
+ EXPECT_EQ(31+20, ymd2yd(2010,2,20)); //2010-02-20
+}
+
+TEST_F(ymd2ydTest, NonLeapYearJune) {
+ int expected = 31+28+31+30+31+18; // 18 June non-leap year
+ EXPECT_EQ(expected, ymd2yd(2011,6,18));
+}
+
+TEST_F(ymd2ydTest, LeapYearFebruary) {
+ EXPECT_EQ(31+20, ymd2yd(2012,2,20)); //2012-02-20 (leap year)
+}
+
+TEST_F(ymd2ydTest, LeapYearDecember) {
+ // 2012-12-31
+ int expected = 31+29+31+30+31+30+31+31+30+31+30+31;
+ EXPECT_EQ(expected, ymd2yd(2012,12,31));
+}