blob: 44e715cf0a56b50771aecec46df9e02334a5f3ce [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
Patrick Williamsb80a0252024-08-16 15:21:31 -040030 std::vector<CrcTestVector> vectors(
31 {{"", 0x1D0F},
32 {"A", 0x9479},
33 {"123456789", 0xE5CC},
34 {longString, 0xE938}});
Patrick Venture161b7212019-03-07 12:17:04 -080035
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