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