15 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_CONSTRUCTOR_TEST_H_ 16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_CONSTRUCTOR_TEST_H_ 21 #include "gmock/gmock.h" 22 #include "gtest/gtest.h" 27 namespace container_internal {
29 template <
class UnordMap>
36 EXPECT_TRUE(m.empty());
37 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
42 EXPECT_TRUE(m.empty());
43 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
44 EXPECT_GE(m.bucket_count(), 123);
50 TypeParam m(123, hasher);
51 EXPECT_EQ(m.hash_function(),
hasher);
52 EXPECT_TRUE(m.empty());
53 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
54 EXPECT_GE(m.bucket_count(), 123);
59 using E =
typename TypeParam::key_equal;
62 TypeParam m(123, hasher, equal);
63 EXPECT_EQ(m.hash_function(),
hasher);
64 EXPECT_EQ(m.key_eq(), equal);
65 EXPECT_TRUE(m.empty());
66 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
67 EXPECT_GE(m.bucket_count(), 123);
72 using E =
typename TypeParam::key_equal;
73 using A =
typename TypeParam::allocator_type;
77 TypeParam m(123, hasher, equal, alloc);
78 EXPECT_EQ(m.hash_function(),
hasher);
79 EXPECT_EQ(m.key_eq(), equal);
80 EXPECT_EQ(m.get_allocator(),
alloc);
81 EXPECT_TRUE(m.empty());
82 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
83 EXPECT_GE(m.bucket_count(), 123);
89 template <
typename... T>
92 #if defined(UNORDERED_MAP_CXX14) || defined(UNORDERED_MAP_CXX17) 103 template <
typename TypeParam>
106 template <
typename TypeParam>
108 using A =
typename TypeParam::allocator_type;
110 TypeParam m(123, alloc);
111 EXPECT_EQ(m.get_allocator(),
alloc);
112 EXPECT_TRUE(m.empty());
113 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
114 EXPECT_GE(m.bucket_count(), 123);
121 template <
typename TypeParam>
124 template <
typename TypeParam>
127 using A =
typename TypeParam::allocator_type;
130 TypeParam m(123, hasher, alloc);
131 EXPECT_EQ(m.hash_function(),
hasher);
132 EXPECT_EQ(m.get_allocator(),
alloc);
133 EXPECT_TRUE(m.empty());
134 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
135 EXPECT_GE(m.bucket_count(), 123);
142 #if ABSL_UNORDERED_SUPPORTS_ALLOC_CTORS 148 template <
typename T>
153 template <
typename TypeParam>
156 template <
typename TypeParam>
158 using A =
typename TypeParam::allocator_type;
161 EXPECT_EQ(m.get_allocator(),
alloc);
162 EXPECT_TRUE(m.empty());
163 EXPECT_THAT(m, ::testing::UnorderedElementsAre());
173 using E =
typename TypeParam::key_equal;
174 using A =
typename TypeParam::allocator_type;
178 std::vector<T> values;
179 std::generate_n(std::back_inserter(values), 10,
181 TypeParam m(values.begin(), values.end(), 123,
hasher, equal,
alloc);
182 EXPECT_EQ(m.hash_function(),
hasher);
183 EXPECT_EQ(m.key_eq(), equal);
184 EXPECT_EQ(m.get_allocator(),
alloc);
185 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
186 EXPECT_GE(m.bucket_count(), 123);
189 template <
typename TypeParam>
192 template <
typename TypeParam>
195 using A =
typename TypeParam::allocator_type;
197 std::vector<T> values;
198 std::generate_n(std::back_inserter(values), 10,
200 TypeParam m(values.begin(), values.end(), 123,
alloc);
201 EXPECT_EQ(m.get_allocator(),
alloc);
202 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
203 EXPECT_GE(m.bucket_count(), 123);
210 template <
typename TypeParam>
213 template <
typename TypeParam>
217 using A =
typename TypeParam::allocator_type;
220 std::vector<T> values;
221 std::generate_n(std::back_inserter(values), 10,
223 TypeParam m(values.begin(), values.end(), 123,
hasher,
alloc);
224 EXPECT_EQ(m.hash_function(),
hasher);
225 EXPECT_EQ(m.get_allocator(),
alloc);
226 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
227 EXPECT_GE(m.bucket_count(), 123);
237 using E =
typename TypeParam::key_equal;
238 using A =
typename TypeParam::allocator_type;
242 TypeParam m(123, hasher, equal, alloc);
245 EXPECT_EQ(m.hash_function(), n.hash_function());
246 EXPECT_EQ(m.key_eq(), n.key_eq());
247 EXPECT_EQ(m.get_allocator(), n.get_allocator());
251 template <
typename TypeParam>
254 template <
typename TypeParam>
258 using E =
typename TypeParam::key_equal;
259 using A =
typename TypeParam::allocator_type;
263 TypeParam m(123, hasher, equal, alloc);
265 TypeParam
n(m, A(11));
266 EXPECT_EQ(m.hash_function(), n.hash_function());
267 EXPECT_EQ(m.key_eq(), n.key_eq());
268 EXPECT_NE(m.get_allocator(), n.get_allocator());
281 using E =
typename TypeParam::key_equal;
282 using A =
typename TypeParam::allocator_type;
286 TypeParam m(123, hasher, equal, alloc);
290 EXPECT_EQ(m.hash_function(), n.hash_function());
291 EXPECT_EQ(m.key_eq(), n.key_eq());
292 EXPECT_EQ(m.get_allocator(), n.get_allocator());
296 template <
typename TypeParam>
299 template <
typename TypeParam>
303 using E =
typename TypeParam::key_equal;
304 using A =
typename TypeParam::allocator_type;
308 TypeParam m(123, hasher, equal, alloc);
312 EXPECT_EQ(m.hash_function(), n.hash_function());
313 EXPECT_EQ(m.key_eq(), n.key_eq());
314 EXPECT_NE(m.get_allocator(), n.get_allocator());
327 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
329 using E =
typename TypeParam::key_equal;
330 using A =
typename TypeParam::allocator_type;
334 TypeParam m(values, 123, hasher, equal, alloc);
335 EXPECT_EQ(m.hash_function(),
hasher);
336 EXPECT_EQ(m.key_eq(), equal);
337 EXPECT_EQ(m.get_allocator(),
alloc);
338 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
339 EXPECT_GE(m.bucket_count(), 123);
342 template <
typename TypeParam>
345 template <
typename TypeParam>
348 using A =
typename TypeParam::allocator_type;
350 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
352 TypeParam m(values, 123, alloc);
353 EXPECT_EQ(m.get_allocator(),
alloc);
354 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
355 EXPECT_GE(m.bucket_count(), 123);
362 template <
typename TypeParam>
365 template <
typename TypeParam>
369 using A =
typename TypeParam::allocator_type;
373 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
374 TypeParam m(values, 123, hasher, alloc);
375 EXPECT_EQ(m.hash_function(),
hasher);
376 EXPECT_EQ(m.get_allocator(),
alloc);
377 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
378 EXPECT_GE(m.bucket_count(), 123);
388 using E =
typename TypeParam::key_equal;
389 using A =
typename TypeParam::allocator_type;
394 TypeParam m({gen(), gen(), gen()}, 123,
hasher, equal,
alloc);
397 EXPECT_EQ(m.hash_function(), n.hash_function());
398 EXPECT_EQ(m.key_eq(), n.key_eq());
408 using E =
typename TypeParam::key_equal;
409 using A =
typename TypeParam::allocator_type;
414 TypeParam m({gen(), gen(), gen()}, 123,
hasher, equal,
alloc);
418 EXPECT_EQ(m.hash_function(), n.hash_function());
419 EXPECT_EQ(m.key_eq(), n.key_eq());
426 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
429 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
435 TypeParam m({gen(), gen(), gen()});
436 TypeParam
n({gen()});
444 TypeParam m({gen(), gen(), gen()});
446 TypeParam
n({gen()});
454 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
457 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
463 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
466 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
474 ConstructorTest, NoArgs, BucketCount, BucketCountHash, BucketCountHashEqual,
475 BucketCountHashEqualAlloc, BucketCountAlloc, BucketCountHashAlloc,
Alloc,
476 InputIteratorBucketHashEqualAlloc, InputIteratorBucketAlloc,
477 InputIteratorBucketHashAlloc, CopyConstructor, CopyConstructorAlloc,
478 MoveConstructor, MoveConstructorAlloc, InitializerListBucketHashEqualAlloc,
479 InitializerListBucketAlloc, InitializerListBucketHashAlloc, Assignment,
480 MoveAssignment, AssignmentFromInitializerList, AssignmentOverwritesExisting,
481 MoveAssignmentOverwritesExisting,
482 AssignmentFromInitializerListOverwritesExisting, AssignmentOnSelf);
487 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_CONSTRUCTOR_TEST_H_
std::false_type has_cxx14_std_apis
auto items(const Map &m) -> std::vector< std::pair< typename Map::key_type, typename Map::mapped_type >>
void InitializerListBucketHashAllocTest(std::false_type)
void MoveConstructorAllocTest(std::false_type)
void InputIteratorBucketHashAllocTest(std::false_type)
TYPED_TEST_SUITE_P(ConstructorTest)
void InitializerListBucketAllocTest(std::false_type)
void AllocTest(std::false_type)
hash_default_hash< T > hasher
std::false_type has_alloc_std_constructors
bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Pred &&pred)
void InputIteratorBucketAllocTest(std::false_type)
TYPED_TEST_P(ConstructorTest, NoArgs)
void BucketCountAllocTest(std::false_type)
decltype(std::declval< const Generator< typename std::conditional< generator_internal::IsMap< Container >::value, typename Container::value_type, typename Container::key_type >::type > & >()()) GeneratedType
std::allocator< int > alloc
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
void CopyConstructorAllocTest(std::false_type)
REGISTER_TYPED_TEST_CASE_P(ConstructorTest, NoArgs, BucketCount, BucketCountHash, BucketCountHashEqual, BucketCountHashEqualAlloc, BucketCountAlloc, BucketCountHashAlloc, Alloc, InputIteratorBucketHashEqualAlloc, InputIteratorBucketAlloc, InputIteratorBucketHashAlloc, CopyConstructor, CopyConstructorAlloc, MoveConstructor, MoveConstructorAlloc, InitializerListBucketHashEqualAlloc, InitializerListBucketAlloc, InitializerListBucketHashAlloc, Assignment, MoveAssignment, AssignmentFromInitializerList, AssignmentOverwritesExisting, MoveAssignmentOverwritesExisting, AssignmentFromInitializerListOverwritesExisting, AssignmentOnSelf)
void BucketCountHashAllocTest(std::false_type)