abseil-cpp/absl/container/internal/hash_policy_traits_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 
15 #include "absl/container/internal/hash_policy_traits.h"
16 
17 #include <functional>
18 #include <memory>
19 #include <new>
20 
21 #include "gmock/gmock.h"
22 #include "gtest/gtest.h"
23 
24 namespace absl {
26 namespace container_internal {
27 namespace {
28 
29 using ::testing::MockFunction;
32 
33 using Alloc = std::allocator<int>;
34 using Slot = int;
35 
36 struct PolicyWithoutOptionalOps {
37  using slot_type = Slot;
38  using key_type = Slot;
39  using init_type = Slot;
40 
41  static std::function<void(void*, Slot*, Slot)> construct;
42  static std::function<void(void*, Slot*)> destroy;
43 
44  static std::function<Slot&(Slot*)> element;
45  static int apply(int v) { return apply_impl(v); }
47  static std::function<Slot&(Slot*)> value;
48 };
49 
50 std::function<void(void*, Slot*, Slot)> PolicyWithoutOptionalOps::construct;
52 
56 
57 struct PolicyWithOptionalOps : PolicyWithoutOptionalOps {
58  static std::function<void(void*, Slot*, Slot*)> transfer;
59 };
60 
61 std::function<void(void*, Slot*, Slot*)> PolicyWithOptionalOps::transfer;
62 
63 struct Test : ::testing::Test {
64  Test() {
65  PolicyWithoutOptionalOps::construct = [&](void* a1, Slot* a2, Slot a3) {
66  construct.Call(a1, a2, std::move(a3));
67  };
68  PolicyWithoutOptionalOps::destroy = [&](void* a1, Slot* a2) {
69  destroy.Call(a1, a2);
70  };
71 
72  PolicyWithoutOptionalOps::element = [&](Slot* a1) -> Slot& {
73  return element.Call(a1);
74  };
75  PolicyWithoutOptionalOps::apply_impl = [&](int a1) -> int {
76  return apply.Call(a1);
77  };
78  PolicyWithoutOptionalOps::value = [&](Slot* a1) -> Slot& {
79  return value.Call(a1);
80  };
81 
82  PolicyWithOptionalOps::transfer = [&](void* a1, Slot* a2, Slot* a3) {
83  return transfer.Call(a1, a2, a3);
84  };
85  }
86 
87  std::allocator<int> alloc;
88  int a = 53;
89 
90  MockFunction<void(void*, Slot*, Slot)> construct;
91  MockFunction<void(void*, Slot*)> destroy;
92 
93  MockFunction<Slot&(Slot*)> element;
94  MockFunction<int(int)> apply;
95  MockFunction<Slot&(Slot*)> value;
96 
97  MockFunction<void(void*, Slot*, Slot*)> transfer;
98 };
99 
101  EXPECT_CALL(construct, Call(&alloc, &a, 53));
103 }
104 
105 TEST_F(Test, destroy) {
106  EXPECT_CALL(destroy, Call(&alloc, &a));
108 }
109 
110 TEST_F(Test, element) {
111  int b = 0;
112  EXPECT_CALL(element, Call(&a)).WillOnce(ReturnRef(b));
114 }
115 
116 TEST_F(Test, apply) {
117  EXPECT_CALL(apply, Call(42)).WillOnce(Return(1337));
119 }
120 
121 TEST_F(Test, value) {
122  int b = 0;
123  EXPECT_CALL(value, Call(&a)).WillOnce(ReturnRef(b));
125 }
126 
127 TEST_F(Test, without_transfer) {
128  int b = 42;
129  EXPECT_CALL(element, Call(&b)).WillOnce(::testing::ReturnRef(b));
130  EXPECT_CALL(construct, Call(&alloc, &a, b));
133 }
134 
135 TEST_F(Test, with_transfer) {
136  int b = 42;
137  EXPECT_CALL(transfer, Call(&alloc, &a, &b));
139 }
140 
141 } // namespace
142 } // namespace container_internal
144 } // namespace absl
Test
void Test(StringPiece pattern, const RE2::Options &options, StringPiece text)
Definition: bloaty/third_party/re2/re2/fuzzing/re2_fuzzer.cc:20
element
static std::function< Slot &(Slot *)> element
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:44
value
static std::function< Slot &(Slot *)> value
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:47
testing::Return
internal::ReturnAction< R > Return(R value)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/gmock-actions.h:1004
absl::container_internal::hash_policy_traits::destroy
static void destroy(Alloc *alloc, slot_type *slot)
Definition: abseil-cpp/absl/container/internal/hash_policy_traits.h:100
absl::container_internal::hash_policy_traits::element
static auto element(slot_type *slot) -> decltype(P::element(slot))
Definition: abseil-cpp/absl/container/internal/hash_policy_traits.h:123
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
testing::ReturnRef
internal::ReturnRefAction< R > ReturnRef(R &x)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/gmock-actions.h:1020
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
absl::container_internal::hash_policy_traits::value
static auto value(T *elem) -> decltype(P::value(elem))
Definition: abseil-cpp/absl/container/internal/hash_policy_traits.h:184
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
a2
T::first_type a2
Definition: abseil-cpp/absl/container/internal/hash_function_defaults_test.cc:307
xds_interop_client.int
int
Definition: xds_interop_client.py:113
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
apply_impl
static std::function< int(int)> apply_impl
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:46
absl::flags_internal::Alloc
void * Alloc(FlagOpFn op)
Definition: abseil-cpp/absl/flags/internal/flag.h:102
a1
T::first_type a1
Definition: abseil-cpp/absl/container/internal/hash_function_defaults_test.cc:305
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
transfer
static std::function< void(void *, Slot *, Slot *)> transfer
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:58
EXPECT_CALL
#define EXPECT_CALL(obj, call)
construct
static std::function< void(void *, Slot *, Slot)> construct
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:41
tests.unit._server_ssl_cert_config_test.Call
Call
Definition: _server_ssl_cert_config_test.py:70
absl::container_internal::hash_policy_traits::construct
static void construct(Alloc *alloc, slot_type *slot, Args &&... args)
Definition: abseil-cpp/absl/container/internal/hash_policy_traits.h:93
absl::container_internal::hash_policy_traits::apply
static auto apply(F &&f, Ts &&... ts) -> decltype(P::apply(std::forward< F >(f), std::forward< Ts >(ts)...))
Definition: abseil-cpp/absl/container/internal/hash_policy_traits.h:168
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
key_type
upb_fieldtype_t key_type
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1071
absl::apply
auto apply(Functor &&functor, Tuple &&t) -> decltype(utility_internal::apply_helper(absl::forward< Functor >(functor), absl::forward< Tuple >(t), absl::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >
Definition: abseil-cpp/absl/utility/utility.h:289
Test
Definition: hpack_parser_test.cc:43
alloc
std::allocator< int > alloc
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:87
destroy
static std::function< void(void *, Slot *)> destroy
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:42
absl::container_internal::hash_policy_traits::transfer
static void transfer(Alloc *alloc, slot_type *new_slot, slot_type *old_slot)
Definition: abseil-cpp/absl/container/internal/hash_policy_traits.h:116
TEST_F
#define TEST_F(test_fixture, test_name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2367


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:00