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

Side by Side Diff: url/url_canon_icu_unittest.cc

Issue 2469133002: Clean up URL test string conversions. (Closed)
Patch Set: More Created 4 years, 1 month 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 | « url/gurl_unittest.cc ('k') | url/url_canon_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/icu/source/common/unicode/ucnv.h" 9 #include "third_party/icu/source/common/unicode/ucnv.h"
10 #include "url/url_canon.h" 10 #include "url/url_canon.h"
11 #include "url/url_canon_icu.h" 11 #include "url/url_canon_icu.h"
12 #include "url/url_canon_stdstring.h" 12 #include "url/url_canon_stdstring.h"
13 #include "url/url_test_utils.h" 13 #include "url/url_test_utils.h"
14 14
15 namespace url { 15 namespace url {
16 16
17 using test_utils::WStringToUTF16;
18
19 namespace { 17 namespace {
20 18
21 // Wrapper around a UConverter object that managers creation and destruction. 19 // Wrapper around a UConverter object that managers creation and destruction.
22 class UConvScoper { 20 class UConvScoper {
23 public: 21 public:
24 explicit UConvScoper(const char* charset_name) { 22 explicit UConvScoper(const char* charset_name) {
25 UErrorCode err = U_ZERO_ERROR; 23 UErrorCode err = U_ZERO_ERROR;
26 converter_ = ucnv_open(charset_name, &err); 24 converter_ = ucnv_open(charset_name, &err);
27 } 25 }
28 26
(...skipping 28 matching lines...) Expand all
57 }; 55 };
58 56
59 for (size_t i = 0; i < arraysize(icu_cases); i++) { 57 for (size_t i = 0; i < arraysize(icu_cases); i++) {
60 UConvScoper conv(icu_cases[i].encoding); 58 UConvScoper conv(icu_cases[i].encoding);
61 ASSERT_TRUE(conv.converter() != NULL); 59 ASSERT_TRUE(conv.converter() != NULL);
62 ICUCharsetConverter converter(conv.converter()); 60 ICUCharsetConverter converter(conv.converter());
63 61
64 std::string str; 62 std::string str;
65 StdStringCanonOutput output(&str); 63 StdStringCanonOutput output(&str);
66 64
67 base::string16 input_str(WStringToUTF16(icu_cases[i].input)); 65 base::string16 input_str(
66 test_utils::TruncateWStringToUTF16(icu_cases[i].input));
68 int input_len = static_cast<int>(input_str.length()); 67 int input_len = static_cast<int>(input_str.length());
69 converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); 68 converter.ConvertFromUTF16(input_str.c_str(), input_len, &output);
70 output.Complete(); 69 output.Complete();
71 70
72 EXPECT_STREQ(icu_cases[i].expected, str.c_str()); 71 EXPECT_STREQ(icu_cases[i].expected, str.c_str());
73 } 72 }
74 73
75 // Test string sizes around the resize boundary for the output to make sure 74 // Test string sizes around the resize boundary for the output to make sure
76 // the converter resizes as needed. 75 // the converter resizes as needed.
77 const int static_size = 16; 76 const int static_size = 16;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 126
128 StdStringCanonOutput output(&out_str); 127 StdStringCanonOutput output(&out_str);
129 CanonicalizeQuery(query_cases[i].input8, in_comp, &converter, &output, 128 CanonicalizeQuery(query_cases[i].input8, in_comp, &converter, &output,
130 &out_comp); 129 &out_comp);
131 output.Complete(); 130 output.Complete();
132 131
133 EXPECT_EQ(query_cases[i].expected, out_str); 132 EXPECT_EQ(query_cases[i].expected, out_str);
134 } 133 }
135 134
136 if (query_cases[i].input16) { 135 if (query_cases[i].input16) {
137 base::string16 input16(WStringToUTF16(query_cases[i].input16)); 136 base::string16 input16(
137 test_utils::TruncateWStringToUTF16(query_cases[i].input16));
138 int len = static_cast<int>(input16.length()); 138 int len = static_cast<int>(input16.length());
139 Component in_comp(0, len); 139 Component in_comp(0, len);
140 std::string out_str; 140 std::string out_str;
141 141
142 StdStringCanonOutput output(&out_str); 142 StdStringCanonOutput output(&out_str);
143 CanonicalizeQuery(input16.c_str(), in_comp, &converter, &output, 143 CanonicalizeQuery(input16.c_str(), in_comp, &converter, &output,
144 &out_comp); 144 &out_comp);
145 output.Complete(); 145 output.Complete();
146 146
147 EXPECT_EQ(query_cases[i].expected, out_str); 147 EXPECT_EQ(query_cases[i].expected, out_str);
148 } 148 }
149 } 149 }
150 150
151 // Extra test for input with embedded NULL; 151 // Extra test for input with embedded NULL;
152 std::string out_str; 152 std::string out_str;
153 StdStringCanonOutput output(&out_str); 153 StdStringCanonOutput output(&out_str);
154 Component out_comp; 154 Component out_comp;
155 CanonicalizeQuery("a \x00z\x01", Component(0, 5), NULL, &output, &out_comp); 155 CanonicalizeQuery("a \x00z\x01", Component(0, 5), NULL, &output, &out_comp);
156 output.Complete(); 156 output.Complete();
157 EXPECT_EQ("?a%20%00z%01", out_str); 157 EXPECT_EQ("?a%20%00z%01", out_str);
158 } 158 }
159 159
160 } // namespace 160 } // namespace
161 161
162 } // namespace url 162 } // namespace url
OLDNEW
« no previous file with comments | « url/gurl_unittest.cc ('k') | url/url_canon_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698