blob: eed26cd2bf63dccb2b4b9c15b709d1216f1fbed7 [file] [log] [blame]
Patrick Venturefe75b192018-06-08 11:19:43 -07001#include "sensors/manager.hpp"
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5#include <sdbusplus/test/sdbus_mock.hpp>
6
Patrick Venture98055432018-06-08 14:04:43 -07007#include "test/sensor_mock.hpp"
8
Patrick Venturefe75b192018-06-08 11:19:43 -07009using ::testing::_;
10using ::testing::IsNull;
11using ::testing::Return;
12using ::testing::StrEq;
13
14TEST(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 Venturea58197c2018-06-11 15:29:45 -070026 .WillOnce(Return(0));
Patrick Venturefe75b192018-06-08 11:19:43 -070027
28 SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host));
29 // Success
30}
Patrick Venture98055432018-06-08 14:04:43 -070031
32TEST(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 Venturea58197c2018-06-11 15:29:45 -070046 .WillOnce(Return(0));
Patrick Venture98055432018-06-08 14:04:43 -070047
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 Venturea58197c2018-06-11 15:29:45 -070058 EXPECT_EQ(s.getSensor(name), sensor_ptr);
Patrick Venture98055432018-06-08 14:04:43 -070059}