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

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

Issue 610533003: Allow custom deleters to opt out of self reset checks for scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sigh android Created 6 years, 2 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
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | crypto/scoped_nss_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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 // Android death tests don't work properly with assert(). Yay.
661 #if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
662 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultDeleter) {
663 scoped_ptr<int> x(new int);
664 EXPECT_DEATH(x.reset(x.get()), "");
665 }
666
667 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultArrayDeleter) {
668 scoped_ptr<int[]> y(new int[4]);
669 EXPECT_DEATH(y.reset(y.get()), "");
670 }
671
672 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultFreeDeleter) {
673 scoped_ptr<int, base::FreeDeleter> z(static_cast<int*>(malloc(sizeof(int))));
674 EXPECT_DEATH(z.reset(z.get()), "");
675 }
676
677 // A custom deleter that doesn't opt out should still crash.
678 TEST(ScopedPtrTest, SelfResetAbortsWithCustomDeleter) {
679 struct CustomDeleter {
680 inline void operator()(int* x) { delete x; }
681 };
682 scoped_ptr<int, CustomDeleter> x(new int);
683 EXPECT_DEATH(x.reset(x.get()), "");
684 }
685 #endif
686
687 TEST(ScopedPtrTest, SelfResetWithCustomDeleterOptOut) {
688 // A custom deleter should be able to opt out of self-reset abort behavior.
689 struct NoOpDeleter {
690 typedef void AllowSelfReset;
691 inline void operator()(int*) {}
692 };
693 scoped_ptr<int> owner(new int);
694 scoped_ptr<int, NoOpDeleter> x(owner.get());
695 x.reset(x.get());
696 }
OLDNEW
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | crypto/scoped_nss_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698