/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/crc32c_test.cc
Line | Count | Source |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
21 | | // Use of this source code is governed by a BSD-style license that can be |
22 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
23 | | |
24 | | #include "yb/rocksdb/util/crc32c.h" |
25 | | #include <gtest/gtest.h> |
26 | | |
27 | | namespace rocksdb { |
28 | | namespace crc32c { |
29 | | |
30 | | class CRC { }; |
31 | | |
32 | 1 | TEST(CRC, StandardResults) { |
33 | | // From rfc3720 section B.4. |
34 | 1 | char buf[32]; |
35 | | |
36 | 1 | memset(buf, 0, sizeof(buf)); |
37 | 1 | ASSERT_EQ(0x8a9136aaU, Value(buf, sizeof(buf))); |
38 | | |
39 | 1 | memset(buf, 0xff, sizeof(buf)); |
40 | 1 | ASSERT_EQ(0x62a8ab43U, Value(buf, sizeof(buf))); |
41 | | |
42 | 33 | for (int i = 0; i < 32; i++) { |
43 | 32 | buf[i] = i; |
44 | 32 | } |
45 | 1 | ASSERT_EQ(0x46dd794eU, Value(buf, sizeof(buf))); |
46 | | |
47 | 33 | for (int i = 0; i < 32; i++) { |
48 | 32 | buf[i] = 31 - i; |
49 | 32 | } |
50 | 1 | ASSERT_EQ(0x113fdb5cU, Value(buf, sizeof(buf))); |
51 | | |
52 | 1 | unsigned char data[48] = { |
53 | 1 | 0x01, 0xc0, 0x00, 0x00, |
54 | 1 | 0x00, 0x00, 0x00, 0x00, |
55 | 1 | 0x00, 0x00, 0x00, 0x00, |
56 | 1 | 0x00, 0x00, 0x00, 0x00, |
57 | 1 | 0x14, 0x00, 0x00, 0x00, |
58 | 1 | 0x00, 0x00, 0x04, 0x00, |
59 | 1 | 0x00, 0x00, 0x00, 0x14, |
60 | 1 | 0x00, 0x00, 0x00, 0x18, |
61 | 1 | 0x28, 0x00, 0x00, 0x00, |
62 | 1 | 0x00, 0x00, 0x00, 0x00, |
63 | 1 | 0x02, 0x00, 0x00, 0x00, |
64 | 1 | 0x00, 0x00, 0x00, 0x00, |
65 | 1 | }; |
66 | 1 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast<char*>(data), sizeof(data))); |
67 | 1 | } |
68 | | |
69 | 1 | TEST(CRC, Values) { |
70 | 1 | ASSERT_NE(Value("a", 1), Value("foo", 3)); |
71 | 1 | } |
72 | | |
73 | 1 | TEST(CRC, Extend) { |
74 | 1 | ASSERT_EQ(Value("hello world", 11), |
75 | 1 | Extend(Value("hello ", 6), "world", 5)); |
76 | 1 | } |
77 | | |
78 | 1 | TEST(CRC, Mask) { |
79 | 1 | uint32_t crc = Value("foo", 3); |
80 | 1 | ASSERT_NE(crc, Mask(crc)); |
81 | 1 | ASSERT_NE(crc, Mask(Mask(crc))); |
82 | 1 | ASSERT_EQ(crc, Unmask(Mask(crc))); |
83 | 1 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); |
84 | 1 | } |
85 | | |
86 | | } // namespace crc32c |
87 | | } // namespace rocksdb |
88 | | |
89 | 13.2k | int main(int argc, char** argv) { |
90 | 13.2k | ::testing::InitGoogleTest(&argc, argv); |
91 | 13.2k | return RUN_ALL_TESTS(); |
92 | 13.2k | } |