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);
21 test_ZeroBuffer(void) {
23 const struct timeval input = {0, 0};
24 const l_fp expected = {{0 + JAN_1970}, 0};
28 TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
29 TEST_ASSERT_TRUE(IsEqual(expected, actual));
31 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
36 test_IntegerAndFractionalBuffer(void) {
38 const struct timeval input = {5, 500000}; /* 5.5 */
39 const l_fp expected = {{5 + JAN_1970}, HALF};
40 double expectedDouble, actualDouble;
43 TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
45 /* Compare the fractional part with an absolute error given. */
46 TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);
48 M_LFPTOD(0, expected.l_uf, expectedDouble);
49 M_LFPTOD(0, actual.l_uf, actualDouble);
51 /* The error should be less than 0.5 us */
52 TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
54 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
59 test_IllegalMicroseconds(void) {
61 const struct timeval input = {0, 1100000}; /* > 999 999 microseconds. */
65 TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual));
67 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
73 test_AlwaysFalseOnWindows(void) {
76 * Under Windows, buftvtots will just return
80 TEST_ASSERT_FALSE(buftvtots("", &actual));
82 TEST_IGNORE_MESSAGE("Non-Windows test, skipping...");