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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/linked_ptr.h" | 7 #include "base/memory/linked_ptr.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 int num = 0; | 13 int num = 0; |
14 | 14 |
15 std::string history; | 15 std::string history; |
16 | 16 |
17 // Class which tracks allocation/deallocation | 17 // Class which tracks allocation/deallocation |
18 struct A { | 18 struct A { |
19 A(): mynum(num++) { history += base::StringPrintf("A%d ctor\n", mynum); } | 19 A(): mynum(num++) { history += base::StringPrintf("A%d ctor\n", mynum); } |
20 virtual ~A() { history += base::StringPrintf("A%d dtor\n", mynum); } | 20 virtual ~A() { history += base::StringPrintf("A%d dtor\n", mynum); } |
21 virtual void Use() { history += base::StringPrintf("A%d use\n", mynum); } | 21 virtual void Use() { history += base::StringPrintf("A%d use\n", mynum); } |
22 int mynum; | 22 int mynum; |
23 }; | 23 }; |
24 | 24 |
25 // Subclass | 25 // Subclass |
26 struct B: public A { | 26 struct B: public A { |
27 B() { history += base::StringPrintf("B%d ctor\n", mynum); } | 27 B() { history += base::StringPrintf("B%d ctor\n", mynum); } |
28 virtual ~B() { history += base::StringPrintf("B%d dtor\n", mynum); } | 28 virtual ~B() { history += base::StringPrintf("B%d dtor\n", mynum); } |
29 virtual void Use() OVERRIDE { | 29 void Use() override { history += base::StringPrintf("B%d use\n", mynum); } |
30 history += base::StringPrintf("B%d use\n", mynum); | |
31 } | |
32 }; | 30 }; |
33 | 31 |
34 } // namespace | 32 } // namespace |
35 | 33 |
36 TEST(LinkedPtrTest, Test) { | 34 TEST(LinkedPtrTest, Test) { |
37 { | 35 { |
38 linked_ptr<A> a0, a1, a2; | 36 linked_ptr<A> a0, a1, a2; |
39 a0 = a0; | 37 a0 = a0; |
40 a1 = a2; | 38 a1 = a2; |
41 ASSERT_EQ(a0.get(), static_cast<A*>(NULL)); | 39 ASSERT_EQ(a0.get(), static_cast<A*>(NULL)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 "A2 dtor\n" | 99 "A2 dtor\n" |
102 "A0 use\n" | 100 "A0 use\n" |
103 "A0 use\n" | 101 "A0 use\n" |
104 "A1 use\n" | 102 "A1 use\n" |
105 "A3 ctor\n" | 103 "A3 ctor\n" |
106 "A0 dtor\n" | 104 "A0 dtor\n" |
107 "A3 dtor\n" | 105 "A3 dtor\n" |
108 "A1 dtor\n" | 106 "A1 dtor\n" |
109 ); | 107 ); |
110 } | 108 } |
OLD | NEW |