blob: 054ad1d44686bafd483a7a94e06ffca020bc379f [file] [log] [blame]
Patrick Venture25243232018-06-14 10:34:34 -07001#include "dbus/dbusactiveread.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07002#include "test/dbushelper_mock.hpp"
Patrick Venture25243232018-06-14 10:34:34 -07003
Patrick Venture25243232018-06-14 10:34:34 -07004#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07005
Patrick Venture25243232018-06-14 10:34:34 -07006#include <string>
7
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07008#include <gmock/gmock.h>
9#include <gtest/gtest.h>
Patrick Venture25243232018-06-14 10:34:34 -070010
Patrick Venturea0764872020-08-08 07:48:43 -070011namespace pid_control
12{
13namespace
14{
15
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070016using ::testing::_;
Patrick Venture25243232018-06-14 10:34:34 -070017using ::testing::Invoke;
18using ::testing::NotNull;
Patrick Venture25243232018-06-14 10:34:34 -070019
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020TEST(DbusActiveReadTest, BoringConstructorTest)
21{
Patrick Venture25243232018-06-14 10:34:34 -070022 // Verify we can construct it.
23
24 sdbusplus::SdBusMock sdbus_mock;
25 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
26 DbusHelperMock helper;
27 std::string path = "/asdf";
28 std::string service = "asdfasdf.asdfasdf";
29
30 DbusActiveRead ar(bus_mock, path, service, &helper);
31}
32
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070033TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue)
34{
Patrick Venture25243232018-06-14 10:34:34 -070035 // Verify it calls to get the value from dbus when requested.
36
37 sdbusplus::SdBusMock sdbus_mock;
38 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
39 DbusHelperMock helper;
40 std::string path = "/asdf";
41 std::string service = "asdfasdf.asdfasdf";
42
43 DbusActiveRead ar(bus_mock, path, service, &helper);
44
Patrick Venture563a3562018-10-30 09:31:26 -070045 EXPECT_CALL(helper, getProperties(_, service, path, NotNull()))
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 .WillOnce(
47 Invoke([&](sdbusplus::bus::bus& bus, const std::string& service,
48 const std::string& path, struct SensorProperties* prop) {
49 prop->scale = -3;
50 prop->value = 10000;
51 prop->unit = "x";
52 }));
Patrick Venture25243232018-06-14 10:34:34 -070053
54 ReadReturn r = ar.read();
55 EXPECT_EQ(10, r.value);
56}
57
Patrick Venture563a3562018-10-30 09:31:26 -070058// WARN: getProperties will raise an exception on failure
Patrick Venture25243232018-06-14 10:34:34 -070059// Instead of just not updating the value.
Patrick Venturea0764872020-08-08 07:48:43 -070060
61} // namespace
62} // namespace pid_control