blob: b046e3f5181d4a38407b5a8acf033badad3e396c [file] [log] [blame]
Sampa Misra0db1dfa2019-03-19 00:15:31 -05001#include <string.h>
2
3#include <array>
4
5#include "libpldm/base.h"
6#include "libpldm/platform.h"
7
8#include <gtest/gtest.h>
9
10TEST(SetStateEffecterStates, testEncodeResponse)
11{
vkaverapa6575b82019-04-03 05:33:52 -050012 std::array<uint8_t,
13 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
14 responseMsg{};
15 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Sampa Misra0db1dfa2019-03-19 00:15:31 -050016 uint8_t completionCode = 0;
17
vkaverapa6575b82019-04-03 05:33:52 -050018 auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response);
Sampa Misra0db1dfa2019-03-19 00:15:31 -050019
20 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -050021 ASSERT_EQ(completionCode, response->payload[0]);
Sampa Misra0db1dfa2019-03-19 00:15:31 -050022}
23
vkaverap98a2c192019-04-03 05:33:52 -050024TEST(SetStateEffecterStates, testEncodeRequest)
25{
vkaverapa6575b82019-04-03 05:33:52 -050026 std::array<uint8_t,
27 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
28 requestMsg{};
29 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
30
vkaverap98a2c192019-04-03 05:33:52 -050031 uint16_t effecterId = 0x0A;
32 uint8_t compEffecterCnt = 0x2;
33 std::array<set_effecter_state_field, 8> stateField{};
34 stateField[0] = {PLDM_REQUEST_SET, 2};
35 stateField[1] = {PLDM_REQUEST_SET, 3};
36
vkaverap98a2c192019-04-03 05:33:52 -050037 auto rc = encode_set_state_effecter_states_req(
vkaverapa6575b82019-04-03 05:33:52 -050038 0, effecterId, compEffecterCnt, stateField.data(), request);
vkaverap98a2c192019-04-03 05:33:52 -050039
40 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -050041 ASSERT_EQ(effecterId, request->payload[0]);
42 ASSERT_EQ(compEffecterCnt, request->payload[sizeof(effecterId)]);
43 ASSERT_EQ(stateField[0].set_request,
44 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt)]);
45 ASSERT_EQ(stateField[0].effecter_state,
46 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
47 sizeof(stateField[0].set_request)]);
48 ASSERT_EQ(stateField[1].set_request,
49 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
50 sizeof(stateField[0])]);
51 ASSERT_EQ(stateField[1].effecter_state,
52 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
53 sizeof(stateField[0]) +
54 sizeof(stateField[1].set_request)]);
vkaverap98a2c192019-04-03 05:33:52 -050055}
56
57TEST(SetStateEffecterStates, testGoodDecodeResponse)
58{
59 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
60 responseMsg{};
61
vkaverap98a2c192019-04-03 05:33:52 -050062 uint8_t completion_code = 0xA0;
63
64 uint8_t retcompletion_code = 0;
65
vkaverapa6575b82019-04-03 05:33:52 -050066 memcpy(responseMsg.data(), &completion_code, sizeof(completion_code));
vkaverap98a2c192019-04-03 05:33:52 -050067
vkaverapa6575b82019-04-03 05:33:52 -050068 auto rc = decode_set_state_effecter_states_resp(
69 responseMsg.data(), responseMsg.size(), &retcompletion_code);
vkaverap98a2c192019-04-03 05:33:52 -050070
71 ASSERT_EQ(rc, PLDM_SUCCESS);
72 ASSERT_EQ(completion_code, retcompletion_code);
73}
74
Sampa Misra0db1dfa2019-03-19 00:15:31 -050075TEST(SetStateEffecterStates, testGoodDecodeRequest)
76{
77 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{};
78
Sampa Misra0db1dfa2019-03-19 00:15:31 -050079 uint16_t effecterId = 0x32;
80 uint8_t compEffecterCnt = 0x2;
81
82 std::array<set_effecter_state_field, 8> stateField{};
83 stateField[0] = {PLDM_REQUEST_SET, 3};
84 stateField[1] = {PLDM_REQUEST_SET, 4};
85
86 uint16_t retEffecterId = 0;
87 uint8_t retCompEffecterCnt = 0;
88
89 std::array<set_effecter_state_field, 8> retStateField{};
90
vkaverapa6575b82019-04-03 05:33:52 -050091 memcpy(requestMsg.data(), &effecterId, sizeof(effecterId));
92 memcpy(requestMsg.data() + sizeof(effecterId), &compEffecterCnt,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050093 sizeof(compEffecterCnt));
vkaverapa6575b82019-04-03 05:33:52 -050094 memcpy(requestMsg.data() + sizeof(effecterId) + sizeof(compEffecterCnt),
Sampa Misra0db1dfa2019-03-19 00:15:31 -050095 &stateField, sizeof(stateField));
96
97 auto rc = decode_set_state_effecter_states_req(
vkaverapa6575b82019-04-03 05:33:52 -050098 requestMsg.data(), requestMsg.size(), &retEffecterId,
99 &retCompEffecterCnt, retStateField.data());
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500100
101 ASSERT_EQ(rc, PLDM_SUCCESS);
102 ASSERT_EQ(effecterId, retEffecterId);
103 ASSERT_EQ(retCompEffecterCnt, compEffecterCnt);
104 ASSERT_EQ(retStateField[0].set_request, stateField[0].set_request);
105 ASSERT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state);
106 ASSERT_EQ(retStateField[1].set_request, stateField[1].set_request);
107 ASSERT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state);
108}
109
110TEST(SetStateEffecterStates, testBadDecodeRequest)
111{
vkaverapa6575b82019-04-03 05:33:52 -0500112 const uint8_t* msg = NULL;
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500113
vkaverapa6575b82019-04-03 05:33:52 -0500114 auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL,
115 NULL, NULL);
Sampa Misra0db1dfa2019-03-19 00:15:31 -0500116
117 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
118}
vkaverap98a2c192019-04-03 05:33:52 -0500119
120TEST(SetStateEffecterStates, testBadDecodeResponse)
121{
122 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
123 responseMsg{};
124
vkaverapa6575b82019-04-03 05:33:52 -0500125 auto rc = decode_set_state_effecter_states_resp(responseMsg.data(),
126 responseMsg.size(), NULL);
vkaverap98a2c192019-04-03 05:33:52 -0500127
128 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
129}