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 | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 9 | using ::testing::_; |
| 10 | using ::testing::IsNull; |
| 11 | using ::testing::Return; |
| 12 | using ::testing::StrEq; |
| 13 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 14 | TEST(SensorManagerTest, BoringConstructorTest) |
| 15 | { |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 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( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 24 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 25 | .WillOnce(Return(0)); |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 26 | |
| 27 | SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host)); |
| 28 | // Success |
| 29 | } |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 30 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 31 | TEST(SensorManagerTest, AddSensorInvalidTypeTest) |
| 32 | { |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 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( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 43 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 44 | .WillOnce(Return(0)); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 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); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 53 | Sensor* sensor_ptr = sensor.get(); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 54 | |
| 55 | s.addSensor(type, name, std::move(sensor)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 56 | EXPECT_EQ(s.getSensor(name), sensor_ptr); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 57 | } |