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

Side by Side Diff: base/scoped_generic_unittest.cc

Issue 1479473002: base: Use std::move() instead of Pass() for real movable types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: basepass: missing-include Created 5 years 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/profiler/win32_stack_frame_unwinder_unittest.cc ('k') | base/sequence_checker_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/scoped_generic.h"
6
7 #include <utility>
5 #include <vector> 8 #include <vector>
6 9
7 #include "base/scoped_generic.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 namespace base { 12 namespace base {
11 13
12 namespace { 14 namespace {
13 15
14 struct IntTraits { 16 struct IntTraits {
15 IntTraits(std::vector<int>* freed) : freed_ints(freed) {} 17 IntTraits(std::vector<int>* freed) : freed_ints(freed) {}
16 18
17 static int InvalidValue() { 19 static int InvalidValue() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed. 80 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed.
79 EXPECT_EQ(kSecond, a.get()); 81 EXPECT_EQ(kSecond, a.get());
80 EXPECT_EQ(kFirst, b.get()); 82 EXPECT_EQ(kFirst, b.get());
81 } 83 }
82 // Values should be deleted in the opposite order. 84 // Values should be deleted in the opposite order.
83 ASSERT_EQ(2u, values_freed.size()); 85 ASSERT_EQ(2u, values_freed.size());
84 EXPECT_EQ(kFirst, values_freed[0]); 86 EXPECT_EQ(kFirst, values_freed[0]);
85 EXPECT_EQ(kSecond, values_freed[1]); 87 EXPECT_EQ(kSecond, values_freed[1]);
86 values_freed.clear(); 88 values_freed.clear();
87 89
88 // Pass constructor. 90 // Move constructor.
89 { 91 {
90 ScopedInt a(kFirst, traits); 92 ScopedInt a(kFirst, traits);
91 ScopedInt b(a.Pass()); 93 ScopedInt b(std::move(a));
92 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed. 94 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed.
93 ASSERT_EQ(IntTraits::InvalidValue(), a.get()); 95 ASSERT_EQ(IntTraits::InvalidValue(), a.get());
94 ASSERT_EQ(kFirst, b.get()); 96 ASSERT_EQ(kFirst, b.get());
95 } 97 }
96 98
97 ASSERT_EQ(1u, values_freed.size()); 99 ASSERT_EQ(1u, values_freed.size());
98 ASSERT_EQ(kFirst, values_freed[0]); 100 ASSERT_EQ(kFirst, values_freed[0]);
99 values_freed.clear(); 101 values_freed.clear();
100 102
101 // Pass assign. 103 // Move assign.
102 { 104 {
103 ScopedInt a(kFirst, traits); 105 ScopedInt a(kFirst, traits);
104 ScopedInt b(kSecond, traits); 106 ScopedInt b(kSecond, traits);
105 b = a.Pass(); 107 b = std::move(a);
106 ASSERT_EQ(1u, values_freed.size()); 108 ASSERT_EQ(1u, values_freed.size());
107 EXPECT_EQ(kSecond, values_freed[0]); 109 EXPECT_EQ(kSecond, values_freed[0]);
108 ASSERT_EQ(IntTraits::InvalidValue(), a.get()); 110 ASSERT_EQ(IntTraits::InvalidValue(), a.get());
109 ASSERT_EQ(kFirst, b.get()); 111 ASSERT_EQ(kFirst, b.get());
110 } 112 }
111 113
112 ASSERT_EQ(2u, values_freed.size()); 114 ASSERT_EQ(2u, values_freed.size());
113 EXPECT_EQ(kFirst, values_freed[1]); 115 EXPECT_EQ(kFirst, values_freed[1]);
114 values_freed.clear(); 116 values_freed.clear();
115 } 117 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 163
162 // Implicit conversion to bool shouldn't work. 164 // Implicit conversion to bool shouldn't work.
163 /*{ 165 /*{
164 ScopedInt a(kFirst, traits); 166 ScopedInt a(kFirst, traits);
165 bool result = a; 167 bool result = a;
166 }*/ 168 }*/
167 } 169 }
168 #endif 170 #endif
169 171
170 } // namespace base 172 } // namespace base
OLDNEW
« no previous file with comments | « base/profiler/win32_stack_frame_unwinder_unittest.cc ('k') | base/sequence_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698