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