blob: 495a0d22f17cd03eace2f2560f5a9d94aa790c11 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#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 Hossain223a73d2019-07-04 12:46:18 -050010constexpr auto hdrSize = sizeof(pldm_msg_hdr);
11
Sampa Misra032bd502019-03-06 05:03:22 -060012TEST(GetDateTime, testEncodeRequest)
13{
14 pldm_msg request{};
Sampa Misra032bd502019-03-06 05:03:22 -060015
16 auto rc = encode_get_date_time_req(0, &request);
17 ASSERT_EQ(rc, PLDM_SUCCESS);
18}
19
20TEST(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
vkaverapa6575b82019-04-03 05:33:52 -050030 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES>
31 responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060032
vkaverapa6575b82019-04-03 05:33:52 -050033 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Sampa Misra032bd502019-03-06 05:03:22 -060034
35 auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes,
vkaverapa6575b82019-04-03 05:33:52 -050036 hours, day, month, year, response);
Sampa Misra032bd502019-03-06 05:03:22 -060037
38 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -050039 ASSERT_EQ(completionCode, response->payload[0]);
Sampa Misra032bd502019-03-06 05:03:22 -060040
vkaverapa6575b82019-04-03 05:33:52 -050041 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 Misra032bd502019-03-06 05:03:22 -060045 &minutes, sizeof(minutes)));
vkaverapa6575b82019-04-03 05:33:52 -050046 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 Misra032bd502019-03-06 05:03:22 -060055 &month, sizeof(month)));
vkaverapa6575b82019-04-03 05:33:52 -050056 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 Misra032bd502019-03-06 05:03:22 -060060}
61
62TEST(GetDateTime, testDecodeResponse)
63{
Zahed Hossain223a73d2019-07-04 12:46:18 -050064 std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060065
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 Hossain223a73d2019-07-04 12:46:18 -050082 memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds,
Sampa Misra032bd502019-03-06 05:03:22 -060083 sizeof(seconds));
Zahed Hossain223a73d2019-07-04 12:46:18 -050084 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
85 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060086 &minutes, sizeof(minutes));
vkaverapa6575b82019-04-03 05:33:52 -050087 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050088 sizeof(minutes) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060089 &hours, sizeof(hours));
vkaverapa6575b82019-04-03 05:33:52 -050090 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050091 sizeof(minutes) + sizeof(hours) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060092 &day, sizeof(day));
vkaverapa6575b82019-04-03 05:33:52 -050093 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050094 sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060095 &month, sizeof(month));
vkaverapa6575b82019-04-03 05:33:52 -050096 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050097 sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) +
98 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060099 &year, sizeof(year));
100
Zahed Hossain223a73d2019-07-04 12:46:18 -0500101 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
102
vkaverapa6575b82019-04-03 05:33:52 -0500103 auto rc = decode_get_date_time_resp(
Zahed Hossain223a73d2019-07-04 12:46:18 -0500104 response, responseMsg.size() - hdrSize, &completionCode, &retSeconds,
vkaverapa6575b82019-04-03 05:33:52 -0500105 &retMinutes, &retHours, &retDay, &retMonth, &retYear);
Sampa Misra032bd502019-03-06 05:03:22 -0600106
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}