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 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 53 | TEST(parseEffecterData, testGoodDecodeEffecterData) |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 54 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 55 | std::vector<uint8_t> effecterData = {1, 1, 0, 1}; |
| 56 | uint8_t effecterCount = 2; |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 57 | set_effecter_state_field stateField0 = {1, 1}; |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 58 | set_effecter_state_field stateField1 = {0, 1}; |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 59 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 60 | auto effecterField = parseEffecterData(effecterData, effecterCount); |
| 61 | EXPECT_NE(effecterField, std::nullopt); |
| 62 | EXPECT_EQ(effecterCount, effecterField->size()); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 63 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 64 | std::vector<set_effecter_state_field> stateField = effecterField.value(); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 65 | 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 Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 69 | } |
| 70 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 71 | TEST(parseEffecterData, testBadDecodeEffecterData) |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 72 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 73 | std::vector<uint8_t> effecterData = {0, 1, 0, 1, 0, 1}; |
| 74 | uint8_t effecterCount = 2; |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 75 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 76 | auto effecterField = parseEffecterData(effecterData, effecterCount); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 77 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 78 | EXPECT_EQ(effecterField, std::nullopt); |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 79 | } |