Update V8 to version 4.5.86.
[chromium-blink-merge.git] / base / strings / string16_unittest.cc
blob4e582181a863aa5114deb33ffc0e860b14f5385a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <sstream>
7 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace base {
14 #if defined(WCHAR_T_IS_UTF32)
16 // We define a custom operator<< for string16 so we can use it with logging.
17 // This tests that conversion.
18 TEST(String16Test, OutputStream) {
19 // Basic stream test.
21 std::ostringstream stream;
22 stream << "Empty '" << string16() << "' standard '"
23 << string16(ASCIIToUTF16("Hello, world")) << "'";
24 EXPECT_STREQ("Empty '' standard 'Hello, world'",
25 stream.str().c_str());
28 // Interesting edge cases.
30 // These should each get converted to the invalid character: EF BF BD.
31 string16 initial_surrogate;
32 initial_surrogate.push_back(0xd800);
33 string16 final_surrogate;
34 final_surrogate.push_back(0xdc00);
36 // Old italic A = U+10300, will get converted to: F0 90 8C 80 'z'.
37 string16 surrogate_pair;
38 surrogate_pair.push_back(0xd800);
39 surrogate_pair.push_back(0xdf00);
40 surrogate_pair.push_back('z');
42 // Will get converted to the invalid char + 's': EF BF BD 's'.
43 string16 unterminated_surrogate;
44 unterminated_surrogate.push_back(0xd800);
45 unterminated_surrogate.push_back('s');
47 std::ostringstream stream;
48 stream << initial_surrogate << "," << final_surrogate << ","
49 << surrogate_pair << "," << unterminated_surrogate;
51 EXPECT_STREQ("\xef\xbf\xbd,\xef\xbf\xbd,\xf0\x90\x8c\x80z,\xef\xbf\xbds",
52 stream.str().c_str());
56 #endif
58 } // namespace base