Chromium Code Reviews| Index: base/memory/scoped_ptr_unittest.cc |
| diff --git a/base/memory/scoped_ptr_unittest.cc b/base/memory/scoped_ptr_unittest.cc |
| index 7a1e41ed1d8668b151c498dd511ba73c5c385ea4..77e7995f8c755db9580f51ca6c3ec4ba2c73c958 100644 |
| --- a/base/memory/scoped_ptr_unittest.cc |
| +++ b/base/memory/scoped_ptr_unittest.cc |
| @@ -656,3 +656,31 @@ TEST(ScopedPtrTest, Conversion) { |
| scoped_ptr<Super> super2 = SubClassReturn(); |
| super2 = SubClassReturn(); |
| } |
| + |
| +#if defined(GTEST_HAS_DEATH_TEST) |
| +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) { |
|
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
|
| + scoped_ptr<int, base::FreeDeleter> z(static_cast<int*>(malloc(sizeof(int)))); |
| + EXPECT_DEATH(z.reset(z.get()), ""); |
| +} |
| +#endif |
| + |
| +TEST(ScopedPtrTest, SelfResetWithCustomDeleter) { |
| + // 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()); |
| +} |