blob: d46215ea673466d81d35c7d10a4a2e608f6a9dbe [file] [log] [blame]
Patrick Venture161b7212019-03-07 12:17:04 -08001#include <ipmiblob/crc.hpp>
Patrick Venture60edc612020-06-24 15:06:41 -07002
3#include <cstdint>
Patrick Venture161b7212019-03-07 12:17:04 -08004#include <string>
5#include <vector>
6
7#include <gtest/gtest.h>
8
9namespace ipmiblob
10{
11
12TEST(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
30 std::vector<CrcTestVector> vectors({{"", 0x1D0F},
31 {"A", 0x9479},
32 {"123456789", 0xE5CC},
33 {longString, 0xE938}});
34
35 for (const CrcTestVector& testVector : vectors)
36 {
37 std::vector<std::uint8_t> input;
38 input.insert(input.begin(), testVector.input.begin(),
39 testVector.input.end());
40 EXPECT_EQ(generateCrc(input), testVector.output);
41 }
42}
43} // namespace ipmiblob