blob: 875326a9c7d131d52d84a4ecf1f8931a342b7f9e [file] [log] [blame]
Patrick Venturecaaebd12019-06-21 14:56:07 -07001#include "filesystem_mock.hpp"
2#include "hwmonio.hpp"
3
4#include <chrono>
5#include <string>
6
7#include <gmock/gmock.h>
8#include <gtest/gtest.h>
9
10namespace hwmonio
11{
12namespace
13{
14
15using ::testing::_;
16using ::testing::Return;
17
18class HwmonIOTest : public ::testing::Test
19{
20 protected:
Patrick Williamse8771fd2023-05-10 07:51:06 -050021 HwmonIOTest() : _hwmonio(_path, &_mock) {}
Patrick Venturecaaebd12019-06-21 14:56:07 -070022
23 const int64_t _value = 12;
24 const std::string _path = "abcd";
25 const std::string _type = "fan";
26 const std::string _id = "a";
27 const std::string _sensor = "1";
28 const size_t _retries = 1;
29 const std::chrono::milliseconds _delay = std::chrono::milliseconds{10};
30
31 FileSystemMock _mock;
32 HwmonIO _hwmonio;
33};
34
35TEST_F(HwmonIOTest, ReadReturnsValue)
36{
37 EXPECT_CALL(_mock, read(_)).WillOnce(Return(_value));
38 EXPECT_THAT(_hwmonio.read(_type, _id, _sensor, _retries, _delay), _value);
39}
40
41int64_t SetErrnoExcept(const std::string&)
42{
43 errno = ETIMEDOUT;
44 throw std::runtime_error("bad times");
45}
46
47TEST_F(HwmonIOTest, ReadExceptsRetryable)
48{
49 EXPECT_CALL(_mock, read(_))
50 .WillOnce(&SetErrnoExcept)
51 .WillOnce(Return(_value));
52 EXPECT_THAT(_hwmonio.read(_type, _id, _sensor, _retries, _delay), _value);
53}
54
55} // namespace
56} // namespace hwmonio