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

Side by Side Diff: base/strings/utf_string_conversions_unittest.cc

Issue 656033009: Convert ARRAYSIZE_UNSAFE -> arraysize in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/strings/utf_offset_string_conversions_unittest.cc ('k') | base/sync_socket_win.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 (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
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
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
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
OLDNEW
« no previous file with comments | « base/strings/utf_offset_string_conversions_unittest.cc ('k') | base/sync_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698