diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 02:10:20 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 02:10:20 +0000 |
commit | 047a03f4cefa75a67070f08b3f6b727f7ea702d5 (patch) | |
tree | d00ccbd9e59106de8fd904b06720be59219d61fe /base/string16_unittest.cc | |
parent | 0511c153260e5d402d7552ff7b47a2acb17bdf2b (diff) | |
download | chromium_src-047a03f4cefa75a67070f08b3f6b727f7ea702d5.zip chromium_src-047a03f4cefa75a67070f08b3f6b727f7ea702d5.tar.gz chromium_src-047a03f4cefa75a67070f08b3f6b727f7ea702d5.tar.bz2 |
Copy the relevant parts of ICU to a new file base/third_party/icu/icu_utf.*
so we can do basic UTF8/16/32 conversions without linking all of ICU.
Change callers who used to call SysUTF8ToWide/SysWideToUTF8 in base to using
these new functions. I will remove the Sys versions of these functions in a
later patch.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/243102
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28219 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string16_unittest.cc')
-rw-r--r-- | base/string16_unittest.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/base/string16_unittest.cc b/base/string16_unittest.cc new file mode 100644 index 0000000..69eed4b --- /dev/null +++ b/base/string16_unittest.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <sstream> + +#include "base/string16.h" +#include "testing/gtest/include/gtest/gtest.h" + +#if defined(WCHAR_T_IS_UTF32) + +// We define a custom operator<< for string16 so we can use it with logging. +// This tests that conversion. +TEST(String16Test, OutputStream) { + // Basic stream test. + { + std::ostringstream stream; + stream << "Empty '" << string16() << "' standard '" + << string16(ASCIIToUTF16("Hello, world")) << "'"; + EXPECT_STREQ("Empty '' standard 'Hello, world'", + stream.str().c_str()); + } + + // Interesting edge cases. + { + // These should each get converted to the invalid character: EF BF BD. + string16 initial_surrogate; + initial_surrogate.push_back(0xd800); + string16 final_surrogate; + final_surrogate.push_back(0xdc00); + + // Old italic A = U+10300, will get converted to: F0 90 8C 80 'z'. + string16 surrogate_pair; + surrogate_pair.push_back(0xd800); + surrogate_pair.push_back(0xdf00); + surrogate_pair.push_back('z'); + + // Will get converted to the invalid char + 's': EF BF BD 's'. + string16 unterminated_surrogate; + unterminated_surrogate.push_back(0xd800); + unterminated_surrogate.push_back('s'); + + std::ostringstream stream; + stream << initial_surrogate << "," << final_surrogate << "," + << surrogate_pair << ",", unterminated_surrogate; + + EXPECT_STREQ("\xef\xbf\xbd,\xef\xbf\xbd,\xf0\x90\x8c\x80z,\xef\xbf\xbds", + stream.str().c_str()); + } +} + +#endif |