blob: 3fde16a1ff2309e6f2af9ef8958f8b429ae208f9 [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
10TEST(GetDateTime, testEncodeRequest)
11{
12 pldm_msg request{};
Sampa Misra032bd502019-03-06 05:03:22 -060013
14 auto rc = encode_get_date_time_req(0, &request);
15 ASSERT_EQ(rc, PLDM_SUCCESS);
16}
17
18TEST(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
vkaverapa6575b82019-04-03 05:33:52 -050028 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES>
29 responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060030
vkaverapa6575b82019-04-03 05:33:52 -050031 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Sampa Misra032bd502019-03-06 05:03:22 -060032
33 auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes,
vkaverapa6575b82019-04-03 05:33:52 -050034 hours, day, month, year, response);
Sampa Misra032bd502019-03-06 05:03:22 -060035
36 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -050037 ASSERT_EQ(completionCode, response->payload[0]);
Sampa Misra032bd502019-03-06 05:03:22 -060038
vkaverapa6575b82019-04-03 05:33:52 -050039 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 Misra032bd502019-03-06 05:03:22 -060043 &minutes, sizeof(minutes)));
vkaverapa6575b82019-04-03 05:33:52 -050044 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 Misra032bd502019-03-06 05:03:22 -060053 &month, sizeof(month)));
vkaverapa6575b82019-04-03 05:33:52 -050054 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 Misra032bd502019-03-06 05:03:22 -060058}
59
60TEST(GetDateTime, testDecodeResponse)
61{
62 std::array<uint8_t, PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060063
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
vkaverapa6575b82019-04-03 05:33:52 -050080 memcpy(responseMsg.data() + sizeof(completionCode), &seconds,
Sampa Misra032bd502019-03-06 05:03:22 -060081 sizeof(seconds));
vkaverapa6575b82019-04-03 05:33:52 -050082 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds),
Sampa Misra032bd502019-03-06 05:03:22 -060083 &minutes, sizeof(minutes));
vkaverapa6575b82019-04-03 05:33:52 -050084 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Sampa Misra032bd502019-03-06 05:03:22 -060085 sizeof(minutes),
86 &hours, sizeof(hours));
vkaverapa6575b82019-04-03 05:33:52 -050087 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Sampa Misra032bd502019-03-06 05:03:22 -060088 sizeof(minutes) + sizeof(hours),
89 &day, sizeof(day));
vkaverapa6575b82019-04-03 05:33:52 -050090 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Sampa Misra032bd502019-03-06 05:03:22 -060091 sizeof(minutes) + sizeof(hours) + sizeof(day),
92 &month, sizeof(month));
vkaverapa6575b82019-04-03 05:33:52 -050093 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Sampa Misra032bd502019-03-06 05:03:22 -060094 sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month),
95 &year, sizeof(year));
96
vkaverapa6575b82019-04-03 05:33:52 -050097 auto rc = decode_get_date_time_resp(
98 responseMsg.data(), responseMsg.size(), &completionCode, &retSeconds,
99 &retMinutes, &retHours, &retDay, &retMonth, &retYear);
Sampa Misra032bd502019-03-06 05:03:22 -0600100
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}