Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 1 | #include "sensors/manager.hpp" |
| 2 | |
| 3 | #include <gmock/gmock.h> |
| 4 | #include <gtest/gtest.h> |
| 5 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 6 | |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 7 | #include "test/sensor_mock.hpp" |
| 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 | |
| 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"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 26 | .WillOnce(Return(0)); |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 27 | |
| 28 | SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host)); |
| 29 | // Success |
| 30 | } |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 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"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 46 | .WillOnce(Return(0)); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 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)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 58 | EXPECT_EQ(s.getSensor(name), sensor_ptr); |
Patrick Venture | 9805543 | 2018-06-08 14:04:43 -0700 | [diff] [blame] | 59 | } |