hash_test.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "util/testharness.h"
  6. namespace leveldb {
  7. class HASH { };
  8. TEST(HASH, SignedUnsignedIssue) {
  9. const unsigned char data1[1] = {0x62};
  10. const unsigned char data2[2] = {0xc3, 0x97};
  11. const unsigned char data3[3] = {0xe2, 0x99, 0xa5};
  12. const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32};
  13. const unsigned char data5[48] = {
  14. 0x01, 0xc0, 0x00, 0x00,
  15. 0x00, 0x00, 0x00, 0x00,
  16. 0x00, 0x00, 0x00, 0x00,
  17. 0x00, 0x00, 0x00, 0x00,
  18. 0x14, 0x00, 0x00, 0x00,
  19. 0x00, 0x00, 0x04, 0x00,
  20. 0x00, 0x00, 0x00, 0x14,
  21. 0x00, 0x00, 0x00, 0x18,
  22. 0x28, 0x00, 0x00, 0x00,
  23. 0x00, 0x00, 0x00, 0x00,
  24. 0x02, 0x00, 0x00, 0x00,
  25. 0x00, 0x00, 0x00, 0x00,
  26. };
  27. ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34);
  28. ASSERT_EQ(
  29. Hash(reinterpret_cast<const char*>(data1), sizeof(data1), 0xbc9f1d34),
  30. 0xef1345c4);
  31. ASSERT_EQ(
  32. Hash(reinterpret_cast<const char*>(data2), sizeof(data2), 0xbc9f1d34),
  33. 0x5b663814);
  34. ASSERT_EQ(
  35. Hash(reinterpret_cast<const char*>(data3), sizeof(data3), 0xbc9f1d34),
  36. 0x323c078f);
  37. ASSERT_EQ(
  38. Hash(reinterpret_cast<const char*>(data4), sizeof(data4), 0xbc9f1d34),
  39. 0xed21633a);
  40. ASSERT_EQ(
  41. Hash(reinterpret_cast<const char*>(data5), sizeof(data5), 0x12345678),
  42. 0xf333dabb);
  43. }
  44. } // namespace leveldb
  45. int main(int argc, char** argv) {
  46. return leveldb::test::RunAllTests();
  47. }