4 #include "ntp_unixtime.h"
7 // Required for Solaris.
10 class buftvtotsTest : public lfptest {
14 TEST_F(buftvtotsTest, ZeroBuffer) {
15 const timeval input = {0, 0};
16 const l_fp expected = {0 + JAN_1970, 0};
20 ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
21 EXPECT_TRUE(IsEqual(expected, actual));
24 TEST_F(buftvtotsTest, IntegerAndFractionalBuffer) {
25 const timeval input = {5, 500000}; // 5.5
26 const l_fp expected = {5 + JAN_1970, HALF};
30 ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
32 // Compare the fractional part with an absolute error given.
33 EXPECT_EQ(expected.l_ui, actual.l_ui);
35 double expectedDouble, actualDouble;
36 M_LFPTOD(0, expected.l_uf, expectedDouble);
37 M_LFPTOD(0, actual.l_uf, actualDouble);
39 // The error should be less than 0.5 us
40 EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
43 TEST_F(buftvtotsTest, IllegalMicroseconds) {
44 const timeval input = {0, 1100000}; // > 999 999 microseconds.
48 ASSERT_FALSE(buftvtots((const char*)(&input), &actual));
52 TEST_F(buftvtotsTest, AlwaysFalseOnWindows) {
54 * Under Windows, buftvtots will just return
58 ASSERT_FALSE(buftvtots("", &actual));