Chromium Code Reviews| Index: base/memory/scoped_ptr_unittest.cc |
| diff --git a/base/memory/scoped_ptr_unittest.cc b/base/memory/scoped_ptr_unittest.cc |
| index e0c15484e0811c5c1e6aaf14c0a4d936be90521a..44ba5609eed52480dc94d7c58dc8c2f4d85c6d88 100644 |
| --- a/base/memory/scoped_ptr_unittest.cc |
| +++ b/base/memory/scoped_ptr_unittest.cc |
| @@ -406,7 +406,6 @@ TEST(ScopedPtrTest, PassBehavior) { |
| // Should auto-destruct logger by end of scope. |
| scoper.Pass(); |
| - EXPECT_FALSE(scoper.get()); |
|
jamesr
2014/09/26 21:58:26
does this test fail now?
danakj
2014/09/26 22:00:09
Oh, this can stay now, thanks. I'm going to add a
|
| } |
| EXPECT_EQ(0, constructed); |
| @@ -602,3 +601,55 @@ TEST(ScopedPtrTest, OverloadedNewAndDelete) { |
| EXPECT_EQ(1, OverloadedNewAndDelete::delete_count()); |
| EXPECT_EQ(1, OverloadedNewAndDelete::new_count()); |
| } |
| + |
| +scoped_ptr<int> NullIntReturn() { |
| + return nullptr; |
| +} |
| + |
| +TEST(ScopedPtrTest, Nullptr) { |
| + scoped_ptr<int> scoper1(nullptr); |
| + scoped_ptr<int> scoper2(new int); |
| + scoper2 = nullptr; |
| + scoped_ptr<int> scoper3(NullIntReturn()); |
| + scoped_ptr<int> scoper4 = NullIntReturn(); |
| + EXPECT_EQ(nullptr, scoper1.get()); |
| + EXPECT_EQ(nullptr, scoper2.get()); |
| + EXPECT_EQ(nullptr, scoper3.get()); |
| + EXPECT_EQ(nullptr, scoper4.get()); |
| +} |
| + |
| +scoped_ptr<int[]> NullIntArrayReturn() { |
| + return nullptr; |
| +} |
| + |
| +TEST(ScopedPtrTest, NullptrArray) { |
| + scoped_ptr<int[]> scoper1(nullptr); |
| + scoped_ptr<int[]> scoper2(new int); |
| + scoper2 = nullptr; |
| + scoped_ptr<int[]> scoper3(NullIntArrayReturn()); |
| + scoped_ptr<int[]> scoper4 = NullIntArrayReturn(); |
| + EXPECT_EQ(nullptr, scoper1.get()); |
| + EXPECT_EQ(nullptr, scoper2.get()); |
| + EXPECT_EQ(nullptr, scoper3.get()); |
| + EXPECT_EQ(nullptr, scoper4.get()); |
| +} |
| + |
| +class Super {}; |
| +class Sub : public Super {}; |
| + |
| +scoped_ptr<Sub> SubClassReturn() { |
| + return make_scoped_ptr(new Sub); |
| +} |
| + |
| +TEST(ScopedPtrTest, Conversion) { |
| + scoped_ptr<Sub> sub1(new Sub); |
| + scoped_ptr<Sub> sub2(new Sub); |
| + |
| + // Upcast with Pass() works. |
| + scoped_ptr<Super> super1 = sub1.Pass(); |
| + super1 = sub2.Pass(); |
| + |
| + // Upcast with an rvalue works. |
| + scoped_ptr<Super> super2 = SubClassReturn(); |
| + super2 = SubClassReturn(); |
| +} |