summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-12-19 08:59:15 -0800
committerPatrick Venture <venture@google.com>2019-01-09 17:26:08 +0000
commit99b95815550d2d84140d00032e341b8206fa9601 (patch)
tree3d51879e8ea0595521e9436ce17c0a8e2c05fdf0
parent12659aa103878c10567620d48726b6ff6f9d7993 (diff)
downloadphosphor-hwmon-99b95815550d2d84140d00032e341b8206fa9601.tar.gz
phosphor-hwmon-99b95815550d2d84140d00032e341b8206fa9601.zip
sensor: add gpio handle test variation
Add a sensor constructor test where the gpio handle is required. Change-Id: I05050fb71a6287183ca94f974e965e3f58de9499 Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--test/Makefile.am4
-rw-r--r--test/sensor_unittest.cpp45
2 files changed, 47 insertions, 2 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 8573194..2682d45 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -30,5 +30,5 @@ sensor_unittest_LDADD = \
$(GPIOPLUS_LIBS) \
$(top_builddir)/sensor.o \
$(top_builddir)/hwmon.o \
- $(top_builddir)/gpio_handle.o \
- env.o
+ env.o \
+ gpio.o
diff --git a/test/sensor_unittest.cpp b/test/sensor_unittest.cpp
index 905b011..a80e252 100644
--- a/test/sensor_unittest.cpp
+++ b/test/sensor_unittest.cpp
@@ -1,7 +1,9 @@
#include "env_mock.hpp"
+#include "gpio_mock.hpp"
#include "hwmonio_mock.hpp"
#include "sensor.hpp"
+#include <gpioplus/test/handle.hpp>
#include <memory>
#include <utility>
@@ -14,10 +16,12 @@ class SensorTest : public ::testing::Test
void SetUp() override
{
envIntf = nullptr;
+ gpioIntf = nullptr;
}
};
using ::testing::Eq;
+using ::testing::Invoke;
using ::testing::Return;
using ::testing::StrictMock;
@@ -49,3 +53,44 @@ TEST_F(SensorTest, BasicConstructorTest)
std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
EXPECT_FALSE(sensor == nullptr);
}
+
+TEST_F(SensorTest, SensorRequiresGpio)
+{
+ /* Constructor test with only the GPIO chip set. */
+
+ StrictMock<EnvMock> eMock;
+ envIntf = &eMock;
+
+ StrictMock<GpioHandleMock> gMock;
+ gpioIntf = &gMock;
+
+ /* The following piece of code can probably be copied above once it's
+ * working.
+ */
+ auto handleMock = std::make_unique<gpioplus::test::HandleMock>();
+
+ auto sensorKey = std::make_pair(std::string("temp"), std::string("5"));
+ std::unique_ptr<hwmonio::HwmonIOInterface> hwmonio_mock =
+ std::make_unique<hwmonio::HwmonIOMock>();
+ std::string path = "/";
+
+ EXPECT_CALL(eMock, getEnv(Eq("GPIOCHIP"), Eq(sensorKey)))
+ .WillOnce(Return("chipA"));
+ EXPECT_CALL(eMock, getEnv(Eq("GPIO"), Eq(sensorKey))).WillOnce(Return("5"));
+
+ EXPECT_CALL(gMock, build(Eq("chipA"), Eq("5")))
+ .WillOnce(Invoke([&](const std::string& chip, const std::string& line) {
+ return std::move(handleMock);
+ }));
+
+ /* Always calls GAIN and OFFSET, can use ON_CALL instead of EXPECT_CALL */
+ EXPECT_CALL(eMock, getEnv(Eq("GAIN"), Eq(sensorKey))).WillOnce(Return(""));
+ EXPECT_CALL(eMock, getEnv(Eq("OFFSET"), Eq(sensorKey)))
+ .WillOnce(Return(""));
+ EXPECT_CALL(eMock, getEnv(Eq("REMOVERCS"), Eq(sensorKey)))
+ .WillOnce(Return(""));
+
+ auto sensor =
+ std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
+ EXPECT_FALSE(sensor == nullptr);
+}
OpenPOWER on IntegriCloud