/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <string>
#include <glog/logging.h>
-#include <gtest/gtest.h>
#include <folly/Range.h>
+#include <folly/hash/Hash.h>
#include <folly/portability/GFlags.h>
+#include <folly/portability/GTest.h>
using folly::StringKeyedMap;
using folly::StringKeyedSetBase;
return alloc_ == other.alloc_;
}
-private:
+ private:
Alloc alloc_;
};
-typedef MemoryLeakCheckerAllocator<std::allocator<char>> KeyLeakChecker;
-typedef MemoryLeakCheckerAllocator<
- std::allocator<std::pair<const StringPiece, int>>> ValueLeakChecker;
+using KeyValuePairLeakChecker = MemoryLeakCheckerAllocator<
+ std::allocator<std::pair<const StringPiece, int>>>;
+using ValueLeakChecker =
+ MemoryLeakCheckerAllocator<std::allocator<StringPiece>>;
-typedef StringKeyedUnorderedMap<int, folly::StringPieceHash,
- std::equal_to<StringPiece>, ValueLeakChecker>
- LeakCheckedUnorderedMap;
+typedef StringKeyedUnorderedMap<
+ int,
+ folly::Hash,
+ std::equal_to<StringPiece>,
+ KeyValuePairLeakChecker>
+ LeakCheckedUnorderedMap;
-typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker> LeakCheckedSet;
+typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker>
+ LeakCheckedSet;
-typedef StringKeyedMap<int, std::less<StringPiece>,
- ValueLeakChecker> LeakCheckedMap;
+typedef StringKeyedMap<int, std::less<StringPiece>, KeyValuePairLeakChecker>
+ LeakCheckedMap;
using LeakCheckedUnorderedSet = BasicStringKeyedUnorderedSet<
- folly::StringPieceHash,
- std::equal_to<folly::StringPiece>,
- ValueLeakChecker>;
+ folly::Hash,
+ std::equal_to<folly::StringPiece>,
+ ValueLeakChecker>;
TEST(StringKeyedUnorderedMapTest, sanity) {
LeakCheckedUnorderedMap map;
EXPECT_EQ(set.size(), 1);
- for (auto it : set) {
- EXPECT_EQ(it, "lo");
+ for (auto entry : set) {
+ EXPECT_EQ(entry, "lo");
}
}
EXPECT_EQ(set.size(), 1);
- for (auto it : set) {
- EXPECT_EQ(it, "lo");
+ for (auto entry : set) {
+ EXPECT_EQ(entry, "lo");
}
}
EXPECT_TRUE(s3.empty());
EXPECT_TRUE(s6 == s5);
- LeakCheckedUnorderedSet s7(std::move(s6), s6.get_allocator());
+ auto s6_allocator = s6.get_allocator();
+ LeakCheckedUnorderedSet s7(std::move(s6), s6_allocator);
EXPECT_TRUE(s6.empty());
EXPECT_TRUE(s7 == s5);
EXPECT_EQ(set2.size(), 2);
set2.erase("lo");
- for (auto it : set2) {
- EXPECT_EQ(it, "hello");
+ for (auto entry : set2) {
+ EXPECT_EQ(entry, "hello");
}
set2.clear();
EXPECT_EQ(map.size(), 1);
- for (auto& it : map) {
- EXPECT_EQ(it.first, "lo");
+ for (auto& entry : map) {
+ EXPECT_EQ(entry.first, "lo");
}
}
EXPECT_EQ(map2.size(), 2);
map2.erase("lo");
- for (auto& it : map2) {
- EXPECT_EQ(it.first, "hello");
+ for (auto& entry : map2) {
+ EXPECT_EQ(entry.first, "hello");
}
map2.clear();