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

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

Issue 18648003: Let JsonDoubleQuote accept StringPiece (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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 | « base/json/string_escape.cc ('k') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 namespace { 11 namespace {
12 12
13 const struct json_narrow_test_data { 13 const struct json_narrow_test_data {
14 const char* to_escape; 14 const char* to_escape;
15 const char* escaped; 15 const char* escaped;
16 } json_narrow_cases[] = { 16 } json_narrow_cases[] = {
17 {"\b\001aZ\"\\wee", "\\b\\u0001aZ\\\"\\\\wee"}, 17 {"\b\001aZ\"\\wee", "\\b\\u0001aZ\\\"\\\\wee"},
18 {"a\b\f\n\r\t\v\1\\.\"z", 18 {"a\b\f\n\r\t\v\1\\.\"z",
19 "a\\b\\f\\n\\r\\t\\u000B\\u0001\\\\.\\\"z"}, 19 "a\\b\\f\\n\\r\\t\\u000B\\u0001\\\\.\\\"z"},
20 {"b\x0f\x7f\xf0\xff!", "b\\u000F\\u007F\\u00F0\\u00FF!"}, 20 {"b\x0f\x7f\xf0\xff!", "b\\u000F\\u007F\\u00F0\\u00FF!"},
21 {"c<>d", "c\\u003C\\u003Ed"}, 21 {"c<>d", "c\\u003C\\u003Ed"},
22 }; 22 };
23 23
24 } // namespace 24 } // namespace
25 25
26 TEST(StringEscapeTest, JsonDoubleQuoteNarrow) { 26 TEST(StringEscapeTest, JsonDoubleQuoteNarrow) {
27 for (size_t i = 0; i < arraysize(json_narrow_cases); ++i) { 27 for (size_t i = 0; i < arraysize(json_narrow_cases); ++i) {
28 std::string in = json_narrow_cases[i].to_escape; 28 const char* in_ptr = json_narrow_cases[i].to_escape;
29 std::string in_str = in_ptr;
29 std::string out; 30 std::string out;
30 JsonDoubleQuote(in, false, &out); 31 JsonDoubleQuote(in_ptr, false, &out);
32 EXPECT_EQ(std::string(json_narrow_cases[i].escaped), out);
33 out.erase();
34 JsonDoubleQuote(in_str, false, &out);
31 EXPECT_EQ(std::string(json_narrow_cases[i].escaped), out); 35 EXPECT_EQ(std::string(json_narrow_cases[i].escaped), out);
32 } 36 }
33 37
34 std::string in = json_narrow_cases[0].to_escape; 38 std::string in = json_narrow_cases[0].to_escape;
35 std::string out; 39 std::string out;
36 JsonDoubleQuote(in, false, &out); 40 JsonDoubleQuote(in, false, &out);
37 41
38 // test quoting 42 // test quoting
39 std::string out_quoted; 43 std::string out_quoted;
40 JsonDoubleQuote(in, true, &out_quoted); 44 JsonDoubleQuote(in, true, &out_quoted);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 null_prepend.push_back(0); 95 null_prepend.push_back(0);
92 in = null_prepend + in; 96 in = null_prepend + in;
93 std::string expected = "test\\u0000"; 97 std::string expected = "test\\u0000";
94 expected += json_wide_cases[0].escaped; 98 expected += json_wide_cases[0].escaped;
95 out.clear(); 99 out.clear();
96 JsonDoubleQuote(in, false, &out); 100 JsonDoubleQuote(in, false, &out);
97 EXPECT_EQ(expected, out); 101 EXPECT_EQ(expected, out);
98 } 102 }
99 103
100 } // namespace base 104 } // namespace base
OLDNEW
« no previous file with comments | « base/json/string_escape.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698