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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 scoped_ptr<Sub> sub2(new Sub); | 649 scoped_ptr<Sub> sub2(new Sub); |
650 | 650 |
651 // Upcast with Pass() works. | 651 // Upcast with Pass() works. |
652 scoped_ptr<Super> super1 = sub1.Pass(); | 652 scoped_ptr<Super> super1 = sub1.Pass(); |
653 super1 = sub2.Pass(); | 653 super1 = sub2.Pass(); |
654 | 654 |
655 // Upcast with an rvalue works. | 655 // Upcast with an rvalue works. |
656 scoped_ptr<Super> super2 = SubClassReturn(); | 656 scoped_ptr<Super> super2 = SubClassReturn(); |
657 super2 = SubClassReturn(); | 657 super2 = SubClassReturn(); |
658 } | 658 } |
659 | |
660 #if defined(GTEST_HAS_DEATH_TEST) | |
661 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultDeleter) { | |
662 scoped_ptr<int> x(new int); | |
663 EXPECT_DEATH(x.reset(x.get()), ""); | |
664 } | |
665 | |
666 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultArrayDeleter) { | |
667 scoped_ptr<int[]> y(new int[4]); | |
668 EXPECT_DEATH(y.reset(y.get()), ""); | |
669 } | |
670 | |
671 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultFreeDeleter) { | |
pneubeck (no reviews)
2014/10/07 09:30:08
It's a bit irritating that you test with a 'defaul
dcheng
2014/10/07 22:40:37
I don't completely follow what you'd like me to ch
| |
672 scoped_ptr<int, base::FreeDeleter> z(static_cast<int*>(malloc(sizeof(int)))); | |
673 EXPECT_DEATH(z.reset(z.get()), ""); | |
674 } | |
675 #endif | |
676 | |
677 TEST(ScopedPtrTest, SelfResetWithCustomDeleter) { | |
678 // A custom deleter should be able to opt out of self-reset abort behavior. | |
679 struct NoOpDeleter { | |
680 typedef void AllowSelfReset; | |
681 inline void operator()(int*) {} | |
682 }; | |
683 scoped_ptr<int> owner(new int); | |
684 scoped_ptr<int, NoOpDeleter> x(owner.get()); | |
685 x.reset(x.get()); | |
686 } | |
OLD | NEW |