3 #include "ntp_stdlib.h"
7 #include "ntp_unixtime.h"
11 // Required for Solaris.
16 void test_ZeroBuffer() {
18 const struct timeval input = {0, 0};
19 const l_fp expected = {0 + JAN_1970, 0};
23 TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
24 TEST_ASSERT_TRUE(IsEqual(expected, actual));
26 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
30 void test_IntegerAndFractionalBuffer() {
32 const struct timeval input = {5, 500000}; // 5.5
33 const l_fp expected = {5 + JAN_1970, HALF};
37 TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
39 // Compare the fractional part with an absolute error given.
40 TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);
42 double expectedDouble, actualDouble;
43 M_LFPTOD(0, expected.l_uf, expectedDouble);
44 M_LFPTOD(0, actual.l_uf, actualDouble);
46 // The error should be less than 0.5 us
47 TEST_ASSERT_DOUBLE_WITHIN(0.0000005,expectedDouble,actualDouble); //delta,epected,actual //_EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
49 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
53 void test_IllegalMicroseconds() {
55 const struct timeval input = {0, 1100000}; // > 999 999 microseconds.
59 TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual));
61 TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
66 void test_AlwaysFalseOnWindows() {
69 * Under Windows, buftvtots will just return
73 TEST_ASSERT_FALSE(buftvtots("", &actual));
75 TEST_IGNORE_MESSAGE("Non-Windows test, skipping...");