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

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

Issue 1305973011: Change assert() to DCHECK() in scoped_ptr.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add //base dependencies as experiment Created 5 years, 3 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') | chrome_elf/chrome_elf.gyp » ('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 <sstream> 7 #include <sstream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 634
635 // Upcast with Pass() works. 635 // Upcast with Pass() works.
636 scoped_ptr<Super> super1 = sub1.Pass(); 636 scoped_ptr<Super> super1 = sub1.Pass();
637 super1 = sub2.Pass(); 637 super1 = sub2.Pass();
638 638
639 // Upcast with an rvalue works. 639 // Upcast with an rvalue works.
640 scoped_ptr<Super> super2 = SubClassReturn(); 640 scoped_ptr<Super> super2 = SubClassReturn();
641 super2 = SubClassReturn(); 641 super2 = SubClassReturn();
642 } 642 }
643 643
644 // Android death tests don't work properly with assert(). Yay. 644 #if DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST)
645 #if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
646 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultDeleter) { 645 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultDeleter) {
647 scoped_ptr<int> x(new int); 646 scoped_ptr<int> x(new int);
648 EXPECT_DEATH(x.reset(x.get()), ""); 647 EXPECT_DEATH(x.reset(x.get()), "");
649 } 648 }
650 649
651 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultArrayDeleter) { 650 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultArrayDeleter) {
652 scoped_ptr<int[]> y(new int[4]); 651 scoped_ptr<int[]> y(new int[4]);
653 EXPECT_DEATH(y.reset(y.get()), ""); 652 EXPECT_DEATH(y.reset(y.get()), "");
654 } 653 }
655 654
656 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultFreeDeleter) { 655 TEST(ScopedPtrTest, SelfResetAbortsWithDefaultFreeDeleter) {
657 scoped_ptr<int, base::FreeDeleter> z(static_cast<int*>(malloc(sizeof(int)))); 656 scoped_ptr<int, base::FreeDeleter> z(static_cast<int*>(malloc(sizeof(int))));
658 EXPECT_DEATH(z.reset(z.get()), ""); 657 EXPECT_DEATH(z.reset(z.get()), "");
659 } 658 }
660 659
661 // A custom deleter that doesn't opt out should still crash. 660 // A custom deleter that doesn't opt out should still crash.
662 TEST(ScopedPtrTest, SelfResetAbortsWithCustomDeleter) { 661 TEST(ScopedPtrTest, SelfResetAbortsWithCustomDeleter) {
663 struct CustomDeleter { 662 struct CustomDeleter {
664 inline void operator()(int* x) { delete x; } 663 inline void operator()(int* x) { delete x; }
665 }; 664 };
666 scoped_ptr<int, CustomDeleter> x(new int); 665 scoped_ptr<int, CustomDeleter> x(new int);
667 EXPECT_DEATH(x.reset(x.get()), ""); 666 EXPECT_DEATH(x.reset(x.get()), "");
668 } 667 }
669 #endif 668 #endif
670 669
671 TEST(ScopedPtrTest, SelfResetWithCustomDeleterOptOut) { 670 TEST(ScopedPtrTest, SelfResetWithCustomDeleterOptOut) {
672 // A custom deleter should be able to opt out of self-reset abort behavior. 671 // A custom deleter should be able to opt out of self-reset abort behavior.
673 struct NoOpDeleter { 672 struct NoOpDeleter {
674 #if !defined(NDEBUG) 673 #if DCHECK_IS_ON()
675 typedef void AllowSelfReset; 674 typedef void AllowSelfReset;
676 #endif 675 #endif
677 inline void operator()(int*) {} 676 inline void operator()(int*) {}
678 }; 677 };
679 scoped_ptr<int> owner(new int); 678 scoped_ptr<int> owner(new int);
680 scoped_ptr<int, NoOpDeleter> x(owner.get()); 679 scoped_ptr<int, NoOpDeleter> x(owner.get());
681 x.reset(x.get()); 680 x.reset(x.get());
682 } 681 }
683 682
684 // Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean 683 // Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean
685 // value first. 684 // value first.
686 TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) { 685 TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) {
687 scoped_ptr<int> x(new int); 686 scoped_ptr<int> x(new int);
688 std::stringstream s1; 687 std::stringstream s1;
689 s1 << x; 688 s1 << x;
690 689
691 std::stringstream s2; 690 std::stringstream s2;
692 s2 << x.get(); 691 s2 << x.get();
693 692
694 EXPECT_EQ(s2.str(), s1.str()); 693 EXPECT_EQ(s2.str(), s1.str());
695 } 694 }
OLDNEW
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | chrome_elf/chrome_elf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698