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

Side by Side Diff: base/values_unittest.cc

Issue 21030009: Make element removal methods in DictionaryValue and ListValue take scoped_ptr's as outparams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 4 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 | « base/values.cc ('k') | chrome/browser/chromeos/extensions/external_cache.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 <limits> 5 #include <limits>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ListValue list; 196 ListValue list;
197 list.Append(new DeletionTestValue(&deletion_flag)); 197 list.Append(new DeletionTestValue(&deletion_flag));
198 EXPECT_FALSE(deletion_flag); 198 EXPECT_FALSE(deletion_flag);
199 EXPECT_TRUE(list.Set(0, Value::CreateNullValue())); 199 EXPECT_TRUE(list.Set(0, Value::CreateNullValue()));
200 EXPECT_TRUE(deletion_flag); 200 EXPECT_TRUE(deletion_flag);
201 } 201 }
202 } 202 }
203 203
204 TEST(ValuesTest, ListRemoval) { 204 TEST(ValuesTest, ListRemoval) {
205 bool deletion_flag = true; 205 bool deletion_flag = true;
206 Value* removed_item = NULL; 206 scoped_ptr<Value> removed_item;
207 207
208 { 208 {
209 ListValue list; 209 ListValue list;
210 list.Append(new DeletionTestValue(&deletion_flag)); 210 list.Append(new DeletionTestValue(&deletion_flag));
211 EXPECT_FALSE(deletion_flag); 211 EXPECT_FALSE(deletion_flag);
212 EXPECT_EQ(1U, list.GetSize()); 212 EXPECT_EQ(1U, list.GetSize());
213 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(), 213 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(),
214 &removed_item)); 214 &removed_item));
215 EXPECT_FALSE(list.Remove(1, &removed_item)); 215 EXPECT_FALSE(list.Remove(1, &removed_item));
216 EXPECT_TRUE(list.Remove(0, &removed_item)); 216 EXPECT_TRUE(list.Remove(0, &removed_item));
217 ASSERT_TRUE(removed_item); 217 ASSERT_TRUE(removed_item);
218 EXPECT_EQ(0U, list.GetSize()); 218 EXPECT_EQ(0U, list.GetSize());
219 } 219 }
220 EXPECT_FALSE(deletion_flag); 220 EXPECT_FALSE(deletion_flag);
221 delete removed_item; 221 removed_item.reset();
222 removed_item = NULL;
223 EXPECT_TRUE(deletion_flag); 222 EXPECT_TRUE(deletion_flag);
224 223
225 { 224 {
226 ListValue list; 225 ListValue list;
227 list.Append(new DeletionTestValue(&deletion_flag)); 226 list.Append(new DeletionTestValue(&deletion_flag));
228 EXPECT_FALSE(deletion_flag); 227 EXPECT_FALSE(deletion_flag);
229 EXPECT_TRUE(list.Remove(0, NULL)); 228 EXPECT_TRUE(list.Remove(0, NULL));
230 EXPECT_TRUE(deletion_flag); 229 EXPECT_TRUE(deletion_flag);
231 EXPECT_EQ(0U, list.GetSize()); 230 EXPECT_EQ(0U, list.GetSize());
232 } 231 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 dict.Set(key, new DeletionTestValue(&deletion_flag)); 267 dict.Set(key, new DeletionTestValue(&deletion_flag));
269 EXPECT_FALSE(deletion_flag); 268 EXPECT_FALSE(deletion_flag);
270 dict.Set(key, Value::CreateNullValue()); 269 dict.Set(key, Value::CreateNullValue());
271 EXPECT_TRUE(deletion_flag); 270 EXPECT_TRUE(deletion_flag);
272 } 271 }
273 } 272 }
274 273
275 TEST(ValuesTest, DictionaryRemoval) { 274 TEST(ValuesTest, DictionaryRemoval) {
276 std::string key = "test"; 275 std::string key = "test";
277 bool deletion_flag = true; 276 bool deletion_flag = true;
278 Value* removed_item = NULL; 277 scoped_ptr<Value> removed_item;
279 278
280 { 279 {
281 DictionaryValue dict; 280 DictionaryValue dict;
282 dict.Set(key, new DeletionTestValue(&deletion_flag)); 281 dict.Set(key, new DeletionTestValue(&deletion_flag));
283 EXPECT_FALSE(deletion_flag); 282 EXPECT_FALSE(deletion_flag);
284 EXPECT_TRUE(dict.HasKey(key)); 283 EXPECT_TRUE(dict.HasKey(key));
285 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); 284 EXPECT_FALSE(dict.Remove("absent key", &removed_item));
286 EXPECT_TRUE(dict.Remove(key, &removed_item)); 285 EXPECT_TRUE(dict.Remove(key, &removed_item));
287 EXPECT_FALSE(dict.HasKey(key)); 286 EXPECT_FALSE(dict.HasKey(key));
288 ASSERT_TRUE(removed_item); 287 ASSERT_TRUE(removed_item);
289 } 288 }
290 EXPECT_FALSE(deletion_flag); 289 EXPECT_FALSE(deletion_flag);
291 delete removed_item; 290 removed_item.reset();
292 removed_item = NULL;
293 EXPECT_TRUE(deletion_flag); 291 EXPECT_TRUE(deletion_flag);
294 292
295 { 293 {
296 DictionaryValue dict; 294 DictionaryValue dict;
297 dict.Set(key, new DeletionTestValue(&deletion_flag)); 295 dict.Set(key, new DeletionTestValue(&deletion_flag));
298 EXPECT_FALSE(deletion_flag); 296 EXPECT_FALSE(deletion_flag);
299 EXPECT_TRUE(dict.HasKey(key)); 297 EXPECT_TRUE(dict.HasKey(key));
300 EXPECT_TRUE(dict.Remove(key, NULL)); 298 EXPECT_TRUE(dict.Remove(key, NULL));
301 EXPECT_TRUE(deletion_flag); 299 EXPECT_TRUE(deletion_flag);
302 EXPECT_FALSE(dict.HasKey(key)); 300 EXPECT_FALSE(dict.HasKey(key));
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 seen2 = true; 767 seen2 = true;
770 } else { 768 } else {
771 ADD_FAILURE(); 769 ADD_FAILURE();
772 } 770 }
773 } 771 }
774 EXPECT_TRUE(seen1); 772 EXPECT_TRUE(seen1);
775 EXPECT_TRUE(seen2); 773 EXPECT_TRUE(seen2);
776 } 774 }
777 775
778 } // namespace base 776 } // namespace base
OLDNEW
« no previous file with comments | « base/values.cc ('k') | chrome/browser/chromeos/extensions/external_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698