Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 1 | #include "manager.hpp" |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 2 | #include "mocked_property_change_listener.hpp" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 3 | #include "types.hpp" |
| 4 | |
| 5 | #include <sdbusplus/bus.hpp> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 8 | |
| 9 | using ::testing::_; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace time |
| 14 | { |
| 15 | |
| 16 | class TestManager : public testing::Test |
| 17 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 18 | public: |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 19 | sdbusplus::bus_t bus; |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 20 | Manager manager; |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 21 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 22 | TestManager() : bus(sdbusplus::bus::new_default()), manager(bus) |
George Liu | c6d3397 | 2020-06-22 10:35:29 +0800 | [diff] [blame] | 23 | {} |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 24 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 25 | void notifyPropertyChanged(const std::string& key, const std::string& value) |
| 26 | { |
| 27 | manager.onPropertyChanged(key, value); |
| 28 | } |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 29 | }; |
| 30 | |
George Liu | 7e5f9f7 | 2022-08-17 12:32:24 +0800 | [diff] [blame] | 31 | TEST_F(TestManager, propertyChanged) |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame] | 32 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 33 | notifyPropertyChanged( |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 34 | "TimeSyncMethod", |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 35 | "xyz.openbmc_project.Time.Synchronization.Method.Manual"); |
George Liu | cb42109 | 2022-08-16 17:02:31 +0800 | [diff] [blame] | 36 | EXPECT_EQ(Mode::Manual, manager.getTimeMode()); |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 37 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 38 | notifyPropertyChanged( |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 39 | "TimeSyncMethod", |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 40 | "xyz.openbmc_project.Time.Synchronization.Method.NTP"); |
George Liu | cb42109 | 2022-08-16 17:02:31 +0800 | [diff] [blame] | 41 | EXPECT_EQ(Mode::NTP, manager.getTimeMode()); |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 42 | |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame] | 43 | ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), ""); |
| 44 | } |
| 45 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 46 | } // namespace time |
| 47 | } // namespace phosphor |