diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-16 07:13:53 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-16 07:13:53 +0000 |
commit | dc9a67601b9d8c952bf399f0309519273f82bfd5 (patch) | |
tree | b618c9da1cef3fa99718897cf523cb8768d4a273 /base | |
parent | a6dbaac4225f2fa5a170bdc657ab306390fdc439 (diff) | |
download | chromium_src-dc9a67601b9d8c952bf399f0309519273f82bfd5.zip chromium_src-dc9a67601b9d8c952bf399f0309519273f82bfd5.tar.gz chromium_src-dc9a67601b9d8c952bf399f0309519273f82bfd5.tar.bz2 |
Remove deprecated wstring Get(As)String() methods from Value, etc.
BUG=23581
TEST=builds and passes tests
Review URL: http://codereview.chromium.org/3117017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/json/json_reader_unittest.cc | 20 | ||||
-rw-r--r-- | base/values.cc | 43 | ||||
-rw-r--r-- | base/values.h | 13 | ||||
-rw-r--r-- | base/values_unittest.cc | 434 |
4 files changed, 11 insertions, 499 deletions
diff --git a/base/json/json_reader_unittest.cc b/base/json/json_reader_unittest.cc index c05fcda..c00c976 100644 --- a/base/json/json_reader_unittest.cc +++ b/base/json/json_reader_unittest.cc @@ -1,10 +1,12 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "testing/gtest/include/gtest/gtest.h" #include "base/json/json_reader.h" #include "base/scoped_ptr.h" +#include "base/string_piece.h" +#include "base/utf_string_conversions.h" #include "base/values.h" #include "build/build_config.h" @@ -168,9 +170,9 @@ TEST(JSONReaderTest, Reading) { root.reset(JSONReader().JsonToValue("\"hello world\"", false, false)); ASSERT_TRUE(root.get()); ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); - std::wstring str_val; + std::string str_val; ASSERT_TRUE(root->GetAsString(&str_val)); - ASSERT_EQ(L"hello world", str_val); + ASSERT_EQ("hello world", str_val); // Empty string root.reset(JSONReader().JsonToValue("\"\"", false, false)); @@ -178,7 +180,7 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); str_val.clear(); ASSERT_TRUE(root->GetAsString(&str_val)); - ASSERT_EQ(L"", str_val); + ASSERT_EQ("", str_val); // Test basic string escapes root.reset(JSONReader().JsonToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\"", @@ -187,7 +189,7 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); str_val.clear(); ASSERT_TRUE(root->GetAsString(&str_val)); - ASSERT_EQ(L" \"\\/\b\f\n\r\t\v", str_val); + ASSERT_EQ(" \"\\/\b\f\n\r\t\v", str_val); // Test hex and unicode escapes including the null character. root.reset(JSONReader().JsonToValue("\"\\x41\\x00\\u1234\"", false, @@ -196,7 +198,7 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); str_val.clear(); ASSERT_TRUE(root->GetAsString(&str_val)); - ASSERT_EQ(std::wstring(L"A\0\x1234", 3), str_val); + ASSERT_EQ(std::wstring(L"A\0\x1234", 3), UTF8ToWide(str_val)); // Test invalid strings root.reset(JSONReader().JsonToValue("\"no closing quote", false, false)); @@ -308,8 +310,8 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(dict_val->Get("null", &null_val)); ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL)); str_val.clear(); - ASSERT_TRUE(dict_val->GetString(L"S", &str_val)); - ASSERT_EQ(L"str", str_val); + ASSERT_TRUE(dict_val->GetString("S", &str_val)); + ASSERT_EQ("str", str_val); root2.reset(JSONReader::Read( "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true)); @@ -444,7 +446,7 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); str_val.clear(); ASSERT_TRUE(root->GetAsString(&str_val)); - ASSERT_EQ(L"\x7f51\x9875", str_val); + ASSERT_EQ(L"\x7f51\x9875", UTF8ToWide(str_val)); // Test invalid utf8 encoded input root.reset(JSONReader().JsonToValue("\"345\xb0\xa1\xb0\xa2\"", diff --git a/base/values.cc b/base/values.cc index 7e348dc..cd2738b 100644 --- a/base/values.cc +++ b/base/values.cc @@ -119,13 +119,6 @@ bool Value::GetAsString(string16* out_value) const { return false; } -#if !defined(WCHAR_T_IS_UTF16) -// TODO(viettrungluu): Deprecated and to be removed: -bool Value::GetAsString(std::wstring* out_value) const { - return false; -} -#endif - Value* Value::DeepCopy() const { // This method should only be getting called for null Values--all subclasses // need to provide their own implementation;. @@ -254,15 +247,6 @@ bool StringValue::GetAsString(string16* out_value) const { return true; } -#if !defined(WCHAR_T_IS_UTF16) -// TODO(viettrungluu): Deprecated and to be removed: -bool StringValue::GetAsString(std::wstring* out_value) const { - if (out_value) - *out_value = UTF8ToWide(value_); - return true; -} -#endif - Value* StringValue::DeepCopy() const { return CreateStringValue(value_); } @@ -631,22 +615,6 @@ bool DictionaryValue::GetReal(const std::wstring& path, } // TODO(viettrungluu): Deprecated and to be removed: -bool DictionaryValue::GetString(const std::wstring& path, - std::string* out_value) const { - return GetString(WideToUTF8(path), out_value); -} - -// TODO(viettrungluu): Deprecated and to be removed: -bool DictionaryValue::GetString(const std::wstring& path, - std::wstring* out_value) const { - Value* value; - if (!Get(WideToUTF8(path), &value)) - return false; - - return value->GetAsString(out_value); -} - -// TODO(viettrungluu): Deprecated and to be removed: bool DictionaryValue::GetBinary(const std::wstring& path, BinaryValue** out_value) const { return GetBinary(WideToUTF8(path), out_value); @@ -985,17 +953,6 @@ bool ListValue::GetString(size_t index, string16* out_value) const { return value->GetAsString(out_value); } -#if !defined(WCHAR_T_IS_UTF16) -// TODO(viettrungluu): Deprecated and to be removed: -bool ListValue::GetString(size_t index, std::wstring* out_value) const { - Value* value; - if (!Get(index, &value)) - return false; - - return value->GetAsString(out_value); -} -#endif - bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { Value* value; bool result = Get(index, &value); diff --git a/base/values.h b/base/values.h index 01a2cf4..7f607fd 100644 --- a/base/values.h +++ b/base/values.h @@ -92,9 +92,6 @@ class Value { virtual bool GetAsReal(double* out_value) const; virtual bool GetAsString(std::string* out_value) const; virtual bool GetAsString(string16* out_value) const; -#if !defined(WCHAR_T_IS_UTF16) - /*DEPRECATED*/virtual bool GetAsString(std::wstring* out_value) const; -#endif // This creates a deep copy of the entire Value tree, and returns a pointer // to the copy. The caller gets ownership of the copy, of course. @@ -159,9 +156,6 @@ class StringValue : public Value { // Subclassed methods bool GetAsString(std::string* out_value) const; bool GetAsString(string16* out_value) const; -#if !defined(WCHAR_T_IS_UTF16) - /*DEPRECATED*/bool GetAsString(std::wstring* out_value) const; -#endif Value* DeepCopy() const; virtual bool Equals(const Value* other) const; @@ -293,10 +287,6 @@ class DictionaryValue : public Value { bool* out_value) const; /*DEPRECATED*/bool GetInteger(const std::wstring& path, int* out_value) const; /*DEPRECATED*/bool GetReal(const std::wstring& path, double* out_value) const; - /*DEPRECATED*/bool GetString(const std::wstring& path, - std::string* out_value) const; - /*DEPRECATED*/bool GetString(const std::wstring& path, - std::wstring* out_value) const; /*DEPRECATED*/bool GetBinary(const std::wstring& path, BinaryValue** out_value) const; /*DEPRECATED*/bool GetDictionary(const std::wstring& path, @@ -433,9 +423,6 @@ class ListValue : public Value { bool GetReal(size_t index, double* out_value) const; bool GetString(size_t index, std::string* out_value) const; bool GetString(size_t index, string16* out_value) const; -#if !defined(WCHAR_T_IS_UTF16) - /*DEPRECATED*/bool GetString(size_t index, std::wstring* out_value) const; -#endif bool GetBinary(size_t index, BinaryValue** out_value) const; bool GetDictionary(size_t index, DictionaryValue** out_value) const; bool GetList(size_t index, ListValue** out_value) const; diff --git a/base/values_unittest.cc b/base/values_unittest.cc index 3b78b5f..4b4016c 100644 --- a/base/values_unittest.cc +++ b/base/values_unittest.cc @@ -34,12 +34,6 @@ class ValuesTest: public testing::Test { } }; -// TODO(viettrungluu): I changed the keys for DictionaryValue from std::wstring -// to std::string. I've temporarily kept the old methods taking std::wstring for -// compatibility. The ...Deprecated tests are the old tests which use these -// methods, and remain to test compatibility. They will be removed once the old -// methods are removed. - TEST_F(ValuesTest, Basic) { // Test basic dictionary getting/setting DictionaryValue settings; @@ -83,52 +77,6 @@ TEST_F(ValuesTest, Basic) { ASSERT_EQ(std::string("http://froogle.com"), bookmark_url); } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, BasicDeprecated) { - // Test basic dictionary getting/setting - DictionaryValue settings; - std::wstring homepage = L"http://google.com"; - ASSERT_FALSE( - settings.GetString(L"global.homepage", &homepage)); - ASSERT_EQ(std::wstring(L"http://google.com"), homepage); - - ASSERT_FALSE(settings.Get(L"global", NULL)); - settings.Set(L"global", Value::CreateBooleanValue(true)); - ASSERT_TRUE(settings.Get(L"global", NULL)); - settings.SetString(L"global.homepage", L"http://scurvy.com"); - ASSERT_TRUE(settings.Get(L"global", NULL)); - homepage = L"http://google.com"; - ASSERT_TRUE(settings.GetString(L"global.homepage", &homepage)); - ASSERT_EQ(std::wstring(L"http://scurvy.com"), homepage); - - // Test storing a dictionary in a list. - ListValue* toolbar_bookmarks; - ASSERT_FALSE( - settings.GetList(L"global.toolbar.bookmarks", &toolbar_bookmarks)); - - toolbar_bookmarks = new ListValue; - settings.Set(L"global.toolbar.bookmarks", toolbar_bookmarks); - ASSERT_TRUE( - settings.GetList(L"global.toolbar.bookmarks", &toolbar_bookmarks)); - - DictionaryValue* new_bookmark = new DictionaryValue; - new_bookmark->SetString(L"name", L"Froogle"); - new_bookmark->SetString(L"url", L"http://froogle.com"); - toolbar_bookmarks->Append(new_bookmark); - - ListValue* bookmark_list; - ASSERT_TRUE(settings.GetList(L"global.toolbar.bookmarks", &bookmark_list)); - DictionaryValue* bookmark; - ASSERT_EQ(1U, bookmark_list->GetSize()); - ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); - std::wstring bookmark_name = L"Unnamed"; - ASSERT_TRUE(bookmark->GetString(L"name", &bookmark_name)); - ASSERT_EQ(std::wstring(L"Froogle"), bookmark_name); - std::wstring bookmark_url; - ASSERT_TRUE(bookmark->GetString(L"url", &bookmark_url)); - ASSERT_EQ(std::wstring(L"http://froogle.com"), bookmark_url); -} - TEST_F(ValuesTest, List) { scoped_ptr<ListValue> mixed_list(new ListValue()); mixed_list->Set(0, Value::CreateBooleanValue(true)); @@ -221,36 +169,6 @@ TEST_F(ValuesTest, StringValue) { ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, StringValueDeprecated) { - // Test overloaded CreateStringValue. - scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow")); - ASSERT_TRUE(narrow_value.get()); - ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); - scoped_ptr<Value> utf16_value( - Value::CreateStringValue(ASCIIToUTF16("utf16"))); - ASSERT_TRUE(utf16_value.get()); - ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); - - // Test overloaded GetString. - std::string narrow = "http://google.com"; - std::wstring wide = L"http://google.com"; - string16 utf16 = ASCIIToUTF16("http://google.com"); - ASSERT_TRUE(narrow_value->GetAsString(&narrow)); - ASSERT_TRUE(narrow_value->GetAsString(&wide)); - ASSERT_TRUE(narrow_value->GetAsString(&utf16)); - ASSERT_EQ(std::string("narrow"), narrow); - ASSERT_EQ(std::wstring(L"narrow"), wide); - ASSERT_EQ(ASCIIToUTF16("narrow"), utf16); - - ASSERT_TRUE(utf16_value->GetAsString(&narrow)); - ASSERT_TRUE(utf16_value->GetAsString(&wide)); - ASSERT_TRUE(utf16_value->GetAsString(&utf16)); - ASSERT_EQ(std::string("utf16"), narrow); - ASSERT_EQ(std::wstring(L"utf16"), wide); - ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); -} - // This is a Value object that allows us to tell if it's been // properly deleted by modifying the value of external flag on destruction. class DeletionTestValue : public Value { @@ -369,35 +287,6 @@ TEST_F(ValuesTest, DictionaryDeletion) { } } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, DictionaryDeletionDeprecated) { - std::wstring key = L"test"; - bool deletion_flag = true; - - { - DictionaryValue dict; - dict.Set(key, new DeletionTestValue(&deletion_flag)); - EXPECT_FALSE(deletion_flag); - } - EXPECT_TRUE(deletion_flag); - - { - DictionaryValue dict; - dict.Set(key, new DeletionTestValue(&deletion_flag)); - EXPECT_FALSE(deletion_flag); - dict.Clear(); - EXPECT_TRUE(deletion_flag); - } - - { - DictionaryValue dict; - dict.Set(key, new DeletionTestValue(&deletion_flag)); - EXPECT_FALSE(deletion_flag); - dict.Set(key, Value::CreateNullValue()); - EXPECT_TRUE(deletion_flag); - } -} - TEST_F(ValuesTest, DictionaryRemoval) { std::string key = "test"; bool deletion_flag = true; @@ -429,38 +318,6 @@ TEST_F(ValuesTest, DictionaryRemoval) { } } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, DictionaryRemovalDeprecated) { - std::wstring key = L"test"; - bool deletion_flag = true; - Value* removed_item = NULL; - - { - DictionaryValue dict; - dict.Set(key, new DeletionTestValue(&deletion_flag)); - EXPECT_FALSE(deletion_flag); - EXPECT_TRUE(dict.HasKey(key)); - EXPECT_FALSE(dict.Remove(L"absent key", &removed_item)); - EXPECT_TRUE(dict.Remove(key, &removed_item)); - EXPECT_FALSE(dict.HasKey(key)); - ASSERT_TRUE(removed_item); - } - EXPECT_FALSE(deletion_flag); - delete removed_item; - removed_item = NULL; - EXPECT_TRUE(deletion_flag); - - { - DictionaryValue dict; - dict.Set(key, new DeletionTestValue(&deletion_flag)); - EXPECT_FALSE(deletion_flag); - EXPECT_TRUE(dict.HasKey(key)); - EXPECT_TRUE(dict.Remove(key, NULL)); - EXPECT_TRUE(deletion_flag); - EXPECT_FALSE(dict.HasKey(key)); - } -} - TEST_F(ValuesTest, DictionaryWithoutPathExpansion) { DictionaryValue dict; dict.Set("this.is.expanded", Value::CreateNullValue()); @@ -608,137 +465,6 @@ TEST_F(ValuesTest, DeepCopy) { ASSERT_EQ(1, copy_list_element_1_value); } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, DeepCopyDeprecated) { - DictionaryValue original_dict; - Value* original_null = Value::CreateNullValue(); - original_dict.Set(L"null", original_null); - Value* original_bool = Value::CreateBooleanValue(true); - original_dict.Set(L"bool", original_bool); - Value* original_int = Value::CreateIntegerValue(42); - original_dict.Set(L"int", original_int); - Value* original_real = Value::CreateRealValue(3.14); - original_dict.Set(L"real", original_real); - Value* original_string = Value::CreateStringValue("hello"); - original_dict.Set(L"string", original_string); - Value* original_utf16 = Value::CreateStringValue(ASCIIToUTF16("hello16")); - original_dict.Set(L"utf16", original_utf16); - - char* original_buffer = new char[42]; - memset(original_buffer, '!', 42); - BinaryValue* original_binary = Value::CreateBinaryValue(original_buffer, 42); - original_dict.Set(L"binary", original_binary); - - ListValue* original_list = new ListValue(); - Value* original_list_element_0 = Value::CreateIntegerValue(0); - original_list->Append(original_list_element_0); - Value* original_list_element_1 = Value::CreateIntegerValue(1); - original_list->Append(original_list_element_1); - original_dict.Set(L"list", original_list); - - scoped_ptr<DictionaryValue> copy_dict( - static_cast<DictionaryValue*>(original_dict.DeepCopy())); - ASSERT_TRUE(copy_dict.get()); - ASSERT_NE(copy_dict.get(), &original_dict); - - Value* copy_null = NULL; - ASSERT_TRUE(copy_dict->Get(L"null", ©_null)); - ASSERT_TRUE(copy_null); - ASSERT_NE(copy_null, original_null); - ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL)); - - Value* copy_bool = NULL; - ASSERT_TRUE(copy_dict->Get(L"bool", ©_bool)); - ASSERT_TRUE(copy_bool); - ASSERT_NE(copy_bool, original_bool); - ASSERT_TRUE(copy_bool->IsType(Value::TYPE_BOOLEAN)); - bool copy_bool_value = false; - ASSERT_TRUE(copy_bool->GetAsBoolean(©_bool_value)); - ASSERT_TRUE(copy_bool_value); - - Value* copy_int = NULL; - ASSERT_TRUE(copy_dict->Get(L"int", ©_int)); - ASSERT_TRUE(copy_int); - ASSERT_NE(copy_int, original_int); - ASSERT_TRUE(copy_int->IsType(Value::TYPE_INTEGER)); - int copy_int_value = 0; - ASSERT_TRUE(copy_int->GetAsInteger(©_int_value)); - ASSERT_EQ(42, copy_int_value); - - Value* copy_real = NULL; - ASSERT_TRUE(copy_dict->Get(L"real", ©_real)); - ASSERT_TRUE(copy_real); - ASSERT_NE(copy_real, original_real); - ASSERT_TRUE(copy_real->IsType(Value::TYPE_REAL)); - double copy_real_value = 0; - ASSERT_TRUE(copy_real->GetAsReal(©_real_value)); - ASSERT_EQ(3.14, copy_real_value); - - Value* copy_string = NULL; - ASSERT_TRUE(copy_dict->Get(L"string", ©_string)); - ASSERT_TRUE(copy_string); - ASSERT_NE(copy_string, original_string); - ASSERT_TRUE(copy_string->IsType(Value::TYPE_STRING)); - std::string copy_string_value; - std::wstring copy_wstring_value; - string16 copy_utf16_value; - ASSERT_TRUE(copy_string->GetAsString(©_string_value)); - ASSERT_TRUE(copy_string->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_string->GetAsString(©_utf16_value)); - ASSERT_EQ(std::string("hello"), copy_string_value); - ASSERT_EQ(std::wstring(L"hello"), copy_wstring_value); - ASSERT_EQ(ASCIIToUTF16("hello"), copy_utf16_value); - - Value* copy_utf16 = NULL; - ASSERT_TRUE(copy_dict->Get(L"utf16", ©_utf16)); - ASSERT_TRUE(copy_utf16); - ASSERT_NE(copy_utf16, original_utf16); - ASSERT_TRUE(copy_utf16->IsType(Value::TYPE_STRING)); - ASSERT_TRUE(copy_utf16->GetAsString(©_string_value)); - ASSERT_TRUE(copy_utf16->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_utf16->GetAsString(©_utf16_value)); - ASSERT_EQ(std::string("hello16"), copy_string_value); - ASSERT_EQ(std::wstring(L"hello16"), copy_wstring_value); - ASSERT_EQ(ASCIIToUTF16("hello16"), copy_utf16_value); - - Value* copy_binary = NULL; - ASSERT_TRUE(copy_dict->Get(L"binary", ©_binary)); - ASSERT_TRUE(copy_binary); - ASSERT_NE(copy_binary, original_binary); - ASSERT_TRUE(copy_binary->IsType(Value::TYPE_BINARY)); - ASSERT_NE(original_binary->GetBuffer(), - static_cast<BinaryValue*>(copy_binary)->GetBuffer()); - ASSERT_EQ(original_binary->GetSize(), - static_cast<BinaryValue*>(copy_binary)->GetSize()); - ASSERT_EQ(0, memcmp(original_binary->GetBuffer(), - static_cast<BinaryValue*>(copy_binary)->GetBuffer(), - original_binary->GetSize())); - - Value* copy_value = NULL; - ASSERT_TRUE(copy_dict->Get(L"list", ©_value)); - ASSERT_TRUE(copy_value); - ASSERT_NE(copy_value, original_list); - ASSERT_TRUE(copy_value->IsType(Value::TYPE_LIST)); - ListValue* copy_list = static_cast<ListValue*>(copy_value); - ASSERT_EQ(2U, copy_list->GetSize()); - - Value* copy_list_element_0; - ASSERT_TRUE(copy_list->Get(0, ©_list_element_0)); - ASSERT_TRUE(copy_list_element_0); - ASSERT_NE(copy_list_element_0, original_list_element_0); - int copy_list_element_0_value; - ASSERT_TRUE(copy_list_element_0->GetAsInteger(©_list_element_0_value)); - ASSERT_EQ(0, copy_list_element_0_value); - - Value* copy_list_element_1; - ASSERT_TRUE(copy_list->Get(1, ©_list_element_1)); - ASSERT_TRUE(copy_list_element_1); - ASSERT_NE(copy_list_element_1, original_list_element_1); - int copy_list_element_1_value; - ASSERT_TRUE(copy_list_element_1->GetAsInteger(©_list_element_1_value)); - ASSERT_EQ(1, copy_list_element_1_value); -} - TEST_F(ValuesTest, Equals) { Value* null1 = Value::CreateNullValue(); Value* null2 = Value::CreateNullValue(); @@ -776,44 +502,6 @@ TEST_F(ValuesTest, Equals) { delete copy; } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, EqualsDeprecated) { - Value* null1 = Value::CreateNullValue(); - Value* null2 = Value::CreateNullValue(); - EXPECT_NE(null1, null2); - EXPECT_TRUE(null1->Equals(null2)); - - Value* boolean = Value::CreateBooleanValue(false); - EXPECT_FALSE(null1->Equals(boolean)); - delete null1; - delete null2; - delete boolean; - - DictionaryValue dv; - dv.SetBoolean(L"a", false); - dv.SetInteger(L"b", 2); - dv.SetReal(L"c", 2.5); - dv.SetString(L"d1", "string"); - dv.SetString(L"d2", L"string"); - dv.Set(L"e", Value::CreateNullValue()); - - DictionaryValue* copy = static_cast<DictionaryValue*>(dv.DeepCopy()); - EXPECT_TRUE(dv.Equals(copy)); - - ListValue* list = new ListValue; - list->Append(Value::CreateNullValue()); - list->Append(new DictionaryValue); - dv.Set(L"f", list); - - EXPECT_FALSE(dv.Equals(copy)); - copy->Set(L"f", list->DeepCopy()); - EXPECT_TRUE(dv.Equals(copy)); - - list->Append(Value::CreateBooleanValue(true)); - EXPECT_FALSE(dv.Equals(copy)); - delete copy; -} - TEST_F(ValuesTest, RemoveEmptyChildren) { scoped_ptr<DictionaryValue> root(new DictionaryValue); // Remove empty lists and dictionaries. @@ -889,82 +577,6 @@ TEST_F(ValuesTest, RemoveEmptyChildren) { } } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, RemoveEmptyChildrenDeprecated) { - scoped_ptr<DictionaryValue> root(new DictionaryValue); - // Remove empty lists and dictionaries. - root->Set(L"empty_dict", new DictionaryValue); - root->Set(L"empty_list", new ListValue); - root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_TRUE(root->empty()); - - // Make sure we don't prune too much. - root->SetBoolean(L"bool", true); - root->Set(L"empty_dict", new DictionaryValue); - root->SetString(L"empty_string", ""); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(2U, root->size()); - - // Should do nothing. - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(2U, root->size()); - - // Nested test cases. These should all reduce back to the bool and string - // set above. - { - root->Set(L"a.b.c.d.e", new DictionaryValue); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(2U, root->size()); - } - { - DictionaryValue* inner = new DictionaryValue; - root->Set(L"dict_with_emtpy_children", inner); - inner->Set(L"empty_dict", new DictionaryValue); - inner->Set(L"empty_list", new ListValue); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(2U, root->size()); - } - { - ListValue* inner = new ListValue; - root->Set(L"list_with_empty_children", inner); - inner->Append(new DictionaryValue); - inner->Append(new ListValue); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(2U, root->size()); - } - - // Nested with siblings. - { - ListValue* inner = new ListValue; - root->Set(L"list_with_empty_children", inner); - inner->Append(new DictionaryValue); - inner->Append(new ListValue); - DictionaryValue* inner2 = new DictionaryValue; - root->Set(L"dict_with_empty_children", inner2); - inner2->Set(L"empty_dict", new DictionaryValue); - inner2->Set(L"empty_list", new ListValue); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(2U, root->size()); - } - - // Make sure nested values don't get pruned. - { - ListValue* inner = new ListValue; - root->Set(L"list_with_empty_children", inner); - ListValue* inner2 = new ListValue; - inner->Append(new DictionaryValue); - inner->Append(inner2); - inner2->Append(Value::CreateStringValue("hello")); - root.reset(root->DeepCopyWithoutEmptyChildren()); - EXPECT_EQ(3U, root->size()); - EXPECT_TRUE(root->GetList(L"list_with_empty_children", &inner)); - EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned. - EXPECT_TRUE(inner->GetList(0, &inner2)); - EXPECT_EQ(1U, inner2->GetSize()); - } -} - TEST_F(ValuesTest, MergeDictionary) { scoped_ptr<DictionaryValue> base(new DictionaryValue); base->SetString("base_key", "base_key_value_base"); @@ -1010,52 +622,6 @@ TEST_F(ValuesTest, MergeDictionary) { EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. } -// TODO(viettrungluu): deprecate: -TEST_F(ValuesTest, MergeDictionaryDeprecated) { - scoped_ptr<DictionaryValue> base(new DictionaryValue); - base->SetString(L"base_key", "base_key_value_base"); - base->SetString(L"collide_key", "collide_key_value_base"); - DictionaryValue* base_sub_dict = new DictionaryValue; - base_sub_dict->SetString(L"sub_base_key", "sub_base_key_value_base"); - base_sub_dict->SetString(L"sub_collide_key", "sub_collide_key_value_base"); - base->Set(L"sub_dict_key", base_sub_dict); - - scoped_ptr<DictionaryValue> merge(new DictionaryValue); - merge->SetString(L"merge_key", "merge_key_value_merge"); - merge->SetString(L"collide_key", "collide_key_value_merge"); - DictionaryValue* merge_sub_dict = new DictionaryValue; - merge_sub_dict->SetString(L"sub_merge_key", "sub_merge_key_value_merge"); - merge_sub_dict->SetString(L"sub_collide_key", "sub_collide_key_value_merge"); - merge->Set(L"sub_dict_key", merge_sub_dict); - - base->MergeDictionary(merge.get()); - - EXPECT_EQ(4U, base->size()); - std::string base_key_value; - EXPECT_TRUE(base->GetString(L"base_key", &base_key_value)); - EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved. - std::string collide_key_value; - EXPECT_TRUE(base->GetString(L"collide_key", &collide_key_value)); - EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced. - std::string merge_key_value; - EXPECT_TRUE(base->GetString(L"merge_key", &merge_key_value)); - EXPECT_EQ("merge_key_value_merge", merge_key_value); // Merged in. - - DictionaryValue* res_sub_dict; - EXPECT_TRUE(base->GetDictionary(L"sub_dict_key", &res_sub_dict)); - EXPECT_EQ(3U, res_sub_dict->size()); - std::string sub_base_key_value; - EXPECT_TRUE(res_sub_dict->GetString(L"sub_base_key", &sub_base_key_value)); - EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved. - std::string sub_collide_key_value; - EXPECT_TRUE(res_sub_dict->GetString(L"sub_collide_key", - &sub_collide_key_value)); - EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. - std::string sub_merge_key_value; - EXPECT_TRUE(res_sub_dict->GetString(L"sub_merge_key", &sub_merge_key_value)); - EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. -} - TEST_F(ValuesTest, GetDifferingPaths) { scoped_ptr<DictionaryValue> dict1(new DictionaryValue()); scoped_ptr<DictionaryValue> dict2(new DictionaryValue()); |