Debian Codegraph @

tests/node_hash_policy_test.cc

raw
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
15 #include <memory>
16 #include "parallel_hashmap/phmap.h"
17
18 #include "gmock/gmock.h"
19 #include "gtest/gtest.h"
20
21 namespace phmap {
22 namespace priv {
23 namespace {
24
25 using ::testing::Pointee;
26
27 struct Policy : node_hash_policy<int&, Policy> {
28 using key_type = int;
29 using init_type = int;
30
31 template <class Alloc>
32 static int* new_element(Alloc*, int value) {
33 return new int(value);
34 }
35
36 template <class Alloc>
37 static void delete_element(Alloc* , int* elem) {
38 delete elem;
39 }
40 };
41
42 using NodePolicy = hash_policy_traits<Policy>;
43
44 struct NodeTest : ::testing::Test {
45 std::allocator<int> alloc;
46 int n = 53;
47 int* a = &n;
48 };
49
50 TEST_F(NodeTest, ConstructDestroy) {
51 NodePolicy::construct(&alloc, &a, 42);
52 EXPECT_THAT(a, Pointee(42));
53 NodePolicy::destroy(&alloc, &a);
54 }
55
56 TEST_F(NodeTest, transfer) {
57 int s = 42;
58 int* b = &s;
59 NodePolicy::transfer(&alloc, &a, &b);
60 EXPECT_EQ(&s, a);
61 }
62
63 } // namespace
64 } // namespace priv
65 } // namespace phmap