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 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 10 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 11 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 12 | TEST(GetDateTime, testEncodeRequest) |
| 13 | { |
| 14 | pldm_msg request{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 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 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 30 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES> |
| 31 | responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 32 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 33 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 34 | |
| 35 | auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 36 | hours, day, month, year, response); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 37 | |
| 38 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 39 | ASSERT_EQ(completionCode, response->payload[0]); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 40 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 41 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 42 | &seconds, sizeof(seconds))); |
| 43 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 44 | sizeof(seconds), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 45 | &minutes, sizeof(minutes))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 46 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 47 | sizeof(seconds) + sizeof(minutes), |
| 48 | &hours, sizeof(hours))); |
| 49 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 50 | sizeof(seconds) + sizeof(minutes) + sizeof(hours), |
| 51 | &day, sizeof(day))); |
| 52 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 53 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 54 | sizeof(day), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 55 | &month, sizeof(month))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 56 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 57 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 58 | sizeof(day) + sizeof(month), |
| 59 | &year, sizeof(year))); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | TEST(GetDateTime, testDecodeResponse) |
| 63 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 64 | std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 65 | |
| 66 | uint8_t completionCode = 0; |
| 67 | |
| 68 | uint8_t seconds = 55; |
| 69 | uint8_t minutes = 2; |
| 70 | uint8_t hours = 8; |
| 71 | uint8_t day = 9; |
| 72 | uint8_t month = 7; |
| 73 | uint16_t year = 2020; |
| 74 | |
| 75 | uint8_t retSeconds = 0; |
| 76 | uint8_t retMinutes = 0; |
| 77 | uint8_t retHours = 0; |
| 78 | uint8_t retDay = 0; |
| 79 | uint8_t retMonth = 0; |
| 80 | uint16_t retYear = 0; |
| 81 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 82 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 83 | sizeof(seconds)); |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 84 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 85 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 86 | &minutes, sizeof(minutes)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 87 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 88 | sizeof(minutes) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 89 | &hours, sizeof(hours)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 90 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 91 | sizeof(minutes) + sizeof(hours) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 92 | &day, sizeof(day)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 93 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 94 | sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 95 | &month, sizeof(month)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 96 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 97 | sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) + |
| 98 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 99 | &year, sizeof(year)); |
| 100 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 101 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 102 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 103 | auto rc = decode_get_date_time_resp( |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 104 | response, responseMsg.size() - hdrSize, &completionCode, &retSeconds, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 105 | &retMinutes, &retHours, &retDay, &retMonth, &retYear); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 106 | |
| 107 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 108 | ASSERT_EQ(seconds, retSeconds); |
| 109 | ASSERT_EQ(minutes, retMinutes); |
| 110 | ASSERT_EQ(hours, retHours); |
| 111 | ASSERT_EQ(day, retDay); |
| 112 | ASSERT_EQ(month, retMonth); |
| 113 | ASSERT_EQ(year, retYear); |
| 114 | } |