Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 1 | #include "dbus/dbusactiveread.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 2 | #include "test/dbushelper_mock.hpp" |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 3 | |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 4 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 5 | |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 8 | #include <gmock/gmock.h> |
| 9 | #include <gtest/gtest.h> |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 10 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 11 | namespace pid_control |
| 12 | { |
| 13 | namespace |
| 14 | { |
| 15 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 16 | using ::testing::_; |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 17 | using ::testing::Invoke; |
| 18 | using ::testing::NotNull; |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 19 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 20 | TEST(DbusActiveReadTest, BoringConstructorTest) |
| 21 | { |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 22 | // Verify we can construct it. |
| 23 | |
| 24 | sdbusplus::SdBusMock sdbus_mock; |
| 25 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 26 | DbusHelperMock helper; |
| 27 | std::string path = "/asdf"; |
| 28 | std::string service = "asdfasdf.asdfasdf"; |
| 29 | |
| 30 | DbusActiveRead ar(bus_mock, path, service, &helper); |
| 31 | } |
| 32 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 33 | TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue) |
| 34 | { |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 35 | // Verify it calls to get the value from dbus when requested. |
| 36 | |
| 37 | sdbusplus::SdBusMock sdbus_mock; |
| 38 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 39 | DbusHelperMock helper; |
| 40 | std::string path = "/asdf"; |
| 41 | std::string service = "asdfasdf.asdfasdf"; |
| 42 | |
| 43 | DbusActiveRead ar(bus_mock, path, service, &helper); |
| 44 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 45 | EXPECT_CALL(helper, getProperties(_, service, path, NotNull())) |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | .WillOnce( |
| 47 | Invoke([&](sdbusplus::bus::bus& bus, const std::string& service, |
| 48 | const std::string& path, struct SensorProperties* prop) { |
| 49 | prop->scale = -3; |
| 50 | prop->value = 10000; |
| 51 | prop->unit = "x"; |
| 52 | })); |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 53 | |
| 54 | ReadReturn r = ar.read(); |
| 55 | EXPECT_EQ(10, r.value); |
| 56 | } |
| 57 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 58 | // WARN: getProperties will raise an exception on failure |
Patrick Venture | 2524323 | 2018-06-14 10:34:34 -0700 | [diff] [blame] | 59 | // Instead of just not updating the value. |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 60 | |
| 61 | } // namespace |
| 62 | } // namespace pid_control |