xref: /aosp_15_r20/external/cronet/base/hash/legacy_hash_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/hash/legacy_hash.h"
6 
7 #include <stdint.h>
8 
9 #include <string_view>
10 
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace base {
14 namespace legacy {
15 
TEST(LegacyHashTest,CityHashV103)16 TEST(LegacyHashTest, CityHashV103) {
17   constexpr struct {
18     std::string_view input;
19     uint64_t output;
20     uint64_t output_with_seed;
21   } kTestCases[] = {
22       {"", 11160318154034397263ull, 14404538258149959151ull},
23       {"0123456789", 12631666426400459317ull, 12757304017804637665ull},
24       {"hello world", 12386028635079221413ull, 4144044770257928618ull},
25   };
26   for (const auto& test_case : kTestCases) {
27     SCOPED_TRACE(test_case.input);
28     auto bytes = as_bytes(make_span(test_case.input));
29     EXPECT_EQ(test_case.output, CityHash64(bytes));
30   }
31   for (const auto& test_case : kTestCases) {
32     SCOPED_TRACE(test_case.input);
33     auto bytes = as_bytes(make_span(test_case.input));
34     EXPECT_EQ(test_case.output_with_seed, CityHash64WithSeed(bytes, 112358));
35   }
36 }
37 
38 }  // namespace legacy
39 }  // namespace base
40