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

Side by Side Diff: base/scoped_generic_unittest.cc

Issue 995093002: Add additional move support to ScopedGeneric in the form of operator=. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rvalue&& all the things Created 5 years, 9 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/scoped_generic.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 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 <vector> 5 #include <vector>
6 6
7 #include "base/scoped_generic.h" 7 #include "base/scoped_generic.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace base { 10 namespace base {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed. 78 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed.
79 EXPECT_EQ(kSecond, a.get()); 79 EXPECT_EQ(kSecond, a.get());
80 EXPECT_EQ(kFirst, b.get()); 80 EXPECT_EQ(kFirst, b.get());
81 } 81 }
82 // Values should be deleted in the opposite order. 82 // Values should be deleted in the opposite order.
83 ASSERT_EQ(2u, values_freed.size()); 83 ASSERT_EQ(2u, values_freed.size());
84 EXPECT_EQ(kFirst, values_freed[0]); 84 EXPECT_EQ(kFirst, values_freed[0]);
85 EXPECT_EQ(kSecond, values_freed[1]); 85 EXPECT_EQ(kSecond, values_freed[1]);
86 values_freed.clear(); 86 values_freed.clear();
87 87
88 // Pass. 88 // Pass constructor.
89 { 89 {
90 ScopedInt a(kFirst, traits); 90 ScopedInt a(kFirst, traits);
91 ScopedInt b(a.Pass()); 91 ScopedInt b(a.Pass());
92 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed. 92 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed.
93 ASSERT_EQ(IntTraits::InvalidValue(), a.get()); 93 ASSERT_EQ(IntTraits::InvalidValue(), a.get());
94 ASSERT_EQ(kFirst, b.get()); 94 ASSERT_EQ(kFirst, b.get());
95 } 95 }
96
96 ASSERT_EQ(1u, values_freed.size()); 97 ASSERT_EQ(1u, values_freed.size());
97 ASSERT_EQ(kFirst, values_freed[0]); 98 ASSERT_EQ(kFirst, values_freed[0]);
99 values_freed.clear();
100
101 // Pass assign.
102 {
103 ScopedInt a(kFirst, traits);
104 ScopedInt b(kSecond, traits);
105 b = a.Pass();
106 ASSERT_EQ(1u, values_freed.size());
107 EXPECT_EQ(kSecond, values_freed[0]);
108 ASSERT_EQ(IntTraits::InvalidValue(), a.get());
109 ASSERT_EQ(kFirst, b.get());
110 }
111
112 ASSERT_EQ(2u, values_freed.size());
113 EXPECT_EQ(kSecond, values_freed[0]);
danakj 2015/03/10 20:56:33 nit: you dont have to check [0] again
Robert Sesek 2015/03/10 21:00:40 Done.
114 EXPECT_EQ(kFirst, values_freed[1]);
115 values_freed.clear();
98 } 116 }
99 117
100 TEST(ScopedGenericTest, Operators) { 118 TEST(ScopedGenericTest, Operators) {
101 std::vector<int> values_freed; 119 std::vector<int> values_freed;
102 IntTraits traits(&values_freed); 120 IntTraits traits(&values_freed);
103 121
104 static const int kFirst = 0; 122 static const int kFirst = 0;
105 static const int kSecond = 1; 123 static const int kSecond = 1;
106 { 124 {
107 ScopedInt a(kFirst, traits); 125 ScopedInt a(kFirst, traits);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 162
145 // Implicit conversion to bool shouldn't work. 163 // Implicit conversion to bool shouldn't work.
146 /*{ 164 /*{
147 ScopedInt a(kFirst, traits); 165 ScopedInt a(kFirst, traits);
148 bool result = a; 166 bool result = a;
149 }*/ 167 }*/
150 } 168 }
151 #endif 169 #endif
152 170
153 } // namespace base 171 } // namespace base
OLDNEW
« no previous file with comments | « base/scoped_generic.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698