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

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

Issue 1993433002: Adds equality operators for comparing scoped_refptr with nullptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses review comments Created 4 years, 7 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
« no previous file with comments | « base/memory/ref_counted.h ('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 "base/test/opaque_ref_counted.h" 7 #include "base/test/opaque_ref_counted.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 scoped_refptr<SelfAssign> p1(new SelfAssign); 197 scoped_refptr<SelfAssign> p1(new SelfAssign);
198 scoped_refptr<SelfAssign> p2(new SelfAssign); 198 scoped_refptr<SelfAssign> p2(new SelfAssign);
199 199
200 EXPECT_EQ(p1, p1); 200 EXPECT_EQ(p1, p1);
201 EXPECT_EQ(p2, p2); 201 EXPECT_EQ(p2, p2);
202 202
203 EXPECT_NE(p1, p2); 203 EXPECT_NE(p1, p2);
204 EXPECT_NE(p2, p1); 204 EXPECT_NE(p2, p1);
205 } 205 }
206 206
207 TEST(RefCountedUnitTest, NullptrEquality) {
208 scoped_refptr<SelfAssign> ptr_to_an_instance(new SelfAssign);
209 scoped_refptr<SelfAssign> ptr_to_nullptr;
210
211 EXPECT_NE(nullptr, ptr_to_an_instance);
212 EXPECT_NE(ptr_to_an_instance, nullptr);
213 EXPECT_EQ(nullptr, ptr_to_nullptr);
214 EXPECT_EQ(ptr_to_nullptr, nullptr);
215 }
216
207 TEST(RefCountedUnitTest, ConvertibleEquality) { 217 TEST(RefCountedUnitTest, ConvertibleEquality) {
208 scoped_refptr<Derived> p1(new Derived); 218 scoped_refptr<Derived> p1(new Derived);
209 scoped_refptr<SelfAssign> p2; 219 scoped_refptr<SelfAssign> p2;
210 220
211 EXPECT_NE(p1, p2); 221 EXPECT_NE(p1, p2);
212 EXPECT_NE(p2, p1); 222 EXPECT_NE(p2, p1);
213 223
214 p2 = p1; 224 p2 = p1;
215 225
216 EXPECT_EQ(p1, p2); 226 EXPECT_EQ(p1, p2);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 498
489 TEST(RefCountedUnitTest, TestOverloadResolutionMove) { 499 TEST(RefCountedUnitTest, TestOverloadResolutionMove) {
490 scoped_refptr<Derived> derived(new Derived); 500 scoped_refptr<Derived> derived(new Derived);
491 scoped_refptr<SelfAssign> expected(derived); 501 scoped_refptr<SelfAssign> expected(derived);
492 EXPECT_EQ(expected, Overloaded(std::move(derived))); 502 EXPECT_EQ(expected, Overloaded(std::move(derived)));
493 503
494 scoped_refptr<Other> other(new Other); 504 scoped_refptr<Other> other(new Other);
495 scoped_refptr<Other> other2(other); 505 scoped_refptr<Other> other2(other);
496 EXPECT_EQ(other2, Overloaded(std::move(other))); 506 EXPECT_EQ(other2, Overloaded(std::move(other)));
497 } 507 }
OLDNEW
« no previous file with comments | « base/memory/ref_counted.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698