Patrick Venture | 161b721 | 2019-03-07 12:17:04 -0800 | [diff] [blame] | 1 | #include <ipmiblob/crc.hpp> |
Patrick Venture | 60edc61 | 2020-06-24 15:06:41 -0700 | [diff] [blame] | 2 | |
| 3 | #include <cstdint> |
Patrick Venture | 161b721 | 2019-03-07 12:17:04 -0800 | [diff] [blame] | 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | namespace ipmiblob |
| 10 | { |
| 11 | |
| 12 | TEST(Crc16Test, VerifyCrcValue) |
| 13 | { |
| 14 | // Verify the crc16 is producing the value we expect. |
| 15 | |
| 16 | // Origin: security/crypta/ipmi/portable/ipmi_utils_test.cc |
| 17 | struct CrcTestVector |
| 18 | { |
| 19 | std::string input; |
| 20 | uint16_t output; |
| 21 | }; |
| 22 | |
| 23 | std::string longString = |
| 24 | "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 25 | "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 26 | "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 27 | "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 28 | "AAAAAAAAAAAAAAAA"; |
| 29 | |
Patrick Williams | b80a025 | 2024-08-16 15:21:31 -0400 | [diff] [blame^] | 30 | std::vector<CrcTestVector> vectors( |
| 31 | {{"", 0x1D0F}, |
| 32 | {"A", 0x9479}, |
| 33 | {"123456789", 0xE5CC}, |
| 34 | {longString, 0xE938}}); |
Patrick Venture | 161b721 | 2019-03-07 12:17:04 -0800 | [diff] [blame] | 35 | |
| 36 | for (const CrcTestVector& testVector : vectors) |
| 37 | { |
| 38 | std::vector<std::uint8_t> input; |
| 39 | input.insert(input.begin(), testVector.input.begin(), |
| 40 | testVector.input.end()); |
| 41 | EXPECT_EQ(generateCrc(input), testVector.output); |
| 42 | } |
| 43 | } |
| 44 | } // namespace ipmiblob |