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

Side by Side Diff: base/memory/ref_counted_unittest.cc

Issue 2723423002: Start BindStateBase ref count from 1 instead of 0 (Closed)
Patch Set: +test Created 3 years, 9 months 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
« base/memory/ref_counted.h ('K') | « base/memory/ref_counted.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/test/gtest_util.h"
9 #include "base/test/opaque_ref_counted.h" 10 #include "base/test/opaque_ref_counted.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace { 13 namespace {
13 14
14 class SelfAssign : public base::RefCounted<SelfAssign> { 15 class SelfAssign : public base::RefCounted<SelfAssign> {
15 protected: 16 protected:
16 virtual ~SelfAssign() {} 17 virtual ~SelfAssign() {}
17 18
18 private: 19 private:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 }; 116 };
116 117
117 scoped_refptr<Other> Overloaded(scoped_refptr<Other> other) { 118 scoped_refptr<Other> Overloaded(scoped_refptr<Other> other) {
118 return other; 119 return other;
119 } 120 }
120 121
121 scoped_refptr<SelfAssign> Overloaded(scoped_refptr<SelfAssign> self_assign) { 122 scoped_refptr<SelfAssign> Overloaded(scoped_refptr<SelfAssign> self_assign) {
122 return self_assign; 123 return self_assign;
123 } 124 }
124 125
126 class InitialValueIsOne : public base::RefCounted<InitialValueIsOne> {
127 public:
128 InitialValueIsOne() : RefCounted<InitialValueIsOne>(1) {}
129
130 private:
131 friend class base::RefCounted<InitialValueIsOne>;
132 ~InitialValueIsOne() {}
133 };
125 134
126 } // end namespace 135 } // end namespace
127 136
128 TEST(RefCountedUnitTest, TestSelfAssignment) { 137 TEST(RefCountedUnitTest, TestSelfAssignment) {
129 SelfAssign* p = new SelfAssign; 138 SelfAssign* p = new SelfAssign;
130 scoped_refptr<SelfAssign> var(p); 139 scoped_refptr<SelfAssign> var(p);
131 var = var; 140 var = var;
132 EXPECT_EQ(var.get(), p); 141 EXPECT_EQ(var.get(), p);
133 } 142 }
134 143
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 530
522 TEST(RefCountedUnitTest, TestOverloadResolutionMove) { 531 TEST(RefCountedUnitTest, TestOverloadResolutionMove) {
523 scoped_refptr<Derived> derived(new Derived); 532 scoped_refptr<Derived> derived(new Derived);
524 scoped_refptr<SelfAssign> expected(derived); 533 scoped_refptr<SelfAssign> expected(derived);
525 EXPECT_EQ(expected, Overloaded(std::move(derived))); 534 EXPECT_EQ(expected, Overloaded(std::move(derived)));
526 535
527 scoped_refptr<Other> other(new Other); 536 scoped_refptr<Other> other(new Other);
528 scoped_refptr<Other> other2(other); 537 scoped_refptr<Other> other2(other);
529 EXPECT_EQ(other2, Overloaded(std::move(other))); 538 EXPECT_EQ(other2, Overloaded(std::move(other)));
530 } 539 }
540
541 TEST(RefCountedUnitTest, TestInitialValueIsOne) {
542 scoped_refptr<InitialValueIsOne> obj = base::MakeShared<InitialValueIsOne>();
543 obj = nullptr;
544
545 scoped_refptr<InitialValueIsOne> obj2 = base::AdoptRef(new InitialValueIsOne);
546 obj2 = nullptr;
547 }
548
549 TEST(RefCountedDeathTest, TestAdoptRef) {
550 EXPECT_DCHECK_DEATH(make_scoped_refptr(new InitialValueIsOne));
551 }
OLDNEW
« base/memory/ref_counted.h ('K') | « base/memory/ref_counted.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698