blob: 9f0e26c4e7de1e8c5ad8a18f3011d3c1c6912d30 [file] [log] [blame]
Patrick Venturefe75b192018-06-08 11:19:43 -07001#include "sensors/manager.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07002#include "test/sensor_mock.hpp"
3
4#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturefe75b192018-06-08 11:19:43 -07005
6#include <gmock/gmock.h>
7#include <gtest/gtest.h>
Patrick Venture98055432018-06-08 14:04:43 -07008
Patrick Venturefe75b192018-06-08 11:19:43 -07009using ::testing::_;
10using ::testing::IsNull;
11using ::testing::Return;
12using ::testing::StrEq;
13
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070014TEST(SensorManagerTest, BoringConstructorTest)
15{
Patrick Venturefe75b192018-06-08 11:19:43 -070016 // 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 Ventureda4a5dd2018-08-31 09:42:48 -070024 IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
Patrick Venturea58197c2018-06-11 15:29:45 -070025 .WillOnce(Return(0));
Patrick Venturefe75b192018-06-08 11:19:43 -070026
James Feist1fe08952019-05-07 09:17:16 -070027 SensorManager s(bus_mock_passive, bus_mock_host);
Patrick Venturefe75b192018-06-08 11:19:43 -070028 // Success
29}
Patrick Venture98055432018-06-08 14:04:43 -070030
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031TEST(SensorManagerTest, AddSensorInvalidTypeTest)
32{
Patrick Venture98055432018-06-08 14:04:43 -070033 // 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 Ventureda4a5dd2018-08-31 09:42:48 -070043 IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
Patrick Venturea58197c2018-06-11 15:29:45 -070044 .WillOnce(Return(0));
Patrick Venture98055432018-06-08 14:04:43 -070045
James Feist1fe08952019-05-07 09:17:16 -070046 SensorManager s(bus_mock_passive, bus_mock_host);
Patrick Venture98055432018-06-08 14:04:43 -070047
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 Venturee2ec0f62018-09-04 12:30:27 -070053 Sensor* sensor_ptr = sensor.get();
Patrick Venture98055432018-06-08 14:04:43 -070054
55 s.addSensor(type, name, std::move(sensor));
Patrick Venturea58197c2018-06-11 15:29:45 -070056 EXPECT_EQ(s.getSensor(name), sensor_ptr);
Patrick Venture98055432018-06-08 14:04:43 -070057}