Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame^] | 1 | #include "cpld.hpp" |
| 2 | #include "handler_mock.hpp" |
| 3 | #include "main.hpp" |
| 4 | |
| 5 | #include <cstdint> |
| 6 | #include <tuple> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | #define MAX_IPMI_BUFFER 64 |
| 12 | |
| 13 | using ::testing::Return; |
| 14 | |
| 15 | namespace google |
| 16 | { |
| 17 | namespace ipmi |
| 18 | { |
| 19 | |
| 20 | TEST(CpldCommandTest, RequestTooSmall) |
| 21 | { |
| 22 | std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion}; |
| 23 | size_t dataLen = request.size(); |
| 24 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 25 | |
| 26 | HandlerMock hMock; |
| 27 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
| 28 | CpldVersion(request.data(), reply, &dataLen, &hMock)); |
| 29 | } |
| 30 | |
| 31 | TEST(CpldCommandTest, ValidRequestReturnsHappy) |
| 32 | { |
| 33 | std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion, 0x04}; |
| 34 | size_t dataLen = request.size(); |
| 35 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 36 | std::uint8_t expectedMaj = 0x5; |
| 37 | std::uint8_t expectedMin = 0x3; |
| 38 | std::uint8_t expectedPt = 0x7; |
| 39 | std::uint8_t expectedSbPtr = 0x9; |
| 40 | |
| 41 | HandlerMock hMock; |
| 42 | EXPECT_CALL(hMock, getCpldVersion(0x04)) |
| 43 | .WillOnce(Return(std::make_tuple(expectedMaj, expectedMin, expectedPt, |
| 44 | expectedSbPtr))); |
| 45 | |
| 46 | EXPECT_EQ(IPMI_CC_OK, CpldVersion(request.data(), reply, &dataLen, &hMock)); |
| 47 | EXPECT_EQ(expectedMaj, reply[1]); |
| 48 | EXPECT_EQ(expectedMin, reply[2]); |
| 49 | EXPECT_EQ(expectedPt, reply[3]); |
| 50 | EXPECT_EQ(expectedSbPtr, reply[4]); |
| 51 | } |
| 52 | |
| 53 | } // namespace ipmi |
| 54 | } // namespace google |