blob: 7091cb119ab67ef2b22f607c4c520006936eb491 [file] [log] [blame]
Patrick Venture0e9aae52020-08-13 13:07:09 -07001#include "commands.hpp"
Patrick Venture07f85152019-03-15 21:36:56 -07002#include "entity_name.hpp"
3#include "handler_mock.hpp"
Patrick Venture07f85152019-03-15 21:36:56 -07004
5#include <cstdint>
6#include <cstring>
7#include <string>
8#include <vector>
9
10#include <gtest/gtest.h>
11
12#define MAX_IPMI_BUFFER 64
13
14using ::testing::Return;
15
16namespace google
17{
18namespace ipmi
19{
20
21TEST(EntityNameCommandTest, InvalidCommandLength)
22{
23 // GetEntityNameRequest is three bytes, let's send 2.
24 std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName, 0x01};
25 size_t dataLen = request.size();
26 std::uint8_t reply[MAX_IPMI_BUFFER];
27
28 HandlerMock hMock;
29 EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
Patrick Venture45fad1b2019-03-18 16:52:14 -070030 getEntityName(request.data(), reply, &dataLen, &hMock));
Patrick Venture07f85152019-03-15 21:36:56 -070031}
32
33TEST(EntityNameCommandTest, ValidRequest)
34{
35 std::uint8_t entityId = 3;
36 std::uint8_t entityInstance = 5;
37 std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName,
38 entityId, entityInstance};
39 size_t dataLen = request.size();
40 std::uint8_t reply[MAX_IPMI_BUFFER];
41 std::string entityName = "asdf";
42
43 HandlerMock hMock;
44 EXPECT_CALL(hMock, getEntityName(entityId, entityInstance))
45 .WillOnce(Return(entityName));
46 EXPECT_EQ(IPMI_CC_OK,
Patrick Venture45fad1b2019-03-18 16:52:14 -070047 getEntityName(request.data(), reply, &dataLen, &hMock));
Patrick Venture07f85152019-03-15 21:36:56 -070048 EXPECT_EQ(reply[1], entityName.length());
49 EXPECT_EQ(0, std::memcmp(&reply[2], entityName.c_str(), reply[1]));
50}
51
52} // namespace ipmi
53} // namespace google