blob: 6c355af29d20dcd6c308127f0964a67aaa4a3244 [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
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050020 TestManager() : bus(sdbusplus::bus::new_default()), manager(bus)
George Liuc6d33972020-06-22 10:35:29 +080021 {}
Lei YU415b9642017-02-09 11:37:26 +080022
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050023 void notifyPropertyChanged(const std::string& key, const std::string& value)
24 {
25 manager.onPropertyChanged(key, value);
26 }
Lei YU415b9642017-02-09 11:37:26 +080027};
28
George Liu7e5f9f72022-08-17 12:32:24 +080029TEST_F(TestManager, propertyChanged)
Lei YU7f4fca52017-02-23 15:15:51 +080030{
Lei YUad143542017-07-25 14:27:07 +080031 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080032 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080033 "xyz.openbmc_project.Time.Synchronization.Method.Manual");
George Liucb421092022-08-16 17:02:31 +080034 EXPECT_EQ(Mode::Manual, manager.getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080035
Lei YUad143542017-07-25 14:27:07 +080036 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080037 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080038 "xyz.openbmc_project.Time.Synchronization.Method.NTP");
George Liucb421092022-08-16 17:02:31 +080039 EXPECT_EQ(Mode::NTP, manager.getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080040
Lei YU7f4fca52017-02-23 15:15:51 +080041 ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
42}
43
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050044} // namespace time
45} // namespace phosphor