1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
5 #include "util/crc32c.h"
6 #include "util/testharness.h"
13 TEST(CRC
, StandardResults
) {
14 // From rfc3720 section B.4.
17 memset(buf
, 0, sizeof(buf
));
18 ASSERT_EQ(0x8a9136aa, Value(buf
, sizeof(buf
)));
20 memset(buf
, 0xff, sizeof(buf
));
21 ASSERT_EQ(0x62a8ab43, Value(buf
, sizeof(buf
)));
23 for (int i
= 0; i
< 32; i
++) {
26 ASSERT_EQ(0x46dd794e, Value(buf
, sizeof(buf
)));
28 for (int i
= 0; i
< 32; i
++) {
31 ASSERT_EQ(0x113fdb5c, Value(buf
, sizeof(buf
)));
33 unsigned char data
[48] = {
34 0x01, 0xc0, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00,
38 0x14, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x04, 0x00,
40 0x00, 0x00, 0x00, 0x14,
41 0x00, 0x00, 0x00, 0x18,
42 0x28, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00,
44 0x02, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00,
47 ASSERT_EQ(0xd9963a56, Value(reinterpret_cast<char*>(data
), sizeof(data
)));
51 ASSERT_NE(Value("a", 1), Value("foo", 3));
55 ASSERT_EQ(Value("hello world", 11),
56 Extend(Value("hello ", 6), "world", 5));
60 uint32_t crc
= Value("foo", 3);
61 ASSERT_NE(crc
, Mask(crc
));
62 ASSERT_NE(crc
, Mask(Mask(crc
)));
63 ASSERT_EQ(crc
, Unmask(Mask(crc
)));
64 ASSERT_EQ(crc
, Unmask(Unmask(Mask(Mask(crc
)))));
68 } // namespace leveldb
70 int main(int argc
, char** argv
) {
71 return leveldb::test::RunAllTests();