diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 22:59:43 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 22:59:43 +0000 |
commit | 8e50b600ed1e65789109022709cf5c349748fb4c (patch) | |
tree | d9d57344003604647e1a96a56ef4d21921ec44c0 /base | |
parent | 0c8a8f7aa683ae7d6c8ba176c1db704cc294defb (diff) | |
download | chromium_src-8e50b600ed1e65789109022709cf5c349748fb4c.zip chromium_src-8e50b600ed1e65789109022709cf5c349748fb4c.tar.gz chromium_src-8e50b600ed1e65789109022709cf5c349748fb4c.tar.bz2 |
revert broken change 10833
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10837 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/json_reader.cc | 3 | ||||
-rw-r--r-- | base/json_reader_unittest.cc | 19 | ||||
-rw-r--r-- | base/json_writer.cc | 6 | ||||
-rw-r--r-- | base/json_writer.h | 6 | ||||
-rw-r--r-- | base/json_writer_unittest.cc | 7 | ||||
-rw-r--r-- | base/string_util.cc | 20 | ||||
-rw-r--r-- | base/string_util.h | 7 | ||||
-rw-r--r-- | base/values.cc | 70 | ||||
-rw-r--r-- | base/values.h | 44 | ||||
-rw-r--r-- | base/values_unittest.cc | 111 |
10 files changed, 131 insertions, 162 deletions
diff --git a/base/json_reader.cc b/base/json_reader.cc index e4dc61c..b5013ef 100644 --- a/base/json_reader.cc +++ b/base/json_reader.cc @@ -277,8 +277,7 @@ Value* JSONReader::BuildValue(bool is_root) { Value* dict_value = BuildValue(false); if (!dict_value) return NULL; - static_cast<DictionaryValue*>(node.get())->Set( - WideToUTF16Hack(dict_key), dict_value); + static_cast<DictionaryValue*>(node.get())->Set(dict_key, dict_value); // After a key/value pair, we expect a comma or the end of the // object. diff --git a/base/json_reader_unittest.cc b/base/json_reader_unittest.cc index bd64162..9153289 100644 --- a/base/json_reader_unittest.cc +++ b/base/json_reader_unittest.cc @@ -5,7 +5,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "base/json_reader.h" #include "base/scoped_ptr.h" -#include "base/string_util.h" #include "base/values.h" #include "build/build_config.h" @@ -298,14 +297,14 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); DictionaryValue* dict_val = static_cast<DictionaryValue*>(root.get()); real_val = 0.0; - ASSERT_TRUE(dict_val->GetReal(ASCIIToUTF16("number"), &real_val)); + ASSERT_TRUE(dict_val->GetReal(L"number", &real_val)); ASSERT_DOUBLE_EQ(9.87654321, real_val); Value* null_val = NULL; - ASSERT_TRUE(dict_val->Get(ASCIIToUTF16("null"), &null_val)); + ASSERT_TRUE(dict_val->Get(L"null", &null_val)); ASSERT_TRUE(null_val->IsType(Value::TYPE_NULL)); - string16 str16_val; - ASSERT_TRUE(dict_val->GetString(ASCIIToUTF16("S"), &str16_val)); - ASSERT_EQ(ASCIIToUTF16("str"), str16_val); + str_val.clear(); + ASSERT_TRUE(dict_val->GetString(L"S", &str_val)); + ASSERT_EQ(L"str", str_val); root2.reset(JSONReader::Read( "{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\", }", true)); @@ -318,15 +317,15 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); dict_val = static_cast<DictionaryValue*>(root.get()); DictionaryValue* inner_dict = NULL; - ASSERT_TRUE(dict_val->GetDictionary(ASCIIToUTF16("inner"), &inner_dict)); + ASSERT_TRUE(dict_val->GetDictionary(L"inner", &inner_dict)); ListValue* inner_array = NULL; - ASSERT_TRUE(inner_dict->GetList(ASCIIToUTF16("array"), &inner_array)); + ASSERT_TRUE(inner_dict->GetList(L"array", &inner_array)); ASSERT_EQ(1U, inner_array->GetSize()); bool_value = true; - ASSERT_TRUE(dict_val->GetBoolean(ASCIIToUTF16("false"), &bool_value)); + ASSERT_TRUE(dict_val->GetBoolean(L"false", &bool_value)); ASSERT_FALSE(bool_value); inner_dict = NULL; - ASSERT_TRUE(dict_val->GetDictionary(ASCIIToUTF16("d"), &inner_dict)); + ASSERT_TRUE(dict_val->GetDictionary(L"d", &inner_dict)); root2.reset(JSONReader::Read( "{\"inner\": {\"array\":[true] , },\"false\":false,\"d\":{},}", true)); diff --git a/base/json_writer.cc b/base/json_writer.cc index 56efce9..20c533b 100644 --- a/base/json_writer.cc +++ b/base/json_writer.cc @@ -76,7 +76,7 @@ void JSONWriter::BuildJSONString(const Value* const node, int depth) { std::wstring value; bool result = node->GetAsString(&value); DCHECK(result); - AppendQuotedString(WideToUTF16Hack(value)); + AppendQuotedString(value); break; } @@ -155,8 +155,8 @@ void JSONWriter::BuildJSONString(const Value* const node, int depth) { } } -void JSONWriter::AppendQuotedString(const string16& str) { - string_escape::JavascriptDoubleQuote(str, true, +void JSONWriter::AppendQuotedString(const std::wstring& str) { + string_escape::JavascriptDoubleQuote(WideToUTF16Hack(str), true, json_string_); } diff --git a/base/json_writer.h b/base/json_writer.h index 330e73c..42232bf 100644 --- a/base/json_writer.h +++ b/base/json_writer.h @@ -5,8 +5,9 @@ #ifndef BASE_JSON_WRITER_H_ #define BASE_JSON_WRITER_H_ +#include <string> + #include "base/basictypes.h" -#include "base/string16.h" class Value; @@ -30,7 +31,7 @@ class JSONWriter { void BuildJSONString(const Value* const node, int depth); // Appends a quoted, escaped, version of str to json_string_. - void AppendQuotedString(const string16& str); + void AppendQuotedString(const std::wstring& str); // Adds space to json_string_ for the indent level. void IndentLine(int depth); @@ -44,3 +45,4 @@ class JSONWriter { }; #endif // BASE_JSON_WRITER_H_ + diff --git a/base/json_writer_unittest.cc b/base/json_writer_unittest.cc index 2c746fd..cddfd4c 100644 --- a/base/json_writer_unittest.cc +++ b/base/json_writer_unittest.cc @@ -4,7 +4,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "base/json_writer.h" -#include "base/string_util.h" #include "base/values.h" TEST(JSONWriterTest, Writing) { @@ -37,10 +36,10 @@ TEST(JSONWriterTest, Writing) { // list list nesting, etc. DictionaryValue root_dict; ListValue* list = new ListValue; - root_dict.Set(ASCIIToUTF16("list"), list); + root_dict.Set(L"list", list); DictionaryValue* inner_dict = new DictionaryValue; list->Append(inner_dict); - inner_dict->SetInteger(ASCIIToUTF16("inner int"), 10); + inner_dict->SetInteger(L"inner int", 10); ListValue* inner_list = new ListValue; list->Append(inner_list); list->Append(Value::CreateBooleanValue(true)); @@ -55,3 +54,5 @@ TEST(JSONWriterTest, Writing) { "}\r\n", output_js); } + + diff --git a/base/string_util.cc b/base/string_util.cc index 4080b1d..a13f79f 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -1039,10 +1039,6 @@ std::string IntToString(int value) { return IntToStringT<std::string, int, unsigned int, true>:: IntToString(value); } -string16 IntToString16(int value) { - return IntToStringT<string16, int, unsigned int, true>:: - IntToString(value); -} std::wstring IntToWString(int value) { return IntToStringT<std::wstring, int, unsigned int, true>:: IntToString(value); @@ -1051,10 +1047,6 @@ std::string UintToString(unsigned int value) { return IntToStringT<std::string, unsigned int, unsigned int, false>:: IntToString(value); } -string16 UintToString16(unsigned int value) { - return IntToStringT<string16, unsigned int, unsigned int, false>:: - IntToString(value); -} std::wstring UintToWString(unsigned int value) { return IntToStringT<std::wstring, unsigned int, unsigned int, false>:: IntToString(value); @@ -1063,10 +1055,6 @@ std::string Int64ToString(int64 value) { return IntToStringT<std::string, int64, uint64, true>:: IntToString(value); } -string16 Int64ToString16(int64 value) { - return IntToStringT<string16, int64, uint64, true>:: - IntToString(value); -} std::wstring Int64ToWString(int64 value) { return IntToStringT<std::wstring, int64, uint64, true>:: IntToString(value); @@ -1075,10 +1063,6 @@ std::string Uint64ToString(uint64 value) { return IntToStringT<std::string, uint64, uint64, false>:: IntToString(value); } -string16 Uint64ToString16(uint64 value) { - return IntToStringT<string16, uint64, uint64, false>:: - IntToString(value); -} std::wstring Uint64ToWString(uint64 value) { return IntToStringT<std::wstring, uint64, uint64, false>:: IntToString(value); @@ -1091,10 +1075,6 @@ std::string DoubleToString(double value) { return std::string(buffer); } -string16 DoubleToString16(double value) { - return ASCIIToUTF16(DoubleToString(value)); -} - std::wstring DoubleToWString(double value) { return ASCIIToWide(DoubleToString(value)); } diff --git a/base/string_util.h b/base/string_util.h index fdad6be..26c42e5 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -189,7 +189,7 @@ std::string UTF16ToUTF8(const string16& utf16); // really should just be passing a string16 around, but we haven't finished // porting whatever module uses wstring and the conversion is being used as a // stopcock. This makes it easy to grep for the ones that should be removed. -#if defined(WCHAR_T_IS_UTF16) +#if defined(OS_WIN) # define WideToUTF16Hack # define UTF16ToWideHack #else @@ -385,21 +385,16 @@ void ReplaceSubstringsAfterOffset(std::string* str, // Specialized string-conversion functions. std::string IntToString(int value); -string16 IntToString16(int value); std::wstring IntToWString(int value); std::string UintToString(unsigned int value); -string16 UintToString16(unsigned int value); std::wstring UintToWString(unsigned int value); std::string Int64ToString(int64 value); -string16 Int64ToString16(int64 value); std::wstring Int64ToWString(int64 value); std::string Uint64ToString(uint64 value); -string16 Uint64ToString16(uint64 value); std::wstring Uint64ToWString(uint64 value); // The DoubleToString methods convert the double to a string format that // ignores the locale. If you want to use locale specific formatting, use ICU. std::string DoubleToString(double value); -string16 DoubleToString16(double value); std::wstring DoubleToWString(double value); // Perform a best-effort conversion of the input string to a numeric type, diff --git a/base/values.cc b/base/values.cc index 29a5896..cf98c0b 100644 --- a/base/values.cc +++ b/base/values.cc @@ -245,13 +245,13 @@ void DictionaryValue::Clear() { dictionary_.clear(); } -bool DictionaryValue::HasKey(const string16& key) const { +bool DictionaryValue::HasKey(const std::wstring& key) const { ValueMap::const_iterator current_entry = dictionary_.find(key); DCHECK((current_entry == dictionary_.end()) || current_entry->second); return current_entry != dictionary_.end(); } -void DictionaryValue::SetInCurrentNode(const string16& key, +void DictionaryValue::SetInCurrentNode(const std::wstring& key, Value* in_value) { // If there's an existing value here, we need to delete it, because // we own all our children. @@ -263,12 +263,12 @@ void DictionaryValue::SetInCurrentNode(const string16& key, dictionary_[key] = in_value; } -bool DictionaryValue::Set(const string16& path, Value* in_value) { +bool DictionaryValue::Set(const std::wstring& path, Value* in_value) { DCHECK(in_value); - string16 key = path; + std::wstring key = path; - size_t delimiter_position = path.find_first_of('.', 0); + size_t delimiter_position = path.find_first_of(L".", 0); // If there isn't a dictionary delimiter in the path, we're done. if (delimiter_position == std::wstring::npos) { SetInCurrentNode(key, in_value); @@ -286,37 +286,37 @@ bool DictionaryValue::Set(const string16& path, Value* in_value) { entry = static_cast<DictionaryValue*>(dictionary_[key]); } - string16 remaining_path = path.substr(delimiter_position + 1); + std::wstring remaining_path = path.substr(delimiter_position + 1); return entry->Set(remaining_path, in_value); } -bool DictionaryValue::SetBoolean(const string16& path, bool in_value) { +bool DictionaryValue::SetBoolean(const std::wstring& path, bool in_value) { return Set(path, CreateBooleanValue(in_value)); } -bool DictionaryValue::SetInteger(const string16& path, int in_value) { +bool DictionaryValue::SetInteger(const std::wstring& path, int in_value) { return Set(path, CreateIntegerValue(in_value)); } -bool DictionaryValue::SetReal(const string16& path, double in_value) { +bool DictionaryValue::SetReal(const std::wstring& path, double in_value) { return Set(path, CreateRealValue(in_value)); } -bool DictionaryValue::SetString(const string16& path, +bool DictionaryValue::SetString(const std::wstring& path, const std::string& in_value) { return Set(path, CreateStringValue(in_value)); } -bool DictionaryValue::SetString(const string16& path, - const string16& in_value) { - return Set(path, CreateStringValue(UTF16ToWideHack(in_value))); +bool DictionaryValue::SetString(const std::wstring& path, + const std::wstring& in_value) { + return Set(path, CreateStringValue(in_value)); } -bool DictionaryValue::Get(const string16& path, Value** out_value) const { - string16 key = path; +bool DictionaryValue::Get(const std::wstring& path, Value** out_value) const { + std::wstring key = path; - size_t delimiter_position = path.find_first_of('.', 0); - if (delimiter_position != string16::npos) { + size_t delimiter_position = path.find_first_of(L".", 0); + if (delimiter_position != std::wstring::npos) { key = path.substr(0, delimiter_position); } @@ -325,7 +325,7 @@ bool DictionaryValue::Get(const string16& path, Value** out_value) const { return false; Value* entry = entry_iterator->second; - if (delimiter_position == string16::npos) { + if (delimiter_position == std::wstring::npos) { if (out_value) *out_value = entry; return true; @@ -339,7 +339,7 @@ bool DictionaryValue::Get(const string16& path, Value** out_value) const { return false; } -bool DictionaryValue::GetBoolean(const string16& path, +bool DictionaryValue::GetBoolean(const std::wstring& path, bool* bool_value) const { Value* value; if (!Get(path, &value)) @@ -348,7 +348,7 @@ bool DictionaryValue::GetBoolean(const string16& path, return value->GetAsBoolean(bool_value); } -bool DictionaryValue::GetInteger(const string16& path, +bool DictionaryValue::GetInteger(const std::wstring& path, int* out_value) const { Value* value; if (!Get(path, &value)) @@ -357,7 +357,7 @@ bool DictionaryValue::GetInteger(const string16& path, return value->GetAsInteger(out_value); } -bool DictionaryValue::GetReal(const string16& path, +bool DictionaryValue::GetReal(const std::wstring& path, double* out_value) const { Value* value; if (!Get(path, &value)) @@ -366,7 +366,7 @@ bool DictionaryValue::GetReal(const string16& path, return value->GetAsReal(out_value); } -bool DictionaryValue::GetString(const string16& path, +bool DictionaryValue::GetString(const std::wstring& path, std::string* out_value) const { Value* value; if (!Get(path, &value)) @@ -375,19 +375,16 @@ bool DictionaryValue::GetString(const string16& path, return value->GetAsString(out_value); } -bool DictionaryValue::GetString(const string16& path, - string16* out_value) const { +bool DictionaryValue::GetString(const std::wstring& path, + std::wstring* out_value) const { Value* value; if (!Get(path, &value)) return false; - std::wstring wout_value; - bool success = value->GetAsString(&wout_value); - out_value->assign(WideToUTF16Hack(wout_value)); - return success; + return value->GetAsString(out_value); } -bool DictionaryValue::GetBinary(const string16& path, +bool DictionaryValue::GetBinary(const std::wstring& path, BinaryValue** out_value) const { Value* value; bool result = Get(path, &value); @@ -400,7 +397,7 @@ bool DictionaryValue::GetBinary(const string16& path, return true; } -bool DictionaryValue::GetDictionary(const string16& path, +bool DictionaryValue::GetDictionary(const std::wstring& path, DictionaryValue** out_value) const { Value* value; bool result = Get(path, &value); @@ -413,7 +410,7 @@ bool DictionaryValue::GetDictionary(const string16& path, return true; } -bool DictionaryValue::GetList(const string16& path, +bool DictionaryValue::GetList(const std::wstring& path, ListValue** out_value) const { Value* value; bool result = Get(path, &value); @@ -426,11 +423,11 @@ bool DictionaryValue::GetList(const string16& path, return true; } -bool DictionaryValue::Remove(const string16& path, Value** out_value) { - string16 key = path; +bool DictionaryValue::Remove(const std::wstring& path, Value** out_value) { + std::wstring key = path; - size_t delimiter_position = path.find_first_of('.', 0); - if (delimiter_position != string16::npos) { + size_t delimiter_position = path.find_first_of(L".", 0); + if (delimiter_position != std::wstring::npos) { key = path.substr(0, delimiter_position); } @@ -439,7 +436,7 @@ bool DictionaryValue::Remove(const string16& path, Value** out_value) { return false; Value* entry = entry_iterator->second; - if (delimiter_position == string16::npos) { + if (delimiter_position == std::wstring::npos) { if (out_value) *out_value = entry; else @@ -654,3 +651,4 @@ bool ListValue::Equals(const Value* other) const { return true; } + diff --git a/base/values.h b/base/values.h index 54298d5..cad1311 100644 --- a/base/values.h +++ b/base/values.h @@ -23,10 +23,10 @@ #include <iterator> #include <map> +#include <string> #include <vector> #include "base/basictypes.h" -#include "base/string16.h" class Value; class FundamentalValue; @@ -36,7 +36,7 @@ class DictionaryValue; class ListValue; typedef std::vector<Value*> ValueVector; -typedef std::map<string16, Value*> ValueMap; +typedef std::map<std::wstring, Value*> ValueMap; // The Value class is the base class for Values. A Value can be // instantiated via the Create*Value() factory methods, or by directly @@ -202,7 +202,7 @@ class DictionaryValue : public Value { virtual bool Equals(const Value* other) const; // Returns true if the current dictionary has a value for the given key. - bool HasKey(const string16& key) const; + bool HasKey(const std::wstring& key) const; // Clears any current contents of this dictionary. void Clear(); @@ -216,15 +216,15 @@ class DictionaryValue : public Value { // to the path in that location. // Note that the dictionary takes ownership of the value // referenced by in_value. - bool Set(const string16& path, Value* in_value); + bool Set(const std::wstring& path, Value* in_value); // Convenience forms of Set(). These methods will replace any existing // value at that path, even if it has a different type. - bool SetBoolean(const string16& path, bool in_value); - bool SetInteger(const string16& path, int in_value); - bool SetReal(const string16& path, double in_value); - bool SetString(const string16& path, const std::string& in_value); - bool SetString(const string16& path, const string16& in_value); + bool SetBoolean(const std::wstring& path, bool in_value); + bool SetInteger(const std::wstring& path, int in_value); + bool SetReal(const std::wstring& path, double in_value); + bool SetString(const std::wstring& path, const std::string& in_value); + bool SetString(const std::wstring& path, const std::wstring& in_value); // Gets the Value associated with the given path starting from this object. // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes @@ -233,20 +233,20 @@ class DictionaryValue : public Value { // through the "value" parameter, and the function will return true. // Otherwise, it will return false and "value" will be untouched. // Note that the dictionary always owns the value that's returned. - bool Get(const string16& path, Value** out_value) const; + bool Get(const std::wstring& path, Value** out_value) const; // These are convenience forms of Get(). The value will be retrieved // and the return value will be true if the path is valid and the value at // the end of the path can be returned in the form specified. - bool GetBoolean(const string16& path, bool* out_value) const; - bool GetInteger(const string16& path, int* out_value) const; - bool GetReal(const string16& path, double* out_value) const; - bool GetString(const string16& path, std::string* out_value) const; - bool GetString(const string16& path, string16* out_value) const; - bool GetBinary(const string16& path, BinaryValue** out_value) const; - bool GetDictionary(const string16& path, + bool GetBoolean(const std::wstring& path, bool* out_value) const; + bool GetInteger(const std::wstring& path, int* out_value) const; + bool GetReal(const std::wstring& path, double* out_value) const; + bool GetString(const std::wstring& path, std::string* out_value) const; + bool GetString(const std::wstring& path, std::wstring* out_value) const; + bool GetBinary(const std::wstring& path, BinaryValue** out_value) const; + bool GetDictionary(const std::wstring& path, DictionaryValue** out_value) const; - bool GetList(const string16& path, ListValue** out_value) const; + bool GetList(const std::wstring& path, ListValue** out_value) const; // Removes the Value with the specified path from this dictionary (or one // of its child dictionaries, if the path is more than just a local key). @@ -254,16 +254,16 @@ class DictionaryValue : public Value { // passed out via out_value. If |out_value| is NULL, the removed value will // be deleted. This method returns true if |path| is a valid path; otherwise // it will return false and the DictionaryValue object will be unchanged. - bool Remove(const string16& path, Value** out_value); + bool Remove(const std::wstring& path, Value** out_value); // This class provides an iterator for the keys in the dictionary. // It can't be used to modify the dictionary. class key_iterator - : private std::iterator<std::input_iterator_tag, const string16> { + : private std::iterator<std::input_iterator_tag, const std::wstring> { public: key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } key_iterator operator++() { ++itr_; return *this; } - const string16& operator*() { return itr_->first; } + const std::wstring& operator*() { return itr_->first; } bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } bool operator==(const key_iterator& other) { return itr_ == other.itr_; } @@ -280,7 +280,7 @@ class DictionaryValue : public Value { // Associates the value |in_value| with the |key|. This method should be // used instead of "dictionary_[key] = foo" so that any previous value can // be properly deleted. - void SetInCurrentNode(const string16& key, Value* in_value); + void SetInCurrentNode(const std::wstring& key, Value* in_value); ValueMap dictionary_; }; diff --git a/base/values_unittest.cc b/base/values_unittest.cc index 63bd65c..dd2121f 100644 --- a/base/values_unittest.cc +++ b/base/values_unittest.cc @@ -6,7 +6,6 @@ #include "base/values.h" #include "base/scoped_ptr.h" -#include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" class ValuesTest: public testing::Test { @@ -15,51 +14,46 @@ class ValuesTest: public testing::Test { TEST(ValuesTest, Basic) { // Test basic dictionary getting/setting DictionaryValue settings; - string16 homepage = ASCIIToUTF16("http://google.com"); - ASSERT_FALSE(settings.GetString(ASCIIToUTF16("global.homepage"), &homepage)); - ASSERT_EQ(ASCIIToUTF16("http://google.com"), homepage); - - ASSERT_FALSE(settings.Get(ASCIIToUTF16("global"), NULL)); - ASSERT_TRUE(settings.Set(ASCIIToUTF16("global"), - Value::CreateBooleanValue(true))); - ASSERT_TRUE(settings.Get(ASCIIToUTF16("global"), NULL)); - ASSERT_TRUE(settings.SetString(ASCIIToUTF16("global.homepage"), - ASCIIToUTF16("http://scurvy.com"))); - ASSERT_TRUE(settings.Get(ASCIIToUTF16("global"), NULL)); - homepage = ASCIIToUTF16("http://google.com"); - ASSERT_TRUE(settings.GetString(ASCIIToUTF16("global.homepage"), &homepage)); - ASSERT_EQ(ASCIIToUTF16("http://scurvy.com"), homepage); + 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)); + ASSERT_TRUE(settings.Set(L"global", Value::CreateBooleanValue(true))); + ASSERT_TRUE(settings.Get(L"global", NULL)); + ASSERT_TRUE(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(ASCIIToUTF16("global.toolbar.bookmarks"), - &toolbar_bookmarks)); + settings.GetList(L"global.toolbar.bookmarks", &toolbar_bookmarks)); toolbar_bookmarks = new ListValue; - settings.Set(ASCIIToUTF16("global.toolbar.bookmarks"), toolbar_bookmarks); + settings.Set(L"global.toolbar.bookmarks", toolbar_bookmarks); ASSERT_TRUE( - settings.GetList(ASCIIToUTF16("global.toolbar.bookmarks"), - &toolbar_bookmarks)); + settings.GetList(L"global.toolbar.bookmarks", &toolbar_bookmarks)); DictionaryValue* new_bookmark = new DictionaryValue; - new_bookmark->SetString(ASCIIToUTF16("name"), ASCIIToUTF16("Froogle")); - new_bookmark->SetString(ASCIIToUTF16("url"), - ASCIIToUTF16("http://froogle.com")); + 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(ASCIIToUTF16("global.toolbar.bookmarks"), - &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)); - string16 bookmark_name = ASCIIToUTF16("Unnamed"); - ASSERT_TRUE(bookmark->GetString(ASCIIToUTF16("name"), &bookmark_name)); - ASSERT_EQ(ASCIIToUTF16("Froogle"), bookmark_name); - string16 bookmark_url; - ASSERT_TRUE(bookmark->GetString(ASCIIToUTF16("url"), &bookmark_url)); - ASSERT_EQ(ASCIIToUTF16("http://froogle.com"), bookmark_url); + 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(ValuesTest, List) { @@ -240,7 +234,7 @@ TEST(ValuesTest, ListRemoval) { } TEST(ValuesTest, DictionaryDeletion) { - string16 key = ASCIIToUTF16("test"); + std::wstring key = L"test"; bool deletion_flag = true; { @@ -268,7 +262,7 @@ TEST(ValuesTest, DictionaryDeletion) { } TEST(ValuesTest, DictionaryRemoval) { - string16 key = ASCIIToUTF16("test"); + std::wstring key = L"test"; bool deletion_flag = true; Value* removed_item = NULL; @@ -277,7 +271,7 @@ TEST(ValuesTest, DictionaryRemoval) { dict.Set(key, new DeletionTestValue(&deletion_flag)); EXPECT_FALSE(deletion_flag); EXPECT_TRUE(dict.HasKey(key)); - EXPECT_FALSE(dict.Remove(ASCIIToUTF16("absent key"), &removed_item)); + 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); @@ -301,29 +295,29 @@ TEST(ValuesTest, DictionaryRemoval) { TEST(ValuesTest, DeepCopy) { DictionaryValue original_dict; Value* original_null = Value::CreateNullValue(); - original_dict.Set(ASCIIToUTF16("null"), original_null); + original_dict.Set(L"null", original_null); Value* original_bool = Value::CreateBooleanValue(true); - original_dict.Set(ASCIIToUTF16("bool"), original_bool); + original_dict.Set(L"bool", original_bool); Value* original_int = Value::CreateIntegerValue(42); - original_dict.Set(ASCIIToUTF16("int"), original_int); + original_dict.Set(L"int", original_int); Value* original_real = Value::CreateRealValue(3.14); - original_dict.Set(ASCIIToUTF16("real"), original_real); + original_dict.Set(L"real", original_real); Value* original_string = Value::CreateStringValue("hello"); - original_dict.Set(ASCIIToUTF16("string"), original_string); + original_dict.Set(L"string", original_string); Value* original_wstring = Value::CreateStringValue(L"peek-a-boo"); - original_dict.Set(ASCIIToUTF16("wstring"), original_wstring); + original_dict.Set(L"wstring", original_wstring); char* original_buffer = new char[42]; memset(original_buffer, '!', 42); BinaryValue* original_binary = Value::CreateBinaryValue(original_buffer, 42); - original_dict.Set(ASCIIToUTF16("binary"), original_binary); + 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(ASCIIToUTF16("list"), original_list); + original_dict.Set(L"list", original_list); DictionaryValue* copy_dict = static_cast<DictionaryValue*>(original_dict.DeepCopy()); @@ -331,13 +325,13 @@ TEST(ValuesTest, DeepCopy) { ASSERT_NE(copy_dict, &original_dict); Value* copy_null = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("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(ASCIIToUTF16("bool"), ©_bool)); + 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)); @@ -346,7 +340,7 @@ TEST(ValuesTest, DeepCopy) { ASSERT_TRUE(copy_bool_value); Value* copy_int = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("int"), ©_int)); + 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)); @@ -355,7 +349,7 @@ TEST(ValuesTest, DeepCopy) { ASSERT_EQ(42, copy_int_value); Value* copy_real = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("real"), ©_real)); + 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)); @@ -364,7 +358,7 @@ TEST(ValuesTest, DeepCopy) { ASSERT_EQ(3.14, copy_real_value); Value* copy_string = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("string"), ©_string)); + 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)); @@ -376,7 +370,7 @@ TEST(ValuesTest, DeepCopy) { ASSERT_EQ(std::wstring(L"hello"), copy_wstring_value); Value* copy_wstring = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("wstring"), ©_wstring)); + ASSERT_TRUE(copy_dict->Get(L"wstring", ©_wstring)); ASSERT_TRUE(copy_wstring); ASSERT_NE(copy_wstring, original_wstring); ASSERT_TRUE(copy_wstring->IsType(Value::TYPE_STRING)); @@ -386,7 +380,7 @@ TEST(ValuesTest, DeepCopy) { ASSERT_EQ(std::wstring(L"peek-a-boo"), copy_wstring_value); Value* copy_binary = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("binary"), ©_binary)); + 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)); @@ -399,7 +393,7 @@ TEST(ValuesTest, DeepCopy) { original_binary->GetSize())); Value* copy_value = NULL; - ASSERT_TRUE(copy_dict->Get(ASCIIToUTF16("list"), ©_value)); + 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)); @@ -438,12 +432,12 @@ TEST(ValuesTest, Equals) { delete boolean; DictionaryValue dv; - dv.SetBoolean(ASCIIToUTF16("a"), false); - dv.SetInteger(ASCIIToUTF16("b"), 2); - dv.SetReal(ASCIIToUTF16("c"), 2.5); - dv.SetString(ASCIIToUTF16("d1"), "string"); - dv.SetString(ASCIIToUTF16("d2"), ASCIIToUTF16("string")); - dv.Set(ASCIIToUTF16("e"), Value::CreateNullValue()); + 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)); @@ -451,13 +445,14 @@ TEST(ValuesTest, Equals) { ListValue* list = new ListValue; list->Append(Value::CreateNullValue()); list->Append(new DictionaryValue); - dv.Set(ASCIIToUTF16("f"), list); + dv.Set(L"f", list); EXPECT_FALSE(dv.Equals(copy)); - copy->Set(ASCIIToUTF16("f"), list->DeepCopy()); + copy->Set(L"f", list->DeepCopy()); EXPECT_TRUE(dv.Equals(copy)); list->Append(Value::CreateBooleanValue(true)); EXPECT_FALSE(dv.Equals(copy)); delete copy; } + |