Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 1 | #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 | |
| 10 | TEST(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 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame^] | 27 | TEST(SetStateEffecterStates, testEncodeRequest) |
| 28 | { |
| 29 | pldm_msg request{}; |
| 30 | uint16_t effecterId = 0x0A; |
| 31 | uint8_t compEffecterCnt = 0x2; |
| 32 | std::array<set_effecter_state_field, 8> stateField{}; |
| 33 | stateField[0] = {PLDM_REQUEST_SET, 2}; |
| 34 | stateField[1] = {PLDM_REQUEST_SET, 3}; |
| 35 | |
| 36 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{}; |
| 37 | |
| 38 | request.body.payload = requestMsg.data(); |
| 39 | request.body.payload_length = requestMsg.size(); |
| 40 | |
| 41 | auto rc = encode_set_state_effecter_states_req( |
| 42 | 0, effecterId, compEffecterCnt, stateField.data(), &request); |
| 43 | |
| 44 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 45 | ASSERT_EQ(effecterId, request.body.payload[0]); |
| 46 | ASSERT_EQ(compEffecterCnt, request.body.payload[sizeof(effecterId)]); |
| 47 | ASSERT_EQ( |
| 48 | stateField[0].set_request, |
| 49 | request.body.payload[sizeof(effecterId) + sizeof(compEffecterCnt)]); |
| 50 | ASSERT_EQ( |
| 51 | stateField[0].effecter_state, |
| 52 | request.body.payload[sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 53 | sizeof(stateField[0].set_request)]); |
| 54 | ASSERT_EQ( |
| 55 | stateField[1].set_request, |
| 56 | request.body.payload[sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 57 | sizeof(stateField[0])]); |
| 58 | ASSERT_EQ( |
| 59 | stateField[1].effecter_state, |
| 60 | request.body.payload[sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 61 | sizeof(stateField[0]) + |
| 62 | sizeof(stateField[1].set_request)]); |
| 63 | } |
| 64 | |
| 65 | TEST(SetStateEffecterStates, testGoodDecodeResponse) |
| 66 | { |
| 67 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 68 | responseMsg{}; |
| 69 | |
| 70 | pldm_msg_payload response{}; |
| 71 | response.payload = responseMsg.data(); |
| 72 | response.payload_length = responseMsg.size(); |
| 73 | |
| 74 | uint8_t completion_code = 0xA0; |
| 75 | |
| 76 | uint8_t retcompletion_code = 0; |
| 77 | |
| 78 | memcpy(response.payload, &completion_code, sizeof(completion_code)); |
| 79 | |
| 80 | auto rc = |
| 81 | decode_set_state_effecter_states_resp(&response, &retcompletion_code); |
| 82 | |
| 83 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 84 | ASSERT_EQ(completion_code, retcompletion_code); |
| 85 | } |
| 86 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 87 | TEST(SetStateEffecterStates, testGoodDecodeRequest) |
| 88 | { |
| 89 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{}; |
| 90 | |
| 91 | pldm_msg_payload request{}; |
| 92 | request.payload = requestMsg.data(); |
| 93 | request.payload_length = requestMsg.size(); |
| 94 | |
| 95 | uint16_t effecterId = 0x32; |
| 96 | uint8_t compEffecterCnt = 0x2; |
| 97 | |
| 98 | std::array<set_effecter_state_field, 8> stateField{}; |
| 99 | stateField[0] = {PLDM_REQUEST_SET, 3}; |
| 100 | stateField[1] = {PLDM_REQUEST_SET, 4}; |
| 101 | |
| 102 | uint16_t retEffecterId = 0; |
| 103 | uint8_t retCompEffecterCnt = 0; |
| 104 | |
| 105 | std::array<set_effecter_state_field, 8> retStateField{}; |
| 106 | |
| 107 | memcpy(request.payload, &effecterId, sizeof(effecterId)); |
| 108 | memcpy(request.payload + sizeof(effecterId), &compEffecterCnt, |
| 109 | sizeof(compEffecterCnt)); |
| 110 | memcpy(request.payload + sizeof(effecterId) + sizeof(compEffecterCnt), |
| 111 | &stateField, sizeof(stateField)); |
| 112 | |
| 113 | auto rc = decode_set_state_effecter_states_req( |
| 114 | &request, &retEffecterId, &retCompEffecterCnt, retStateField.data()); |
| 115 | |
| 116 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 117 | ASSERT_EQ(effecterId, retEffecterId); |
| 118 | ASSERT_EQ(retCompEffecterCnt, compEffecterCnt); |
| 119 | ASSERT_EQ(retStateField[0].set_request, stateField[0].set_request); |
| 120 | ASSERT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state); |
| 121 | ASSERT_EQ(retStateField[1].set_request, stateField[1].set_request); |
| 122 | ASSERT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state); |
| 123 | } |
| 124 | |
| 125 | TEST(SetStateEffecterStates, testBadDecodeRequest) |
| 126 | { |
| 127 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{}; |
| 128 | |
| 129 | pldm_msg_payload request{}; |
| 130 | request.payload = requestMsg.data(); |
| 131 | request.payload_length = requestMsg.size(); |
| 132 | |
| 133 | auto rc = decode_set_state_effecter_states_req(&request, NULL, NULL, NULL); |
| 134 | |
| 135 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 136 | } |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame^] | 137 | |
| 138 | TEST(SetStateEffecterStates, testBadDecodeResponse) |
| 139 | { |
| 140 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 141 | responseMsg{}; |
| 142 | |
| 143 | pldm_msg_payload response{}; |
| 144 | response.payload = responseMsg.data(); |
| 145 | response.payload_length = responseMsg.size(); |
| 146 | |
| 147 | auto rc = decode_set_state_effecter_states_resp(&response, NULL); |
| 148 | |
| 149 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 150 | } |