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