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