4 #include "timevalops.h"
7 // Required on Solaris for ldexp.
10 class tvtotsTest : public lfptest {
13 TEST_F(tvtotsTest, Seconds) {
14 timeval input = {500, 0}; // 500.0 s
15 l_fp expected = {500, 0};
18 TVTOTS(&input, &actual);
20 EXPECT_TRUE(IsEqual(expected, actual));
23 TEST_F(tvtotsTest, MicrosecondsRounded) {
24 /* 0.0005 can not be represented exact in a l_fp structure.
25 * It would equal to 2147483,648. This means that
26 * HALF_PROMILLE_UP (which is 2147484) should be
27 * the correct rounding. */
29 timeval input = {0, 500}; // 0.0005 exact
30 l_fp expected = {0, HALF_PROMILLE_UP};
33 TVTOTS(&input, &actual);
34 EXPECT_TRUE(IsEqual(expected, actual));
37 TEST_F(tvtotsTest, MicrosecondsExact) {
38 // 0.5 can be represented exact in both l_fp and timeval.
39 const timeval input = {10, 500000}; // 0.5 exact
40 const l_fp expected = {10, HALF}; // 0.5 exact
43 TVTOTS(&input, &actual);
45 // Compare the fractional part with an absolute error given.
46 EXPECT_EQ(expected.l_ui, actual.l_ui);
48 double expectedDouble, actualDouble;
49 M_LFPTOD(0, expected.l_uf, expectedDouble);
50 M_LFPTOD(0, actual.l_uf, actualDouble);
52 // The error should be less than 0.5 us
53 EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);