OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 6 #include "base/logging.h" |
7 #include "base/strings/string_piece.h" | 7 #include "base/strings/string_piece.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // The result will either be in UTF-16 or UTF-32. | 87 // The result will either be in UTF-16 or UTF-32. |
88 #if defined(WCHAR_T_IS_UTF16) | 88 #if defined(WCHAR_T_IS_UTF16) |
89 {"A\xF0\x90\x8C\x80z", L"A\xd800\xdf00z", true}, | 89 {"A\xF0\x90\x8C\x80z", L"A\xd800\xdf00z", true}, |
90 {"A\xF4\x8F\xBF\xBEz", L"A\xdbff\xdffez", true}, | 90 {"A\xF4\x8F\xBF\xBEz", L"A\xdbff\xdffez", true}, |
91 #elif defined(WCHAR_T_IS_UTF32) | 91 #elif defined(WCHAR_T_IS_UTF32) |
92 {"A\xF0\x90\x8C\x80z", L"A\x10300z", true}, | 92 {"A\xF0\x90\x8C\x80z", L"A\x10300z", true}, |
93 {"A\xF4\x8F\xBF\xBEz", L"A\x10fffez", true}, | 93 {"A\xF4\x8F\xBF\xBEz", L"A\x10fffez", true}, |
94 #endif | 94 #endif |
95 }; | 95 }; |
96 | 96 |
97 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(convert_cases); i++) { | 97 for (size_t i = 0; i < arraysize(convert_cases); i++) { |
98 std::wstring converted; | 98 std::wstring converted; |
99 EXPECT_EQ(convert_cases[i].success, | 99 EXPECT_EQ(convert_cases[i].success, |
100 UTF8ToWide(convert_cases[i].utf8, | 100 UTF8ToWide(convert_cases[i].utf8, |
101 strlen(convert_cases[i].utf8), | 101 strlen(convert_cases[i].utf8), |
102 &converted)); | 102 &converted)); |
103 std::wstring expected(convert_cases[i].wide); | 103 std::wstring expected(convert_cases[i].wide); |
104 EXPECT_EQ(expected, converted); | 104 EXPECT_EQ(expected, converted); |
105 } | 105 } |
106 | 106 |
107 // Manually test an embedded NULL. | 107 // Manually test an embedded NULL. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Non-characters are passed through. | 165 // Non-characters are passed through. |
166 {L"\xffffHello", "\xEF\xBF\xBFHello", true}, | 166 {L"\xffffHello", "\xEF\xBF\xBFHello", true}, |
167 {L"\x10fffeHello", "\xF4\x8F\xBF\xBEHello", true}, | 167 {L"\x10fffeHello", "\xF4\x8F\xBF\xBEHello", true}, |
168 // Invalid Unicode code points. | 168 // Invalid Unicode code points. |
169 {L"\xfffffffHello", "\xEF\xBF\xBDHello", false}, | 169 {L"\xfffffffHello", "\xEF\xBF\xBDHello", false}, |
170 // The first character is a truncated UTF-16 character. | 170 // The first character is a truncated UTF-16 character. |
171 {L"\xd800\x597d", "\xef\xbf\xbd\xe5\xa5\xbd", false}, | 171 {L"\xd800\x597d", "\xef\xbf\xbd\xe5\xa5\xbd", false}, |
172 {L"\xdc01Hello", "\xef\xbf\xbdHello", false}, | 172 {L"\xdc01Hello", "\xef\xbf\xbdHello", false}, |
173 }; | 173 }; |
174 | 174 |
175 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(convert_cases); i++) { | 175 for (size_t i = 0; i < arraysize(convert_cases); i++) { |
176 std::string converted; | 176 std::string converted; |
177 EXPECT_EQ(convert_cases[i].success, | 177 EXPECT_EQ(convert_cases[i].success, |
178 WideToUTF8(convert_cases[i].utf32, | 178 WideToUTF8(convert_cases[i].utf32, |
179 wcslen(convert_cases[i].utf32), | 179 wcslen(convert_cases[i].utf32), |
180 &converted)); | 180 &converted)); |
181 std::string expected(convert_cases[i].utf8); | 181 std::string expected(convert_cases[i].utf8); |
182 EXPECT_EQ(expected, converted); | 182 EXPECT_EQ(expected, converted); |
183 } | 183 } |
184 } | 184 } |
185 #endif // defined(WCHAR_T_IS_UTF32) | 185 #endif // defined(WCHAR_T_IS_UTF32) |
(...skipping 16 matching lines...) Expand all Loading... |
202 EXPECT_EQ(arraysize(wmulti) - 1, wmultistring.length()); | 202 EXPECT_EQ(arraysize(wmulti) - 1, wmultistring.length()); |
203 std::string expected; | 203 std::string expected; |
204 memcpy(WriteInto(&expected, arraysize(multi)), multi, sizeof(multi)); | 204 memcpy(WriteInto(&expected, arraysize(multi)), multi, sizeof(multi)); |
205 EXPECT_EQ(arraysize(multi) - 1, expected.length()); | 205 EXPECT_EQ(arraysize(multi) - 1, expected.length()); |
206 const std::string& converted = WideToUTF8(wmultistring); | 206 const std::string& converted = WideToUTF8(wmultistring); |
207 EXPECT_EQ(arraysize(multi) - 1, converted.length()); | 207 EXPECT_EQ(arraysize(multi) - 1, converted.length()); |
208 EXPECT_EQ(expected, converted); | 208 EXPECT_EQ(expected, converted); |
209 } | 209 } |
210 | 210 |
211 } // base | 211 } // base |
OLD | NEW |