1*07f85150SPatrick Venture #include "entity_name.hpp"
2*07f85150SPatrick Venture #include "handler_mock.hpp"
3*07f85150SPatrick Venture #include "main.hpp"
4*07f85150SPatrick Venture 
5*07f85150SPatrick Venture #include <cstdint>
6*07f85150SPatrick Venture #include <cstring>
7*07f85150SPatrick Venture #include <string>
8*07f85150SPatrick Venture #include <vector>
9*07f85150SPatrick Venture 
10*07f85150SPatrick Venture #include <gtest/gtest.h>
11*07f85150SPatrick Venture 
12*07f85150SPatrick Venture #define MAX_IPMI_BUFFER 64
13*07f85150SPatrick Venture 
14*07f85150SPatrick Venture using ::testing::Return;
15*07f85150SPatrick Venture 
16*07f85150SPatrick Venture namespace google
17*07f85150SPatrick Venture {
18*07f85150SPatrick Venture namespace ipmi
19*07f85150SPatrick Venture {
20*07f85150SPatrick Venture 
21*07f85150SPatrick Venture TEST(EntityNameCommandTest, InvalidCommandLength)
22*07f85150SPatrick Venture {
23*07f85150SPatrick Venture     // GetEntityNameRequest is three bytes, let's send 2.
24*07f85150SPatrick Venture     std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName, 0x01};
25*07f85150SPatrick Venture     size_t dataLen = request.size();
26*07f85150SPatrick Venture     std::uint8_t reply[MAX_IPMI_BUFFER];
27*07f85150SPatrick Venture 
28*07f85150SPatrick Venture     HandlerMock hMock;
29*07f85150SPatrick Venture     EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
30*07f85150SPatrick Venture               GetEntityName(request.data(), reply, &dataLen, &hMock));
31*07f85150SPatrick Venture }
32*07f85150SPatrick Venture 
33*07f85150SPatrick Venture TEST(EntityNameCommandTest, ValidRequest)
34*07f85150SPatrick Venture {
35*07f85150SPatrick Venture     std::uint8_t entityId = 3;
36*07f85150SPatrick Venture     std::uint8_t entityInstance = 5;
37*07f85150SPatrick Venture     std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName,
38*07f85150SPatrick Venture                                          entityId, entityInstance};
39*07f85150SPatrick Venture     size_t dataLen = request.size();
40*07f85150SPatrick Venture     std::uint8_t reply[MAX_IPMI_BUFFER];
41*07f85150SPatrick Venture     std::string entityName = "asdf";
42*07f85150SPatrick Venture 
43*07f85150SPatrick Venture     HandlerMock hMock;
44*07f85150SPatrick Venture     EXPECT_CALL(hMock, getEntityName(entityId, entityInstance))
45*07f85150SPatrick Venture         .WillOnce(Return(entityName));
46*07f85150SPatrick Venture     EXPECT_EQ(IPMI_CC_OK,
47*07f85150SPatrick Venture               GetEntityName(request.data(), reply, &dataLen, &hMock));
48*07f85150SPatrick Venture     EXPECT_EQ(reply[1], entityName.length());
49*07f85150SPatrick Venture     EXPECT_EQ(0, std::memcmp(&reply[2], entityName.c_str(), reply[1]));
50*07f85150SPatrick Venture }
51*07f85150SPatrick Venture 
52*07f85150SPatrick Venture } // namespace ipmi
53*07f85150SPatrick Venture } // namespace google
54