xref: /openbmc/phosphor-pid-control/test/dbus_active_unittest.cpp (revision bd63bcaca2ac9edf1778136cf240e3bbe8b31566)
12524323eSPatrick Venture #include "dbus/dbusactiveread.hpp"
2da4a5dd1SPatrick Venture #include "test/dbushelper_mock.hpp"
32524323eSPatrick Venture 
42524323eSPatrick Venture #include <sdbusplus/test/sdbus_mock.hpp>
5a83a3eccSPatrick Venture 
68729eb98SPatrick Venture #include <memory>
72524323eSPatrick Venture #include <string>
82524323eSPatrick Venture 
9da4a5dd1SPatrick Venture #include <gmock/gmock.h>
10da4a5dd1SPatrick Venture #include <gtest/gtest.h>
112524323eSPatrick Venture 
12a076487aSPatrick Venture namespace pid_control
13a076487aSPatrick Venture {
14a076487aSPatrick Venture namespace
15a076487aSPatrick Venture {
16a076487aSPatrick Venture 
17da4a5dd1SPatrick Venture using ::testing::_;
182524323eSPatrick Venture using ::testing::Invoke;
192524323eSPatrick Venture using ::testing::NotNull;
202524323eSPatrick Venture 
TEST(DbusActiveReadTest,BoringConstructorTest)21da4a5dd1SPatrick Venture TEST(DbusActiveReadTest, BoringConstructorTest)
22da4a5dd1SPatrick Venture {
232524323eSPatrick Venture     // Verify we can construct it.
242524323eSPatrick Venture 
252524323eSPatrick Venture     sdbusplus::SdBusMock sdbus_mock;
262524323eSPatrick Venture     auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
278729eb98SPatrick Venture     auto helper = std::make_unique<DbusHelperMock>();
282524323eSPatrick Venture     std::string path = "/asdf";
292524323eSPatrick Venture     std::string service = "asdfasdf.asdfasdf";
302524323eSPatrick Venture 
318729eb98SPatrick Venture     DbusActiveRead ar(bus_mock, path, service, std::move(helper));
322524323eSPatrick Venture }
332524323eSPatrick Venture 
TEST(DbusActiveReadTest,Read_VerifyCallsToDbusForValue)34da4a5dd1SPatrick Venture TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue)
35da4a5dd1SPatrick Venture {
362524323eSPatrick Venture     // Verify it calls to get the value from dbus when requested.
372524323eSPatrick Venture 
382524323eSPatrick Venture     sdbusplus::SdBusMock sdbus_mock;
392524323eSPatrick Venture     auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
408729eb98SPatrick Venture     auto helper = std::make_unique<DbusHelperMock>();
412524323eSPatrick Venture     std::string path = "/asdf";
422524323eSPatrick Venture     std::string service = "asdfasdf.asdfasdf";
432524323eSPatrick Venture 
449b93692dSPatrick Venture     EXPECT_CALL(*helper, getProperties(service, path, NotNull()))
45*a1ae4fa1SHarvey.Wu         .WillOnce(Invoke([&]([[maybe_unused]] const std::string& service,
46*a1ae4fa1SHarvey.Wu                              [[maybe_unused]] const std::string& path,
47*a1ae4fa1SHarvey.Wu                              SensorProperties* prop) {
482524323eSPatrick Venture             prop->scale = -3;
492524323eSPatrick Venture             prop->value = 10000;
502524323eSPatrick Venture             prop->unit = "x";
512524323eSPatrick Venture         }));
522524323eSPatrick Venture 
538729eb98SPatrick Venture     DbusActiveRead ar(bus_mock, path, service, std::move(helper));
548729eb98SPatrick Venture 
552524323eSPatrick Venture     ReadReturn r = ar.read();
562524323eSPatrick Venture     EXPECT_EQ(10, r.value);
572524323eSPatrick Venture }
582524323eSPatrick Venture 
59563a356fSPatrick Venture // WARN: getProperties will raise an exception on failure
602524323eSPatrick Venture // Instead of just not updating the value.
61a076487aSPatrick Venture 
62a076487aSPatrick Venture } // namespace
63a076487aSPatrick Venture } // namespace pid_control
64