1 #include "config.h"
2 
3 #include "bmc_epoch.hpp"
4 #include "manager.hpp"
5 #include "types.hpp"
6 
7 #include <sdbusplus/bus.hpp>
8 
9 #include <gtest/gtest.h>
10 
11 namespace phosphor
12 {
13 namespace time
14 {
15 
16 class TestBmcEpoch : public testing::Test
17 {
18   public:
19     sdbusplus::bus_t bus;
20     Manager manager;
21     sd_event* event;
22     std::unique_ptr<BmcEpoch> bmcEpoch;
23 
24     TestBmcEpoch() : bus(sdbusplus::bus::new_default()), manager(bus)
25     {
26         // BmcEpoch requires sd_event to init
27         sd_event_default(&event);
28         bus.attach_event(event, SD_EVENT_PRIORITY_NORMAL);
29         bmcEpoch = std::make_unique<BmcEpoch>(bus, objpathBmc, manager);
30     }
31 
32     ~TestBmcEpoch() override
33     {
34         bus.detach_event();
35         sd_event_unref(event);
36     }
37 };
38 
39 TEST_F(TestBmcEpoch, onModeChange)
40 {
41     bmcEpoch->onModeChanged(Mode::NTP);
42     EXPECT_EQ(Mode::NTP, manager.getTimeMode());
43 
44     bmcEpoch->onModeChanged(Mode::Manual);
45     EXPECT_EQ(Mode::Manual, manager.getTimeMode());
46 }
47 
48 TEST_F(TestBmcEpoch, empty)
49 {
50     // Default mode is MANUAL
51     EXPECT_EQ(Mode::Manual, manager.getTimeMode());
52 }
53 
54 TEST_F(TestBmcEpoch, getElapsed)
55 {
56     auto t1 = bmcEpoch->elapsed();
57     EXPECT_NE(0, t1);
58     auto t2 = bmcEpoch->elapsed();
59     EXPECT_GE(t2, t1);
60 }
61 
62 TEST_F(TestBmcEpoch, setElapsedOK)
63 {
64     // TODO: setting time will call sd-bus functions and it will fail on host
65     // if we have gmock for sdbusplus::bus, we can test setElapsed.
66     // But for now we can not test it
67 }
68 
69 } // namespace time
70 } // namespace phosphor
71