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