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