1 #include "sensors/manager.hpp"
2 #include "test/sensor_mock.hpp"
3 
4 #include <sdbusplus/test/sdbus_mock.hpp>
5 
6 #include <gmock/gmock.h>
7 #include <gtest/gtest.h>
8 
9 namespace pid_control
10 {
11 namespace
12 {
13 
14 using ::testing::_;
15 using ::testing::IsNull;
16 using ::testing::Return;
17 using ::testing::StrEq;
18 
19 TEST(SensorManagerTest, BoringConstructorTest)
20 {
21     // Build a boring SensorManager.
22 
23     sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host;
24     auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive);
25     auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host);
26 
27     EXPECT_CALL(sdbus_mock_host,
28                 sd_bus_add_object_manager(
29                     IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
30         .WillOnce(Return(0));
31 
32     SensorManager s(bus_mock_passive, bus_mock_host);
33     // Success
34 }
35 
36 TEST(SensorManagerTest, AddSensorInvalidTypeTest)
37 {
38     // AddSensor doesn't validate the type of sensor you're adding, because
39     // ultimately it doesn't care -- but if we decide to change that this
40     // test will start failing :D
41 
42     sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host;
43     auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive);
44     auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host);
45 
46     EXPECT_CALL(sdbus_mock_host,
47                 sd_bus_add_object_manager(
48                     IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
49         .WillOnce(Return(0));
50 
51     SensorManager s(bus_mock_passive, bus_mock_host);
52 
53     std::string name = "name";
54     std::string type = "invalid";
55     int64_t timeout = 1;
56     std::unique_ptr<Sensor> sensor = std::make_unique<SensorMock>(name,
57                                                                   timeout);
58     Sensor* sensor_ptr = sensor.get();
59 
60     s.addSensor(type, name, std::move(sensor));
61     EXPECT_EQ(s.getSensor(name), sensor_ptr);
62 }
63 
64 } // namespace
65 } // namespace pid_control
66