Patrick Venture | a62466c | 2021-02-08 14:55:18 -0800 | [diff] [blame] | 1 | #include "FruUtils.hpp" |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "gtest/gtest.h" |
| 6 | |
| 7 | extern "C" |
| 8 | { |
| 9 | // Include for I2C_SMBUS_BLOCK_MAX |
| 10 | #include <linux/i2c.h> |
| 11 | } |
| 12 | |
| 13 | TEST(ValidateHeaderTest, InvalidFruVersionReturnsFalse) |
| 14 | { |
| 15 | // Validates the FruVersion is checked for the only legal value. |
| 16 | constexpr std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> fru_header = { |
| 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 18 | |
| 19 | EXPECT_FALSE(validateHeader(fru_header)); |
| 20 | } |
Vijay Khemka | 1694ef6 | 2021-02-12 23:14:49 +0000 | [diff] [blame] | 21 | |
| 22 | TEST(VerifyOffsetTest, EmptyFruDataReturnsFalse) |
| 23 | { |
| 24 | // Validates the FruData size is checked for non empty. |
| 25 | std::vector<uint8_t> fru_data = {}; |
| 26 | |
| 27 | EXPECT_FALSE(verifyOffset(fru_data, fruAreas::fruAreaChassis, 0)); |
| 28 | } |
| 29 | |
| 30 | TEST(VerifyOffsetTest, AreaOutOfRangeReturnsFalse) |
| 31 | { |
| 32 | // Validates the FruArea value, check if it is within range. |
| 33 | const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x00, 0x00, 0x00, |
| 34 | 0x00, 0x00, 0x00, 0x00}; |
| 35 | |
| 36 | unsigned int areaOutOfRange = 8; |
| 37 | EXPECT_FALSE( |
| 38 | verifyOffset(fru_data, static_cast<fruAreas>(areaOutOfRange), 0)); |
| 39 | } |
| 40 | |
| 41 | TEST(VerifyOffsetTest, OverlapNextAreaReturnsFalse) |
| 42 | { |
| 43 | // Validates the Overlap of offsets with overlapped values. |
| 44 | const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x01, 0x02, 0x03, |
| 45 | 0x04, 0x00, 0x00, 0x00}; |
| 46 | |
| 47 | EXPECT_FALSE(verifyOffset(fru_data, fruAreas::fruAreaChassis, 2)); |
| 48 | } |
| 49 | |
| 50 | TEST(VerifyOffsetTest, OverlapPrevAreaReturnsFalse) |
| 51 | { |
| 52 | // Validates the Overlap of offsets with overlapped values. |
| 53 | const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x01, 0x03, 0x02, |
| 54 | 0x07, 0x00, 0x00, 0x00}; |
| 55 | |
| 56 | EXPECT_FALSE(verifyOffset(fru_data, fruAreas::fruAreaProduct, 2)); |
| 57 | } |
| 58 | |
| 59 | TEST(VerifyOffsetTest, ValidInputDataNoOverlapReturnsTrue) |
| 60 | { |
| 61 | // Validates all inputs with expected value and no overlap. |
| 62 | const std::vector<uint8_t> fru_data = {0x01, 0x00, 0x01, 0x02, 0x03, |
| 63 | 0x04, 0x00, 0x00, 0x00}; |
| 64 | |
| 65 | EXPECT_TRUE(verifyOffset(fru_data, fruAreas::fruAreaChassis, 1)); |
| 66 | } |