OLD | NEW |
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 #include "base/basictypes.h" |
5 #include "base/string_piece.h" | 6 #include "base/string_piece.h" |
6 #include "base/string_util.h" | 7 #include "base/string_util.h" |
7 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 | 10 |
10 #ifdef WCHAR_T_IS_UTF32 | 11 #ifdef WCHAR_T_IS_UTF32 |
11 static const std::wstring kSysWideOldItalicLetterA = L"\x10300"; | 12 static const std::wstring kSysWideOldItalicLetterA = L"\x10300"; |
12 #else | 13 #else |
13 static const std::wstring kSysWideOldItalicLetterA = L"\xd800\xdf00"; | 14 static const std::wstring kSysWideOldItalicLetterA = L"\xd800\xdf00"; |
14 #endif | 15 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 utf8_null.push_back('b'); | 63 utf8_null.push_back('b'); |
63 | 64 |
64 std::wstring expected_null(L"a"); | 65 std::wstring expected_null(L"a"); |
65 expected_null.push_back(0); | 66 expected_null.push_back(0); |
66 expected_null.push_back('b'); | 67 expected_null.push_back('b'); |
67 | 68 |
68 EXPECT_EQ(expected_null, SysUTF8ToWide(utf8_null)); | 69 EXPECT_EQ(expected_null, SysUTF8ToWide(utf8_null)); |
69 } | 70 } |
70 | 71 |
71 // We assume the test is running in a UTF8 locale. | 72 // We assume the test is running in a UTF8 locale. |
| 73 #if defined(OS_LINUX) |
72 TEST(SysStrings, SysWideToNativeMB) { | 74 TEST(SysStrings, SysWideToNativeMB) { |
73 using base::SysWideToNativeMB; | 75 using base::SysWideToNativeMB; |
74 EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world")); | 76 EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world")); |
75 EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d")); | 77 EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d")); |
76 | 78 |
77 // >16 bits | 79 // >16 bits |
78 EXPECT_EQ("\xF0\x90\x8C\x80", SysWideToNativeMB(kSysWideOldItalicLetterA)); | 80 EXPECT_EQ("\xF0\x90\x8C\x80", SysWideToNativeMB(kSysWideOldItalicLetterA)); |
79 | 81 |
80 // Error case. When Windows finds a UTF-16 character going off the end of | 82 // Error case. When Windows finds a UTF-16 character going off the end of |
81 // a string, it just converts that literal value to UTF-8, even though this | 83 // a string, it just converts that literal value to UTF-8, even though this |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EXPECT_EQ(wide, trip); | 171 EXPECT_EQ(wide, trip); |
170 } | 172 } |
171 | 173 |
172 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { | 174 for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { |
173 std::wstring wide = kConvertRoundtripCases[i]; | 175 std::wstring wide = kConvertRoundtripCases[i]; |
174 std::wstring trip = UTF8ToWide(base::SysWideToNativeMB(wide)); | 176 std::wstring trip = UTF8ToWide(base::SysWideToNativeMB(wide)); |
175 EXPECT_EQ(wide.size(), trip.size()); | 177 EXPECT_EQ(wide.size(), trip.size()); |
176 EXPECT_EQ(wide, trip); | 178 EXPECT_EQ(wide, trip); |
177 } | 179 } |
178 } | 180 } |
| 181 #endif // OS_LINUX |
OLD | NEW |