diff options
| author | Patrick Venture <venture@google.com> | 2018-06-14 10:34:34 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-06-28 20:21:31 +0000 |
| commit | 2524323eb4167307b9260bb34aab2b8f8ee4c991 (patch) | |
| tree | 0fd42c38ef4f8a007f3b49843811564ff61a37c9 | |
| parent | 0ef1faf70ba2af62260d99bb10ab5b674c0ebbd0 (diff) | |
| download | phosphor-pid-control-2524323eb4167307b9260bb34aab2b8f8ee4c991.tar.gz phosphor-pid-control-2524323eb4167307b9260bb34aab2b8f8ee4c991.zip | |
test: dbus: dbusactiveread
Add initial unit-tests.
Change-Id: Id62894faf56a645dc44c51a173a67185ea5d9cd6
Signed-off-by: Patrick Venture <venture@google.com>
| -rw-r--r-- | test/Makefile.am | 5 | ||||
| -rw-r--r-- | test/dbus_active_unittest.cpp | 52 |
2 files changed, 56 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index d8056e2..6622169 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -14,7 +14,7 @@ AM_LDFLAGS = \ check_PROGRAMS = sensor_manager_unittest sensor_pluggable_unittest \ sensor_host_unittest util_unittest pid_zone_unittest \ pid_thermalcontroller_unittest pid_fancontroller_unittest \ - dbus_passive_unittest + dbus_passive_unittest dbus_active_unittest TESTS = $(check_PROGRAMS) # Until libconfig is mocked out or replaced, include it. @@ -48,3 +48,6 @@ pid_fancontroller_unittest_LDADD = $(top_builddir)/pid/ec/pid.o \ dbus_passive_unittest_SOURCES = dbus_passive_unittest.cpp dbus_passive_unittest_LDADD = $(top_builddir)/dbus/util.o \ $(top_builddir)/dbus/dbuspassive.o + +dbus_active_unittest_SOURCES = dbus_active_unittest.cpp +dbus_active_unittest_LDADD = $(top_builddir)/dbus/dbusactiveread.o diff --git a/test/dbus_active_unittest.cpp b/test/dbus_active_unittest.cpp new file mode 100644 index 0000000..c83e9ce --- /dev/null +++ b/test/dbus_active_unittest.cpp @@ -0,0 +1,52 @@ +#include "dbus/dbusactiveread.hpp" + +#include <gmock/gmock.h> +#include <gtest/gtest.h> +#include <sdbusplus/test/sdbus_mock.hpp> +#include <string> + +#include "test/dbushelper_mock.hpp" + +using ::testing::Invoke; +using ::testing::NotNull; +using ::testing::_; + +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. |

