| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 <sstream> | 5 #include <sstream> |
| 6 #include <unordered_set> |
| 6 | 7 |
| 7 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 8 | 9 |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 | 14 |
| 14 #if defined(WCHAR_T_IS_UTF32) | |
| 15 | |
| 16 // We define a custom operator<< for string16 so we can use it with logging. | 15 // We define a custom operator<< for string16 so we can use it with logging. |
| 17 // This tests that conversion. | 16 // This tests that conversion. |
| 18 TEST(String16Test, OutputStream) { | 17 TEST(String16Test, OutputStream) { |
| 19 // Basic stream test. | 18 // Basic stream test. |
| 20 { | 19 { |
| 21 std::ostringstream stream; | 20 std::ostringstream stream; |
| 22 stream << "Empty '" << string16() << "' standard '" | 21 stream << "Empty '" << string16() << "' standard '" |
| 23 << string16(ASCIIToUTF16("Hello, world")) << "'"; | 22 << string16(ASCIIToUTF16("Hello, world")) << "'"; |
| 24 EXPECT_STREQ("Empty '' standard 'Hello, world'", | 23 EXPECT_STREQ("Empty '' standard 'Hello, world'", |
| 25 stream.str().c_str()); | 24 stream.str().c_str()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 | 45 |
| 47 std::ostringstream stream; | 46 std::ostringstream stream; |
| 48 stream << initial_surrogate << "," << final_surrogate << "," | 47 stream << initial_surrogate << "," << final_surrogate << "," |
| 49 << surrogate_pair << "," << unterminated_surrogate; | 48 << surrogate_pair << "," << unterminated_surrogate; |
| 50 | 49 |
| 51 EXPECT_STREQ("\xef\xbf\xbd,\xef\xbf\xbd,\xf0\x90\x8c\x80z,\xef\xbf\xbds", | 50 EXPECT_STREQ("\xef\xbf\xbd,\xef\xbf\xbd,\xf0\x90\x8c\x80z,\xef\xbf\xbds", |
| 52 stream.str().c_str()); | 51 stream.str().c_str()); |
| 53 } | 52 } |
| 54 } | 53 } |
| 55 | 54 |
| 56 #endif | 55 TEST(String16Test, Hash) { |
| 56 string16 str1 = ASCIIToUTF16("hello"); |
| 57 string16 str2 = ASCIIToUTF16("world"); |
| 58 |
| 59 std::unordered_set<string16> set; |
| 60 |
| 61 set.insert(str1); |
| 62 EXPECT_EQ(1u, set.count(str1)); |
| 63 EXPECT_EQ(0u, set.count(str2)); |
| 64 } |
| 57 | 65 |
| 58 } // namespace base | 66 } // namespace base |
| OLD | NEW |