From 5384a936451a2414b69f11b7b6f46eb2370efef0 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 5 Dec 2017 10:14:19 +0100 Subject: [PATCH] test: extend util unit test --- test/unit/util.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/unit/util.c b/test/unit/util.c index 17f0c28..096c3ff 100644 --- a/test/unit/util.c +++ b/test/unit/util.c @@ -4,6 +4,7 @@ void test_unit(void) { NTP_int64 ntp_ts, ntp_fuzz; struct timespec ts, ts2; + struct timeval tv; struct sockaddr_un sun; double x, y; Float f; @@ -40,6 +41,32 @@ void test_unit(void) { TEST_CHECK(UTI_DoubleToNtp32(1000000) == htonl(0xffffffff)); TEST_CHECK(UTI_DoubleToNtp32(-1.0) == htonl(0)); + UTI_DoubleToTimeval(0.4e-6, &tv); + TEST_CHECK(tv.tv_sec == 0); + TEST_CHECK(tv.tv_usec == 0); + UTI_DoubleToTimeval(-0.4e-6, &tv); + TEST_CHECK(tv.tv_sec == 0); + TEST_CHECK(tv.tv_usec == 0); + UTI_DoubleToTimeval(0.5e-6, &tv); + TEST_CHECK(tv.tv_sec == 0); + TEST_CHECK(tv.tv_usec == 1); + UTI_DoubleToTimeval(-0.5e-6, &tv); + TEST_CHECK(tv.tv_sec == -1); + TEST_CHECK(tv.tv_usec == 999999); + + UTI_DoubleToTimespec(0.9e-9, &ts); + TEST_CHECK(ts.tv_sec == 0); + TEST_CHECK(ts.tv_nsec == 0); + UTI_DoubleToTimespec(1.0e-9, &ts); + TEST_CHECK(ts.tv_sec == 0); + TEST_CHECK(ts.tv_nsec == 1); + UTI_DoubleToTimespec(-0.9e-9, &ts); + TEST_CHECK(ts.tv_sec == 0); + TEST_CHECK(ts.tv_nsec == 0); + UTI_DoubleToTimespec(-1.0e-9, &ts); + TEST_CHECK(ts.tv_sec == -1); + TEST_CHECK(ts.tv_nsec == 999999999); + ntp_ts.hi = htonl(JAN_1970); ntp_ts.lo = 0xffffffff; UTI_Ntp64ToTimespec(&ntp_ts, &ts);