node_hash_policy_test.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <memory>
18 
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
22 
23 namespace absl {
24 namespace container_internal {
25 namespace {
26 
27 using ::testing::Pointee;
28 
29 struct Policy : node_hash_policy<int&, Policy> {
30  using key_type = int;
31  using init_type = int;
32 
33  template <class Alloc>
34  static int* new_element(Alloc* alloc, int value) {
35  return new int(value);
36  }
37 
38  template <class Alloc>
39  static void delete_element(Alloc* alloc, int* elem) {
40  delete elem;
41  }
42 };
43 
44 using NodePolicy = hash_policy_traits<Policy>;
45 
46 struct NodeTest : ::testing::Test {
47  std::allocator<int> alloc;
48  int n = 53;
49  int* a = &n;
50 };
51 
52 TEST_F(NodeTest, ConstructDestroy) {
54  EXPECT_THAT(a, Pointee(42));
56 }
57 
58 TEST_F(NodeTest, transfer) {
59  int s = 42;
60  int* b = &s;
62  EXPECT_EQ(&s, a);
63 }
64 
65 } // namespace
66 } // namespace container_internal
67 } // namespace absl
Definition: algorithm.h:29
int * a
static std::function< void(void *, Slot *)> destroy
size_t value
TEST_F(GraphCyclesTest, NoCycle)
static std::function< void(void *, Slot *, Slot *)> transfer
static std::function< void(void *, Slot *, Slot)> construct
std::allocator< int > alloc
uint64_t b
Definition: layout_test.cc:50


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:19:57