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