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

Side by Side Diff: base/sys_string_conversions_unittest.cc

Issue 7129056: Cleanup in base/test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reverted, rebased again Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « base/base.gyp ('k') | base/test/scoped_locale.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 5
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/test/test_util.h" 10 #include "base/test/scoped_locale.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 #ifdef WCHAR_T_IS_UTF32 15 #ifdef WCHAR_T_IS_UTF32
16 static const std::wstring kSysWideOldItalicLetterA = L"\x10300"; 16 static const std::wstring kSysWideOldItalicLetterA = L"\x10300";
17 #else 17 #else
18 static const std::wstring kSysWideOldItalicLetterA = L"\xd800\xdf00"; 18 static const std::wstring kSysWideOldItalicLetterA = L"\xd800\xdf00";
19 #endif 19 #endif
20 20
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 expected_null.push_back(0); 70 expected_null.push_back(0);
71 expected_null.push_back('b'); 71 expected_null.push_back('b');
72 72
73 EXPECT_EQ(expected_null, SysUTF8ToWide(utf8_null)); 73 EXPECT_EQ(expected_null, SysUTF8ToWide(utf8_null));
74 } 74 }
75 75
76 #if defined(OS_LINUX) // Tests depend on setting a specific Linux locale. 76 #if defined(OS_LINUX) // Tests depend on setting a specific Linux locale.
77 77
78 TEST(SysStrings, SysWideToNativeMB) { 78 TEST(SysStrings, SysWideToNativeMB) {
79 using base::SysWideToNativeMB; 79 using base::SysWideToNativeMB;
80 base::ScopedSetLocale locale("en_US.utf-8"); 80 base::ScopedLocale locale("en_US.utf-8");
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.
90 // 90 //
(...skipping 10 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 using base::SysNativeMBToWide; 110 using base::SysNativeMBToWide;
111 base::ScopedSetLocale locale("en_US.utf-8"); 111 base::ScopedLocale locale("en_US.utf-8");
112 EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world")); 112 EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world"));
113 EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd")); 113 EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd"));
114 // >16 bits 114 // >16 bits
115 EXPECT_EQ(kSysWideOldItalicLetterA, SysNativeMBToWide("\xF0\x90\x8C\x80")); 115 EXPECT_EQ(kSysWideOldItalicLetterA, SysNativeMBToWide("\xF0\x90\x8C\x80"));
116 116
117 // Error case. When Windows finds an invalid UTF-8 character, it just skips 117 // Error case. When Windows finds an invalid UTF-8 character, it just skips
118 // it. This seems weird because it's inconsistent with the reverse conversion. 118 // it. This seems weird because it's inconsistent with the reverse conversion.
119 // 119 //
120 // This is what XP does, but Vista has different behavior, so we don't bother 120 // This is what XP does, but Vista has different behavior, so we don't bother
121 // verifying it: 121 // verifying it:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 L"\xd807\xdd40\xd807\xdd41\xd807\xdd42\xd807\xdd43\xd807\xdd44", 155 L"\xd807\xdd40\xd807\xdd41\xd807\xdd42\xd807\xdd43\xd807\xdd44",
156 #elif defined(WCHAR_T_IS_UTF32) 156 #elif defined(WCHAR_T_IS_UTF32)
157 L"\x10300", 157 L"\x10300",
158 // ????? (Mathematical Alphanumeric Symbols (U+011d40 - U+011d44 : A,B,C,D,E) 158 // ????? (Mathematical Alphanumeric Symbols (U+011d40 - U+011d44 : A,B,C,D,E)
159 L"\x11d40\x11d41\x11d42\x11d43\x11d44", 159 L"\x11d40\x11d41\x11d42\x11d43\x11d44",
160 #endif 160 #endif
161 }; 161 };
162 162
163 163
164 TEST(SysStrings, SysNativeMBAndWide) { 164 TEST(SysStrings, SysNativeMBAndWide) {
165 base::ScopedSetLocale locale("en_US.utf-8"); 165 base::ScopedLocale locale("en_US.utf-8");
166 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { 166 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
167 std::wstring wide = kConvertRoundtripCases[i]; 167 std::wstring wide = kConvertRoundtripCases[i];
168 std::wstring trip = base::SysNativeMBToWide(base::SysWideToNativeMB(wide)); 168 std::wstring trip = base::SysNativeMBToWide(base::SysWideToNativeMB(wide));
169 EXPECT_EQ(wide.size(), trip.size()); 169 EXPECT_EQ(wide.size(), trip.size());
170 EXPECT_EQ(wide, trip); 170 EXPECT_EQ(wide, trip);
171 } 171 }
172 172
173 // We assume our test is running in UTF-8, so double check through ICU. 173 // We assume our test is running in UTF-8, so double check through ICU.
174 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { 174 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
175 std::wstring wide = kConvertRoundtripCases[i]; 175 std::wstring wide = kConvertRoundtripCases[i];
176 std::wstring trip = base::SysNativeMBToWide(WideToUTF8(wide)); 176 std::wstring trip = base::SysNativeMBToWide(WideToUTF8(wide));
177 EXPECT_EQ(wide.size(), trip.size()); 177 EXPECT_EQ(wide.size(), trip.size());
178 EXPECT_EQ(wide, trip); 178 EXPECT_EQ(wide, trip);
179 } 179 }
180 180
181 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { 181 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
182 std::wstring wide = kConvertRoundtripCases[i]; 182 std::wstring wide = kConvertRoundtripCases[i];
183 std::wstring trip = UTF8ToWide(base::SysWideToNativeMB(wide)); 183 std::wstring trip = UTF8ToWide(base::SysWideToNativeMB(wide));
184 EXPECT_EQ(wide.size(), trip.size()); 184 EXPECT_EQ(wide.size(), trip.size());
185 EXPECT_EQ(wide, trip); 185 EXPECT_EQ(wide, trip);
186 } 186 }
187 } 187 }
188 #endif // OS_LINUX 188 #endif // OS_LINUX
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/test/scoped_locale.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698