| OLD | NEW |
| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "third_party/icu/source/common/unicode/ucnv.h" | 7 #include "third_party/icu/source/common/unicode/ucnv.h" |
| 8 #include "url/url_canon.h" | 8 #include "url/url_canon.h" |
| 9 #include "url/url_canon_icu.h" | 9 #include "url/url_canon_icu.h" |
| 10 #include "url/url_canon_stdstring.h" | 10 #include "url/url_canon_stdstring.h" |
| 11 #include "url/url_test_utils.h" | 11 #include "url/url_test_utils.h" |
| 12 | 12 |
| 13 // Some implementations of base/basictypes.h may define ARRAYSIZE. | |
| 14 // If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro | |
| 15 // which is in our version of basictypes.h. | |
| 16 #ifndef ARRAYSIZE | |
| 17 #define ARRAYSIZE ARRAYSIZE_UNSAFE | |
| 18 #endif | |
| 19 | |
| 20 namespace url { | 13 namespace url { |
| 21 | 14 |
| 22 using test_utils::WStringToUTF16; | 15 using test_utils::WStringToUTF16; |
| 23 | 16 |
| 24 namespace { | 17 namespace { |
| 25 | 18 |
| 26 // Wrapper around a UConverter object that managers creation and destruction. | 19 // Wrapper around a UConverter object that managers creation and destruction. |
| 27 class UConvScoper { | 20 class UConvScoper { |
| 28 public: | 21 public: |
| 29 explicit UConvScoper(const char* charset_name) { | 22 explicit UConvScoper(const char* charset_name) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 {L"\x4f60\x597d", "utf-8", "\xe4\xbd\xa0\xe5\xa5\xbd"}, | 47 {L"\x4f60\x597d", "utf-8", "\xe4\xbd\xa0\xe5\xa5\xbd"}, |
| 55 // Non-BMP UTF-8. | 48 // Non-BMP UTF-8. |
| 56 {L"!\xd800\xdf00!", "utf-8", "!\xf0\x90\x8c\x80!"}, | 49 {L"!\xd800\xdf00!", "utf-8", "!\xf0\x90\x8c\x80!"}, |
| 57 // Big5 | 50 // Big5 |
| 58 {L"\x4f60\x597d", "big5", "\xa7\x41\xa6\x6e"}, | 51 {L"\x4f60\x597d", "big5", "\xa7\x41\xa6\x6e"}, |
| 59 // Unrepresentable character in the destination set. | 52 // Unrepresentable character in the destination set. |
| 60 {L"hello\x4f60\x06de\x597dworld", "big5", | 53 {L"hello\x4f60\x06de\x597dworld", "big5", |
| 61 "hello\xa7\x41%26%231758%3B\xa6\x6eworld"}, | 54 "hello\xa7\x41%26%231758%3B\xa6\x6eworld"}, |
| 62 }; | 55 }; |
| 63 | 56 |
| 64 for (size_t i = 0; i < ARRAYSIZE(icu_cases); i++) { | 57 for (size_t i = 0; i < arraysize(icu_cases); i++) { |
| 65 UConvScoper conv(icu_cases[i].encoding); | 58 UConvScoper conv(icu_cases[i].encoding); |
| 66 ASSERT_TRUE(conv.converter() != NULL); | 59 ASSERT_TRUE(conv.converter() != NULL); |
| 67 ICUCharsetConverter converter(conv.converter()); | 60 ICUCharsetConverter converter(conv.converter()); |
| 68 | 61 |
| 69 std::string str; | 62 std::string str; |
| 70 StdStringCanonOutput output(&str); | 63 StdStringCanonOutput output(&str); |
| 71 | 64 |
| 72 base::string16 input_str(WStringToUTF16(icu_cases[i].input)); | 65 base::string16 input_str(WStringToUTF16(icu_cases[i].input)); |
| 73 int input_len = static_cast<int>(input_str.length()); | 66 int input_len = static_cast<int>(input_str.length()); |
| 74 converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); | 67 converter.ConvertFromUTF16(input_str.c_str(), input_len, &output); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "gb2312", | 104 {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "gb2312", |
| 112 "?q=%C4%E3%BA%C3"}, | 105 "?q=%C4%E3%BA%C3"}, |
| 113 {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "big5", "?q=%A7A%A6n"}, | 106 {"q=\xe4\xbd\xa0\xe5\xa5\xbd", L"q=\x4f60\x597d", "big5", "?q=%A7A%A6n"}, |
| 114 // Unencodable character in the destination character set should be | 107 // Unencodable character in the destination character set should be |
| 115 // escaped. The escape sequence unescapes to be the entity name: | 108 // escaped. The escape sequence unescapes to be the entity name: |
| 116 // "?q=你" | 109 // "?q=你" |
| 117 {"q=Chinese\xef\xbc\xa7", L"q=Chinese\xff27", "iso-8859-1", | 110 {"q=Chinese\xef\xbc\xa7", L"q=Chinese\xff27", "iso-8859-1", |
| 118 "?q=Chinese%26%2365319%3B"}, | 111 "?q=Chinese%26%2365319%3B"}, |
| 119 }; | 112 }; |
| 120 | 113 |
| 121 for (size_t i = 0; i < ARRAYSIZE(query_cases); i++) { | 114 for (size_t i = 0; i < arraysize(query_cases); i++) { |
| 122 Component out_comp; | 115 Component out_comp; |
| 123 | 116 |
| 124 UConvScoper conv(query_cases[i].encoding); | 117 UConvScoper conv(query_cases[i].encoding); |
| 125 ASSERT_TRUE(!query_cases[i].encoding || conv.converter()); | 118 ASSERT_TRUE(!query_cases[i].encoding || conv.converter()); |
| 126 ICUCharsetConverter converter(conv.converter()); | 119 ICUCharsetConverter converter(conv.converter()); |
| 127 | 120 |
| 128 if (query_cases[i].input8) { | 121 if (query_cases[i].input8) { |
| 129 int len = static_cast<int>(strlen(query_cases[i].input8)); | 122 int len = static_cast<int>(strlen(query_cases[i].input8)); |
| 130 Component in_comp(0, len); | 123 Component in_comp(0, len); |
| 131 std::string out_str; | 124 std::string out_str; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 158 StdStringCanonOutput output(&out_str); | 151 StdStringCanonOutput output(&out_str); |
| 159 Component out_comp; | 152 Component out_comp; |
| 160 CanonicalizeQuery("a \x00z\x01", Component(0, 5), NULL, &output, &out_comp); | 153 CanonicalizeQuery("a \x00z\x01", Component(0, 5), NULL, &output, &out_comp); |
| 161 output.Complete(); | 154 output.Complete(); |
| 162 EXPECT_EQ("?a%20%00z%01", out_str); | 155 EXPECT_EQ("?a%20%00z%01", out_str); |
| 163 } | 156 } |
| 164 | 157 |
| 165 } // namespace | 158 } // namespace |
| 166 | 159 |
| 167 } // namespace url | 160 } // namespace url |
| OLD | NEW |