| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <math.h> | 5 #include <math.h> |
| 6 #include <stdarg.h> | 6 #include <stdarg.h> |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 kConvertCodepageCases[i].on_error == OnStringConversionError::FAIL) { | 318 kConvertCodepageCases[i].on_error == OnStringConversionError::FAIL) { |
| 319 std::string encoded; | 319 std::string encoded; |
| 320 success = UTF16ToCodepage(utf16, kConvertCodepageCases[i].codepage_name, | 320 success = UTF16ToCodepage(utf16, kConvertCodepageCases[i].codepage_name, |
| 321 kConvertCodepageCases[i].on_error, &encoded); | 321 kConvertCodepageCases[i].on_error, &encoded); |
| 322 EXPECT_EQ(kConvertCodepageCases[i].success, success); | 322 EXPECT_EQ(kConvertCodepageCases[i].success, success); |
| 323 EXPECT_EQ(kConvertCodepageCases[i].encoded, encoded); | 323 EXPECT_EQ(kConvertCodepageCases[i].encoded, encoded); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 static const struct { | |
| 329 const char* codepage_name; | |
| 330 const char* encoded; | |
| 331 size_t input_offset; | |
| 332 size_t u16_output_offset; | |
| 333 size_t wide_output_offset; | |
| 334 } kAdjustOffsetCases[] = { | |
| 335 {"gb2312", "", 0, string16::npos, std::wstring::npos}, | |
| 336 {"gb2312", "\xC4\xE3\xBA\xC3", 0, 0, 0}, | |
| 337 {"gb2312", "\xC4\xE3\xBA\xC3", 2, 1, 1}, | |
| 338 {"gb2312", "\xC4\xE3\xBA\xC3", 4, string16::npos, std::wstring::npos}, | |
| 339 {"gb2312", "\xC4\xE3\xBA\xC3", 1, string16::npos, std::wstring::npos}, | |
| 340 {"gb2312", "\xC4\xE3\xBA\xC3", std::string::npos, string16::npos, | |
| 341 std::wstring::npos}, | |
| 342 {"gb18030", "\x95\x32\x82\x36\xD2\xBB", 2, string16::npos, | |
| 343 std::wstring::npos}, | |
| 344 {"gb18030", "\x95\x32\x82\x36\xD2\xBB", 4, 2, 1}, | |
| 345 }; | |
| 346 | |
| 347 TEST(ICUStringConversionsTest, AdjustOffset) { | |
| 348 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kAdjustOffsetCases); ++i) { | |
| 349 string16 utf16; | |
| 350 size_t offset = kAdjustOffsetCases[i].input_offset; | |
| 351 EXPECT_TRUE(CodepageToUTF16AndAdjustOffset(kAdjustOffsetCases[i].encoded, | |
| 352 kAdjustOffsetCases[i].codepage_name, | |
| 353 OnStringConversionError::FAIL, &utf16, &offset)); | |
| 354 EXPECT_EQ(kAdjustOffsetCases[i].u16_output_offset, offset); | |
| 355 | |
| 356 std::wstring wide; | |
| 357 offset = kAdjustOffsetCases[i].input_offset; | |
| 358 CodepageToWideAndAdjustOffset(kAdjustOffsetCases[i].encoded, | |
| 359 kAdjustOffsetCases[i].codepage_name, | |
| 360 OnStringConversionError::FAIL, &wide, &offset); | |
| 361 #if defined(WCHAR_T_IS_UTF16) | |
| 362 EXPECT_EQ(kAdjustOffsetCases[i].u16_output_offset, offset); | |
| 363 #elif defined(WCHAR_T_IS_UTF32) | |
| 364 EXPECT_EQ(kAdjustOffsetCases[i].wide_output_offset, offset); | |
| 365 #endif | |
| 366 } | |
| 367 } | |
| 368 | |
| 369 } // namespace base | 328 } // namespace base |
| OLD | NEW |