Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 1 | #include "sensors/manager.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 2 | #include "test/sensor_mock.hpp" |
| 3 | |
| 4 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 5 | |
| 6 | #include <gmock/gmock.h> |
| 7 | #include <gtest/gtest.h> |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 8 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 9 | namespace pid_control |
| 10 | { |
| 11 | namespace |
| 12 | { |
| 13 | |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 14 | using ::testing::_; |
| 15 | using ::testing::IsNull; |
| 16 | using ::testing::Return; |
| 17 | using ::testing::StrEq; |
| 18 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 19 | TEST(SensorManagerTest, BoringConstructorTest) |
| 20 | { |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 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( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 29 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 30 | .WillOnce(Return(0)); |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 31 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 32 | SensorManager s(bus_mock_passive, bus_mock_host); |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 33 | // Success |
| 34 | } |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 35 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 36 | TEST(SensorManagerTest, AddSensorInvalidTypeTest) |
| 37 | { |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 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( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 48 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 49 | .WillOnce(Return(0)); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 50 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 51 | SensorManager s(bus_mock_passive, bus_mock_host); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 52 | |
| 53 | std::string name = "name"; |
| 54 | std::string type = "invalid"; |
| 55 | int64_t timeout = 1; |
| 56 | std::unique_ptr<Sensor> sensor = |
| 57 | std::make_unique<SensorMock>(name, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 58 | Sensor* sensor_ptr = sensor.get(); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 59 | |
| 60 | s.addSensor(type, name, std::move(sensor)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 61 | EXPECT_EQ(s.getSensor(name), sensor_ptr); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 62 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 63 | |
| 64 | } // namespace |
| 65 | } // namespace pid_control |