blob: f64b3a089684bf6e15374a2912e190fcd7db0ed6 [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 void notifyPropertyChanged(const std::string& key, const std::string& value)
26 {
27 manager.onPropertyChanged(key, value);
28 }
Lei YU415b9642017-02-09 11:37:26 +080029};
30
George Liu7e5f9f72022-08-17 12:32:24 +080031TEST_F(TestManager, propertyChanged)
Lei YU7f4fca52017-02-23 15:15:51 +080032{
Lei YUad143542017-07-25 14:27:07 +080033 notifyPropertyChanged(
Lei YU710d49b2017-08-01 17:10:17 +080034 "TimeSyncMethod",
Lei YUad143542017-07-25 14:27:07 +080035 "xyz.openbmc_project.Time.Synchronization.Method.Manual");
George Liucb421092022-08-16 17:02:31 +080036 EXPECT_EQ(Mode::Manual, manager.getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +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.NTP");
George Liucb421092022-08-16 17:02:31 +080041 EXPECT_EQ(Mode::NTP, manager.getTimeMode());
Lei YUa5003ce2017-02-24 15:35:25 +080042
Lei YU7f4fca52017-02-23 15:15:51 +080043 ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
44}
45
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050046} // namespace time
47} // namespace phosphor