Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "libpldm/base.h" |
| 6 | #include "libpldm/bios.h" |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | TEST(GetDateTime, testEncodeRequest) |
| 11 | { |
| 12 | pldm_msg request{}; |
| 13 | request.body.payload = nullptr; |
| 14 | request.body.payload_length = 0; |
| 15 | |
| 16 | auto rc = encode_get_date_time_req(0, &request); |
| 17 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 18 | } |
| 19 | |
| 20 | TEST(GetDateTime, testEncodeResponse) |
| 21 | { |
| 22 | uint8_t completionCode = 0; |
| 23 | uint8_t seconds = 50; |
| 24 | uint8_t minutes = 20; |
| 25 | uint8_t hours = 5; |
| 26 | uint8_t day = 23; |
| 27 | uint8_t month = 11; |
| 28 | uint16_t year = 2019; |
| 29 | |
| 30 | std::array<uint8_t, PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
| 31 | pldm_msg response{}; |
| 32 | |
| 33 | response.body.payload = responseMsg.data(); |
| 34 | response.body.payload_length = responseMsg.size(); |
| 35 | |
| 36 | auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes, |
| 37 | hours, day, month, year, &response); |
| 38 | |
| 39 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 40 | ASSERT_EQ(completionCode, response.body.payload[0]); |
| 41 | |
| 42 | ASSERT_EQ(0, |
| 43 | memcmp(response.body.payload + sizeof(response.body.payload[0]), |
| 44 | &seconds, sizeof(seconds))); |
| 45 | ASSERT_EQ(0, memcmp(response.body.payload + |
| 46 | sizeof(response.body.payload[0]) + sizeof(seconds), |
| 47 | &minutes, sizeof(minutes))); |
| 48 | ASSERT_EQ(0, |
| 49 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 50 | sizeof(seconds) + sizeof(minutes), |
| 51 | &hours, sizeof(hours))); |
| 52 | ASSERT_EQ(0, |
| 53 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 54 | sizeof(seconds) + sizeof(minutes) + sizeof(hours), |
| 55 | &day, sizeof(day))); |
| 56 | ASSERT_EQ(0, memcmp(response.body.payload + |
| 57 | sizeof(response.body.payload[0]) + sizeof(seconds) + |
| 58 | sizeof(minutes) + sizeof(hours) + sizeof(day), |
| 59 | &month, sizeof(month))); |
| 60 | ASSERT_EQ(0, |
| 61 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 62 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 63 | sizeof(day) + sizeof(month), |
| 64 | &year, sizeof(year))); |
| 65 | } |
| 66 | |
| 67 | TEST(GetDateTime, testDecodeResponse) |
| 68 | { |
| 69 | std::array<uint8_t, PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
| 70 | pldm_msg_payload response{}; |
| 71 | response.payload = responseMsg.data(); |
| 72 | response.payload_length = responseMsg.size(); |
| 73 | |
| 74 | uint8_t completionCode = 0; |
| 75 | |
| 76 | uint8_t seconds = 55; |
| 77 | uint8_t minutes = 2; |
| 78 | uint8_t hours = 8; |
| 79 | uint8_t day = 9; |
| 80 | uint8_t month = 7; |
| 81 | uint16_t year = 2020; |
| 82 | |
| 83 | uint8_t retSeconds = 0; |
| 84 | uint8_t retMinutes = 0; |
| 85 | uint8_t retHours = 0; |
| 86 | uint8_t retDay = 0; |
| 87 | uint8_t retMonth = 0; |
| 88 | uint16_t retYear = 0; |
| 89 | |
| 90 | memcpy(response.payload + sizeof(completionCode), &seconds, |
| 91 | sizeof(seconds)); |
| 92 | memcpy(response.payload + sizeof(completionCode) + sizeof(seconds), |
| 93 | &minutes, sizeof(minutes)); |
| 94 | memcpy(response.payload + sizeof(completionCode) + sizeof(seconds) + |
| 95 | sizeof(minutes), |
| 96 | &hours, sizeof(hours)); |
| 97 | memcpy(response.payload + sizeof(completionCode) + sizeof(seconds) + |
| 98 | sizeof(minutes) + sizeof(hours), |
| 99 | &day, sizeof(day)); |
| 100 | memcpy(response.payload + sizeof(completionCode) + sizeof(seconds) + |
| 101 | sizeof(minutes) + sizeof(hours) + sizeof(day), |
| 102 | &month, sizeof(month)); |
| 103 | memcpy(response.payload + sizeof(completionCode) + sizeof(seconds) + |
| 104 | sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month), |
| 105 | &year, sizeof(year)); |
| 106 | |
| 107 | auto rc = decode_get_date_time_resp(&response, &completionCode, &retSeconds, |
| 108 | &retMinutes, &retHours, &retDay, |
| 109 | &retMonth, &retYear); |
| 110 | |
| 111 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 112 | ASSERT_EQ(seconds, retSeconds); |
| 113 | ASSERT_EQ(minutes, retMinutes); |
| 114 | ASSERT_EQ(hours, retHours); |
| 115 | ASSERT_EQ(day, retDay); |
| 116 | ASSERT_EQ(month, retMonth); |
| 117 | ASSERT_EQ(year, retYear); |
| 118 | } |