21 #include "gmock/gmock.h" 22 #include "gtest/gtest.h" 26 namespace container_internal {
29 using ::testing::Pair;
31 TEST(Memory, AlignmentLargerThanBase) {
32 std::allocator<int8_t>
alloc;
33 void* mem = Allocate<2>(&
alloc, 3);
34 EXPECT_EQ(0, reinterpret_cast<uintptr_t>(mem) % 2);
35 memcpy(mem,
"abc", 3);
36 Deallocate<2>(&
alloc, mem, 3);
39 TEST(Memory, AlignmentSmallerThanBase) {
40 std::allocator<int64_t>
alloc;
41 void* mem = Allocate<2>(&
alloc, 3);
42 EXPECT_EQ(0, reinterpret_cast<uintptr_t>(mem) % 2);
43 memcpy(mem,
"abc", 3);
44 Deallocate<2>(&
alloc, mem, 3);
47 class Fixture :
public ::testing::Test {
48 using Alloc = std::allocator<std::string>;
51 Fixture() {
ptr_ = std::allocator_traits<Alloc>::allocate(*
alloc(), 1); }
54 std::allocator_traits<Alloc>::deallocate(*
alloc(),
ptr_, 1);
56 std::string*
ptr() {
return ptr_; }
64 TEST_F(Fixture, ConstructNoArgs) {
66 EXPECT_EQ(*
ptr(),
"");
69 TEST_F(Fixture, ConstructOneArg) {
71 EXPECT_EQ(*
ptr(),
"abcde");
74 TEST_F(Fixture, ConstructTwoArg) {
76 EXPECT_EQ(*
ptr(),
"aaaaa");
81 Pair(std::forward_as_tuple(), std::forward_as_tuple()));
86 std::make_pair(std::forward_as_tuple(1), std::forward_as_tuple(
'A')),
92 std::make_pair(std::forward_as_tuple(1), std::forward_as_tuple(
'A')),
98 std::make_pair(std::forward_as_tuple(1), std::forward_as_tuple(
'A')),
99 PairArgs(std::piecewise_construct, std::forward_as_tuple(1),
100 std::forward_as_tuple(
'A')));
104 EXPECT_EQ(1, WithConstructed<absl::string_view>(
105 std::make_tuple(std::string(
"a")),
109 template <
class F,
class Arg>
111 DecomposeValueImpl(
int, F&& f, Arg&&
arg) {
115 template <
class F,
class Arg>
116 const char* DecomposeValueImpl(
char, F&& f, Arg&&
arg) {
117 return "not decomposable";
120 template <
class F,
class Arg>
121 decltype(DecomposeValueImpl(0, std::declval<F>(), std::declval<Arg>()))
122 TryDecomposeValue(F&& f, Arg&&
arg) {
123 return DecomposeValueImpl(0, std::forward<F>(f), std::forward<Arg>(
arg));
127 auto f = [](
const int& x,
int&& y) {
132 EXPECT_EQ(
'A', TryDecomposeValue(f, 42));
137 ADD_FAILURE() <<
"Must not be called";
140 EXPECT_STREQ(
"not decomposable", TryDecomposeValue(f, 42));
143 template <
class F,
class... Args>
144 decltype(
DecomposePair(std::declval<F>(), std::declval<Args>()...))
146 return DecomposePair(std::forward<F>(f), std::forward<Args>(args)...);
149 template <
class F,
class... Args>
151 return "not decomposable";
154 template <
class F,
class... Args>
156 TryDecomposePair(F&& f, Args&&... args) {
161 auto f = [](
const int& x, std::piecewise_construct_t, std::tuple<int&&> k,
162 std::tuple<double>&&
v) {
163 EXPECT_EQ(&x, &std::get<0>(k));
165 EXPECT_EQ(0.5, std::get<0>(
v));
168 EXPECT_EQ(
'A', TryDecomposePair(f, 42, 0.5));
169 EXPECT_EQ(
'A', TryDecomposePair(f, std::make_pair(42, 0.5)));
170 EXPECT_EQ(
'A', TryDecomposePair(f, std::piecewise_construct,
171 std::make_tuple(42), std::make_tuple(0.5)));
176 ADD_FAILURE() <<
"Must not be called";
179 EXPECT_STREQ(
"not decomposable",
180 TryDecomposePair(f));
181 EXPECT_STREQ(
"not decomposable",
182 TryDecomposePair(f, std::piecewise_construct, std::make_tuple(),
183 std::make_tuple(0.5)));
void ConstructFromTuple(Alloc *alloc, T *ptr, Tuple &&t)
TEST(NotificationTest, SanityTest)
decltype(std::declval< F >()(std::declval< const Arg & >(), std::declval< Arg >())) DecomposeValue(F &&f, Arg &&arg)
constexpr size_type size() const noexcept
static std::function< void(void *, Slot *)> destroy
std::pair< std::tuple<>, std::tuple<> > PairArgs()
TEST_F(GraphCyclesTest, NoCycle)
auto DecomposePair(F &&f, Args &&...args) -> decltype(memory_internal::DecomposePairImpl(std::forward< F >(f), PairArgs(std::forward< Args >(args)...)))
decltype(std::declval< F >()(std::declval< T >())) WithConstructed(Tuple &&t, F &&f)
std::allocator< int > alloc
decltype(std::declval< F >()(std::declval< const K & >(), std::piecewise_construct, std::declval< std::tuple< K >>(), std::declval< V >())) DecomposePairImpl(F &&f, std::pair< std::tuple< K >, V > p)