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

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

Issue 7065030: Add missing test to WeakPtr (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 WeakPtrFactory<int> factory(&data); 73 WeakPtrFactory<int> factory(&data);
74 a = factory.GetWeakPtr(); 74 a = factory.GetWeakPtr();
75 b = factory.GetWeakPtr(); 75 b = factory.GetWeakPtr();
76 EXPECT_EQ(&data, a.get()); 76 EXPECT_EQ(&data, a.get());
77 EXPECT_EQ(&data, b.get()); 77 EXPECT_EQ(&data, b.get());
78 } 78 }
79 EXPECT_TRUE(a.get() == NULL); 79 EXPECT_TRUE(a.get() == NULL);
80 EXPECT_TRUE(b.get() == NULL); 80 EXPECT_TRUE(b.get() == NULL);
81 } 81 }
82 82
83 TEST(WeakPtrTest, MultipleStaged) {
84 WeakPtr<int> a;
85 {
86 int data;
87 WeakPtrFactory<int> factory(&data);
88 a = factory.GetWeakPtr();
89 {
90 WeakPtr<int> b = factory.GetWeakPtr();
willchan no longer on Chromium 2011/05/24 22:29:24 Maybe you should also add EXPECTs for b? Up to you
91 }
92 EXPECT_TRUE(a.get() != NULL);
93 }
94 EXPECT_TRUE(a.get() == NULL);
95 }
96
83 TEST(WeakPtrTest, UpCast) { 97 TEST(WeakPtrTest, UpCast) {
84 Derived data; 98 Derived data;
85 WeakPtrFactory<Derived> factory(&data); 99 WeakPtrFactory<Derived> factory(&data);
86 WeakPtr<Base> ptr = factory.GetWeakPtr(); 100 WeakPtr<Base> ptr = factory.GetWeakPtr();
87 ptr = factory.GetWeakPtr(); 101 ptr = factory.GetWeakPtr();
88 EXPECT_EQ(ptr.get(), &data); 102 EXPECT_EQ(ptr.get(), &data);
89 } 103 }
90 104
91 TEST(WeakPtrTest, SupportsWeakPtr) { 105 TEST(WeakPtrTest, SupportsWeakPtr) {
92 Producer f; 106 Producer f;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Test that it is OK to create a class that has a WeakPtr member on one 142 // Test that it is OK to create a class that has a WeakPtr member on one
129 // thread, but use it on another. This tests that we do not trip runtime 143 // thread, but use it on another. This tests that we do not trip runtime
130 // checks that ensure that a weak reference is not used by multiple threads. 144 // checks that ensure that a weak reference is not used by multiple threads.
131 scoped_ptr<Consumer> consumer(OffThreadObjectCreator<Consumer>::NewObject()); 145 scoped_ptr<Consumer> consumer(OffThreadObjectCreator<Consumer>::NewObject());
132 Producer producer; 146 Producer producer;
133 consumer->producer = producer.AsWeakPtr(); 147 consumer->producer = producer.AsWeakPtr();
134 EXPECT_EQ(&producer, consumer->producer.get()); 148 EXPECT_EQ(&producer, consumer->producer.get());
135 } 149 }
136 150
137 } // namespace base 151 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698