| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 // Used to test depth subtyping. | 11 // Used to test depth subtyping. |
| 12 class ConDecLoggerParent { | 12 class ConDecLoggerParent { |
| 13 public: | 13 public: |
| 14 virtual ~ConDecLoggerParent() {} | 14 virtual ~ConDecLoggerParent() {} |
| 15 virtual void set_ptr(int* ptr) = 0; | 15 virtual void set_ptr(int* ptr) = 0; |
| 16 | 16 |
| 17 virtual int SomeMeth(int x) const = 0; | 17 virtual int SomeMeth(int x) const = 0; |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 class ConDecLogger : public ConDecLoggerParent { | 20 class ConDecLogger : public ConDecLoggerParent { |
| 21 public: | 21 public: |
| 22 ConDecLogger() : ptr_(NULL) { } | 22 ConDecLogger() : ptr_(NULL) { } |
| 23 explicit ConDecLogger(int* ptr) { set_ptr(ptr); } | 23 explicit ConDecLogger(int* ptr) { set_ptr(ptr); } |
| 24 virtual ~ConDecLogger() { --*ptr_; } | 24 virtual ~ConDecLogger() { --*ptr_; } |
| 25 | 25 |
| 26 virtual void set_ptr(int* ptr) { ptr_ = ptr; ++*ptr_; } | 26 virtual void set_ptr(int* ptr) OVERRIDE { ptr_ = ptr; ++*ptr_; } |
| 27 | 27 |
| 28 virtual int SomeMeth(int x) const { return x; } | 28 virtual int SomeMeth(int x) const OVERRIDE { return x; } |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 int* ptr_; | 31 int* ptr_; |
| 32 DISALLOW_COPY_AND_ASSIGN(ConDecLogger); | 32 DISALLOW_COPY_AND_ASSIGN(ConDecLogger); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 scoped_ptr<ConDecLogger> PassThru(scoped_ptr<ConDecLogger> logger) { | 35 scoped_ptr<ConDecLogger> PassThru(scoped_ptr<ConDecLogger> logger) { |
| 36 return logger.Pass(); | 36 return logger.Pass(); |
| 37 } | 37 } |
| 38 | 38 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 scoped_ptr<ConDecLoggerParent> scoper_parent; | 348 scoped_ptr<ConDecLoggerParent> scoper_parent; |
| 349 scoper_parent = UpcastUsingPassAs(scoper.Pass()); | 349 scoper_parent = UpcastUsingPassAs(scoper.Pass()); |
| 350 EXPECT_EQ(1, constructed); | 350 EXPECT_EQ(1, constructed); |
| 351 EXPECT_TRUE(scoper_parent.get()); | 351 EXPECT_TRUE(scoper_parent.get()); |
| 352 EXPECT_FALSE(scoper.get()); | 352 EXPECT_FALSE(scoper.get()); |
| 353 } | 353 } |
| 354 EXPECT_EQ(0, constructed); | 354 EXPECT_EQ(0, constructed); |
| 355 } | 355 } |
| 356 | 356 |
| 357 // TODO scoped_ptr_malloc | 357 // TODO scoped_ptr_malloc |
| OLD | NEW |