blob: 7091cb119ab67ef2b22f607c4c520006936eb491 [file] [log] [blame]
#include "commands.hpp"
#include "entity_name.hpp"
#include "handler_mock.hpp"
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#define MAX_IPMI_BUFFER 64
using ::testing::Return;
namespace google
{
namespace ipmi
{
TEST(EntityNameCommandTest, InvalidCommandLength)
{
// GetEntityNameRequest is three bytes, let's send 2.
std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName, 0x01};
size_t dataLen = request.size();
std::uint8_t reply[MAX_IPMI_BUFFER];
HandlerMock hMock;
EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
getEntityName(request.data(), reply, &dataLen, &hMock));
}
TEST(EntityNameCommandTest, ValidRequest)
{
std::uint8_t entityId = 3;
std::uint8_t entityInstance = 5;
std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName,
entityId, entityInstance};
size_t dataLen = request.size();
std::uint8_t reply[MAX_IPMI_BUFFER];
std::string entityName = "asdf";
HandlerMock hMock;
EXPECT_CALL(hMock, getEntityName(entityId, entityInstance))
.WillOnce(Return(entityName));
EXPECT_EQ(IPMI_CC_OK,
getEntityName(request.data(), reply, &dataLen, &hMock));
EXPECT_EQ(reply[1], entityName.length());
EXPECT_EQ(0, std::memcmp(&reply[2], entityName.c_str(), reply[1]));
}
} // namespace ipmi
} // namespace google