21 #include "gmock/gmock.h" 22 #include "gtest/gtest.h" 25 namespace container_internal {
28 using ::testing::MockFunction;
29 using ::testing::Return;
30 using ::testing::ReturnRef;
32 using Alloc = std::allocator<int>;
35 struct PolicyWithoutOptionalOps {
36 using slot_type = Slot;
37 using key_type = Slot;
38 using init_type = Slot;
40 static std::function<void(void*, Slot*, Slot)>
construct;
41 static std::function<void(void*, Slot*)>
destroy;
43 static std::function<Slot&(Slot*)>
element;
46 static std::function<Slot&(Slot*)>
value;
56 struct PolicyWithOptionalOps : PolicyWithoutOptionalOps {
57 static std::function<void(void*, Slot*, Slot*)>
transfer;
62 struct Test : ::testing::Test {
64 PolicyWithoutOptionalOps::construct = [&](
void*
a1, Slot*
a2, Slot a3) {
67 PolicyWithoutOptionalOps::destroy = [&](
void*
a1, Slot*
a2) {
71 PolicyWithoutOptionalOps::element = [&](Slot*
a1) -> Slot& {
74 PolicyWithoutOptionalOps::apply_impl = [&](
int a1) ->
int {
75 return apply.Call(a1);
77 PolicyWithoutOptionalOps::value = [&](Slot*
a1) -> Slot& {
78 return value.Call(a1);
81 PolicyWithOptionalOps::transfer = [&](
void*
a1, Slot*
a2, Slot* a3) {
89 MockFunction<void(void*, Slot*, Slot)>
construct;
90 MockFunction<void(void*, Slot*)>
destroy;
92 MockFunction<Slot&(Slot*)>
element;
94 MockFunction<Slot&(Slot*)>
value;
96 MockFunction<void(void*, Slot*, Slot*)>
transfer;
111 EXPECT_CALL(
element, Call(&
a)).WillOnce(ReturnRef(b));
116 EXPECT_CALL(
apply, Call(42)).WillOnce(Return(1337));
122 EXPECT_CALL(
value, Call(&
a)).WillOnce(ReturnRef(b));
126 TEST_F(Test, without_transfer) {
128 EXPECT_CALL(
element, Call(&b)).WillOnce(::testing::ReturnRef(b));
134 TEST_F(Test, with_transfer) {
static std::function< Slot &(Slot *)> element
static std::function< int(int)> apply_impl
static std::function< Slot &(Slot *)> value
static void transfer(Alloc *alloc, slot_type *new_slot, slot_type *old_slot)
static std::function< void(void *, Slot *)> destroy
static auto value(T *elem) -> decltype(P::value(elem))
TEST_F(GraphCyclesTest, NoCycle)
static std::function< void(void *, Slot *, Slot *)> transfer
static std::function< void(void *, Slot *, Slot)> construct
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 >
static auto apply(F &&f, Ts &&...ts) -> decltype(P::apply(std::forward< F >(f), std::forward< Ts >(ts)...))
static void construct(Alloc *alloc, slot_type *slot, Args &&...args)
std::allocator< int > alloc
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
static void destroy(Alloc *alloc, slot_type *slot)
static auto element(slot_type *slot) -> decltype(P::element(slot))