blob: 1c6caa30d4a0df5944069123873c8a382f47e066 [file] [log] [blame]
Patrick Venturebb90d4f2019-03-15 13:42:06 -07001#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
13using ::testing::Return;
14
15namespace google
16{
17namespace ipmi
18{
19
20TEST(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
31TEST(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