Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "absl/container/internal/node_hash_policy.h"
00016
00017 #include <memory>
00018
00019 #include "gmock/gmock.h"
00020 #include "gtest/gtest.h"
00021 #include "absl/container/internal/hash_policy_traits.h"
00022
00023 namespace absl {
00024 namespace container_internal {
00025 namespace {
00026
00027 using ::testing::Pointee;
00028
00029 struct Policy : node_hash_policy<int&, Policy> {
00030 using key_type = int;
00031 using init_type = int;
00032
00033 template <class Alloc>
00034 static int* new_element(Alloc* alloc, int value) {
00035 return new int(value);
00036 }
00037
00038 template <class Alloc>
00039 static void delete_element(Alloc* alloc, int* elem) {
00040 delete elem;
00041 }
00042 };
00043
00044 using NodePolicy = hash_policy_traits<Policy>;
00045
00046 struct NodeTest : ::testing::Test {
00047 std::allocator<int> alloc;
00048 int n = 53;
00049 int* a = &n;
00050 };
00051
00052 TEST_F(NodeTest, ConstructDestroy) {
00053 NodePolicy::construct(&alloc, &a, 42);
00054 EXPECT_THAT(a, Pointee(42));
00055 NodePolicy::destroy(&alloc, &a);
00056 }
00057
00058 TEST_F(NodeTest, transfer) {
00059 int s = 42;
00060 int* b = &s;
00061 NodePolicy::transfer(&alloc, &a, &b);
00062 EXPECT_EQ(&s, a);
00063 }
00064
00065 }
00066 }
00067 }