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 | // Proxies for Manager's private members and functions |
| 26 | Mode getTimeMode() |
| 27 | { |
| 28 | return manager.timeMode; |
| 29 | } |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 30 | void notifyPropertyChanged(const std::string& key, const std::string& value) |
| 31 | { |
| 32 | manager.onPropertyChanged(key, value); |
| 33 | } |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 34 | }; |
| 35 | |
George Liu | 7e5f9f7 | 2022-08-17 12:32:24 +0800 | [diff] [blame^] | 36 | TEST_F(TestManager, propertyChanged) |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +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.Manual"); |
George Liu | 0a70452 | 2020-04-13 14:51:40 +0800 | [diff] [blame] | 41 | EXPECT_EQ(Mode::Manual, getTimeMode()); |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 42 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 43 | notifyPropertyChanged( |
Lei YU | 710d49b | 2017-08-01 17:10:17 +0800 | [diff] [blame] | 44 | "TimeSyncMethod", |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 45 | "xyz.openbmc_project.Time.Synchronization.Method.NTP"); |
George Liu | 0a70452 | 2020-04-13 14:51:40 +0800 | [diff] [blame] | 46 | EXPECT_EQ(Mode::NTP, getTimeMode()); |
Lei YU | a5003ce | 2017-02-24 15:35:25 +0800 | [diff] [blame] | 47 | |
Lei YU | 7f4fca5 | 2017-02-23 15:15:51 +0800 | [diff] [blame] | 48 | ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), ""); |
| 49 | } |
| 50 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 51 | } // namespace time |
| 52 | } // namespace phosphor |