blob: 1010bd85335f213f18e365266d9bdfe8e2428ce8 [file] [log] [blame]
#include <string.h>
#include <array>
#include "libpldm/base.h"
#include "libpldm/platform.h"
#include <gtest/gtest.h>
constexpr auto hdrSize = sizeof(pldm_msg_hdr);
TEST(SetStateEffecterStates, testEncodeResponse)
{
std::array<uint8_t,
sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
responseMsg{};
auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
uint8_t completionCode = 0;
auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response);
ASSERT_EQ(rc, PLDM_SUCCESS);
ASSERT_EQ(completionCode, response->payload[0]);
}
TEST(SetStateEffecterStates, testEncodeRequest)
{
std::array<uint8_t,
sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
requestMsg{};
auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
uint16_t effecterId = 0x0A;
uint8_t compEffecterCnt = 0x2;
std::array<set_effecter_state_field, 8> stateField{};
stateField[0] = {PLDM_REQUEST_SET, 2};
stateField[1] = {PLDM_REQUEST_SET, 3};
auto rc = encode_set_state_effecter_states_req(
0, effecterId, compEffecterCnt, stateField.data(), request);
ASSERT_EQ(rc, PLDM_SUCCESS);
ASSERT_EQ(effecterId, request->payload[0]);
ASSERT_EQ(compEffecterCnt, request->payload[sizeof(effecterId)]);
ASSERT_EQ(stateField[0].set_request,
request->payload[sizeof(effecterId) + sizeof(compEffecterCnt)]);
ASSERT_EQ(stateField[0].effecter_state,
request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
sizeof(stateField[0].set_request)]);
ASSERT_EQ(stateField[1].set_request,
request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
sizeof(stateField[0])]);
ASSERT_EQ(stateField[1].effecter_state,
request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
sizeof(stateField[0]) +
sizeof(stateField[1].set_request)]);
}
TEST(SetStateEffecterStates, testGoodDecodeResponse)
{
std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
responseMsg{};
uint8_t completion_code = 0xA0;
uint8_t retcompletion_code = 0;
memcpy(responseMsg.data() + hdrSize, &completion_code,
sizeof(completion_code));
auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
auto rc = decode_set_state_effecter_states_resp(
response, responseMsg.size() - hdrSize, &retcompletion_code);
ASSERT_EQ(rc, PLDM_SUCCESS);
ASSERT_EQ(completion_code, retcompletion_code);
}
TEST(SetStateEffecterStates, testGoodDecodeRequest)
{
std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
requestMsg{};
uint16_t effecterId = 0x32;
uint8_t compEffecterCnt = 0x2;
std::array<set_effecter_state_field, 8> stateField{};
stateField[0] = {PLDM_REQUEST_SET, 3};
stateField[1] = {PLDM_REQUEST_SET, 4};
uint16_t retEffecterId = 0;
uint8_t retCompEffecterCnt = 0;
std::array<set_effecter_state_field, 8> retStateField{};
memcpy(requestMsg.data() + hdrSize, &effecterId, sizeof(effecterId));
memcpy(requestMsg.data() + sizeof(effecterId) + hdrSize, &compEffecterCnt,
sizeof(compEffecterCnt));
memcpy(requestMsg.data() + sizeof(effecterId) + sizeof(compEffecterCnt) +
hdrSize,
&stateField, sizeof(stateField));
auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
auto rc = decode_set_state_effecter_states_req(
request, requestMsg.size() - hdrSize, &retEffecterId,
&retCompEffecterCnt, retStateField.data());
ASSERT_EQ(rc, PLDM_SUCCESS);
ASSERT_EQ(effecterId, retEffecterId);
ASSERT_EQ(retCompEffecterCnt, compEffecterCnt);
ASSERT_EQ(retStateField[0].set_request, stateField[0].set_request);
ASSERT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state);
ASSERT_EQ(retStateField[1].set_request, stateField[1].set_request);
ASSERT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state);
}
TEST(SetStateEffecterStates, testBadDecodeRequest)
{
const struct pldm_msg* msg = NULL;
auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL,
NULL, NULL);
ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}
TEST(SetStateEffecterStates, testBadDecodeResponse)
{
std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
responseMsg{};
auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
auto rc = decode_set_state_effecter_states_resp(response,
responseMsg.size(), NULL);
ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}