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

Side by Side Diff: base/i18n/case_conversion_unittest.cc

Issue 1104483002: added test to test case converting with nonASCII (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change also first locate to known Created 5 years, 7 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 | « no previous file | no next file » | 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/case_conversion.h" 5 #include "base/i18n/case_conversion.h"
6 #include "base/i18n/rtl.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/icu/source/i18n/unicode/usearch.h"
8 10
9 namespace base { 11 namespace base {
10 namespace { 12 namespace {
11 13
12 // Test upper and lower case string conversion. 14 // Test upper and lower case string conversion.
13 TEST(CaseConversionTest, UpperLower) { 15 TEST(CaseConversionTest, UpperLower) {
14 string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); 16 const string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE."));
15 const string16 expected_lower(ASCIIToUTF16("text with upper & lower case.")); 17 const string16 expected_lower(ASCIIToUTF16("text with upper & lower case."));
16 const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE.")); 18 const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE."));
17 19
18 string16 result = base::i18n::ToLower(mixed); 20 string16 result = base::i18n::ToLower(mixed);
19 EXPECT_EQ(expected_lower, result); 21 EXPECT_EQ(expected_lower, result);
20 22
21 result = base::i18n::ToUpper(mixed); 23 result = base::i18n::ToUpper(mixed);
22 EXPECT_EQ(expected_upper, result); 24 EXPECT_EQ(expected_upper, result);
23 } 25 }
24 26
25 // TODO(jshin): More tests are needed, especially with non-ASCII characters. 27 TEST(CaseConversionTest, NonASCII) {
28 const string16 mixed(WideToUTF16(
29 L"\xC4\xD6\xE4\xF6\x20\xCF\xEF\x20\xF7\x25"
30 L"\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F07\x1F0F"
31 L"\x20\x1E00\x1E01"));
32 const string16 expected_lower(WideToUTF16(
33 L"\xE4\xF6\xE4\xF6\x20\xEF\xEF"
34 L"\x20\xF7\x25\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F07"
35 L"\x1F07\x20\x1E01\x1E01"));
36 const string16 expected_upper(WideToUTF16(
37 L"\xC4\xD6\xC4\xD6\x20\xCF\xCF"
38 L"\x20\xF7\x25\xA4\x23\x2A\x5E\x60\x40\xA3\x24\x2030\x201A\x7E\x20\x1F0F"
39 L"\x1F0F\x20\x1E00\x1E00"));
40
41 string16 result = base::i18n::ToLower(mixed);
42 EXPECT_EQ(expected_lower, result);
43
44 result = base::i18n::ToUpper(mixed);
45 EXPECT_EQ(expected_upper, result);
46 }
47
48 TEST(CaseConversionTest, TurkishLocaleConversion) {
49 const string16 mixed(WideToUTF16(L"\x49\x131"));
50 const string16 expected_lower(WideToUTF16(L"\x69\x131"));
51 const string16 expected_upper(WideToUTF16(L"\x49\x49"));
52
53 std::string default_locale(uloc_getDefault());
54 i18n::SetICUDefaultLocale("en_US");
55
56 string16 result = base::i18n::ToLower(mixed);
57 EXPECT_EQ(expected_lower, result);
58
59 result = base::i18n::ToUpper(mixed);
60 EXPECT_EQ(expected_upper, result);
61
62 i18n::SetICUDefaultLocale("tr");
63
64 const string16 expected_lower_turkish(WideToUTF16(L"\x131\x131"));
65 const string16 expected_upper_turkish(WideToUTF16(L"\x49\x49"));
66
67 result = base::i18n::ToLower(mixed);
68 EXPECT_EQ(expected_lower_turkish, result);
69
70 result = base::i18n::ToUpper(mixed);
71 EXPECT_EQ(expected_upper_turkish, result);
72
73 base::i18n::SetICUDefaultLocale(default_locale.data());
74 }
26 75
27 } // namespace 76 } // namespace
28 } // namespace base 77 } // namespace base
78
79
80
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698