Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: core/fxcrt/cfx_retain_ptr_unittest.cpp

Issue 2560783003: Catch stray Retains() and Releases() outside of RetainPtr<>. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 11
12 namespace { 12 namespace {
13 13
14 class PseudoRetainable { 14 class PseudoRetainable {
15 public: 15 public:
16 PseudoRetainable() : retain_count_(0), release_count_(0) {} 16 PseudoRetainable() : retain_count_(0), release_count_(0) {}
17 void Retain() { ++retain_count_; }
18 void Release() { ++release_count_; }
19 int retain_count() const { return retain_count_; } 17 int retain_count() const { return retain_count_; }
20 int release_count() const { return release_count_; } 18 int release_count() const { return release_count_; }
21 19
22 private: 20 private:
21 template <typename U>
22 friend struct ::ReleaseDeleter;
23 template <typename U>
24 friend class ::CFX_RetainPtr;
25
26 void Retain() { ++retain_count_; }
27 void Release() { ++release_count_; }
28
23 int retain_count_; 29 int retain_count_;
24 int release_count_; 30 int release_count_;
25 }; 31 };
26 32
27 } // namespace 33 } // namespace
28 34
29 TEST(fxcrt, RetainPtrNull) { 35 TEST(fxcrt, RetainPtrNull) {
30 CFX_RetainPtr<PseudoRetainable> ptr; 36 CFX_RetainPtr<PseudoRetainable> ptr;
31 EXPECT_EQ(nullptr, ptr.Get()); 37 EXPECT_EQ(nullptr, ptr.Get());
32 } 38 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 222
217 TEST(fxcrt, RetainPtrMakeRetained) { 223 TEST(fxcrt, RetainPtrMakeRetained) {
218 auto ptr = pdfium::MakeRetain<CFX_Retainable>(); 224 auto ptr = pdfium::MakeRetain<CFX_Retainable>();
219 EXPECT_TRUE(ptr->HasOneRef()); 225 EXPECT_TRUE(ptr->HasOneRef());
220 { 226 {
221 CFX_RetainPtr<CFX_Retainable> other = ptr; 227 CFX_RetainPtr<CFX_Retainable> other = ptr;
222 EXPECT_FALSE(ptr->HasOneRef()); 228 EXPECT_FALSE(ptr->HasOneRef());
223 } 229 }
224 EXPECT_TRUE(ptr->HasOneRef()); 230 EXPECT_TRUE(ptr->HasOneRef());
225 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698