blob: c880c20e51e0037379486b3e85a5b1d5680f40ed [file] [log] [blame]
George Liu83409572019-12-24 18:42:54 +08001#include "utils.hpp"
2
3#include <gtest/gtest.h>
4
5using namespace pldm::utils;
6
7TEST(decodeDate, testGooduintToDate)
8{
9 uint64_t data = 20191212115959;
10 uint16_t year = 2019;
11 uint8_t month = 12;
12 uint8_t day = 12;
13 uint8_t hours = 11;
14 uint8_t minutes = 59;
15 uint8_t seconds = 59;
16
17 uint16_t retyear = 0;
18 uint8_t retmonth = 0;
19 uint8_t retday = 0;
20 uint8_t rethours = 0;
21 uint8_t retminutes = 0;
22 uint8_t retseconds = 0;
23
24 auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours,
25 &retminutes, &retseconds);
26
27 EXPECT_EQ(ret, true);
28 EXPECT_EQ(year, retyear);
29 EXPECT_EQ(month, retmonth);
30 EXPECT_EQ(day, retday);
31 EXPECT_EQ(hours, rethours);
32 EXPECT_EQ(minutes, retminutes);
33 EXPECT_EQ(seconds, retseconds);
34}
35
36TEST(decodeDate, testBaduintToDate)
37{
38 uint64_t data = 10191212115959;
39
40 uint16_t retyear = 0;
41 uint8_t retmonth = 0;
42 uint8_t retday = 0;
43 uint8_t rethours = 0;
44 uint8_t retminutes = 0;
45 uint8_t retseconds = 0;
46
47 auto ret = uintToDate(data, &retyear, &retmonth, &retday, &rethours,
48 &retminutes, &retseconds);
49
50 EXPECT_EQ(ret, false);
51}
52
George Liuba4c1fb2020-02-05 14:13:30 +080053TEST(parseEffecterData, testGoodDecodeEffecterData)
George Liu83409572019-12-24 18:42:54 +080054{
George Liuba4c1fb2020-02-05 14:13:30 +080055 std::vector<uint8_t> effecterData = {1, 1, 0, 1};
56 uint8_t effecterCount = 2;
George Liu83409572019-12-24 18:42:54 +080057 set_effecter_state_field stateField0 = {1, 1};
George Liuba4c1fb2020-02-05 14:13:30 +080058 set_effecter_state_field stateField1 = {0, 1};
George Liu83409572019-12-24 18:42:54 +080059
George Liuba4c1fb2020-02-05 14:13:30 +080060 auto effecterField = parseEffecterData(effecterData, effecterCount);
61 EXPECT_NE(effecterField, std::nullopt);
62 EXPECT_EQ(effecterCount, effecterField->size());
George Liu83409572019-12-24 18:42:54 +080063
George Liuba4c1fb2020-02-05 14:13:30 +080064 std::vector<set_effecter_state_field> stateField = effecterField.value();
George Liu83409572019-12-24 18:42:54 +080065 EXPECT_EQ(stateField[0].set_request, stateField0.set_request);
66 EXPECT_EQ(stateField[0].effecter_state, stateField0.effecter_state);
67 EXPECT_EQ(stateField[1].set_request, stateField1.set_request);
68 EXPECT_EQ(stateField[1].effecter_state, stateField1.effecter_state);
George Liu83409572019-12-24 18:42:54 +080069}
70
George Liuba4c1fb2020-02-05 14:13:30 +080071TEST(parseEffecterData, testBadDecodeEffecterData)
George Liu83409572019-12-24 18:42:54 +080072{
George Liuba4c1fb2020-02-05 14:13:30 +080073 std::vector<uint8_t> effecterData = {0, 1, 0, 1, 0, 1};
74 uint8_t effecterCount = 2;
George Liu83409572019-12-24 18:42:54 +080075
George Liuba4c1fb2020-02-05 14:13:30 +080076 auto effecterField = parseEffecterData(effecterData, effecterCount);
George Liu83409572019-12-24 18:42:54 +080077
George Liuba4c1fb2020-02-05 14:13:30 +080078 EXPECT_EQ(effecterField, std::nullopt);
George Liu83409572019-12-24 18:42:54 +080079}