blob: d9cc757f1a849060c5d7e8ecaec2dd0c083a8b27 [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
Lei YU415b9642017-02-09 11:37:26 +08009namespace phosphor
10{
11namespace time
12{
13
14class TestManager : public testing::Test
15{
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050016 public:
Patrick Williams38679262022-07-22 19:26:55 -050017 sdbusplus::bus_t bus;
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050018 Manager manager;
Lei YU415b9642017-02-09 11:37:26 +080019
Patrick Williamsea220362023-05-10 07:50:45 -050020 TestManager() : bus(sdbusplus::bus::new_default()), manager(bus) {}
Lei YU415b9642017-02-09 11:37:26 +080021
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050022 void notifyPropertyChanged(const std::string& key, const std::string& value)
23 {
24 manager.onPropertyChanged(key, value);
25 }
Lei YU415b9642017-02-09 11:37:26 +080026};
27
George Liu7e5f9f72022-08-17 12:32:24 +080028TEST_F(TestManager, propertyChanged)
Lei YU7f4fca52017-02-23 15:15:51 +080029{
Lei YUad143542017-07-25 14:27:07 +080030 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080031 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080032 "xyz.openbmc_project.Time.Synchronization.Method.Manual");
George Liucb421092022-08-16 17:02:31 +080033 EXPECT_EQ(Mode::Manual, manager.getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080034
Lei YUad143542017-07-25 14:27:07 +080035 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080036 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080037 "xyz.openbmc_project.Time.Synchronization.Method.NTP");
George Liucb421092022-08-16 17:02:31 +080038 EXPECT_EQ(Mode::NTP, manager.getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080039
Lei YU7f4fca52017-02-23 15:15:51 +080040 ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
41}
42
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050043} // namespace time
44} // namespace phosphor