hash_tables_unittest.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "butil/containers/hash_tables.h"
  5. #include "butil/basictypes.h"
  6. #include <gtest/gtest.h>
  7. namespace {
  8. class HashPairTest : public testing::Test {
  9. };
  10. #define INSERT_PAIR_TEST(Type, value1, value2) \
  11. { \
  12. Type pair(value1, value2); \
  13. butil::hash_map<Type, int> map; \
  14. map[pair] = 1; \
  15. }
  16. // Verify that a hash_map can be constructed for pairs of integers of various
  17. // sizes.
  18. TEST_F(HashPairTest, IntegerPairs) {
  19. typedef std::pair<int16_t, int16_t> Int16Int16Pair;
  20. typedef std::pair<int16_t, int32_t> Int16Int32Pair;
  21. typedef std::pair<int16_t, int64_t> Int16Int64Pair;
  22. INSERT_PAIR_TEST(Int16Int16Pair, 4, 6);
  23. INSERT_PAIR_TEST(Int16Int32Pair, 9, (1 << 29) + 378128932);
  24. INSERT_PAIR_TEST(Int16Int64Pair, 10,
  25. (GG_INT64_C(1) << 60) + GG_INT64_C(78931732321));
  26. typedef std::pair<int32_t, int16_t> Int32Int16Pair;
  27. typedef std::pair<int32_t, int32_t> Int32Int32Pair;
  28. typedef std::pair<int32_t, int64_t> Int32Int64Pair;
  29. INSERT_PAIR_TEST(Int32Int16Pair, 4, 6);
  30. INSERT_PAIR_TEST(Int32Int32Pair, 9, (1 << 29) + 378128932);
  31. INSERT_PAIR_TEST(Int32Int64Pair, 10,
  32. (GG_INT64_C(1) << 60) + GG_INT64_C(78931732321));
  33. typedef std::pair<int64_t, int16_t> Int64Int16Pair;
  34. typedef std::pair<int64_t, int32_t> Int64Int32Pair;
  35. typedef std::pair<int64_t, int64_t> Int64Int64Pair;
  36. INSERT_PAIR_TEST(Int64Int16Pair, 4, 6);
  37. INSERT_PAIR_TEST(Int64Int32Pair, 9, (1 << 29) + 378128932);
  38. INSERT_PAIR_TEST(Int64Int64Pair, 10,
  39. (GG_INT64_C(1) << 60) + GG_INT64_C(78931732321));
  40. }
  41. } // namespace