- add sources.
[platform/framework/web/crosswalk.git] / src / base / strings / string16_unittest.cc
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.
4
5 #include <sstream>
6
7 #include "base/strings/string16.h"
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 #if defined(WCHAR_T_IS_UTF32)
13
14 // We define a custom operator<< for string16 so we can use it with logging.
15 // This tests that conversion.
16 TEST(String16Test, OutputStream) {
17   // Basic stream test.
18   {
19     std::ostringstream stream;
20     stream << "Empty '" << string16() << "' standard '"
21            << string16(ASCIIToUTF16("Hello, world")) << "'";
22     EXPECT_STREQ("Empty '' standard 'Hello, world'",
23                  stream.str().c_str());
24   }
25
26   // Interesting edge cases.
27   {
28     // These should each get converted to the invalid character: EF BF BD.
29     string16 initial_surrogate;
30     initial_surrogate.push_back(0xd800);
31     string16 final_surrogate;
32     final_surrogate.push_back(0xdc00);
33
34     // Old italic A = U+10300, will get converted to: F0 90 8C 80 'z'.
35     string16 surrogate_pair;
36     surrogate_pair.push_back(0xd800);
37     surrogate_pair.push_back(0xdf00);
38     surrogate_pair.push_back('z');
39
40     // Will get converted to the invalid char + 's': EF BF BD 's'.
41     string16 unterminated_surrogate;
42     unterminated_surrogate.push_back(0xd800);
43     unterminated_surrogate.push_back('s');
44
45     std::ostringstream stream;
46     stream << initial_surrogate << "," << final_surrogate << ","
47            << surrogate_pair << "," << unterminated_surrogate;
48
49     EXPECT_STREQ("\xef\xbf\xbd,\xef\xbf\xbd,\xf0\x90\x8c\x80z,\xef\xbf\xbds",
50                  stream.str().c_str());
51   }
52 }
53
54 #endif