Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: base/containers/mru_cache_unittest.cc

Issue 1763273002: base: Remove OwningMRUCache in favor of scoped_ptrs in MRUCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + fix Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/containers/mru_cache_unittest.cc
diff --git a/base/containers/mru_cache_unittest.cc b/base/containers/mru_cache_unittest.cc
index 8ebecdb7b62af008e450315f37ae42c36f9327a5..d38337ef489dd8315135d7242b033e1837b4af2f 100644
--- a/base/containers/mru_cache_unittest.cc
+++ b/base/containers/mru_cache_unittest.cc
@@ -5,6 +5,7 @@
#include <stddef.h>
#include "base/containers/mru_cache.h"
+#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -187,15 +188,15 @@ TEST(MRUCacheTest, KeyReplacement) {
// Make sure that the owning version release its pointers properly.
TEST(MRUCacheTest, Owning) {
- typedef base::OwningMRUCache<int, CachedItem*> Cache;
+ using Cache = base::MRUCache<int, scoped_ptr<CachedItem>>;
Cache cache(Cache::NO_AUTO_EVICT);
int initial_count = cached_item_live_count;
// First insert and item and then overwrite it.
static const int kItem1Key = 1;
- cache.Put(kItem1Key, new CachedItem(20));
- cache.Put(kItem1Key, new CachedItem(22));
+ cache.Put(kItem1Key, make_scoped_ptr(new CachedItem(20)));
+ cache.Put(kItem1Key, make_scoped_ptr(new CachedItem(22)));
// There should still be one item, and one extra live item.
Cache::iterator iter = cache.Get(kItem1Key);
@@ -211,8 +212,8 @@ TEST(MRUCacheTest, Owning) {
// go away.
{
Cache cache2(Cache::NO_AUTO_EVICT);
- cache2.Put(1, new CachedItem(20));
- cache2.Put(2, new CachedItem(20));
+ cache2.Put(1, make_scoped_ptr(new CachedItem(20)));
+ cache2.Put(2, make_scoped_ptr(new CachedItem(20)));
}
// There should be no objects leaked.
@@ -221,8 +222,8 @@ TEST(MRUCacheTest, Owning) {
// Check that Clear() also frees things correctly.
{
Cache cache2(Cache::NO_AUTO_EVICT);
- cache2.Put(1, new CachedItem(20));
- cache2.Put(2, new CachedItem(20));
+ cache2.Put(1, make_scoped_ptr(new CachedItem(20)));
+ cache2.Put(2, make_scoped_ptr(new CachedItem(20)));
EXPECT_EQ(initial_count + 2, cached_item_live_count);
cache2.Clear();
EXPECT_EQ(initial_count, cached_item_live_count);
@@ -230,7 +231,7 @@ TEST(MRUCacheTest, Owning) {
}
TEST(MRUCacheTest, AutoEvict) {
- typedef base::OwningMRUCache<int, CachedItem*> Cache;
+ using Cache = base::MRUCache<int, scoped_ptr<CachedItem>>;
static const Cache::size_type kMaxSize = 3;
int initial_count = cached_item_live_count;
@@ -239,10 +240,10 @@ TEST(MRUCacheTest, AutoEvict) {
Cache cache(kMaxSize);
static const int kItem1Key = 1, kItem2Key = 2, kItem3Key = 3, kItem4Key = 4;
- cache.Put(kItem1Key, new CachedItem(20));
- cache.Put(kItem2Key, new CachedItem(21));
- cache.Put(kItem3Key, new CachedItem(22));
- cache.Put(kItem4Key, new CachedItem(23));
+ cache.Put(kItem1Key, make_scoped_ptr(new CachedItem(20)));
+ cache.Put(kItem2Key, make_scoped_ptr(new CachedItem(21)));
+ cache.Put(kItem3Key, make_scoped_ptr(new CachedItem(22)));
+ cache.Put(kItem4Key, make_scoped_ptr(new CachedItem(23)));
// The cache should only have kMaxSize items in it even though we inserted
// more.

Powered by Google App Engine
This is Rietveld 408576698