Index: Source/wtf/HashMapTest.cpp |
diff --git a/Source/wtf/HashMapTest.cpp b/Source/wtf/HashMapTest.cpp |
index cbdbca6eb6c1c11b65ad3537b508e6267e0067ea..fff8121e7c1eb2ed525425fd0a8fcc03c2225aa3 100644 |
--- a/Source/wtf/HashMapTest.cpp |
+++ b/Source/wtf/HashMapTest.cpp |
@@ -303,6 +303,56 @@ TEST(HashMapTest, ValueTypeDestructed) |
EXPECT_EQ(0, InstanceCounter::counter); |
} |
+class CopyCounter { |
+public: |
+ CopyCounter() = default; |
+ explicit CopyCounter(int data) : m_data(data) { } |
+ |
+ CopyCounter(const CopyCounter& copy) : m_data(copy.m_data) { ++counter; } |
+ |
+ int data() const { return m_data; } |
+ |
+ bool isHashTableDeletedValue() const { return m_data == HashTableDeletedValue; } |
+ |
+ static int counter; |
tkent
2015/06/18 23:41:50
counter -> s_counter
|
+private: |
+ int m_data; |
+}; |
+ |
+int CopyCounter::counter = 0; |
+ |
+struct CopyCounterHash { |
+ static unsigned hash(const CopyCounter& key) |
+ { |
+ return IntHash<unsigned>::hash(key.data()); |
+ } |
+ |
+ static bool equal(const CopyCounter& a, const CopyCounter& b) |
+ { |
+ return a.data() == b.data(); |
+ } |
+ |
+ static const bool safeToCompareToEmptyOrDeleted = true; |
+}; |
+ |
+ |
+struct CopyCounterHashTraits: SimpleClassHashTraits<CopyCounter> { |
+ static const bool hasIsEmptyValueFunction = true; |
+ static bool isEmptyValue(const CopyCounter& counter) { return !counter.data(); } |
+}; |
+ |
+ |
+TEST(HashMapTest, LookupNoKeyCopies) |
+{ |
+ HashMap<CopyCounter, int, CopyCounterHash, CopyCounterHashTraits> map; |
+ |
+ map.contains(CopyCounter(1)); |
+ auto it = map.find(CopyCounter(1)); |
+ ALLOW_UNUSED_LOCAL(it); |
+ |
+ EXPECT_EQ(0, CopyCounter::counter); |
+} |
+ |
} // anonymous namespace |
} // namespace WTF |