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

Side by Side Diff: chrome/common/json_value_serializer_unittest.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 // Test JSONValueSerializer interface (uses JSONWriter). 116 // Test JSONValueSerializer interface (uses JSONWriter).
117 JSONStringValueSerializer serializer(&output_js); 117 JSONStringValueSerializer serializer(&output_js);
118 ASSERT_TRUE(serializer.Serialize(valueRoot)); 118 ASSERT_TRUE(serializer.Serialize(valueRoot));
119 ASSERT_EQ(expected_output, output_js); 119 ASSERT_EQ(expected_output, output_js);
120 } 120 }
121 121
122 TEST(JSONValueSerializerTest, UnicodeStrings) { 122 TEST(JSONValueSerializerTest, UnicodeStrings) {
123 // unicode string json -> escaped ascii text 123 // unicode string json -> escaped ascii text
124 DictionaryValue root; 124 DictionaryValue root;
125 string16 test(WideToUTF16(L"\x7F51\x9875")); 125 string16 test(base::WideToUTF16(L"\x7F51\x9875"));
126 root.SetString("web", test); 126 root.SetString("web", test);
127 127
128 std::string expected = "{\"web\":\"\\u7F51\\u9875\"}"; 128 std::string expected = "{\"web\":\"\\u7F51\\u9875\"}";
129 129
130 std::string actual; 130 std::string actual;
131 JSONStringValueSerializer serializer(&actual); 131 JSONStringValueSerializer serializer(&actual);
132 ASSERT_TRUE(serializer.Serialize(root)); 132 ASSERT_TRUE(serializer.Serialize(root));
133 ASSERT_EQ(expected, actual); 133 ASSERT_EQ(expected, actual);
134 134
135 // escaped ascii text -> json 135 // escaped ascii text -> json
136 JSONStringValueSerializer deserializer(expected); 136 JSONStringValueSerializer deserializer(expected);
137 scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL, NULL)); 137 scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL, NULL));
138 ASSERT_TRUE(deserial_root.get()); 138 ASSERT_TRUE(deserial_root.get());
139 DictionaryValue* dict_root = 139 DictionaryValue* dict_root =
140 static_cast<DictionaryValue*>(deserial_root.get()); 140 static_cast<DictionaryValue*>(deserial_root.get());
141 string16 web_value; 141 string16 web_value;
142 ASSERT_TRUE(dict_root->GetString("web", &web_value)); 142 ASSERT_TRUE(dict_root->GetString("web", &web_value));
143 ASSERT_EQ(test, web_value); 143 ASSERT_EQ(test, web_value);
144 } 144 }
145 145
146 TEST(JSONValueSerializerTest, HexStrings) { 146 TEST(JSONValueSerializerTest, HexStrings) {
147 // hex string json -> escaped ascii text 147 // hex string json -> escaped ascii text
148 DictionaryValue root; 148 DictionaryValue root;
149 string16 test(WideToUTF16(L"\x01\x02")); 149 string16 test(base::WideToUTF16(L"\x01\x02"));
150 root.SetString("test", test); 150 root.SetString("test", test);
151 151
152 std::string expected = "{\"test\":\"\\u0001\\u0002\"}"; 152 std::string expected = "{\"test\":\"\\u0001\\u0002\"}";
153 153
154 std::string actual; 154 std::string actual;
155 JSONStringValueSerializer serializer(&actual); 155 JSONStringValueSerializer serializer(&actual);
156 ASSERT_TRUE(serializer.Serialize(root)); 156 ASSERT_TRUE(serializer.Serialize(root));
157 ASSERT_EQ(expected, actual); 157 ASSERT_EQ(expected, actual);
158 158
159 // escaped ascii text -> json 159 // escaped ascii text -> json
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 base::FilePath source_file_path; 330 base::FilePath source_file_path;
331 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_file_path)); 331 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_file_path));
332 source_file_path = source_file_path.Append( 332 source_file_path = source_file_path.Append(
333 FILE_PATH_LITERAL("serializer_test_nowhitespace.js")); 333 FILE_PATH_LITERAL("serializer_test_nowhitespace.js"));
334 ASSERT_TRUE(file_util::PathExists(source_file_path)); 334 ASSERT_TRUE(file_util::PathExists(source_file_path));
335 JSONFileValueSerializer serializer(source_file_path); 335 JSONFileValueSerializer serializer(source_file_path);
336 scoped_ptr<Value> root; 336 scoped_ptr<Value> root;
337 root.reset(serializer.Deserialize(NULL, NULL)); 337 root.reset(serializer.Deserialize(NULL, NULL));
338 ASSERT_TRUE(root.get()); 338 ASSERT_TRUE(root.get());
339 } 339 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_tests/extension_manifests_initvalue_unittest.cc ('k') | chrome/common/logging_chrome.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698