Alexei Svitkine | 9de32cb | 2018-02-06 20:21:21 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium 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. |
| 4 | |
| 5 | #include "components/variations/hashing.h" |
| 6 | |
| 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | |
| 13 | namespace variations { |
| 14 | |
| 15 | TEST(HashingTest, HashName) { |
| 16 | // Checks that hashing is stable on all platforms. |
| 17 | struct { |
| 18 | const char* name; |
| 19 | uint32_t hash_value; |
| 20 | } known_hashes[] = {{"a", 937752454u}, |
| 21 | {"1", 723085877u}, |
| 22 | {"Trial Name", 2713117220u}, |
| 23 | {"Group Name", 3201815843u}, |
| 24 | {"My Favorite Experiment", 3722155194u}, |
| 25 | {"My Awesome Group Name", 4109503236u}, |
| 26 | {"abcdefghijklmonpqrstuvwxyz", 787728696u}, |
| 27 | {"0123456789ABCDEF", 348858318U}}; |
| 28 | |
| 29 | for (size_t i = 0; i < arraysize(known_hashes); ++i) { |
| 30 | EXPECT_EQ(known_hashes[i].hash_value, HashName(known_hashes[i].name)); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | } // namespace variations |