xref: /openbmc/phosphor-time-manager/test/TestManager.cpp (revision b99426b6b398f0cc5a650af76d663f86b1cee4ec)
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 namespace phosphor
10 {
11 namespace time
12 {
13 
14 class TestManager : public testing::Test
15 {
16   public:
17     sdbusplus::bus_t bus;
18     Manager manager;
19 
20     TestManager() : bus(sdbusplus::bus::new_default()), manager(bus)
21     {}
22 
23     void notifyPropertyChanged(const std::string& key, const std::string& value)
24     {
25         manager.onPropertyChanged(key, value);
26     }
27 };
28 
29 TEST_F(TestManager, propertyChanged)
30 {
31     notifyPropertyChanged(
32         "TimeSyncMethod",
33         "xyz.openbmc_project.Time.Synchronization.Method.Manual");
34     EXPECT_EQ(Mode::Manual, manager.getTimeMode());
35 
36     notifyPropertyChanged(
37         "TimeSyncMethod",
38         "xyz.openbmc_project.Time.Synchronization.Method.NTP");
39     EXPECT_EQ(Mode::NTP, manager.getTimeMode());
40 
41     ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
42 }
43 
44 } // namespace time
45 } // namespace phosphor
46