26 #include <glog/logging.h> 41 static unsigned long long freed = 0;
43 template <
typename Alloc>
58 template <
class UAlloc>
62 value_type*
allocate(
size_t n,
const void* hint =
nullptr) {
77 template <
class...
Args>
89 typename std::allocator_traits<Alloc>::template rebind_alloc<U>>
110 std::allocator<std::pair<const StringPiece, int>>>;
119 std::allocator<std::pair<const std::string, int>>>>;
128 folly::transparent<folly::hasher<StringPiece>>,
132 TEST(StringKeyedUnorderedMapTest, sanity) {
147 map =
static_cast<decltype(map)&
>(
map);
152 map.erase(map.find(
"hello"));
156 for (
auto& it : map) {
161 TEST(StringKeyedUnorderedMapTest, constructors) {
172 for (
auto& it : map2) {
180 map2.emplace(
"key1", 1);
201 EXPECT_EQ(map4.find(
"key0"), map4.end());
207 EXPECT_EQ(map4.max_size(), map3.max_size());
215 TEST(StringKeyedSetTest, sanity) {
230 set =
static_cast<decltype(
set)&
>(
set);
235 auto it =
set.begin();
240 set.erase(
set.find(
"hello"));
244 for (
auto entry :
set) {
249 TEST(StringKeyedSetTest, constructors) {
259 for (
auto it : set2) {
267 set2.emplace(
"key1");
286 EXPECT_EQ(set4.find(
"key0"), set4.end());
292 EXPECT_EQ(set4.max_size(), set3.max_size());
297 EXPECT_NE(set4.find(
"key1"), set4.end());
300 TEST(StringKeyedUnorderedSetTest, sanity) {
315 set =
static_cast<decltype(
set)&
>(
set);
320 set.erase(
set.find(
"hello"));
324 for (
auto entry :
set) {
329 TEST(StringKeyedUnorderedSetTest, constructors) {
337 std::list<StringPiece> lst{
"abc",
"def"};
355 auto s6_allocator = s6.get_allocator();
382 for (
auto entry : set2) {
390 set2.emplace(
"key1");
395 EXPECT_EQ(set3.insert(
"key1").second,
false);
397 EXPECT_EQ(set3.emplace(
"key0").second,
true);
411 EXPECT_EQ(set4.find(
"key0"), set4.end());
417 EXPECT_EQ(set4.max_size(), set3.max_size());
422 EXPECT_NE(set4.find(
"key1"), set4.end());
425 TEST(StringKeyedMapTest, sanity) {
440 map =
static_cast<decltype(map)&
>(
map);
445 auto it = map.begin();
450 map.erase(map.find(
"hello"));
454 for (
auto& entry : map) {
459 TEST(StringKeyedMapTest, constructors) {
469 for (
auto& entry : map2) {
477 map2.emplace(
"key1", 1);
494 EXPECT_EQ(map4.find(
"key0"), map4.end());
500 EXPECT_EQ(map4.max_size(), map3.max_size());
509 FLAGS_logtostderr =
true;
510 google::InitGoogleLogging(argv[0]);
512 gflags::ParseCommandLineFlags(&argc, &argv,
true);
518 TEST(StringKeyed, memory_balance) {
521 LOG(INFO) <<
"allocated: " <<
allocated <<
" freed: " << freed
522 <<
" balance: " << balance
525 : freed <
allocated ?
" positive (leak)" :
"");
void destroy(value_type *p)
std::pair< typename Super::iterator, bool > insert(std::pair< StringPiece, Mapped > const &p)
TEST(StringKeyedUnorderedMapTest, sanity)
std::pair< iterator, bool > insert(value_type val)
static unsigned long long freed
bool operator!=(const MemoryLeakCheckerAllocator &other) const
MemoryLeakCheckerAllocator(Alloc alloc)
pointer allocate(size_type n)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
iterator erase(const_iterator position)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
StringKeyedMap< int, std::less< StringPiece >, KeyValuePairLeakChecker > LeakCheckedMap
std::allocator< T >::value_type value_type
BasicStringKeyedUnorderedSet< folly::transparent< folly::hasher< StringPiece >>, folly::transparent< std::equal_to< folly::StringPiece >>, MemoryLeakCheckerAllocator< std::allocator< std::string >>> LeakCheckedUnorderedSet
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
void construct(U *p, Args &&...args)
int main(int argc, char **argv)
#define EXPECT_GE(val1, val2)
std::pair< iterator, bool > emplace(StringPiece key, Args &&...args)
MemoryLeakCheckerAllocator< std::allocator< StringPiece >> ValueLeakChecker
bool operator==(const MemoryLeakCheckerAllocator &other) const
constexpr auto size(C const &c) -> decltype(c.size())
value_type const * const_reference
constexpr auto empty(C const &c) -> decltype(c.empty())
MemoryLeakCheckerAllocator(const MemoryLeakCheckerAllocator< UAlloc > &other)
void construct(value_type *p, Args &&...args)
std::pair< iterator, bool > emplace(Args &&...args)
auto end(TestAdlIterable &instance)
const Alloc & allocator() const
MemoryLeakCheckerAllocator< typename std::allocator_traits< Alloc >::template rebind_alloc< U > > other
MemoryLeakCheckerAllocator()
void deallocate(pointer p, size_type n)
std::pair< iterator, bool > insert(value_type val)
F14NodeSet< std::string, Hash, Eq, Alloc > BasicStringKeyedUnorderedSet
#define EXPECT_TRUE(condition)
value_type * allocate(size_t n, const void *hint=nullptr)
Alloc::value_type value_type
#define EXPECT_NE(val1, val2)
static unsigned long long allocated
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
void deallocate(value_type *p, size_t n)
#define EXPECT_FALSE(condition)
Range< const char * > StringPiece
iterator erase(const_iterator position)
StringKeyedSetBase< std::less< StringPiece >, ValueLeakChecker > LeakCheckedSet
value_type const * const_pointer
constexpr detail::First first
std::ptrdiff_t difference_type