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