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

Side by Side Diff: base/memory/scoped_ptr_unittest.cc

Issue 11149006: Extend scoped_ptr to be closer to unique_ptr. Support custom deleters, and deleting arrays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: utility -> algorithm. Mac needs it. Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 scoper2.swap(scoper1); 115 scoper2.swap(scoper1);
116 EXPECT_EQ(logger, scoper2.get()); 116 EXPECT_EQ(logger, scoper2.get());
117 EXPECT_FALSE(scoper1.get()); 117 EXPECT_FALSE(scoper1.get());
118 EXPECT_FALSE(scoper1 == scoper2.get()); 118 EXPECT_FALSE(scoper1 == scoper2.get());
119 EXPECT_TRUE(scoper1 != scoper2.get()); 119 EXPECT_TRUE(scoper1 != scoper2.get());
120 } 120 }
121 EXPECT_EQ(0, constructed); 121 EXPECT_EQ(0, constructed);
122 } 122 }
123 123
124 TEST(ScopedPtrTest, ScopedPtrArray) {
125 int constructed = 0;
126
127 {
128 scoped_ptr<int[]> scoper(new int[10]);
129 }
130 EXPECT_EQ(0, constructed);
131 }
132
124 TEST(ScopedPtrTest, ScopedPtrDepthSubtyping) { 133 TEST(ScopedPtrTest, ScopedPtrDepthSubtyping) {
125 int constructed = 0; 134 int constructed = 0;
126 135
127 // Test construction from a scoped_ptr to a derived class. 136 // Test construction from a scoped_ptr to a derived class.
128 { 137 {
129 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 138 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
130 EXPECT_EQ(1, constructed); 139 EXPECT_EQ(1, constructed);
131 EXPECT_TRUE(scoper.get()); 140 EXPECT_TRUE(scoper.get());
132 141
133 scoped_ptr<ConDecLoggerParent> scoper_parent(scoper.Pass()); 142 scoped_ptr<ConDecLoggerParent> scoper_parent(scoper.Pass());
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 scoped_ptr<ConDecLoggerParent> scoper_parent; 359 scoped_ptr<ConDecLoggerParent> scoper_parent;
351 scoper_parent = UpcastUsingPassAs(scoper.Pass()); 360 scoper_parent = UpcastUsingPassAs(scoper.Pass());
352 EXPECT_EQ(1, constructed); 361 EXPECT_EQ(1, constructed);
353 EXPECT_TRUE(scoper_parent.get()); 362 EXPECT_TRUE(scoper_parent.get());
354 EXPECT_FALSE(scoper.get()); 363 EXPECT_FALSE(scoper.get());
355 } 364 }
356 EXPECT_EQ(0, constructed); 365 EXPECT_EQ(0, constructed);
357 } 366 }
358 367
359 // TODO scoped_ptr_malloc 368 // TODO scoped_ptr_malloc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698