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 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 12 | 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 Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 16 | uint8_t completionCode = 0; |
| 17 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 18 | auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response); |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 19 | |
| 20 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 21 | ASSERT_EQ(completionCode, response->payload[0]); |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 22 | } |
| 23 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 24 | TEST(SetStateEffecterStates, testEncodeRequest) |
| 25 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 26 | 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 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 31 | 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 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 37 | auto rc = encode_set_state_effecter_states_req( |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 38 | 0, effecterId, compEffecterCnt, stateField.data(), request); |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 39 | |
| 40 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 41 | 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)]); |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | TEST(SetStateEffecterStates, testGoodDecodeResponse) |
| 58 | { |
| 59 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 60 | responseMsg{}; |
| 61 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 62 | uint8_t completion_code = 0xA0; |
| 63 | |
| 64 | uint8_t retcompletion_code = 0; |
| 65 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 66 | memcpy(responseMsg.data(), &completion_code, sizeof(completion_code)); |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 67 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 68 | auto rc = decode_set_state_effecter_states_resp( |
| 69 | responseMsg.data(), responseMsg.size(), &retcompletion_code); |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 70 | |
| 71 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 72 | ASSERT_EQ(completion_code, retcompletion_code); |
| 73 | } |
| 74 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 75 | TEST(SetStateEffecterStates, testGoodDecodeRequest) |
| 76 | { |
| 77 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> requestMsg{}; |
| 78 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 79 | 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 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 91 | memcpy(requestMsg.data(), &effecterId, sizeof(effecterId)); |
| 92 | memcpy(requestMsg.data() + sizeof(effecterId), &compEffecterCnt, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 93 | sizeof(compEffecterCnt)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 94 | memcpy(requestMsg.data() + sizeof(effecterId) + sizeof(compEffecterCnt), |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 95 | &stateField, sizeof(stateField)); |
| 96 | |
| 97 | auto rc = decode_set_state_effecter_states_req( |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 98 | requestMsg.data(), requestMsg.size(), &retEffecterId, |
| 99 | &retCompEffecterCnt, retStateField.data()); |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 100 | |
| 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 | |
| 110 | TEST(SetStateEffecterStates, testBadDecodeRequest) |
| 111 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 112 | const uint8_t* msg = NULL; |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 113 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 114 | auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL, |
| 115 | NULL, NULL); |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 116 | |
| 117 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 118 | } |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 119 | |
| 120 | TEST(SetStateEffecterStates, testBadDecodeResponse) |
| 121 | { |
| 122 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 123 | responseMsg{}; |
| 124 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 125 | auto rc = decode_set_state_effecter_states_resp(responseMsg.data(), |
| 126 | responseMsg.size(), NULL); |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 127 | |
| 128 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 129 | } |