| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| |
| // the following code are modified from RocksDB: |
| // https://github.com/facebook/rocksdb/blob/master/util/crc32c_test.cc |
| |
| #include "util/crc32c.h" |
| |
| #include <gtest/gtest.h> |
| |
| #include <vector> |
| |
| #include "util/slice.h" |
| |
| namespace doris { |
| namespace crc32c { |
| |
| class CRC {}; |
| |
| TEST(CRC, StandardResults) { |
| // Original Fast_CRC32 tests. |
| // From rfc3720 section B.4. |
| char buf[32]; |
| |
| memset(buf, 0, sizeof(buf)); |
| ASSERT_EQ(0x8a9136aaU, Value(buf, sizeof(buf))); |
| |
| memset(buf, 0xff, sizeof(buf)); |
| ASSERT_EQ(0x62a8ab43U, Value(buf, sizeof(buf))); |
| |
| for (int i = 0; i < 32; i++) { |
| buf[i] = static_cast<char>(i); |
| } |
| ASSERT_EQ(0x46dd794eU, Value(buf, sizeof(buf))); |
| |
| for (int i = 0; i < 32; i++) { |
| buf[i] = static_cast<char>(31 - i); |
| } |
| ASSERT_EQ(0x113fdb5cU, Value(buf, sizeof(buf))); |
| |
| unsigned char data[48] = { |
| 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, |
| 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| }; |
| ASSERT_EQ(0xd9963a56, Value(reinterpret_cast<char*>(data), sizeof(data))); |
| } |
| |
| TEST(CRC, Values) { |
| ASSERT_NE(Value("a", 1), Value("foo", 3)); |
| } |
| |
| TEST(CRC, Extend) { |
| ASSERT_EQ(Value("hello world", 11), Extend(Value("hello ", 6), "world", 5)); |
| |
| std::vector<Slice> slices = {Slice("hello "), Slice("world")}; |
| ASSERT_EQ(Value("hello world", 11), Value(slices)); |
| } |
| |
| } // namespace crc32c |
| } // namespace doris |
| |
| int main(int argc, char** argv) { |
| ::testing::InitGoogleTest(&argc, argv); |
| return RUN_ALL_TESTS(); |
| } |