blob: b5b67c718bfba5bc1803983736e67263a62002ca [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 Venturea0764872020-08-08 07:48:43 -07009namespace pid_control
10{
11namespace
12{
13
Patrick Venturefe75b192018-06-08 11:19:43 -070014using ::testing::_;
15using ::testing::IsNull;
16using ::testing::Return;
17using ::testing::StrEq;
18
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019TEST(SensorManagerTest, BoringConstructorTest)
20{
Patrick Venturefe75b192018-06-08 11:19:43 -070021 // 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 Ventureda4a5dd2018-08-31 09:42:48 -070029 IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
Patrick Venturea58197c2018-06-11 15:29:45 -070030 .WillOnce(Return(0));
Patrick Venturefe75b192018-06-08 11:19:43 -070031
James Feist1fe08952019-05-07 09:17:16 -070032 SensorManager s(bus_mock_passive, bus_mock_host);
Patrick Venturefe75b192018-06-08 11:19:43 -070033 // Success
34}
Patrick Venture98055432018-06-08 14:04:43 -070035
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070036TEST(SensorManagerTest, AddSensorInvalidTypeTest)
37{
Patrick Venture98055432018-06-08 14:04:43 -070038 // 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 Ventureda4a5dd2018-08-31 09:42:48 -070048 IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
Patrick Venturea58197c2018-06-11 15:29:45 -070049 .WillOnce(Return(0));
Patrick Venture98055432018-06-08 14:04:43 -070050
James Feist1fe08952019-05-07 09:17:16 -070051 SensorManager s(bus_mock_passive, bus_mock_host);
Patrick Venture98055432018-06-08 14:04:43 -070052
53 std::string name = "name";
54 std::string type = "invalid";
55 int64_t timeout = 1;
Patrick Williams8c051122023-05-10 07:50:59 -050056 std::unique_ptr<Sensor> sensor = std::make_unique<SensorMock>(name,
57 timeout);
Patrick Venturee2ec0f62018-09-04 12:30:27 -070058 Sensor* sensor_ptr = sensor.get();
Patrick Venture98055432018-06-08 14:04:43 -070059
60 s.addSensor(type, name, std::move(sensor));
Patrick Venturea58197c2018-06-11 15:29:45 -070061 EXPECT_EQ(s.getSensor(name), sensor_ptr);
Patrick Venture98055432018-06-08 14:04:43 -070062}
Patrick Venturea0764872020-08-08 07:48:43 -070063
64} // namespace
65} // namespace pid_control