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 using ::testing::_;
10 using ::testing::IsNull;
11 using ::testing::Return;
12 using ::testing::StrEq;
13 
14 TEST(SensorManagerTest, BoringConstructorTest)
15 {
16     // Build a boring SensorManager.
17 
18     sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host;
19     auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive);
20     auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host);
21 
22     EXPECT_CALL(sdbus_mock_host,
23                 sd_bus_add_object_manager(
24                     IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
25         .WillOnce(Return(0));
26 
27     SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host));
28     // Success
29 }
30 
31 TEST(SensorManagerTest, AddSensorInvalidTypeTest)
32 {
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(), _, StrEq("/xyz/openbmc_project/extsensors")))
44         .WillOnce(Return(0));
45 
46     SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host));
47 
48     std::string name = "name";
49     std::string type = "invalid";
50     int64_t timeout = 1;
51     std::unique_ptr<Sensor> sensor =
52         std::make_unique<SensorMock>(name, timeout);
53     Sensor* sensor_ptr = sensor.get();
54 
55     s.addSensor(type, name, std::move(sensor));
56     EXPECT_EQ(s.getSensor(name), sensor_ptr);
57 }
58