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

Unified Diff: base/utf_offset_string_conversions_unittest.cc

Issue 6898026: Eliminate wstring from base/utf_offset_string_conversions.h, net/base/escape.h, and net/base/net_... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: base/utf_offset_string_conversions_unittest.cc
===================================================================
--- base/utf_offset_string_conversions_unittest.cc (revision 82762)
+++ base/utf_offset_string_conversions_unittest.cc (working copy)
@@ -13,37 +13,16 @@
namespace {
-static const size_t kNpos = std::wstring::npos;
+static const size_t kNpos = string16::npos;
-// Given a null-terminated string of wchar_t with each wchar_t representing
-// a UTF-16 code unit, returns a string16 made up of wchar_t's in the input.
-// Each wchar_t should be <= 0xFFFF and a non-BMP character (> U+FFFF)
-// should be represented as a surrogate pair (two UTF-16 units)
-// *even* where wchar_t is 32-bit (Linux and Mac).
-//
-// This is to help write tests for functions with string16 params until
-// the C++ 0x UTF-16 literal is well-supported by compilers.
-string16 BuildString16(const wchar_t* s) {
-#if defined(WCHAR_T_IS_UTF16)
- return string16(s);
-#elif defined(WCHAR_T_IS_UTF32)
- string16 u16;
- while (*s != 0) {
- DCHECK(static_cast<unsigned int>(*s) <= 0xFFFFu);
- u16.push_back(*s++);
- }
- return u16;
-#endif
-}
-
} // namespace
TEST(UTFOffsetStringConversionsTest, AdjustOffset) {
- struct UTF8ToWideCase {
+ struct UTF8ToUTF16Case {
const char* utf8;
size_t input_offset;
size_t output_offset;
- } utf8_to_wide_cases[] = {
+ } utf8_to_utf16_cases[] = {
{"", 0, kNpos},
{"\xe4\xbd\xa0\xe5\xa5\xbd", 1, kNpos},
{"\xe4\xbd\xa0\xe5\xa5\xbd", 3, 1},
@@ -56,29 +35,11 @@
{"A\xF0\x90\x8C\x80z", 5, 2},
#endif
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_wide_cases); ++i) {
- size_t offset = utf8_to_wide_cases[i].input_offset;
- UTF8ToWideAndAdjustOffset(utf8_to_wide_cases[i].utf8, &offset);
- EXPECT_EQ(utf8_to_wide_cases[i].output_offset, offset);
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf8_to_utf16_cases); ++i) {
+ size_t offset = utf8_to_utf16_cases[i].input_offset;
+ UTF8ToUTF16AndAdjustOffset(utf8_to_utf16_cases[i].utf8, &offset);
+ EXPECT_EQ(utf8_to_utf16_cases[i].output_offset, offset);
}
-
-#if defined(WCHAR_T_IS_UTF32)
- struct UTF16ToWideCase {
- const wchar_t* wide;
- size_t input_offset;
- size_t output_offset;
- } utf16_to_wide_cases[] = {
- {L"\xD840\xDC00\x4E00", 0, 0},
- {L"\xD840\xDC00\x4E00", 1, kNpos},
- {L"\xD840\xDC00\x4E00", 2, 1},
- };
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(utf16_to_wide_cases); ++i) {
- size_t offset = utf16_to_wide_cases[i].input_offset;
- UTF16ToWideAndAdjustOffset(BuildString16(utf16_to_wide_cases[i].wide),
- &offset);
- EXPECT_EQ(utf16_to_wide_cases[i].output_offset, offset);
- }
-#endif
}
TEST(UTFOffsetStringConversionsTest, LimitOffsets) {
@@ -88,7 +49,7 @@
for (size_t t = 0; t < kItems; ++t)
size_ts.push_back(t);
std::for_each(size_ts.begin(), size_ts.end(),
- LimitOffset<std::wstring>(kLimit));
+ LimitOffset<string16>(kLimit));
size_t unlimited_count = 0;
for (std::vector<size_t>::iterator ti = size_ts.begin(); ti != size_ts.end();
++ti) {
@@ -102,7 +63,7 @@
for (size_t t = kItems; t > 0; --t)
size_ts.push_back(t - 1);
std::for_each(size_ts.begin(), size_ts.end(),
- LimitOffset<std::wstring>(kLimit));
+ LimitOffset<string16>(kLimit));
unlimited_count = 0;
for (std::vector<size_t>::iterator ti = size_ts.begin(); ti != size_ts.end();
++ti) {

Powered by Google App Engine
This is Rietveld 408576698