blob: 142cc1a157a873fc9f8c58cfbbfe40cbb44f4285 [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 Ventureda4a5dd2018-08-31 09:42:48 -070011using ::testing::_;
Patrick Venture25243232018-06-14 10:34:34 -070012using ::testing::Invoke;
13using ::testing::NotNull;
Patrick Venture25243232018-06-14 10:34:34 -070014
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070015TEST(DbusActiveReadTest, BoringConstructorTest)
16{
Patrick Venture25243232018-06-14 10:34:34 -070017 // 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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue)
29{
Patrick Venture25243232018-06-14 10:34:34 -070030 // 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
Patrick Venture563a3562018-10-30 09:31:26 -070040 EXPECT_CALL(helper, getProperties(_, service, path, NotNull()))
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070041 .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 }));
Patrick Venture25243232018-06-14 10:34:34 -070048
49 ReadReturn r = ar.read();
50 EXPECT_EQ(10, r.value);
51}
52
Patrick Venture563a3562018-10-30 09:31:26 -070053// WARN: getProperties will raise an exception on failure
Patrick Venture25243232018-06-14 10:34:34 -070054// Instead of just not updating the value.