Patrick Venture | 0e2d68d | 2018-12-19 07:53:45 -0800 | [diff] [blame^] | 1 | #include "env_mock.hpp" |
| 2 | #include "hwmonio_mock.hpp" |
| 3 | #include "sensor.hpp" |
| 4 | |
| 5 | #include <memory> |
| 6 | #include <utility> |
| 7 | |
| 8 | #include <gmock/gmock.h> |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | class SensorTest : public ::testing::Test |
| 12 | { |
| 13 | protected: |
| 14 | void SetUp() override |
| 15 | { |
| 16 | envIntf = nullptr; |
| 17 | } |
| 18 | }; |
| 19 | |
| 20 | using ::testing::Eq; |
| 21 | using ::testing::Return; |
| 22 | using ::testing::StrictMock; |
| 23 | |
| 24 | TEST_F(SensorTest, BasicConstructorTest) |
| 25 | { |
| 26 | /* Constructor test with nothing in an rcList or GPIO chip. */ |
| 27 | |
| 28 | StrictMock<EnvMock> eMock; |
| 29 | envIntf = &eMock; |
| 30 | |
| 31 | auto sensorKey = std::make_pair(std::string("temp"), std::string("5")); |
| 32 | std::unique_ptr<hwmonio::HwmonIOInterface> hwmonio_mock = |
| 33 | std::make_unique<hwmonio::HwmonIOMock>(); |
| 34 | std::string path = "/"; |
| 35 | |
| 36 | /* Always calls GPIOCHIP and GPIO checks, returning empty string. */ |
| 37 | EXPECT_CALL(eMock, getEnv(Eq("GPIOCHIP"), Eq(sensorKey))) |
| 38 | .WillOnce(Return("")); |
| 39 | EXPECT_CALL(eMock, getEnv(Eq("GPIO"), Eq(sensorKey))).WillOnce(Return("")); |
| 40 | |
| 41 | /* Always calls GAIN and OFFSET, can use ON_CALL instead of EXPECT_CALL */ |
| 42 | EXPECT_CALL(eMock, getEnv(Eq("GAIN"), Eq(sensorKey))).WillOnce(Return("")); |
| 43 | EXPECT_CALL(eMock, getEnv(Eq("OFFSET"), Eq(sensorKey))) |
| 44 | .WillOnce(Return("")); |
| 45 | EXPECT_CALL(eMock, getEnv(Eq("REMOVERCS"), Eq(sensorKey))) |
| 46 | .WillOnce(Return("")); |
| 47 | |
| 48 | auto sensor = |
| 49 | std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path); |
| 50 | EXPECT_FALSE(sensor == nullptr); |
| 51 | } |