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

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: fix unittest Created 8 years, 1 month 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 "base/callback.h"
8 #include "base/bind.h"
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 10
11 // TODO(ajwong): Add unittest for a class that defines a delete operator.
12
9 namespace { 13 namespace {
10 14
11 // Used to test depth subtyping. 15 // Used to test depth subtyping.
12 class ConDecLoggerParent { 16 class ConDecLoggerParent {
13 public: 17 public:
14 virtual ~ConDecLoggerParent() {} 18 virtual ~ConDecLoggerParent() {}
15 19
16 virtual void SetPtr(int* ptr) = 0; 20 virtual void SetPtr(int* ptr) = 0;
17 21
18 virtual int SomeMeth(int x) const = 0; 22 virtual int SomeMeth(int x) const = 0;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 118
115 scoper2.swap(scoper1); 119 scoper2.swap(scoper1);
116 EXPECT_EQ(logger, scoper2.get()); 120 EXPECT_EQ(logger, scoper2.get());
117 EXPECT_FALSE(scoper1.get()); 121 EXPECT_FALSE(scoper1.get());
118 EXPECT_FALSE(scoper1 == scoper2.get()); 122 EXPECT_FALSE(scoper1 == scoper2.get());
119 EXPECT_TRUE(scoper1 != scoper2.get()); 123 EXPECT_TRUE(scoper1 != scoper2.get());
120 } 124 }
121 EXPECT_EQ(0, constructed); 125 EXPECT_EQ(0, constructed);
122 } 126 }
123 127
128 TEST(ScopedPtrTest, ScopedPtrArray) {
129 int constructed = 0;
130
131 {
132 scoped_ptr<int[]> scoper(new int[10]);
133 }
134 EXPECT_EQ(0, constructed);
135 }
136
124 TEST(ScopedPtrTest, ScopedPtrDepthSubtyping) { 137 TEST(ScopedPtrTest, ScopedPtrDepthSubtyping) {
125 int constructed = 0; 138 int constructed = 0;
126 139
127 // Test construction from a scoped_ptr to a derived class. 140 // Test construction from a scoped_ptr to a derived class.
128 { 141 {
129 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 142 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
130 EXPECT_EQ(1, constructed); 143 EXPECT_EQ(1, constructed);
131 EXPECT_TRUE(scoper.get()); 144 EXPECT_TRUE(scoper.get());
132 145
133 scoped_ptr<ConDecLoggerParent> scoper_parent(scoper.Pass()); 146 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; 363 scoped_ptr<ConDecLoggerParent> scoper_parent;
351 scoper_parent = UpcastUsingPassAs(scoper.Pass()); 364 scoper_parent = UpcastUsingPassAs(scoper.Pass());
352 EXPECT_EQ(1, constructed); 365 EXPECT_EQ(1, constructed);
353 EXPECT_TRUE(scoper_parent.get()); 366 EXPECT_TRUE(scoper_parent.get());
354 EXPECT_FALSE(scoper.get()); 367 EXPECT_FALSE(scoper.get());
355 } 368 }
356 EXPECT_EQ(0, constructed); 369 EXPECT_EQ(0, constructed);
357 } 370 }
358 371
359 // TODO scoped_ptr_malloc 372 // TODO scoped_ptr_malloc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698