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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/memory/scoped_ptr_unittest.cc
diff --git a/base/memory/scoped_ptr_unittest.cc b/base/memory/scoped_ptr_unittest.cc
index ea135333eaef4cd820dfc4f7844522a420d3358e..63125dbf49bb6f349d5e3231d582141e061fe19d 100644
--- a/base/memory/scoped_ptr_unittest.cc
+++ b/base/memory/scoped_ptr_unittest.cc
@@ -45,6 +45,11 @@ scoped_ptr<ConDecLogger> TestReturnOfType(int* constructed) {
return scoped_ptr<ConDecLogger>(new ConDecLogger(constructed));
}
+scoped_ptr<ConDecLoggerParent> UpcastUsingPassAs(
+ scoped_ptr<ConDecLogger> object) {
+ return object.PassAs<ConDecLoggerParent>();
+}
+
} // namespace
TEST(ScopedPtrTest, ScopedPtr) {
@@ -333,4 +338,20 @@ TEST(ScopedPtrTest, ReturnTypeBehavior) {
EXPECT_EQ(0, constructed);
}
+TEST(ScopedPtrTest, PassAs) {
+ int constructed = 0;
+ {
+ scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
+ EXPECT_EQ(1, constructed);
+ EXPECT_TRUE(scoper.get());
+
+ scoped_ptr<ConDecLoggerParent> scoper_parent;
+ scoper_parent = UpcastUsingPassAs(scoper.Pass());
+ EXPECT_EQ(1, constructed);
+ EXPECT_TRUE(scoper_parent.get());
+ EXPECT_FALSE(scoper.get());
+ }
+ EXPECT_EQ(0, constructed);
+}
+
// TODO scoped_ptr_malloc

Powered by Google App Engine
This is Rietveld 408576698