1 #include "manager.hpp"
2 #include "mocked_property_change_listener.hpp"
3 #include "types.hpp"
4 
5 #include <sdbusplus/bus.hpp>
6 
7 #include <gtest/gtest.h>
8 
9 using ::testing::_;
10 
11 namespace phosphor
12 {
13 namespace time
14 {
15 
16 class TestManager : public testing::Test
17 {
18   public:
19     sdbusplus::bus_t bus;
20     Manager manager;
21 
22     TestManager() : bus(sdbusplus::bus::new_default()), manager(bus)
23     {}
24 
25     // Proxies for Manager's private members and functions
26     Mode getTimeMode()
27     {
28         return manager.timeMode;
29     }
30     void notifyPropertyChanged(const std::string& key, const std::string& value)
31     {
32         manager.onPropertyChanged(key, value);
33     }
34 };
35 
36 TEST_F(TestManager, propertyChanged)
37 {
38     notifyPropertyChanged(
39         "TimeSyncMethod",
40         "xyz.openbmc_project.Time.Synchronization.Method.Manual");
41     EXPECT_EQ(Mode::Manual, getTimeMode());
42 
43     notifyPropertyChanged(
44         "TimeSyncMethod",
45         "xyz.openbmc_project.Time.Synchronization.Method.NTP");
46     EXPECT_EQ(Mode::NTP, getTimeMode());
47 
48     ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
49 }
50 
51 } // namespace time
52 } // namespace phosphor
53