diff options
author | Patrick Venture <venture@google.com> | 2019-03-06 08:50:15 -0800 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-03-06 13:06:33 -0800 |
commit | 56c876f3a108f4f4fdbe13898ac3ba47b98b9a20 (patch) | |
tree | d2049b0859c810f37d7198026c8d241fb7cf1f6f | |
parent | 27512cf82dd7caf27a5886c050623499686d1fe8 (diff) | |
download | phosphor-hwmon-56c876f3a108f4f4fdbe13898ac3ba47b98b9a20.tar.gz phosphor-hwmon-56c876f3a108f4f4fdbe13898ac3ba47b98b9a20.zip |
test: rework to use Pair-wise comparison
Use Pair-wise comparison instead of straight equality check.
Change-Id: I3aa567015bfbd81578275fc0edf1ef785fde7678
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | test/sensor_unittest.cpp | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/test/sensor_unittest.cpp b/test/sensor_unittest.cpp index eff613e..8271b54 100644 --- a/test/sensor_unittest.cpp +++ b/test/sensor_unittest.cpp @@ -18,11 +18,16 @@ class SensorTest : public ::testing::Test envIntf = nullptr; gpioIntf = nullptr; } + + std::string temp = "temp"; + std::string five = "5"; }; using ::testing::Eq; using ::testing::Invoke; +using ::testing::Pair; using ::testing::Return; +using ::testing::StrEq; using ::testing::StrictMock; TEST_F(SensorTest, BasicConstructorTest) @@ -32,21 +37,23 @@ TEST_F(SensorTest, BasicConstructorTest) StrictMock<EnvMock> eMock; envIntf = &eMock; - auto sensorKey = std::make_pair(std::string("temp"), std::string("5")); + auto sensorKey = std::make_pair(temp, five); 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))) + EXPECT_CALL(eMock, getEnv(StrEq("GPIOCHIP"), Pair(temp, five))) + .WillOnce(Return("")); + EXPECT_CALL(eMock, getEnv(StrEq("GPIO"), Pair(temp, five))) .WillOnce(Return("")); - EXPECT_CALL(eMock, getEnv(Eq("GPIO"), Eq(sensorKey))).WillOnce(Return("")); /* 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))) + EXPECT_CALL(eMock, getEnv(StrEq("GAIN"), Pair(temp, five))) + .WillOnce(Return("")); + EXPECT_CALL(eMock, getEnv(StrEq("OFFSET"), Pair(temp, five))) .WillOnce(Return("")); - EXPECT_CALL(eMock, getEnv(Eq("REMOVERCS"), Eq(sensorKey))) + EXPECT_CALL(eMock, getEnv(StrEq("REMOVERCS"), Pair(temp, five))) .WillOnce(Return("")); auto sensor = @@ -69,25 +76,27 @@ TEST_F(SensorTest, SensorRequiresGpio) */ auto handleMock = std::make_unique<gpioplus::test::HandleMock>(); - auto sensorKey = std::make_pair(std::string("temp"), std::string("5")); + auto sensorKey = std::make_pair(temp, five); std::unique_ptr<hwmonio::HwmonIOInterface> hwmonio_mock = std::make_unique<hwmonio::HwmonIOMock>(); std::string path = "/"; - EXPECT_CALL(eMock, getEnv(Eq("GPIOCHIP"), Eq(sensorKey))) + EXPECT_CALL(eMock, getEnv(StrEq("GPIOCHIP"), Pair(temp, five))) .WillOnce(Return("chipA")); - EXPECT_CALL(eMock, getEnv(Eq("GPIO"), Eq(sensorKey))).WillOnce(Return("5")); + EXPECT_CALL(eMock, getEnv(StrEq("GPIO"), Pair(temp, five))) + .WillOnce(Return("5")); - EXPECT_CALL(gMock, build(Eq("chipA"), Eq("5"))) + EXPECT_CALL(gMock, build(StrEq("chipA"), StrEq("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))) + EXPECT_CALL(eMock, getEnv(StrEq("GAIN"), Pair(temp, five))) .WillOnce(Return("")); - EXPECT_CALL(eMock, getEnv(Eq("REMOVERCS"), Eq(sensorKey))) + EXPECT_CALL(eMock, getEnv(StrEq("OFFSET"), Pair(temp, five))) + .WillOnce(Return("")); + EXPECT_CALL(eMock, getEnv(StrEq("REMOVERCS"), Pair(temp, five))) .WillOnce(Return("")); auto sensor = @@ -104,21 +113,22 @@ TEST_F(SensorTest, SensorHasGainAndOffsetAdjustValue) StrictMock<EnvMock> eMock; envIntf = &eMock; - auto sensorKey = std::make_pair(std::string("temp"), std::string("5")); + auto sensorKey = std::make_pair(temp, five); 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))) + EXPECT_CALL(eMock, getEnv(StrEq("GPIOCHIP"), Pair(temp, five))) + .WillOnce(Return("")); + EXPECT_CALL(eMock, getEnv(StrEq("GPIO"), Pair(temp, five))) .WillOnce(Return("")); - EXPECT_CALL(eMock, getEnv(Eq("GPIO"), Eq(sensorKey))).WillOnce(Return("")); - EXPECT_CALL(eMock, getEnv(Eq("GAIN"), Eq(sensorKey))) + EXPECT_CALL(eMock, getEnv(StrEq("GAIN"), Pair(temp, five))) .WillOnce(Return("10")); - EXPECT_CALL(eMock, getEnv(Eq("OFFSET"), Eq(sensorKey))) + EXPECT_CALL(eMock, getEnv(StrEq("OFFSET"), Pair(temp, five))) .WillOnce(Return("15")); - EXPECT_CALL(eMock, getEnv(Eq("REMOVERCS"), Eq(sensorKey))) + EXPECT_CALL(eMock, getEnv(StrEq("REMOVERCS"), Pair(temp, five))) .WillOnce(Return("")); auto sensor = |