node_hash_policy_test.cc
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
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 }  // namespace
00066 }  // namespace container_internal
00067 }  // namespace absl


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