summaryrefslogtreecommitdiffstats
path: root/test/dbus_active_unittest.cpp
blob: e6dcc9d6ba4dc9144925ad05173d91efcc231e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "dbus/dbusactiveread.hpp"
#include "test/dbushelper_mock.hpp"

#include <sdbusplus/test/sdbus_mock.hpp>
#include <string>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

using ::testing::_;
using ::testing::Invoke;
using ::testing::NotNull;

TEST(DbusActiveReadTest, BoringConstructorTest)
{
    // Verify we can construct it.

    sdbusplus::SdBusMock sdbus_mock;
    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
    DbusHelperMock helper;
    std::string path = "/asdf";
    std::string service = "asdfasdf.asdfasdf";

    DbusActiveRead ar(bus_mock, path, service, &helper);
}

TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue)
{
    // Verify it calls to get the value from dbus when requested.

    sdbusplus::SdBusMock sdbus_mock;
    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
    DbusHelperMock helper;
    std::string path = "/asdf";
    std::string service = "asdfasdf.asdfasdf";

    DbusActiveRead ar(bus_mock, path, service, &helper);

    EXPECT_CALL(helper, getProperties(_, service, path, NotNull()))
        .WillOnce(
            Invoke([&](sdbusplus::bus::bus& bus, const std::string& service,
                       const std::string& path, struct SensorProperties* prop) {
                prop->scale = -3;
                prop->value = 10000;
                prop->unit = "x";
            }));

    ReadReturn r = ar.read();
    EXPECT_EQ(10, r.value);
}

// WARN: getProperties will raise an exception on failure
// Instead of just not updating the value.
OpenPOWER on IntegriCloud