3 #include "ntp_stdlib.h"
7 #include "ntp_unixtime.h"
11 /* Required for Solaris. */
14 void test_ZeroBuffer(void);
15 void test_IntegerAndFractionalBuffer(void);
16 void test_IllegalMicroseconds(void);
17 void test_AlwaysFalseOnWindows(void);
24 const struct timeval input = {0, 0};
25 const l_fp expected = {{0 + JAN_1970}, 0};
29 TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
30 TEST_ASSERT_TRUE(IsEqual(expected, actual));
32 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
40 test_IntegerAndFractionalBuffer(void)
43 const struct timeval input = {5, 500000}; /* 5.5 */
44 const l_fp expected = {{5 + JAN_1970}, HALF};
45 double expectedDouble, actualDouble;
48 TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
50 /* Compare the fractional part with an absolute error given. */
51 TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);
53 M_LFPTOD(0, expected.l_uf, expectedDouble);
54 M_LFPTOD(0, actual.l_uf, actualDouble);
56 /* The error should be less than 0.5 us */
57 TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
59 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
66 test_IllegalMicroseconds(void)
69 const struct timeval input = {0, 1100000}; /* > 999 999 microseconds. */
73 TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual));
75 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
83 test_AlwaysFalseOnWindows(void)
87 * Under Windows, buftvtots will just return
91 TEST_ASSERT_FALSE(buftvtots("", &actual));
93 TEST_IGNORE_MESSAGE("Non-Windows test, skipping...");