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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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/scoped_vector.h ('k') | base/memory/shared_memory_mac_unittest.cc » ('j') | 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/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace { 15 namespace {
16 16
17 // The LifeCycleObject notifies its Observer upon construction & destruction. 17 // The LifeCycleObject notifies its Observer upon construction & destruction.
18 class LifeCycleObject { 18 class LifeCycleObject {
19 public: 19 public:
20 class Observer { 20 class Observer {
21 public: 21 public:
22 virtual void OnLifeCycleConstruct(LifeCycleObject* o) = 0; 22 virtual void OnLifeCycleConstruct(LifeCycleObject* o) = 0;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return new LifeCycleObject(this); 105 return new LifeCycleObject(this);
106 } 106 }
107 107
108 // Returns true iff |object| is the same object that this watcher is tracking. 108 // Returns true iff |object| is the same object that this watcher is tracking.
109 bool IsWatching(LifeCycleObject* object) const { 109 bool IsWatching(LifeCycleObject* object) const {
110 return object == constructed_life_cycle_object_.get(); 110 return object == constructed_life_cycle_object_.get();
111 } 111 }
112 112
113 private: 113 private:
114 LifeCycleState life_cycle_state_; 114 LifeCycleState life_cycle_state_;
115 scoped_ptr<LifeCycleObject> constructed_life_cycle_object_; 115 std::unique_ptr<LifeCycleObject> constructed_life_cycle_object_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(LifeCycleWatcher); 117 DISALLOW_COPY_AND_ASSIGN(LifeCycleWatcher);
118 }; 118 };
119 119
120 TEST(ScopedVectorTest, LifeCycleWatcher) { 120 TEST(ScopedVectorTest, LifeCycleWatcher) {
121 LifeCycleWatcher watcher; 121 LifeCycleWatcher watcher;
122 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); 122 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state());
123 LifeCycleObject* object = watcher.NewLifeCycleObject(); 123 LifeCycleObject* object = watcher.NewLifeCycleObject();
124 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); 124 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state());
125 delete object; 125 delete object;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it) 318 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it)
319 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state()); 319 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state());
320 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers); 320 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers);
321 ++it) 321 ++it)
322 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); 322 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state());
323 } 323 }
324 324
325 // Assertions for push_back(scoped_ptr). 325 // Assertions for push_back(scoped_ptr).
326 TEST(ScopedVectorTest, PushBackScopedPtr) { 326 TEST(ScopedVectorTest, PushBackScopedPtr) {
327 int delete_counter = 0; 327 int delete_counter = 0;
328 scoped_ptr<DeleteCounter> elem(new DeleteCounter(&delete_counter)); 328 std::unique_ptr<DeleteCounter> elem(new DeleteCounter(&delete_counter));
329 EXPECT_EQ(0, delete_counter); 329 EXPECT_EQ(0, delete_counter);
330 { 330 {
331 ScopedVector<DeleteCounter> v; 331 ScopedVector<DeleteCounter> v;
332 v.push_back(std::move(elem)); 332 v.push_back(std::move(elem));
333 EXPECT_EQ(0, delete_counter); 333 EXPECT_EQ(0, delete_counter);
334 } 334 }
335 EXPECT_EQ(1, delete_counter); 335 EXPECT_EQ(1, delete_counter);
336 } 336 }
337 337
338 } // namespace 338 } // namespace
OLDNEW
« no previous file with comments | « base/memory/scoped_vector.h ('k') | base/memory/shared_memory_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698