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

Side by Side Diff: base/i18n/rtl_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/i18n/number_formatting_unittest.cc ('k') | base/json/string_escape_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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/i18n/rtl.h" 5 #include "base/i18n/rtl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 #if defined(WCHAR_T_IS_UTF32) 89 #if defined(WCHAR_T_IS_UTF32)
90 L" ! \x10401" L"abc 123", 90 L" ! \x10401" L"abc 123",
91 #elif defined(WCHAR_T_IS_UTF16) 91 #elif defined(WCHAR_T_IS_UTF16)
92 L" ! \xd801\xdc01" L"abc 123", 92 L" ! \xd801\xdc01" L"abc 123",
93 #else 93 #else
94 #error wchar_t should be either UTF-16 or UTF-32 94 #error wchar_t should be either UTF-16 or UTF-32
95 #endif 95 #endif
96 LEFT_TO_RIGHT }, 96 LEFT_TO_RIGHT },
97 }; 97 };
98 98
99 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) 99 for (size_t i = 0; i < arraysize(cases); ++i)
100 EXPECT_EQ(cases[i].direction, 100 EXPECT_EQ(cases[i].direction,
101 GetFirstStrongCharacterDirection(WideToUTF16(cases[i].text))); 101 GetFirstStrongCharacterDirection(WideToUTF16(cases[i].text)));
102 } 102 }
103 103
104 104
105 // Note that the cases with LRE, LRO, RLE and RLO are invalid for 105 // Note that the cases with LRE, LRO, RLE and RLO are invalid for
106 // GetLastStrongCharacterDirection because they should be followed by PDF 106 // GetLastStrongCharacterDirection because they should be followed by PDF
107 // character. 107 // character.
108 TEST_F(RTLTest, GetLastStrongCharacterDirection) { 108 TEST_F(RTLTest, GetLastStrongCharacterDirection) {
109 struct { 109 struct {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 #if defined(WCHAR_T_IS_UTF32) 151 #if defined(WCHAR_T_IS_UTF32)
152 L"abc 123" L" ! \x10401 !", 152 L"abc 123" L" ! \x10401 !",
153 #elif defined(WCHAR_T_IS_UTF16) 153 #elif defined(WCHAR_T_IS_UTF16)
154 L"abc 123" L" ! \xd801\xdc01 !", 154 L"abc 123" L" ! \xd801\xdc01 !",
155 #else 155 #else
156 #error wchar_t should be either UTF-16 or UTF-32 156 #error wchar_t should be either UTF-16 or UTF-32
157 #endif 157 #endif
158 LEFT_TO_RIGHT }, 158 LEFT_TO_RIGHT },
159 }; 159 };
160 160
161 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) 161 for (size_t i = 0; i < arraysize(cases); ++i)
162 EXPECT_EQ(cases[i].direction, 162 EXPECT_EQ(cases[i].direction,
163 GetLastStrongCharacterDirection(WideToUTF16(cases[i].text))); 163 GetLastStrongCharacterDirection(WideToUTF16(cases[i].text)));
164 } 164 }
165 165
166 TEST_F(RTLTest, GetStringDirection) { 166 TEST_F(RTLTest, GetStringDirection) {
167 struct { 167 struct {
168 const wchar_t* text; 168 const wchar_t* text;
169 TextDirection direction; 169 TextDirection direction;
170 } cases[] = { 170 } cases[] = {
171 // Test pure LTR string. 171 // Test pure LTR string.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 #if defined(WCHAR_T_IS_UTF32) 229 #if defined(WCHAR_T_IS_UTF32)
230 L" ! \x10401" L"abc 123", 230 L" ! \x10401" L"abc 123",
231 #elif defined(WCHAR_T_IS_UTF16) 231 #elif defined(WCHAR_T_IS_UTF16)
232 L" ! \xd801\xdc01" L"abc 123", 232 L" ! \xd801\xdc01" L"abc 123",
233 #else 233 #else
234 #error wchar_t should be either UTF-16 or UTF-32 234 #error wchar_t should be either UTF-16 or UTF-32
235 #endif 235 #endif
236 LEFT_TO_RIGHT }, 236 LEFT_TO_RIGHT },
237 }; 237 };
238 238
239 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) 239 for (size_t i = 0; i < arraysize(cases); ++i)
240 EXPECT_EQ(cases[i].direction, 240 EXPECT_EQ(cases[i].direction,
241 GetStringDirection(WideToUTF16(cases[i].text))); 241 GetStringDirection(WideToUTF16(cases[i].text)));
242 } 242 }
243 243
244 TEST_F(RTLTest, WrapPathWithLTRFormatting) { 244 TEST_F(RTLTest, WrapPathWithLTRFormatting) {
245 const wchar_t* cases[] = { 245 const wchar_t* cases[] = {
246 // Test common path, such as "c:\foo\bar". 246 // Test common path, such as "c:\foo\bar".
247 L"c:/foo/bar", 247 L"c:/foo/bar",
248 // Test path with file name, such as "c:\foo\bar\test.jpg". 248 // Test path with file name, such as "c:\foo\bar\test.jpg".
249 L"c:/foo/bar/test.jpg", 249 L"c:/foo/bar/test.jpg",
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 { L"\x05d0" L"abc.txt", true, true }, 348 { L"\x05d0" L"abc.txt", true, true },
349 { L"abc\x05d0\x05d1", false, true }, 349 { L"abc\x05d0\x05d1", false, true },
350 { L"abc\x05d0\x05d1.jpg", false, true }, 350 { L"abc\x05d0\x05d1.jpg", false, true },
351 }; 351 };
352 352
353 const bool was_rtl = IsRTL(); 353 const bool was_rtl = IsRTL();
354 354
355 for (size_t i = 0; i < 2; ++i) { 355 for (size_t i = 0; i < 2; ++i) {
356 // Toggle the application default text direction (to try each direction). 356 // Toggle the application default text direction (to try each direction).
357 SetRTL(!IsRTL()); 357 SetRTL(!IsRTL());
358 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 358 for (size_t i = 0; i < arraysize(cases); ++i) {
359 string16 input = WideToUTF16(cases[i].path); 359 string16 input = WideToUTF16(cases[i].path);
360 string16 output = GetDisplayStringInLTRDirectionality(input); 360 string16 output = GetDisplayStringInLTRDirectionality(input);
361 // Test the expected wrapping behavior for the current UI directionality. 361 // Test the expected wrapping behavior for the current UI directionality.
362 if (IsRTL() ? cases[i].wrap_rtl : cases[i].wrap_ltr) 362 if (IsRTL() ? cases[i].wrap_rtl : cases[i].wrap_ltr)
363 EXPECT_NE(output, input); 363 EXPECT_NE(output, input);
364 else 364 else
365 EXPECT_EQ(output, input); 365 EXPECT_EQ(output, input);
366 } 366 }
367 } 367 }
368 368
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 EXPECT_EQ(test_case, adjusted_string) << " for test case [" << test_case 432 EXPECT_EQ(test_case, adjusted_string) << " for test case [" << test_case
433 << "] with IsRTL() == " << IsRTL(); 433 << "] with IsRTL() == " << IsRTL();
434 } 434 }
435 } 435 }
436 436
437 EXPECT_EQ(was_rtl, IsRTL()); 437 EXPECT_EQ(was_rtl, IsRTL());
438 } 438 }
439 439
440 } // namespace i18n 440 } // namespace i18n
441 } // namespace base 441 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/number_formatting_unittest.cc ('k') | base/json/string_escape_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698