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([&](const std::string& service, 46 const std::string& path, SensorProperties* prop) { 47 prop->scale = -3; 48 prop->value = 10000; 49 prop->unit = "x"; 50 })); 51 52 DbusActiveRead ar(bus_mock, path, service, std::move(helper)); 53 54 ReadReturn r = ar.read(); 55 EXPECT_EQ(10, r.value); 56 } 57 58 // WARN: getProperties will raise an exception on failure 59 // Instead of just not updating the value. 60 61 } // namespace 62 } // namespace pid_control 63