OLD | NEW |
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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 { | 595 { |
596 OverloadedNewAndDelete::ResetCounters(); | 596 OverloadedNewAndDelete::ResetCounters(); |
597 scoped_ptr<OverloadedNewAndDelete> scoper(new OverloadedNewAndDelete()); | 597 scoped_ptr<OverloadedNewAndDelete> scoper(new OverloadedNewAndDelete()); |
598 EXPECT_TRUE(scoper.get()); | 598 EXPECT_TRUE(scoper.get()); |
599 | 599 |
600 scoped_ptr<OverloadedNewAndDelete> scoper2(scoper.Pass()); | 600 scoped_ptr<OverloadedNewAndDelete> scoper2(scoper.Pass()); |
601 } | 601 } |
602 EXPECT_EQ(1, OverloadedNewAndDelete::delete_count()); | 602 EXPECT_EQ(1, OverloadedNewAndDelete::delete_count()); |
603 EXPECT_EQ(1, OverloadedNewAndDelete::new_count()); | 603 EXPECT_EQ(1, OverloadedNewAndDelete::new_count()); |
604 } | 604 } |
| 605 |
| 606 scoped_ptr<int> NullIntReturn() { |
| 607 return nullptr; |
| 608 } |
| 609 |
| 610 TEST(ScopedPtrTest, Nullptr) { |
| 611 scoped_ptr<int> scoper1(nullptr); |
| 612 scoped_ptr<int> scoper2(new int); |
| 613 scoper2 = nullptr; |
| 614 scoped_ptr<int> scoper3(NullIntReturn()); |
| 615 scoped_ptr<int> scoper4 = NullIntReturn(); |
| 616 EXPECT_EQ(nullptr, scoper1.get()); |
| 617 EXPECT_EQ(nullptr, scoper2.get()); |
| 618 EXPECT_EQ(nullptr, scoper3.get()); |
| 619 EXPECT_EQ(nullptr, scoper4.get()); |
| 620 } |
| 621 |
| 622 scoped_ptr<int[]> NullIntArrayReturn() { |
| 623 return nullptr; |
| 624 } |
| 625 |
| 626 TEST(ScopedPtrTest, NullptrArray) { |
| 627 scoped_ptr<int[]> scoper1(nullptr); |
| 628 scoped_ptr<int[]> scoper2(new int); |
| 629 scoper2 = nullptr; |
| 630 scoped_ptr<int[]> scoper3(NullIntArrayReturn()); |
| 631 scoped_ptr<int[]> scoper4 = NullIntArrayReturn(); |
| 632 EXPECT_EQ(nullptr, scoper1.get()); |
| 633 EXPECT_EQ(nullptr, scoper2.get()); |
| 634 EXPECT_EQ(nullptr, scoper3.get()); |
| 635 EXPECT_EQ(nullptr, scoper4.get()); |
| 636 } |
OLD | NEW |