diff options
Diffstat (limited to 'contrib/ntp/tests/libntp/tstotv.c')
-rw-r--r-- | contrib/ntp/tests/libntp/tstotv.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/contrib/ntp/tests/libntp/tstotv.c b/contrib/ntp/tests/libntp/tstotv.c new file mode 100644 index 0000000..0801727 --- /dev/null +++ b/contrib/ntp/tests/libntp/tstotv.c @@ -0,0 +1,44 @@ +#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); +} |