blob: 2f5990c837352e1aca2a2cedca6bd74eb0127adf [file] [log] [blame]
Lei YU415b9642017-02-09 11:37:26 +08001#include "manager.hpp"
Lei YUa5003ce2017-02-24 15:35:25 +08002#include "mocked_property_change_listener.hpp"
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05003#include "types.hpp"
4
5#include <sdbusplus/bus.hpp>
6
7#include <gtest/gtest.h>
Lei YUa5003ce2017-02-24 15:35:25 +08008
9using ::testing::_;
Lei YU415b9642017-02-09 11:37:26 +080010
11namespace phosphor
12{
13namespace time
14{
15
16class TestManager : public testing::Test
17{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050018 public:
Patrick Williams38679262022-07-22 19:26:55 -050019 sdbusplus::bus_t bus;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050020 Manager manager;
Lei YU415b9642017-02-09 11:37:26 +080021
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050022 TestManager() : bus(sdbusplus::bus::new_default()), manager(bus)
George Liuc6d33972020-06-22 10:35:29 +080023 {}
Lei YU415b9642017-02-09 11:37:26 +080024
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050025 // Proxies for Manager's private members and functions
26 Mode getTimeMode()
27 {
28 return manager.timeMode;
29 }
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050030 void notifyPropertyChanged(const std::string& key, const std::string& value)
31 {
32 manager.onPropertyChanged(key, value);
33 }
Lei YU415b9642017-02-09 11:37:26 +080034};
35
George Liu7e5f9f72022-08-17 12:32:24 +080036TEST_F(TestManager, propertyChanged)
Lei YU7f4fca52017-02-23 15:15:51 +080037{
Lei YUad143542017-07-25 14:27:07 +080038 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080039 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080040 "xyz.openbmc_project.Time.Synchronization.Method.Manual");
George Liu0a704522020-04-13 14:51:40 +080041 EXPECT_EQ(Mode::Manual, getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080042
Lei YUad143542017-07-25 14:27:07 +080043 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080044 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080045 "xyz.openbmc_project.Time.Synchronization.Method.NTP");
George Liu0a704522020-04-13 14:51:40 +080046 EXPECT_EQ(Mode::NTP, getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080047
Lei YU7f4fca52017-02-23 15:15:51 +080048 ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
49}
50
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050051} // namespace time
52} // namespace phosphor