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

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

Issue 380007: Clean up recent string conversion function changes, part 1: Remove unnecessar... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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/i18n/icu_string_conversions.cc ('k') | base/utf_string_conversions.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) 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
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
OLDNEW
« no previous file with comments | « base/i18n/icu_string_conversions.cc ('k') | base/utf_string_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698