4 #include "timevalops.h"
8 #include <math.h> /* Required on Solaris for ldexp. */
10 void test_Seconds(void);
11 void test_MicrosecondsRounded(void);
12 void test_MicrosecondsExact(void);
17 struct timeval input = {500, 0}; /* 500.0 s */
18 l_fp expected = {{500}, 0};
21 TVTOTS(&input, &actual);
23 TEST_ASSERT_TRUE(IsEqual(expected, actual));
28 test_MicrosecondsRounded(void)
30 /* 0.0005 can not be represented exact in a l_fp structure.
31 * It would equal to 2147483,648. This means that
32 * HALF_PROMILLE_UP (which is 2147484) should be
33 * the correct rounding. */
35 struct timeval input = {0, 500}; /* 0.0005 exact */
36 l_fp expected = {{0}, HALF_PROMILLE_UP};
39 TVTOTS(&input, &actual);
41 TEST_ASSERT_TRUE(IsEqual(expected, actual));
46 test_MicrosecondsExact(void)
48 /* 0.5 can be represented exact in both l_fp and timeval. */
49 const struct timeval input = {10, 500000}; /* 0.5 exact */
50 const l_fp expected = {{10}, HALF}; /* 0.5 exact */
53 TVTOTS(&input, &actual);
55 /* Compare the fractional part with an absolute error given. */
56 TEST_ASSERT_EQUAL_UINT(expected.l_ui, actual.l_ui);
58 double expectedDouble, actualDouble;
59 M_LFPTOD(0, expected.l_uf, expectedDouble);
60 M_LFPTOD(0, actual.l_uf, actualDouble);
62 /* The error should be less than 0.5 us */
63 TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);