| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/string_piece.h" | 6 #include "base/string_piece.h" |
| 7 #include "base/utf_offset_string_conversions.h" | 7 #include "base/utf_offset_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 TEST(UTFOffsetStringConversionsTest, AdjustOffset) { | 37 TEST(UTFOffsetStringConversionsTest, AdjustOffset) { |
| 38 struct UTF8ToWideCase { | 38 struct UTF8ToWideCase { |
| 39 const char* utf8; | 39 const char* utf8; |
| 40 size_t input_offset; | 40 size_t input_offset; |
| 41 size_t output_offset; | 41 size_t output_offset; |
| 42 } utf8_to_wide_cases[] = { | 42 } utf8_to_wide_cases[] = { |
| 43 {"", 0, std::wstring::npos}, | 43 {"", 0, std::wstring::npos}, |
| 44 {"\xe4\xbd\xa0\xe5\xa5\xbd", 1, std::wstring::npos}, | 44 {"\xe4\xbd\xa0\xe5\xa5\xbd", 1, std::wstring::npos}, |
| 45 {"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1}, | 45 {"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1}, |
| 46 {"\xed\xb0\x80z", 3, 0}, | 46 {"\xed\xb0\x80z", 3, 1}, |
| 47 {"A\xF0\x90\x8C\x80z", 1, 1}, | 47 {"A\xF0\x90\x8C\x80z", 1, 1}, |
| 48 {"A\xF0\x90\x8C\x80z", 2, std::wstring::npos}, | 48 {"A\xF0\x90\x8C\x80z", 2, std::wstring::npos}, |
| 49 #if defined(WCHAR_T_IS_UTF16) | 49 #if defined(WCHAR_T_IS_UTF16) |
| 50 {"A\xF0\x90\x8C\x80z", 5, 3}, | 50 {"A\xF0\x90\x8C\x80z", 5, 3}, |
| 51 #elif defined(WCHAR_T_IS_UTF32) | 51 #elif defined(WCHAR_T_IS_UTF32) |
| 52 {"A\xF0\x90\x8C\x80z", 5, 2}, | 52 {"A\xF0\x90\x8C\x80z", 5, 2}, |
| 53 #endif | 53 #endif |
| 54 }; | 54 }; |
| 55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_wide_cases); ++i) { | 55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_wide_cases); ++i) { |
| 56 size_t offset = utf8_to_wide_cases[i].input_offset; | 56 size_t offset = utf8_to_wide_cases[i].input_offset; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf16_to_wide_cases); ++i) { | 71 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf16_to_wide_cases); ++i) { |
| 72 size_t offset = utf16_to_wide_cases[i].input_offset; | 72 size_t offset = utf16_to_wide_cases[i].input_offset; |
| 73 UTF16ToWideAndAdjustOffset(BuildString16(utf16_to_wide_cases[i].wide), | 73 UTF16ToWideAndAdjustOffset(BuildString16(utf16_to_wide_cases[i].wide), |
| 74 &offset); | 74 &offset); |
| 75 EXPECT_EQ(utf16_to_wide_cases[i].output_offset, offset); | 75 EXPECT_EQ(utf16_to_wide_cases[i].output_offset, offset); |
| 76 } | 76 } |
| 77 #endif | 77 #endif |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namaspace base | 80 } // namaspace base |
| OLD | NEW |