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

Side by Side Diff: base/values_unittest.cc

Issue 3163020: Fix DictionaryValue::Equals() to also detect differences in key names. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: fix test expectations Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 delete boolean; 478 delete boolean;
479 479
480 DictionaryValue dv; 480 DictionaryValue dv;
481 dv.SetBoolean("a", false); 481 dv.SetBoolean("a", false);
482 dv.SetInteger("b", 2); 482 dv.SetInteger("b", 2);
483 dv.SetReal("c", 2.5); 483 dv.SetReal("c", 2.5);
484 dv.SetString("d1", "string"); 484 dv.SetString("d1", "string");
485 dv.SetString("d2", ASCIIToUTF16("http://google.com")); 485 dv.SetString("d2", ASCIIToUTF16("http://google.com"));
486 dv.Set("e", Value::CreateNullValue()); 486 dv.Set("e", Value::CreateNullValue());
487 487
488 DictionaryValue* copy = static_cast<DictionaryValue*>(dv.DeepCopy()); 488 scoped_ptr<DictionaryValue> copy;
489 EXPECT_TRUE(dv.Equals(copy)); 489 copy.reset(static_cast<DictionaryValue*>(dv.DeepCopy()));
490 EXPECT_TRUE(dv.Equals(copy.get()));
490 491
491 ListValue* list = new ListValue; 492 ListValue* list = new ListValue;
492 list->Append(Value::CreateNullValue()); 493 list->Append(Value::CreateNullValue());
493 list->Append(new DictionaryValue); 494 list->Append(new DictionaryValue);
494 dv.Set("f", list); 495 dv.Set("f", list);
495 496
496 EXPECT_FALSE(dv.Equals(copy)); 497 EXPECT_FALSE(dv.Equals(copy.get()));
497 copy->Set("f", list->DeepCopy()); 498 copy->Set("f", list->DeepCopy());
498 EXPECT_TRUE(dv.Equals(copy)); 499 EXPECT_TRUE(dv.Equals(copy.get()));
499 500
500 list->Append(Value::CreateBooleanValue(true)); 501 list->Append(Value::CreateBooleanValue(true));
501 EXPECT_FALSE(dv.Equals(copy)); 502 EXPECT_FALSE(dv.Equals(copy.get()));
502 delete copy; 503
504 // Check if Equals detects differences in only the keys.
505 copy.reset(static_cast<DictionaryValue*>(dv.DeepCopy()));
506 EXPECT_TRUE(dv.Equals(copy.get()));
507 copy->Remove("a", NULL);
508 copy->SetBoolean("aa", false);
509 EXPECT_FALSE(dv.Equals(copy.get()));
503 } 510 }
504 511
505 TEST_F(ValuesTest, RemoveEmptyChildren) { 512 TEST_F(ValuesTest, RemoveEmptyChildren) {
506 scoped_ptr<DictionaryValue> root(new DictionaryValue); 513 scoped_ptr<DictionaryValue> root(new DictionaryValue);
507 // Remove empty lists and dictionaries. 514 // Remove empty lists and dictionaries.
508 root->Set("empty_dict", new DictionaryValue); 515 root->Set("empty_dict", new DictionaryValue);
509 root->Set("empty_list", new ListValue); 516 root->Set("empty_list", new ListValue);
510 root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue); 517 root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue);
511 root.reset(root->DeepCopyWithoutEmptyChildren()); 518 root.reset(root->DeepCopyWithoutEmptyChildren());
512 EXPECT_TRUE(root->empty()); 519 EXPECT_TRUE(root->empty());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 "s1", 732 "s1",
726 "s1.s2" 733 "s1.s2"
727 }; 734 };
728 dict1.reset(new DictionaryValue()); 735 dict1.reset(new DictionaryValue());
729 dict1->Set("s1.s2", new DictionaryValue()); 736 dict1->Set("s1.s2", new DictionaryValue());
730 dict2.reset(new DictionaryValue()); 737 dict2.reset(new DictionaryValue());
731 dict2->SetInteger("s1", 1); 738 dict2->SetInteger("s1", 1);
732 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths8, 739 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths8,
733 arraysize(expected_paths8)); 740 arraysize(expected_paths8));
734 } 741 }
OLDNEW
« no previous file with comments | « base/values.cc ('k') | chrome/test/data/extensions/ui/create_extension_detail_value_expected_output/good-extension1.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698