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

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

Issue 9283028: Add scoped_ptr<>::PassAs<>(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 11 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 27 matching lines...) Expand all
38 38
39 void GrabAndDrop(scoped_ptr<ConDecLogger> logger) { 39 void GrabAndDrop(scoped_ptr<ConDecLogger> logger) {
40 } 40 }
41 41
42 // Do not delete this function! It's existence is to test that you can 42 // Do not delete this function! It's existence is to test that you can
43 // return a temporarily constructed version of the scoper. 43 // return a temporarily constructed version of the scoper.
44 scoped_ptr<ConDecLogger> TestReturnOfType(int* constructed) { 44 scoped_ptr<ConDecLogger> TestReturnOfType(int* constructed) {
45 return scoped_ptr<ConDecLogger>(new ConDecLogger(constructed)); 45 return scoped_ptr<ConDecLogger>(new ConDecLogger(constructed));
46 } 46 }
47 47
48 scoped_ptr<ConDecLoggerParent> UpcastUsingPassAs(
49 scoped_ptr<ConDecLogger> object) {
50 return object.PassAs<ConDecLoggerParent>();
51 }
52
48 } // namespace 53 } // namespace
49 54
50 TEST(ScopedPtrTest, ScopedPtr) { 55 TEST(ScopedPtrTest, ScopedPtr) {
51 int constructed = 0; 56 int constructed = 0;
52 57
53 { 58 {
54 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 59 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
55 EXPECT_EQ(1, constructed); 60 EXPECT_EQ(1, constructed);
56 EXPECT_TRUE(scoper.get()); 61 EXPECT_TRUE(scoper.get());
57 62
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 EXPECT_EQ(0, constructed); 331 EXPECT_EQ(0, constructed);
327 332
328 // Call TestReturnOfType() so the compiler doesn't warn for an unused 333 // Call TestReturnOfType() so the compiler doesn't warn for an unused
329 // function. 334 // function.
330 { 335 {
331 TestReturnOfType(&constructed); 336 TestReturnOfType(&constructed);
332 } 337 }
333 EXPECT_EQ(0, constructed); 338 EXPECT_EQ(0, constructed);
334 } 339 }
335 340
341 TEST(ScopedPtrTest, PassAs) {
342 int constructed = 0;
343 {
344 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
345 EXPECT_EQ(1, constructed);
346 EXPECT_TRUE(scoper.get());
347
348 scoped_ptr<ConDecLoggerParent> scoper_parent;
349 scoper_parent = UpcastUsingPassAs(scoper.Pass());
350 EXPECT_EQ(1, constructed);
351 EXPECT_TRUE(scoper_parent.get());
352 EXPECT_FALSE(scoper.get());
353 }
354 EXPECT_EQ(0, constructed);
355 }
356
336 // TODO scoped_ptr_malloc 357 // TODO scoped_ptr_malloc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698