| 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" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Used to test depth subtyping. | 14 // Used to test depth subtyping. |
| 15 class ConDecLoggerParent { | 15 class ConDecLoggerParent { |
| 16 public: | 16 public: |
| 17 virtual ~ConDecLoggerParent() {} | 17 virtual ~ConDecLoggerParent() {} |
| 18 | 18 |
| 19 virtual void SetPtr(int* ptr) = 0; | 19 virtual void SetPtr(int* ptr) = 0; |
| 20 | 20 |
| 21 virtual int SomeMeth(int x) const = 0; | 21 virtual int SomeMeth(int x) const = 0; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 class ConDecLogger : public ConDecLoggerParent { | 24 class ConDecLogger : public ConDecLoggerParent { |
| 25 public: | 25 public: |
| 26 ConDecLogger() : ptr_(NULL) { } | 26 ConDecLogger() : ptr_(NULL) { } |
| 27 explicit ConDecLogger(int* ptr) { SetPtr(ptr); } | 27 explicit ConDecLogger(int* ptr) { SetPtr(ptr); } |
| 28 virtual ~ConDecLogger() { --*ptr_; } | 28 ~ConDecLogger() override { --*ptr_; } |
| 29 | 29 |
| 30 virtual void SetPtr(int* ptr) override { ptr_ = ptr; ++*ptr_; } | 30 void SetPtr(int* ptr) override { |
| 31 ptr_ = ptr; |
| 32 ++*ptr_; |
| 33 } |
| 31 | 34 |
| 32 virtual int SomeMeth(int x) const override { return x; } | 35 int SomeMeth(int x) const override { return x; } |
| 33 | 36 |
| 34 private: | 37 private: |
| 35 int* ptr_; | 38 int* ptr_; |
| 36 | 39 |
| 37 DISALLOW_COPY_AND_ASSIGN(ConDecLogger); | 40 DISALLOW_COPY_AND_ASSIGN(ConDecLogger); |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 struct CountingDeleter { | 43 struct CountingDeleter { |
| 41 explicit CountingDeleter(int* count) : count_(count) {} | 44 explicit CountingDeleter(int* count) : count_(count) {} |
| 42 inline void operator()(double* ptr) const { | 45 inline void operator()(double* ptr) const { |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 TEST(ScopedPtrTest, SelfResetWithCustomDeleterOptOut) { | 690 TEST(ScopedPtrTest, SelfResetWithCustomDeleterOptOut) { |
| 688 // A custom deleter should be able to opt out of self-reset abort behavior. | 691 // A custom deleter should be able to opt out of self-reset abort behavior. |
| 689 struct NoOpDeleter { | 692 struct NoOpDeleter { |
| 690 typedef void AllowSelfReset; | 693 typedef void AllowSelfReset; |
| 691 inline void operator()(int*) {} | 694 inline void operator()(int*) {} |
| 692 }; | 695 }; |
| 693 scoped_ptr<int> owner(new int); | 696 scoped_ptr<int> owner(new int); |
| 694 scoped_ptr<int, NoOpDeleter> x(owner.get()); | 697 scoped_ptr<int, NoOpDeleter> x(owner.get()); |
| 695 x.reset(x.get()); | 698 x.reset(x.get()); |
| 696 } | 699 } |
| OLD | NEW |