1# -*- coding: utf-8 -*-
2# SPDX-License-Identifier: BSD-2-Clause
3import unittest
4import ntp.ntpc
5
6
7class TestPylibNtpc(unittest.TestCase):
8    lfp_set = [
9        ("0xcfba1ce0.80000000", 1276092000.5,
10         "cfba1ce0.80000000 2010-06-09T14:00:00.500Z"),
11        ("==cfba1ce0.80000000", 1276092000.5,
12         "cfba1ce0.80000000 2010-06-09T14:00:00.500Z"),
13        ]
14
15    def test_statustoa(self):
16        self.assertEqual("leap_add_sec, sync_22, 7 events, no_sys_peer",
17                         ntp.ntpc.statustoa(ntp.ntpc.TYPE_SYS, 0x12345678));
18        self.assertEqual("authenb, reach, sel_sys.peer, 7 events, access_denied",
19                         ntp.ntpc.statustoa(ntp.ntpc.TYPE_PEER, 0x12345678));
20        self.assertEqual("7 events, clk_8",
21                         ntp.ntpc.statustoa(ntp.ntpc.TYPE_CLOCK, 0x12345678));
22
23    def test_lfp(self):
24        for (in_string, to_float, to_string) in self.lfp_set:
25            self.assertEqual(ntp.ntpc.prettydate(in_string), to_string);
26            self.assertAlmostEqual(ntp.ntpc.lfptofloat(in_string), to_float);
27
28
29if __name__ == '__main__':
30    unittest.main()
31