diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 15:42:58 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-03 15:42:58 +0000 |
commit | e2e593d0f2786242b85ca4b8cb000f9f875b2db3 (patch) | |
tree | f47ce111779fb7bd11ceab480912b56232d171ff /base/values_unittest.cc | |
parent | 5713f3265b87f12432a31c4a90e59b5f3f2f8f7e (diff) | |
download | chromium_src-e2e593d0f2786242b85ca4b8cb000f9f875b2db3.zip chromium_src-e2e593d0f2786242b85ca4b8cb000f9f875b2db3.tar.gz chromium_src-e2e593d0f2786242b85ca4b8cb000f9f875b2db3.tar.bz2 |
Remove Value/StringValue's ...UTF16() methods in favour of overloading.
Still to do: do the same for DictionaryValue.
BUG=none
TEST=builds
Review URL: http://codereview.chromium.org/3023037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values_unittest.cc')
-rw-r--r-- | base/values_unittest.cc | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/base/values_unittest.cc b/base/values_unittest.cc index f0b9d9e..fb414c1 100644 --- a/base/values_unittest.cc +++ b/base/values_unittest.cc @@ -18,7 +18,8 @@ class ValuesTest: public testing::Test { // 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. +// methods are removed. There are also parts of tests marked DEPRECATED which +// are to be deleted. TEST(ValuesTest, Basic) { // Test basic dictionary getting/setting @@ -182,11 +183,36 @@ TEST(ValuesTest, StringValue) { 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"; + string16 utf16 = ASCIIToUTF16("http://google.com"); + ASSERT_TRUE(narrow_value->GetAsString(&narrow)); + ASSERT_TRUE(narrow_value->GetAsString(&utf16)); + ASSERT_EQ(std::string("narrow"), narrow); + ASSERT_EQ(ASCIIToUTF16("narrow"), utf16); + + ASSERT_TRUE(utf16_value->GetAsString(&narrow)); + ASSERT_TRUE(utf16_value->GetAsString(&utf16)); + ASSERT_EQ(std::string("utf16"), narrow); + ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); +} + +// TODO(viettrungluu): deprecate: +TEST(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> wide_value(Value::CreateStringValue(L"wide")); ASSERT_TRUE(wide_value.get()); ASSERT_TRUE(wide_value->IsType(Value::TYPE_STRING)); scoped_ptr<Value> utf16_value( - Value::CreateStringValueFromUTF16(ASCIIToUTF16("utf16"))); + Value::CreateStringValue(ASCIIToUTF16("utf16"))); ASSERT_TRUE(utf16_value.get()); ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); @@ -196,21 +222,21 @@ TEST(ValuesTest, StringValue) { string16 utf16 = ASCIIToUTF16("http://google.com"); ASSERT_TRUE(narrow_value->GetAsString(&narrow)); ASSERT_TRUE(narrow_value->GetAsString(&wide)); - ASSERT_TRUE(narrow_value->GetAsUTF16(&utf16)); + 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(wide_value->GetAsString(&narrow)); ASSERT_TRUE(wide_value->GetAsString(&wide)); - ASSERT_TRUE(wide_value->GetAsUTF16(&utf16)); + ASSERT_TRUE(wide_value->GetAsString(&utf16)); ASSERT_EQ(std::string("wide"), narrow); ASSERT_EQ(std::wstring(L"wide"), wide); ASSERT_EQ(ASCIIToUTF16("wide"), utf16); ASSERT_TRUE(utf16_value->GetAsString(&narrow)); ASSERT_TRUE(utf16_value->GetAsString(&wide)); - ASSERT_TRUE(utf16_value->GetAsUTF16(&utf16)); + ASSERT_TRUE(utf16_value->GetAsString(&utf16)); ASSERT_EQ(std::string("utf16"), narrow); ASSERT_EQ(std::wstring(L"utf16"), wide); ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); @@ -483,11 +509,8 @@ TEST(ValuesTest, DeepCopy) { original_dict.Set("real", original_real); Value* original_string = Value::CreateStringValue("hello"); original_dict.Set("string", original_string); - Value* original_wstring = Value::CreateStringValue(L"peek-a-boo"); - original_dict.Set("wstring", original_wstring); - Value* original_utf16 = - Value::CreateStringValueFromUTF16(ASCIIToUTF16("hello16")); - original_dict.Set("utf16", original_utf16); + Value* original_string16 = Value::CreateStringValue(ASCIIToUTF16("hello16")); + original_dict.Set("string16", original_string16); char* original_buffer = new char[42]; memset(original_buffer, '!', 42); @@ -545,38 +568,21 @@ TEST(ValuesTest, DeepCopy) { 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; + string16 copy_string16_value; ASSERT_TRUE(copy_string->GetAsString(©_string_value)); - ASSERT_TRUE(copy_string->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_string->GetAsUTF16(©_utf16_value)); + ASSERT_TRUE(copy_string->GetAsString(©_string16_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_wstring = NULL; - ASSERT_TRUE(copy_dict->Get("wstring", ©_wstring)); - ASSERT_TRUE(copy_wstring); - ASSERT_NE(copy_wstring, original_wstring); - ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING)); - ASSERT_TRUE(copy_wstring->GetAsString(©_string_value)); - ASSERT_TRUE(copy_wstring->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_wstring->GetAsUTF16(©_utf16_value)); - ASSERT_EQ(std::string("peek-a-boo"), copy_string_value); - ASSERT_EQ(std::wstring(L"peek-a-boo"), copy_wstring_value); - ASSERT_EQ(ASCIIToUTF16("peek-a-boo"), copy_utf16_value); - - Value* copy_utf16 = NULL; - ASSERT_TRUE(copy_dict->Get("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->GetAsUTF16(©_utf16_value)); + ASSERT_EQ(ASCIIToUTF16("hello"), copy_string16_value); + + Value* copy_string16 = NULL; + ASSERT_TRUE(copy_dict->Get("string16", ©_string16)); + ASSERT_TRUE(copy_string16); + ASSERT_NE(copy_string16, original_string16); + ASSERT_TRUE(copy_string16->IsType(Value::TYPE_STRING)); + ASSERT_TRUE(copy_string16->GetAsString(©_string_value)); + ASSERT_TRUE(copy_string16->GetAsString(©_string16_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); + ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value); Value* copy_binary = NULL; ASSERT_TRUE(copy_dict->Get("binary", ©_binary)); @@ -631,8 +637,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { original_dict.Set(L"string", original_string); Value* original_wstring = Value::CreateStringValue(L"peek-a-boo"); original_dict.Set(L"wstring", original_wstring); - Value* original_utf16 = - Value::CreateStringValueFromUTF16(ASCIIToUTF16("hello16")); + Value* original_utf16 = Value::CreateStringValue(ASCIIToUTF16("hello16")); original_dict.Set(L"utf16", original_utf16); char* original_buffer = new char[42]; @@ -695,7 +700,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { string16 copy_utf16_value; ASSERT_TRUE(copy_string->GetAsString(©_string_value)); ASSERT_TRUE(copy_string->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_string->GetAsUTF16(©_utf16_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); @@ -707,7 +712,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING)); ASSERT_TRUE(copy_wstring->GetAsString(©_string_value)); ASSERT_TRUE(copy_wstring->GetAsString(©_wstring_value)); - ASSERT_TRUE(copy_wstring->GetAsUTF16(©_utf16_value)); + ASSERT_TRUE(copy_wstring->GetAsString(©_utf16_value)); ASSERT_EQ(std::string("peek-a-boo"), copy_string_value); ASSERT_EQ(std::wstring(L"peek-a-boo"), copy_wstring_value); ASSERT_EQ(ASCIIToUTF16("peek-a-boo"), copy_utf16_value); @@ -719,7 +724,7 @@ TEST(ValuesTest, DeepCopyDeprecated) { 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->GetAsUTF16(©_utf16_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); |