LevelDB project 1 10225501460 林子骥 10211900416 郭夏辉
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

1 month ago
  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.
  4. #include "util/hash.h"
  5. #include "gtest/gtest.h"
  6. namespace leveldb {
  7. TEST(HASH, SignedUnsignedIssue) {
  8. const uint8_t data1[1] = {0x62};
  9. const uint8_t data2[2] = {0xc3, 0x97};
  10. const uint8_t data3[3] = {0xe2, 0x99, 0xa5};
  11. const uint8_t data4[4] = {0xe1, 0x80, 0xb9, 0x32};
  12. const uint8_t data5[48] = {
  13. 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14. 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
  15. 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00,
  16. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  17. };
  18. ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34);
  19. ASSERT_EQ(
  20. Hash(reinterpret_cast<const char*>(data1), sizeof(data1), 0xbc9f1d34),
  21. 0xef1345c4);
  22. ASSERT_EQ(
  23. Hash(reinterpret_cast<const char*>(data2), sizeof(data2), 0xbc9f1d34),
  24. 0x5b663814);
  25. ASSERT_EQ(
  26. Hash(reinterpret_cast<const char*>(data3), sizeof(data3), 0xbc9f1d34),
  27. 0x323c078f);
  28. ASSERT_EQ(
  29. Hash(reinterpret_cast<const char*>(data4), sizeof(data4), 0xbc9f1d34),
  30. 0xed21633a);
  31. ASSERT_EQ(
  32. Hash(reinterpret_cast<const char*>(data5), sizeof(data5), 0x12345678),
  33. 0xf333dabb);
  34. }
  35. } // namespace leveldb