blob: 0de82e4a933afeec73b15d12b7f31b0b4f1e26c4 [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{
12 pldm_msg response{};
13 uint8_t completionCode = 0;
14
15 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
16 responseMsg{};
17
18 response.body.payload = responseMsg.data();
19 response.body.payload_length = responseMsg.size();
20
21 auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, &response);
22
23 ASSERT_EQ(rc, PLDM_SUCCESS);
24 ASSERT_EQ(completionCode, response.body.payload[0]);
25}
26
27TEST(SetStateEffecterStates, testGoodDecodeRequest)
28{
29 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{};
30
31 pldm_msg_payload request{};
32 request.payload = requestMsg.data();
33 request.payload_length = requestMsg.size();
34
35 uint16_t effecterId = 0x32;
36 uint8_t compEffecterCnt = 0x2;
37
38 std::array<set_effecter_state_field, 8> stateField{};
39 stateField[0] = {PLDM_REQUEST_SET, 3};
40 stateField[1] = {PLDM_REQUEST_SET, 4};
41
42 uint16_t retEffecterId = 0;
43 uint8_t retCompEffecterCnt = 0;
44
45 std::array<set_effecter_state_field, 8> retStateField{};
46
47 memcpy(request.payload, &effecterId, sizeof(effecterId));
48 memcpy(request.payload + sizeof(effecterId), &compEffecterCnt,
49 sizeof(compEffecterCnt));
50 memcpy(request.payload + sizeof(effecterId) + sizeof(compEffecterCnt),
51 &stateField, sizeof(stateField));
52
53 auto rc = decode_set_state_effecter_states_req(
54 &request, &retEffecterId, &retCompEffecterCnt, retStateField.data());
55
56 ASSERT_EQ(rc, PLDM_SUCCESS);
57 ASSERT_EQ(effecterId, retEffecterId);
58 ASSERT_EQ(retCompEffecterCnt, compEffecterCnt);
59 ASSERT_EQ(retStateField[0].set_request, stateField[0].set_request);
60 ASSERT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state);
61 ASSERT_EQ(retStateField[1].set_request, stateField[1].set_request);
62 ASSERT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state);
63}
64
65TEST(SetStateEffecterStates, testBadDecodeRequest)
66{
67 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{};
68
69 pldm_msg_payload request{};
70 request.payload = requestMsg.data();
71 request.payload_length = requestMsg.size();
72
73 auto rc = decode_set_state_effecter_states_req(&request, NULL, NULL, NULL);
74
75 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
76}