| Index: base/memory/scoped_ptr_unittest.cc
|
| diff --git a/base/memory/scoped_ptr_unittest.cc b/base/memory/scoped_ptr_unittest.cc
|
| index 2ea44e9393efef2ea9e0cc89d10f2c85bfd834dd..3da8d3bd708ffebfafc178a8dad23ddb1b06c56b 100644
|
| --- a/base/memory/scoped_ptr_unittest.cc
|
| +++ b/base/memory/scoped_ptr_unittest.cc
|
| @@ -656,3 +656,41 @@ TEST(ScopedPtrTest, Conversion) {
|
| scoped_ptr<Super> super2 = SubClassReturn();
|
| super2 = SubClassReturn();
|
| }
|
| +
|
| +// Android death tests don't work properly with assert(). Yay.
|
| +#if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
|
| +TEST(ScopedPtrTest, SelfResetAbortsWithDefaultDeleter) {
|
| + scoped_ptr<int> x(new int);
|
| + EXPECT_DEATH(x.reset(x.get()), "");
|
| +}
|
| +
|
| +TEST(ScopedPtrTest, SelfResetAbortsWithDefaultArrayDeleter) {
|
| + scoped_ptr<int[]> y(new int[4]);
|
| + EXPECT_DEATH(y.reset(y.get()), "");
|
| +}
|
| +
|
| +TEST(ScopedPtrTest, SelfResetAbortsWithDefaultFreeDeleter) {
|
| + scoped_ptr<int, base::FreeDeleter> z(static_cast<int*>(malloc(sizeof(int))));
|
| + EXPECT_DEATH(z.reset(z.get()), "");
|
| +}
|
| +
|
| +// A custom deleter that doesn't opt out should still crash.
|
| +TEST(ScopedPtrTest, SelfResetAbortsWithCustomDeleter) {
|
| + struct CustomDeleter {
|
| + inline void operator()(int* x) { delete x; }
|
| + };
|
| + scoped_ptr<int, CustomDeleter> x(new int);
|
| + EXPECT_DEATH(x.reset(x.get()), "");
|
| +}
|
| +#endif
|
| +
|
| +TEST(ScopedPtrTest, SelfResetWithCustomDeleterOptOut) {
|
| + // A custom deleter should be able to opt out of self-reset abort behavior.
|
| + struct NoOpDeleter {
|
| + typedef void AllowSelfReset;
|
| + inline void operator()(int*) {}
|
| + };
|
| + scoped_ptr<int> owner(new int);
|
| + scoped_ptr<int, NoOpDeleter> x(owner.get());
|
| + x.reset(x.get());
|
| +}
|
|
|