1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/metrics/crc32.h" 6 7 #include <stdint.h> 8 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace base { 12 13 // Table was generated similarly to sample code for CRC-32 given on: 14 // http://www.w3.org/TR/PNG/#D-CRCAppendix. TEST(Crc32Test,TableTest)15TEST(Crc32Test, TableTest) { 16 for (int i = 0; i < 256; ++i) { 17 uint32_t checksum = i; 18 for (int j = 0; j < 8; ++j) { 19 const uint32_t kReversedPolynomial = 0xEDB88320L; 20 if (checksum & 1) 21 checksum = kReversedPolynomial ^ (checksum >> 1); 22 else 23 checksum >>= 1; 24 } 25 EXPECT_EQ(kCrcTable[i], checksum); 26 } 27 } 28 29 // A CRC of nothing should always be zero. TEST(Crc32Test,ZeroTest)30TEST(Crc32Test, ZeroTest) { 31 EXPECT_EQ(0U, Crc32(0, nullptr, 0)); 32 } 33 34 } // namespace base 35