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

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

Issue 10797017: base: Make ScopedVector::clear() destroy elements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-add updated clear method and write a test for weak_clear Created 8 years, 5 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
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/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 TEST(ScopedVectorTest, LifeCycleWatcher) { 101 TEST(ScopedVectorTest, LifeCycleWatcher) {
102 LifeCycleWatcher watcher; 102 LifeCycleWatcher watcher;
103 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); 103 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state());
104 LifeCycleObject* object = watcher.NewLifeCycleObject(); 104 LifeCycleObject* object = watcher.NewLifeCycleObject();
105 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); 105 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state());
106 delete object; 106 delete object;
107 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); 107 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state());
108 } 108 }
109 109
110 TEST(ScopedVectorTest, Reset) { 110 TEST(ScopedVectorTest, Clear) {
111 LifeCycleWatcher watcher; 111 LifeCycleWatcher watcher;
112 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); 112 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state());
113 ScopedVector<LifeCycleObject> scoped_vector; 113 ScopedVector<LifeCycleObject> scoped_vector;
114 scoped_vector.push_back(watcher.NewLifeCycleObject()); 114 scoped_vector.push_back(watcher.NewLifeCycleObject());
115 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); 115 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state());
116 scoped_vector.reset(); 116 scoped_vector.clear();
117 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); 117 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state());
118 EXPECT_EQ(static_cast<size_t>(0), scoped_vector.size());
119 }
120
121 TEST(ScopedVectorTest, WeakClear) {
122 LifeCycleWatcher watcher;
123 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state());
124 ScopedVector<LifeCycleObject> scoped_vector;
125 scoped_ptr<LifeCycleObject> object(watcher.NewLifeCycleObject());
126 scoped_vector.push_back(object.get());
127 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state());
128 scoped_vector.weak_clear();
129 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state());
130 EXPECT_EQ(static_cast<size_t>(0), scoped_vector.size());
118 } 131 }
119 132
120 TEST(ScopedVectorTest, Scope) { 133 TEST(ScopedVectorTest, Scope) {
121 LifeCycleWatcher watcher; 134 LifeCycleWatcher watcher;
122 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); 135 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state());
123 { 136 {
124 ScopedVector<LifeCycleObject> scoped_vector; 137 ScopedVector<LifeCycleObject> scoped_vector;
125 scoped_vector.push_back(watcher.NewLifeCycleObject()); 138 scoped_vector.push_back(watcher.NewLifeCycleObject());
126 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); 139 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state());
127 } 140 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 for(LifeCycleWatcher* it = watchers; it != watchers + 1; ++it) 234 for(LifeCycleWatcher* it = watchers; it != watchers + 1; ++it)
222 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); 235 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state());
223 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it) 236 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it)
224 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state()); 237 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state());
225 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers); 238 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers);
226 ++it) 239 ++it)
227 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); 240 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state());
228 } 241 }
229 242
230 } // namespace 243 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698