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

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

Issue 1273243002: Updates to base unittests so they run correctly in libchrome on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Existing tests using ScopedLocale are wrapped by OS_LINUX, trying that Created 5 years, 4 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/files/file_path_unittest.cc ('k') | 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 expected_null.push_back(0); 69 expected_null.push_back(0);
70 expected_null.push_back('b'); 70 expected_null.push_back('b');
71 71
72 EXPECT_EQ(expected_null, SysUTF8ToWide(utf8_null)); 72 EXPECT_EQ(expected_null, SysUTF8ToWide(utf8_null));
73 } 73 }
74 74
75 #if defined(OS_LINUX) // Tests depend on setting a specific Linux locale. 75 #if defined(OS_LINUX) // Tests depend on setting a specific Linux locale.
76 76
77 TEST(SysStrings, SysWideToNativeMB) { 77 TEST(SysStrings, SysWideToNativeMB) {
78 #if !defined(SYSTEM_NATIVE_UTF8) 78 #if !defined(SYSTEM_NATIVE_UTF8)
79 ScopedLocale locale("en_US.utf-8"); 79 ScopedLocale locale("en_US.UTF-8");
80 #endif 80 #endif
81 EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world")); 81 EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world"));
82 EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d")); 82 EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d"));
83 83
84 // >16 bits 84 // >16 bits
85 EXPECT_EQ("\xF0\x90\x8C\x80", SysWideToNativeMB(kSysWideOldItalicLetterA)); 85 EXPECT_EQ("\xF0\x90\x8C\x80", SysWideToNativeMB(kSysWideOldItalicLetterA));
86 86
87 // Error case. When Windows finds a UTF-16 character going off the end of 87 // Error case. When Windows finds a UTF-16 character going off the end of
88 // a string, it just converts that literal value to UTF-8, even though this 88 // a string, it just converts that literal value to UTF-8, even though this
89 // is invalid. 89 // is invalid.
(...skipping 11 matching lines...) Expand all
101 std::string expected_null("a"); 101 std::string expected_null("a");
102 expected_null.push_back(0); 102 expected_null.push_back(0);
103 expected_null.push_back('b'); 103 expected_null.push_back('b');
104 104
105 EXPECT_EQ(expected_null, SysWideToNativeMB(wide_null)); 105 EXPECT_EQ(expected_null, SysWideToNativeMB(wide_null));
106 } 106 }
107 107
108 // We assume the test is running in a UTF8 locale. 108 // We assume the test is running in a UTF8 locale.
109 TEST(SysStrings, SysNativeMBToWide) { 109 TEST(SysStrings, SysNativeMBToWide) {
110 #if !defined(SYSTEM_NATIVE_UTF8) 110 #if !defined(SYSTEM_NATIVE_UTF8)
111 ScopedLocale locale("en_US.utf-8"); 111 ScopedLocale locale("en_US.UTF-8");
112 #endif 112 #endif
113 EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world")); 113 EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world"));
114 EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd")); 114 EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd"));
115 // >16 bits 115 // >16 bits
116 EXPECT_EQ(kSysWideOldItalicLetterA, SysNativeMBToWide("\xF0\x90\x8C\x80")); 116 EXPECT_EQ(kSysWideOldItalicLetterA, SysNativeMBToWide("\xF0\x90\x8C\x80"));
117 117
118 // Error case. When Windows finds an invalid UTF-8 character, it just skips 118 // Error case. When Windows finds an invalid UTF-8 character, it just skips
119 // it. This seems weird because it's inconsistent with the reverse conversion. 119 // it. This seems weird because it's inconsistent with the reverse conversion.
120 // 120 //
121 // This is what XP does, but Vista has different behavior, so we don't bother 121 // This is what XP does, but Vista has different behavior, so we don't bother
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 #elif defined(WCHAR_T_IS_UTF32) 157 #elif defined(WCHAR_T_IS_UTF32)
158 L"\x10300", 158 L"\x10300",
159 // ????? (Mathematical Alphanumeric Symbols (U+011d40 - U+011d44 : A,B,C,D,E) 159 // ????? (Mathematical Alphanumeric Symbols (U+011d40 - U+011d44 : A,B,C,D,E)
160 L"\x11d40\x11d41\x11d42\x11d43\x11d44", 160 L"\x11d40\x11d41\x11d42\x11d43\x11d44",
161 #endif 161 #endif
162 }; 162 };
163 163
164 164
165 TEST(SysStrings, SysNativeMBAndWide) { 165 TEST(SysStrings, SysNativeMBAndWide) {
166 #if !defined(SYSTEM_NATIVE_UTF8) 166 #if !defined(SYSTEM_NATIVE_UTF8)
167 ScopedLocale locale("en_US.utf-8"); 167 ScopedLocale locale("en_US.UTF-8");
168 #endif 168 #endif
169 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { 169 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
170 std::wstring wide = kConvertRoundtripCases[i]; 170 std::wstring wide = kConvertRoundtripCases[i];
171 std::wstring trip = SysNativeMBToWide(SysWideToNativeMB(wide)); 171 std::wstring trip = SysNativeMBToWide(SysWideToNativeMB(wide));
172 EXPECT_EQ(wide.size(), trip.size()); 172 EXPECT_EQ(wide.size(), trip.size());
173 EXPECT_EQ(wide, trip); 173 EXPECT_EQ(wide, trip);
174 } 174 }
175 175
176 // We assume our test is running in UTF-8, so double check through ICU. 176 // We assume our test is running in UTF-8, so double check through ICU.
177 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { 177 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
178 std::wstring wide = kConvertRoundtripCases[i]; 178 std::wstring wide = kConvertRoundtripCases[i];
179 std::wstring trip = SysNativeMBToWide(WideToUTF8(wide)); 179 std::wstring trip = SysNativeMBToWide(WideToUTF8(wide));
180 EXPECT_EQ(wide.size(), trip.size()); 180 EXPECT_EQ(wide.size(), trip.size());
181 EXPECT_EQ(wide, trip); 181 EXPECT_EQ(wide, trip);
182 } 182 }
183 183
184 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { 184 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
185 std::wstring wide = kConvertRoundtripCases[i]; 185 std::wstring wide = kConvertRoundtripCases[i];
186 std::wstring trip = UTF8ToWide(SysWideToNativeMB(wide)); 186 std::wstring trip = UTF8ToWide(SysWideToNativeMB(wide));
187 EXPECT_EQ(wide.size(), trip.size()); 187 EXPECT_EQ(wide.size(), trip.size());
188 EXPECT_EQ(wide, trip); 188 EXPECT_EQ(wide, trip);
189 } 189 }
190 } 190 }
191 #endif // OS_LINUX 191 #endif // OS_LINUX
192 192
193 } // namespace base 193 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698