xref: /openbmc/phosphor-time-manager/test/TestManager.cpp (revision ea220361b8da915b093a98aa3ad19061b6c2ef88)
1415b964fSLei YU #include "manager.hpp"
2a5003cebSLei YU #include "mocked_property_change_listener.hpp"
3ab4cc6a5SGunnar Mills #include "types.hpp"
4ab4cc6a5SGunnar Mills 
5ab4cc6a5SGunnar Mills #include <sdbusplus/bus.hpp>
6ab4cc6a5SGunnar Mills 
7ab4cc6a5SGunnar Mills #include <gtest/gtest.h>
8a5003cebSLei YU 
9415b964fSLei YU namespace phosphor
10415b964fSLei YU {
11415b964fSLei YU namespace time
12415b964fSLei YU {
13415b964fSLei YU 
14415b964fSLei YU class TestManager : public testing::Test
15415b964fSLei YU {
16415b964fSLei YU   public:
1738679266SPatrick Williams     sdbusplus::bus_t bus;
18415b964fSLei YU     Manager manager;
19415b964fSLei YU 
TestManager()20*ea220361SPatrick Williams     TestManager() : bus(sdbusplus::bus::new_default()), manager(bus) {}
21415b964fSLei YU 
notifyPropertyChanged(const std::string & key,const std::string & value)22ab4cc6a5SGunnar Mills     void notifyPropertyChanged(const std::string& key, const std::string& value)
237f4fca55SLei YU     {
247f4fca55SLei YU         manager.onPropertyChanged(key, value);
257f4fca55SLei YU     }
26415b964fSLei YU };
27415b964fSLei YU 
TEST_F(TestManager,propertyChanged)287e5f9f79SGeorge Liu TEST_F(TestManager, propertyChanged)
297f4fca55SLei YU {
30ad14354fSLei YU     notifyPropertyChanged(
31710d49beSLei YU         "TimeSyncMethod",
32ad14354fSLei YU         "xyz.openbmc_project.Time.Synchronization.Method.Manual");
33cb421097SGeorge Liu     EXPECT_EQ(Mode::Manual, manager.getTimeMode());
34a5003cebSLei YU 
35ad14354fSLei YU     notifyPropertyChanged(
36710d49beSLei YU         "TimeSyncMethod",
37ad14354fSLei YU         "xyz.openbmc_project.Time.Synchronization.Method.NTP");
38cb421097SGeorge Liu     EXPECT_EQ(Mode::NTP, manager.getTimeMode());
39a5003cebSLei YU 
407f4fca55SLei YU     ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
417f4fca55SLei YU }
427f4fca55SLei YU 
43ab4cc6a5SGunnar Mills } // namespace time
44ab4cc6a5SGunnar Mills } // namespace phosphor
45