| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "wtf/text/TextCodecICU.h" | 5 #include "wtf/text/TextCodecICU.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "wtf/Vector.h" |
| 8 #include "wtf/text/CharacterNames.h" | 9 #include "wtf/text/CharacterNames.h" |
| 9 | 10 |
| 10 namespace WTF { | 11 namespace WTF { |
| 11 | 12 |
| 12 TEST(TextCodecICUTest, IgnorableCodePoint) { | 13 TEST(TextCodecICUTest, IgnorableCodePoint) { |
| 13 TextEncoding iso2022jp("iso-2022-jp"); | 14 TextEncoding iso2022jp("iso-2022-jp"); |
| 14 std::unique_ptr<TextCodec> codec = TextCodecICU::create(iso2022jp, nullptr); | 15 std::unique_ptr<TextCodec> codec = TextCodecICU::create(iso2022jp, nullptr); |
| 15 Vector<UChar> source; | 16 Vector<UChar> source; |
| 16 source.append('a'); | 17 source.append('a'); |
| 17 source.append(zeroWidthJoinerCharacter); | 18 source.append(zeroWidthJoinerCharacter); |
| 18 CString encoded = | 19 CString encoded = |
| 19 codec->encode(source.data(), source.size(), EntitiesForUnencodables); | 20 codec->encode(source.data(), source.size(), EntitiesForUnencodables); |
| 20 EXPECT_STREQ("a‍", encoded.data()); | 21 EXPECT_STREQ("a‍", encoded.data()); |
| 21 } | 22 } |
| 23 |
| 24 TEST(TextCodecICUTest, UTF32AndQuestionMarks) { |
| 25 Vector<String> aliases; |
| 26 Vector<CString> results; |
| 27 |
| 28 const UChar poo[] = {0xd83d, 0xdca9}; // U+1F4A9 PILE OF POO |
| 29 |
| 30 aliases.append("UTF-32"); |
| 31 results.append("\xFF\xFE\x00\x00\xA9\xF4\x01\x00"); |
| 32 |
| 33 aliases.append("UTF-32LE"); |
| 34 results.append("\xA9\xF4\x01\x00"); |
| 35 |
| 36 aliases.append("UTF-32BE"); |
| 37 results.append("\x00\x01\xF4\xA9"); |
| 38 |
| 39 ASSERT_EQ(aliases.size(), results.size()); |
| 40 for (unsigned i = 0; i < aliases.size(); ++i) { |
| 41 const String& alias = aliases[i]; |
| 42 const CString& expected = results[i]; |
| 43 |
| 44 TextEncoding encoding(alias); |
| 45 std::unique_ptr<TextCodec> codec = TextCodecICU::create(encoding, nullptr); |
| 46 { |
| 47 const UChar* data = nullptr; |
| 48 CString encoded = codec->encode(data, 0, QuestionMarksForUnencodables); |
| 49 EXPECT_STREQ("", encoded.data()); |
| 50 } |
| 51 { |
| 52 CString encoded = codec->encode(poo, WTF_ARRAY_LENGTH(poo), |
| 53 QuestionMarksForUnencodables); |
| 54 EXPECT_STREQ(expected.data(), encoded.data()); |
| 55 } |
| 56 } |
| 22 } | 57 } |
| 58 } |
| OLD | NEW |