George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | using namespace pldm::utils; |
| 6 | |
| 7 | TEST(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 | |
| 36 | TEST(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 | |
| 53 | TEST(decodeEffecterData, testGoodDecodeEffecterData) |
| 54 | { |
| 55 | std::vector<uint8_t> effecterData = {2, 1, 1, 0, 1, 2}; |
| 56 | uint16_t effecter_id = 2; |
| 57 | set_effecter_state_field stateField0 = {1, 1}; |
| 58 | set_effecter_state_field stateField1 = {0, 0}; |
| 59 | set_effecter_state_field stateField2 = {1, 2}; |
| 60 | |
| 61 | uint16_t retEffecter_id = 0; |
| 62 | std::vector<set_effecter_state_field> stateField = {}; |
| 63 | auto rc = decodeEffecterData(effecterData, retEffecter_id, stateField); |
| 64 | |
| 65 | EXPECT_EQ(rc, true); |
| 66 | EXPECT_EQ(effecter_id, retEffecter_id); |
| 67 | EXPECT_EQ(stateField[0].set_request, stateField0.set_request); |
| 68 | EXPECT_EQ(stateField[0].effecter_state, stateField0.effecter_state); |
| 69 | EXPECT_EQ(stateField[1].set_request, stateField1.set_request); |
| 70 | EXPECT_EQ(stateField[1].effecter_state, stateField1.effecter_state); |
| 71 | EXPECT_EQ(stateField[2].set_request, stateField2.set_request); |
| 72 | EXPECT_EQ(stateField[2].effecter_state, stateField2.effecter_state); |
| 73 | } |
| 74 | |
| 75 | TEST(decodeEffecterData, testBadDecodeEffecterData) |
| 76 | { |
| 77 | std::vector<uint8_t> effecterData = {2, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 78 | |
| 79 | uint16_t retEffecter_id = 0; |
| 80 | std::vector<set_effecter_state_field> stateField = {}; |
| 81 | auto rc = decodeEffecterData(effecterData, retEffecter_id, stateField); |
| 82 | |
| 83 | EXPECT_EQ(rc, false); |
| 84 | } |