| OLD | NEW |
| 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" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/icu_test_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 15 #include "third_party/icu/source/i18n/unicode/usearch.h" | 16 #include "third_party/icu/source/i18n/unicode/usearch.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 namespace i18n { | 19 namespace i18n { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // A test utility function to set the application default text direction. | 23 // A test utility function to set the application default text direction. |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 L"abc", | 299 L"abc", |
| 299 L"a" L"\x5d0\x5d1", | 300 L"a" L"\x5d0\x5d1", |
| 300 L"a" L"\x5d1" L"b", | 301 L"a" L"\x5d1" L"b", |
| 301 L"\x5d0\x5d1\x5d2", | 302 L"\x5d0\x5d1\x5d2", |
| 302 L"\x5d0\x5d1" L"a", | 303 L"\x5d0\x5d1" L"a", |
| 303 L"\x5d0" L"a" L"\x5d1", | 304 L"\x5d0" L"a" L"\x5d1", |
| 304 }; | 305 }; |
| 305 | 306 |
| 306 const bool was_rtl = IsRTL(); | 307 const bool was_rtl = IsRTL(); |
| 307 | 308 |
| 309 test::ScopedRestoreICUDefaultLocale restore_locale; |
| 308 for (size_t i = 0; i < 2; ++i) { | 310 for (size_t i = 0; i < 2; ++i) { |
| 309 // Toggle the application default text direction (to try each direction). | 311 // Toggle the application default text direction (to try each direction). |
| 310 SetRTL(!IsRTL()); | 312 SetRTL(!IsRTL()); |
| 311 | 313 |
| 312 string16 empty; | 314 string16 empty; |
| 313 WrapStringWithLTRFormatting(&empty); | 315 WrapStringWithLTRFormatting(&empty); |
| 314 EXPECT_TRUE(empty.empty()); | 316 EXPECT_TRUE(empty.empty()); |
| 315 WrapStringWithRTLFormatting(&empty); | 317 WrapStringWithRTLFormatting(&empty); |
| 316 EXPECT_TRUE(empty.empty()); | 318 EXPECT_TRUE(empty.empty()); |
| 317 | 319 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 345 { L"\x05d0\x05d1\x05d2", true, true }, | 347 { L"\x05d0\x05d1\x05d2", true, true }, |
| 346 { L"\x05d0\x05d1\x05d2.txt", true, true }, | 348 { L"\x05d0\x05d1\x05d2.txt", true, true }, |
| 347 { L"\x05d0" L"abc", true, true }, | 349 { L"\x05d0" L"abc", true, true }, |
| 348 { L"\x05d0" L"abc.txt", true, true }, | 350 { L"\x05d0" L"abc.txt", true, true }, |
| 349 { L"abc\x05d0\x05d1", false, true }, | 351 { L"abc\x05d0\x05d1", false, true }, |
| 350 { L"abc\x05d0\x05d1.jpg", false, true }, | 352 { L"abc\x05d0\x05d1.jpg", false, true }, |
| 351 }; | 353 }; |
| 352 | 354 |
| 353 const bool was_rtl = IsRTL(); | 355 const bool was_rtl = IsRTL(); |
| 354 | 356 |
| 357 test::ScopedRestoreICUDefaultLocale restore_locale; |
| 355 for (size_t i = 0; i < 2; ++i) { | 358 for (size_t i = 0; i < 2; ++i) { |
| 356 // Toggle the application default text direction (to try each direction). | 359 // Toggle the application default text direction (to try each direction). |
| 357 SetRTL(!IsRTL()); | 360 SetRTL(!IsRTL()); |
| 358 for (size_t i = 0; i < arraysize(cases); ++i) { | 361 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 359 string16 input = WideToUTF16(cases[i].path); | 362 string16 input = WideToUTF16(cases[i].path); |
| 360 string16 output = GetDisplayStringInLTRDirectionality(input); | 363 string16 output = GetDisplayStringInLTRDirectionality(input); |
| 361 // Test the expected wrapping behavior for the current UI directionality. | 364 // Test the expected wrapping behavior for the current UI directionality. |
| 362 if (IsRTL() ? cases[i].wrap_rtl : cases[i].wrap_ltr) | 365 if (IsRTL() ? cases[i].wrap_rtl : cases[i].wrap_ltr) |
| 363 EXPECT_NE(output, input); | 366 EXPECT_NE(output, input); |
| 364 else | 367 else |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 L",\x05d0 foo bar", | 434 L",\x05d0 foo bar", |
| 432 L"\x202a \x05d0 foo bar", | 435 L"\x202a \x05d0 foo bar", |
| 433 L"\x202d \x05d0 foo bar", | 436 L"\x202d \x05d0 foo bar", |
| 434 L"\x202b foo \x05d0 bar", | 437 L"\x202b foo \x05d0 bar", |
| 435 L"\x202e foo \x05d0 bar", | 438 L"\x202e foo \x05d0 bar", |
| 436 L"\x0622 foo \x05d0 bar", | 439 L"\x0622 foo \x05d0 bar", |
| 437 }; | 440 }; |
| 438 | 441 |
| 439 const bool was_rtl = IsRTL(); | 442 const bool was_rtl = IsRTL(); |
| 440 | 443 |
| 444 test::ScopedRestoreICUDefaultLocale restore_locale; |
| 441 for (size_t i = 0; i < 2; ++i) { | 445 for (size_t i = 0; i < 2; ++i) { |
| 442 // Toggle the application default text direction (to try each direction). | 446 // Toggle the application default text direction (to try each direction). |
| 443 SetRTL(!IsRTL()); | 447 SetRTL(!IsRTL()); |
| 444 | 448 |
| 445 for (size_t i = 0; i < arraysize(cases); ++i) { | 449 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 446 string16 test_case = WideToUTF16(cases[i]); | 450 string16 test_case = WideToUTF16(cases[i]); |
| 447 string16 adjusted_string = test_case; | 451 string16 adjusted_string = test_case; |
| 448 | 452 |
| 449 if (!AdjustStringForLocaleDirection(&adjusted_string)) | 453 if (!AdjustStringForLocaleDirection(&adjusted_string)) |
| 450 continue; | 454 continue; |
| 451 | 455 |
| 452 EXPECT_NE(test_case, adjusted_string); | 456 EXPECT_NE(test_case, adjusted_string); |
| 453 EXPECT_TRUE(UnadjustStringForLocaleDirection(&adjusted_string)); | 457 EXPECT_TRUE(UnadjustStringForLocaleDirection(&adjusted_string)); |
| 454 EXPECT_EQ(test_case, adjusted_string) << " for test case [" << test_case | 458 EXPECT_EQ(test_case, adjusted_string) << " for test case [" << test_case |
| 455 << "] with IsRTL() == " << IsRTL(); | 459 << "] with IsRTL() == " << IsRTL(); |
| 456 } | 460 } |
| 457 } | 461 } |
| 458 | 462 |
| 459 EXPECT_EQ(was_rtl, IsRTL()); | 463 EXPECT_EQ(was_rtl, IsRTL()); |
| 460 } | 464 } |
| 461 | 465 |
| 462 } // namespace i18n | 466 } // namespace i18n |
| 463 } // namespace base | 467 } // namespace base |
| OLD | NEW |