hash_tables_unittest.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright 2013 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 "base/containers/hash_tables.h"
6
7#include "base/basictypes.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace {
11
12class HashPairTest : public testing::Test {
13};
14
15#define INSERT_PAIR_TEST(Type, value1, value2) \
16  { \
17    Type pair(value1, value2); \
18    base::hash_map<Type, int> map; \
19    map[pair] = 1; \
20  }
21
22// Verify that a hash_map can be constructed for pairs of integers of various
23// sizes.
24TEST_F(HashPairTest, IntegerPairs) {
25  typedef std::pair<int16, int16> Int16Int16Pair;
26  typedef std::pair<int16, int32> Int16Int32Pair;
27  typedef std::pair<int16, int64> Int16Int64Pair;
28
29  INSERT_PAIR_TEST(Int16Int16Pair, 4, 6);
30  INSERT_PAIR_TEST(Int16Int32Pair, 9, (1 << 29) + 378128932);
31  INSERT_PAIR_TEST(Int16Int64Pair, 10,
32                   (GG_INT64_C(1) << 60) + GG_INT64_C(78931732321));
33
34  typedef std::pair<int32, int16> Int32Int16Pair;
35  typedef std::pair<int32, int32> Int32Int32Pair;
36  typedef std::pair<int32, int64> Int32Int64Pair;
37
38  INSERT_PAIR_TEST(Int32Int16Pair, 4, 6);
39  INSERT_PAIR_TEST(Int32Int32Pair, 9, (1 << 29) + 378128932);
40  INSERT_PAIR_TEST(Int32Int64Pair, 10,
41                   (GG_INT64_C(1) << 60) + GG_INT64_C(78931732321));
42
43  typedef std::pair<int64, int16> Int64Int16Pair;
44  typedef std::pair<int64, int32> Int64Int32Pair;
45  typedef std::pair<int64, int64> Int64Int64Pair;
46
47  INSERT_PAIR_TEST(Int64Int16Pair, 4, 6);
48  INSERT_PAIR_TEST(Int64Int32Pair, 9, (1 << 29) + 378128932);
49  INSERT_PAIR_TEST(Int64Int64Pair, 10,
50                   (GG_INT64_C(1) << 60) + GG_INT64_C(78931732321));
51}
52
53}  // namespace
54