| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium 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 "core/fxcrt/cfx_retain_ptr.h" | 5 #include "core/fxcrt/cfx_retain_ptr.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "testing/fx_string_testhelpers.h" | 9 #include "testing/fx_string_testhelpers.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 EXPECT_EQ(1, obj1.release_count()); | 121 EXPECT_EQ(1, obj1.release_count()); |
| 122 EXPECT_EQ(1, obj2.retain_count()); | 122 EXPECT_EQ(1, obj2.retain_count()); |
| 123 EXPECT_EQ(0, obj2.release_count()); | 123 EXPECT_EQ(0, obj2.release_count()); |
| 124 } | 124 } |
| 125 EXPECT_EQ(1, obj1.retain_count()); | 125 EXPECT_EQ(1, obj1.retain_count()); |
| 126 EXPECT_EQ(1, obj1.release_count()); | 126 EXPECT_EQ(1, obj1.release_count()); |
| 127 EXPECT_EQ(1, obj2.retain_count()); | 127 EXPECT_EQ(1, obj2.retain_count()); |
| 128 EXPECT_EQ(1, obj2.release_count()); | 128 EXPECT_EQ(1, obj2.release_count()); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST(fxcrt, RetainPtrLeak) { |
| 132 PseudoRetainable obj; |
| 133 PseudoRetainable* leak; |
| 134 { |
| 135 CFX_RetainPtr<PseudoRetainable> ptr(&obj); |
| 136 leak = ptr.Leak(); |
| 137 EXPECT_EQ(1, obj.retain_count()); |
| 138 EXPECT_EQ(0, obj.release_count()); |
| 139 } |
| 140 EXPECT_EQ(1, obj.retain_count()); |
| 141 EXPECT_EQ(0, obj.release_count()); |
| 142 { |
| 143 CFX_RetainPtr<PseudoRetainable> ptr; |
| 144 ptr.Unleak(leak); |
| 145 EXPECT_EQ(1, obj.retain_count()); |
| 146 EXPECT_EQ(0, obj.release_count()); |
| 147 } |
| 148 EXPECT_EQ(1, obj.retain_count()); |
| 149 EXPECT_EQ(1, obj.release_count()); |
| 150 } |
| 151 |
| 131 TEST(fxcrt, RetainPtrSwapNull) { | 152 TEST(fxcrt, RetainPtrSwapNull) { |
| 132 PseudoRetainable obj1; | 153 PseudoRetainable obj1; |
| 133 { | 154 { |
| 134 CFX_RetainPtr<PseudoRetainable> ptr1(&obj1); | 155 CFX_RetainPtr<PseudoRetainable> ptr1(&obj1); |
| 135 { | 156 { |
| 136 CFX_RetainPtr<PseudoRetainable> ptr2; | 157 CFX_RetainPtr<PseudoRetainable> ptr2; |
| 137 ptr1.Swap(ptr2); | 158 ptr1.Swap(ptr2); |
| 138 EXPECT_FALSE(ptr1); | 159 EXPECT_FALSE(ptr1); |
| 139 EXPECT_TRUE(ptr2); | 160 EXPECT_TRUE(ptr2); |
| 140 EXPECT_EQ(1, obj1.retain_count()); | 161 EXPECT_EQ(1, obj1.retain_count()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 237 |
| 217 TEST(fxcrt, RetainPtrMakeRetained) { | 238 TEST(fxcrt, RetainPtrMakeRetained) { |
| 218 auto ptr = pdfium::MakeRetain<CFX_Retainable>(); | 239 auto ptr = pdfium::MakeRetain<CFX_Retainable>(); |
| 219 EXPECT_TRUE(ptr->HasOneRef()); | 240 EXPECT_TRUE(ptr->HasOneRef()); |
| 220 { | 241 { |
| 221 CFX_RetainPtr<CFX_Retainable> other = ptr; | 242 CFX_RetainPtr<CFX_Retainable> other = ptr; |
| 222 EXPECT_FALSE(ptr->HasOneRef()); | 243 EXPECT_FALSE(ptr->HasOneRef()); |
| 223 } | 244 } |
| 224 EXPECT_TRUE(ptr->HasOneRef()); | 245 EXPECT_TRUE(ptr->HasOneRef()); |
| 225 } | 246 } |
| OLD | NEW |