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

Side by Side Diff: base/json/string_escape_unittest.cc

Issue 1132063004: Fix JSONStringEscapeTest.EscapeBytes on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/json/string_escape.h" 5 #include "base/json/string_escape.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EXPECT_EQ("?\xEF\xBF\xBD@", actual); 152 EXPECT_EQ("?\xEF\xBF\xBD@", actual);
153 } 153 }
154 } 154 }
155 155
156 TEST(JSONStringEscapeTest, EscapeBytes) { 156 TEST(JSONStringEscapeTest, EscapeBytes) {
157 const struct { 157 const struct {
158 const char* to_escape; 158 const char* to_escape;
159 const char* escaped; 159 const char* escaped;
160 } cases[] = { 160 } cases[] = {
161 {"b\x0f\x7f\xf0\xff!", "b\\u000F\\u007F\\u00F0\\u00FF!"}, 161 {"b\x0f\x7f\xf0\xff!", "b\\u000F\\u007F\\u00F0\\u00FF!"},
162 {"\xe5\xc4\x4f\x05\xb6\xfd\0", "\\u00E5\\u00C4O\\u0005\\u00B6\\u00FD"}, 162 {"\xe5\xc4\x4f\x05\xb6\xfd", "\\u00E5\\u00C4O\\u0005\\u00B6\\u00FD"},
163 }; 163 };
164 164
165 for (size_t i = 0; i < arraysize(cases); ++i) { 165 for (size_t i = 0; i < arraysize(cases); ++i) {
166 std::string in = std::string(cases[i].to_escape); 166 std::string in = std::string(cases[i].to_escape);
167 EXPECT_FALSE(IsStringUTF8(in)); 167 EXPECT_FALSE(IsStringUTF8(in));
168 168
169 EXPECT_EQ(std::string(cases[i].escaped), 169 EXPECT_EQ(std::string(cases[i].escaped),
170 EscapeBytesAsInvalidJSONString(in, false)); 170 EscapeBytesAsInvalidJSONString(in, false));
171 EXPECT_EQ("\"" + std::string(cases[i].escaped) + "\"", 171 EXPECT_EQ("\"" + std::string(cases[i].escaped) + "\"",
172 EscapeBytesAsInvalidJSONString(in, true)); 172 EscapeBytesAsInvalidJSONString(in, true));
173 } 173 }
174 174
175 const char kEmbedNull[] = { '\xab', '\x39', '\0', '\x9f', '\xab' }; 175 const char kEmbedNull[] = { '\xab', '\x39', '\0', '\x9f', '\xab' };
176 std::string in(kEmbedNull, arraysize(kEmbedNull)); 176 std::string in(kEmbedNull, arraysize(kEmbedNull));
177 EXPECT_FALSE(IsStringUTF8(in)); 177 EXPECT_FALSE(IsStringUTF8(in));
178 EXPECT_EQ(std::string("\\u00AB9\\u0000\\u009F\\u00AB"), 178 EXPECT_EQ(std::string("\\u00AB9\\u0000\\u009F\\u00AB"),
179 EscapeBytesAsInvalidJSONString(in, false)); 179 EscapeBytesAsInvalidJSONString(in, false));
180 } 180 }
181 181
182 } // namespace base 182 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698