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