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

Side by Side Diff: base/values_unittest.cc

Issue 1129083003: More base::Values-related bare pointer -> scoped_ptr conversions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bad merge Created 5 years, 7 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/values.cc ('k') | cc/debug/invalidation_benchmark.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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EXPECT_FALSE(deletion_flag); 313 EXPECT_FALSE(deletion_flag);
314 EXPECT_TRUE(dict.HasKey(key)); 314 EXPECT_TRUE(dict.HasKey(key));
315 EXPECT_TRUE(dict.Remove(key, NULL)); 315 EXPECT_TRUE(dict.Remove(key, NULL));
316 EXPECT_TRUE(deletion_flag); 316 EXPECT_TRUE(deletion_flag);
317 EXPECT_FALSE(dict.HasKey(key)); 317 EXPECT_FALSE(dict.HasKey(key));
318 } 318 }
319 } 319 }
320 320
321 TEST(ValuesTest, DictionaryWithoutPathExpansion) { 321 TEST(ValuesTest, DictionaryWithoutPathExpansion) {
322 DictionaryValue dict; 322 DictionaryValue dict;
323 dict.Set("this.is.expanded", make_scoped_ptr(Value::CreateNullValue())); 323 dict.Set("this.is.expanded", Value::CreateNullValue());
324 dict.SetWithoutPathExpansion("this.isnt.expanded", 324 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
325 make_scoped_ptr(Value::CreateNullValue()));
326 325
327 EXPECT_FALSE(dict.HasKey("this.is.expanded")); 326 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
328 EXPECT_TRUE(dict.HasKey("this")); 327 EXPECT_TRUE(dict.HasKey("this"));
329 Value* value1; 328 Value* value1;
330 EXPECT_TRUE(dict.Get("this", &value1)); 329 EXPECT_TRUE(dict.Get("this", &value1));
331 DictionaryValue* value2; 330 DictionaryValue* value2;
332 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2)); 331 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
333 EXPECT_EQ(value1, value2); 332 EXPECT_EQ(value1, value2);
334 EXPECT_EQ(1U, value2->size()); 333 EXPECT_EQ(1U, value2->size());
335 334
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 384
386 removed_item.reset(); 385 removed_item.reset();
387 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item)); 386 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item));
388 ASSERT_TRUE(removed_item); 387 ASSERT_TRUE(removed_item);
389 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN)); 388 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN));
390 EXPECT_TRUE(dict.empty()); 389 EXPECT_TRUE(dict.empty());
391 } 390 }
392 391
393 TEST(ValuesTest, DeepCopy) { 392 TEST(ValuesTest, DeepCopy) {
394 DictionaryValue original_dict; 393 DictionaryValue original_dict;
395 scoped_ptr<Value> scoped_null(Value::CreateNullValue()); 394 scoped_ptr<Value> scoped_null = Value::CreateNullValue();
396 Value* original_null = scoped_null.get(); 395 Value* original_null = scoped_null.get();
397 original_dict.Set("null", scoped_null.Pass()); 396 original_dict.Set("null", scoped_null.Pass());
398 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); 397 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true));
399 FundamentalValue* original_bool = scoped_bool.get(); 398 FundamentalValue* original_bool = scoped_bool.get();
400 original_dict.Set("bool", scoped_bool.Pass()); 399 original_dict.Set("bool", scoped_bool.Pass());
401 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); 400 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42));
402 FundamentalValue* original_int = scoped_int.get(); 401 FundamentalValue* original_int = scoped_int.get();
403 original_dict.Set("int", scoped_int.Pass()); 402 original_dict.Set("int", scoped_int.Pass());
404 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); 403 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14));
405 FundamentalValue* original_double = scoped_double.get(); 404 FundamentalValue* original_double = scoped_double.get();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 ASSERT_TRUE(copy_nested_dictionary); 541 ASSERT_TRUE(copy_nested_dictionary);
543 EXPECT_TRUE(copy_nested_dictionary->HasKey("key")); 542 EXPECT_TRUE(copy_nested_dictionary->HasKey("key"));
544 } 543 }
545 544
546 TEST(ValuesTest, Equals) { 545 TEST(ValuesTest, Equals) {
547 scoped_ptr<Value> null1(Value::CreateNullValue()); 546 scoped_ptr<Value> null1(Value::CreateNullValue());
548 scoped_ptr<Value> null2(Value::CreateNullValue()); 547 scoped_ptr<Value> null2(Value::CreateNullValue());
549 EXPECT_NE(null1.get(), null2.get()); 548 EXPECT_NE(null1.get(), null2.get());
550 EXPECT_TRUE(null1->Equals(null2.get())); 549 EXPECT_TRUE(null1->Equals(null2.get()));
551 550
552 scoped_ptr<Value> boolean(new FundamentalValue(false)); 551 FundamentalValue boolean(false);
553 EXPECT_FALSE(null1->Equals(boolean.get())); 552 EXPECT_FALSE(null1->Equals(&boolean));
554 553
555 DictionaryValue dv; 554 DictionaryValue dv;
556 dv.SetBoolean("a", false); 555 dv.SetBoolean("a", false);
557 dv.SetInteger("b", 2); 556 dv.SetInteger("b", 2);
558 dv.SetDouble("c", 2.5); 557 dv.SetDouble("c", 2.5);
559 dv.SetString("d1", "string"); 558 dv.SetString("d1", "string");
560 dv.SetString("d2", ASCIIToUTF16("http://google.com")); 559 dv.SetString("d2", ASCIIToUTF16("http://google.com"));
561 dv.Set("e", make_scoped_ptr(Value::CreateNullValue())); 560 dv.Set("e", Value::CreateNullValue());
562 561
563 scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy(); 562 scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy();
564 EXPECT_TRUE(dv.Equals(copy.get())); 563 EXPECT_TRUE(dv.Equals(copy.get()));
565 564
566 scoped_ptr<ListValue> list(new ListValue); 565 scoped_ptr<ListValue> list(new ListValue);
567 ListValue* original_list = list.get(); 566 ListValue* original_list = list.get();
568 list->Append(make_scoped_ptr(Value::CreateNullValue())); 567 list->Append(Value::CreateNullValue());
569 list->Append(make_scoped_ptr(new DictionaryValue)); 568 list->Append(make_scoped_ptr(new DictionaryValue));
570 scoped_ptr<Value> list_copy(list->CreateDeepCopy()); 569 scoped_ptr<Value> list_copy(list->CreateDeepCopy());
571 570
572 dv.Set("f", list.Pass()); 571 dv.Set("f", list.Pass());
573 EXPECT_FALSE(dv.Equals(copy.get())); 572 EXPECT_FALSE(dv.Equals(copy.get()));
574 copy->Set("f", list_copy.Pass()); 573 copy->Set("f", list_copy.Pass());
575 EXPECT_TRUE(dv.Equals(copy.get())); 574 EXPECT_TRUE(dv.Equals(copy.get()));
576 575
577 original_list->Append(make_scoped_ptr(new FundamentalValue(true))); 576 original_list->Append(make_scoped_ptr(new FundamentalValue(true)));
578 EXPECT_FALSE(dv.Equals(copy.get())); 577 EXPECT_FALSE(dv.Equals(copy.get()));
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 EXPECT_FALSE(main_list.GetList(1, NULL)); 1136 EXPECT_FALSE(main_list.GetList(1, NULL));
1138 EXPECT_FALSE(main_list.GetList(2, NULL)); 1137 EXPECT_FALSE(main_list.GetList(2, NULL));
1139 EXPECT_FALSE(main_list.GetList(3, NULL)); 1138 EXPECT_FALSE(main_list.GetList(3, NULL));
1140 EXPECT_FALSE(main_list.GetList(4, NULL)); 1139 EXPECT_FALSE(main_list.GetList(4, NULL));
1141 EXPECT_FALSE(main_list.GetList(5, NULL)); 1140 EXPECT_FALSE(main_list.GetList(5, NULL));
1142 EXPECT_TRUE(main_list.GetList(6, NULL)); 1141 EXPECT_TRUE(main_list.GetList(6, NULL));
1143 EXPECT_FALSE(main_list.GetList(7, NULL)); 1142 EXPECT_FALSE(main_list.GetList(7, NULL));
1144 } 1143 }
1145 1144
1146 } // namespace base 1145 } // namespace base
OLDNEW
« no previous file with comments | « base/values.cc ('k') | cc/debug/invalidation_benchmark.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698