OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/mru_cache.h" | 6 #include "base/memory/mru_cache.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 cache.Put(kItem4Key, new CachedItem(23)); | 244 cache.Put(kItem4Key, new CachedItem(23)); |
245 | 245 |
246 // The cache should only have kMaxSize items in it even though we inserted | 246 // The cache should only have kMaxSize items in it even though we inserted |
247 // more. | 247 // more. |
248 EXPECT_EQ(kMaxSize, cache.size()); | 248 EXPECT_EQ(kMaxSize, cache.size()); |
249 } | 249 } |
250 | 250 |
251 // There should be no objects leaked. | 251 // There should be no objects leaked. |
252 EXPECT_EQ(initial_count, cached_item_live_count); | 252 EXPECT_EQ(initial_count, cached_item_live_count); |
253 } | 253 } |
| 254 |
| 255 TEST(MRUCacheTest, HashingMRUCache) { |
| 256 // Very simple test to make sure that the hashing cache works correctly. |
| 257 typedef base::HashingMRUCache<std::string, CachedItem> Cache; |
| 258 Cache cache(Cache::NO_AUTO_EVICT); |
| 259 |
| 260 CachedItem one(1); |
| 261 cache.Put("First", one); |
| 262 |
| 263 CachedItem two(2); |
| 264 cache.Put("Second", two); |
| 265 |
| 266 EXPECT_EQ(one.value, cache.Get("First")->second.value); |
| 267 EXPECT_EQ(two.value, cache.Get("Second")->second.value); |
| 268 cache.ShrinkToSize(1); |
| 269 EXPECT_EQ(two.value, cache.Get("Second")->second.value); |
| 270 EXPECT_EQ(cache.end(), cache.Get("First")); |
| 271 } |
OLD | NEW |