diff options
author | Patrick Venture <venture@google.com> | 2019-01-24 14:06:44 -0800 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-01-25 08:27:49 -0800 |
commit | cd40c8815a9533cb72d97e1d316e91650f14b024 (patch) | |
tree | 60d138aa328a9aa966f71a39a8b16c36ff449128 | |
parent | e9764ff47f548c7c2a0e1205a94b75afdf27a993 (diff) | |
download | phosphor-hwmon-cd40c8815a9533cb72d97e1d316e91650f14b024.tar.gz phosphor-hwmon-cd40c8815a9533cb72d97e1d316e91650f14b024.zip |
test: add adjustvalue test
Add a test that calls adjust value on a sensor value to verify it's
processed as expected.
Change-Id: Iff299efced680c730d7ba5bdeff71617446db042
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | test/sensor_unittest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/sensor_unittest.cpp b/test/sensor_unittest.cpp index a80e252..eff613e 100644 --- a/test/sensor_unittest.cpp +++ b/test/sensor_unittest.cpp @@ -94,3 +94,38 @@ TEST_F(SensorTest, SensorRequiresGpio) std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path); EXPECT_FALSE(sensor == nullptr); } + +TEST_F(SensorTest, SensorHasGainAndOffsetAdjustValue) +{ + /* Construct a sensor that has a gain and offset, then verify they are used + * when adjusting the value. + */ + + StrictMock<EnvMock> eMock; + envIntf = &eMock; + + 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 = "/"; + + /* Always calls GPIOCHIP and GPIO checks, returning empty string. */ + EXPECT_CALL(eMock, getEnv(Eq("GPIOCHIP"), Eq(sensorKey))) + .WillOnce(Return("")); + EXPECT_CALL(eMock, getEnv(Eq("GPIO"), Eq(sensorKey))).WillOnce(Return("")); + + EXPECT_CALL(eMock, getEnv(Eq("GAIN"), Eq(sensorKey))) + .WillOnce(Return("10")); + EXPECT_CALL(eMock, getEnv(Eq("OFFSET"), Eq(sensorKey))) + .WillOnce(Return("15")); + 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); + + double startingValue = 1.0; + double resultValue = sensor->adjustValue(startingValue); + EXPECT_DOUBLE_EQ(resultValue, 25.0); +} |