blob: 4d9ae735431f6eeeb0858cbdbd122b177c94af3f [file] [log] [blame]
Lei YU415b9642017-02-09 11:37:26 +08001#include <sdbusplus/bus.hpp>
2#include <gtest/gtest.h>
3
4#include "types.hpp"
5#include "manager.hpp"
6
7namespace phosphor
8{
9namespace time
10{
11
12class TestManager : public testing::Test
13{
14 public:
15 sdbusplus::bus::bus bus;
16 Manager manager;
17
18 TestManager()
19 : bus(sdbusplus::bus::new_default()),
20 manager(bus)
21 {
22 // Empty
23 }
24
25 // Proxies for Manager's private members and functions
26 Mode getTimeMode()
27 {
28 return manager.timeMode;
29 }
30 Owner getTimeOwner()
31 {
32 return manager.timeOwner;
33 }
34 Mode convertToMode(const std::string& mode)
35 {
36 return Manager::convertToMode(mode);
37 }
38 Owner convertToOwner(const std::string& owner)
39 {
40 return Manager::convertToOwner(owner);
41 }
42};
43
44TEST_F(TestManager, empty)
45{
46 EXPECT_EQ(Mode::NTP, getTimeMode());
47 EXPECT_EQ(Owner::BMC, getTimeOwner());
48}
49
50TEST_F(TestManager, convertToMode)
51{
52 EXPECT_EQ(Mode::NTP, convertToMode("NTP"));
53 EXPECT_EQ(Mode::MANUAL, convertToMode("MANUAL"));
54
55 // All unrecognized strings are mapped to Ntp
56 EXPECT_EQ(Mode::NTP, convertToMode(""));
57 EXPECT_EQ(Mode::NTP, convertToMode("Manual"));
58 EXPECT_EQ(Mode::NTP, convertToMode("whatever"));
59}
60
61
62TEST_F(TestManager, convertToOwner)
63{
64 EXPECT_EQ(Owner::BMC, convertToOwner("BMC"));
65 EXPECT_EQ(Owner::HOST, convertToOwner("HOST"));
66 EXPECT_EQ(Owner::SPLIT, convertToOwner("SPLIT"));
67 EXPECT_EQ(Owner::BOTH, convertToOwner("BOTH"));
68
69 // All unrecognized strings are mapped to Bmc
70 EXPECT_EQ(Owner::BMC, convertToOwner(""));
71 EXPECT_EQ(Owner::BMC, convertToOwner("Split"));
72 EXPECT_EQ(Owner::BMC, convertToOwner("xyz"));
73}
74
75}
76}