| 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 "platform/text/Character.h" | 5 #include "platform/text/Character.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "wtf/text/CharacterNames.h" | 8 #include "wtf/text/CharacterNames.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 static void TestSpecificUCharRange(UChar rangeStart, UChar rangeEnd) { | |
| 13 UChar below[1]; | |
| 14 UChar start[1]; | |
| 15 UChar midway[1]; | |
| 16 UChar end[1]; | |
| 17 UChar above[1]; | |
| 18 | |
| 19 below[0] = rangeStart - 1; | |
| 20 start[0] = rangeStart; | |
| 21 midway[0] = ((int)rangeStart + (int)rangeEnd) / 2; | |
| 22 end[0] = rangeEnd; | |
| 23 above[0] = rangeEnd + 1; | |
| 24 | |
| 25 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(below, 1)); | |
| 26 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(start, 1)); | |
| 27 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(midway, 1)); | |
| 28 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(end, 1)); | |
| 29 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(above, 1)); | |
| 30 } | |
| 31 | |
| 32 TEST(CharacterTest, TestCharacterRangeCodePath) { | |
| 33 static UChar c1[] = {0x0}; | |
| 34 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c1, 1)); | |
| 35 | |
| 36 TestSpecificUCharRange(0x2E5, 0x2E9); | |
| 37 TestSpecificUCharRange(0x300, 0x36F); | |
| 38 TestSpecificUCharRange(0x0591, 0x05BD); | |
| 39 TestSpecificUCharRange(0x05BF, 0x05CF); | |
| 40 TestSpecificUCharRange(0x0600, 0x109F); | |
| 41 TestSpecificUCharRange(0x1100, 0x11FF); | |
| 42 TestSpecificUCharRange(0x135D, 0x135F); | |
| 43 TestSpecificUCharRange(0x1700, 0x18AF); | |
| 44 TestSpecificUCharRange(0x1900, 0x194F); | |
| 45 TestSpecificUCharRange(0x1980, 0x19DF); | |
| 46 TestSpecificUCharRange(0x1A00, 0x1CFF); | |
| 47 | |
| 48 static UChar c2[] = {0x1DBF}; | |
| 49 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c2, 1)); | |
| 50 static UChar c3[] = {0x1DC0}; | |
| 51 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c3, 1)); | |
| 52 static UChar c4[] = {0x1DD0}; | |
| 53 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c4, 1)); | |
| 54 static UChar c5[] = {0x1DFF}; | |
| 55 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c5, 1)); | |
| 56 static UChar c6[] = {0x1E00}; | |
| 57 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c6, 1)); | |
| 58 static UChar c7[] = {0x2000}; | |
| 59 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c7, 1)); | |
| 60 static UChar c8[] = {0x2001}; | |
| 61 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c8, 1)); | |
| 62 | |
| 63 TestSpecificUCharRange(0x20D0, 0x20FF); | |
| 64 TestSpecificUCharRange(0x2CEF, 0x2CF1); | |
| 65 TestSpecificUCharRange(0x302A, 0x302F); | |
| 66 | |
| 67 TestSpecificUCharRange(0xA67C, 0xA67D); | |
| 68 TestSpecificUCharRange(0xA6F0, 0xA6F1); | |
| 69 TestSpecificUCharRange(0xA800, 0xABFF); | |
| 70 | |
| 71 TestSpecificUCharRange(0xD7B0, 0xD7FF); | |
| 72 TestSpecificUCharRange(0xFE00, 0xFE0F); | |
| 73 TestSpecificUCharRange(0xFE20, 0xFE2F); | |
| 74 } | |
| 75 | |
| 76 testing::AssertionResult isCJKIdeographOrSymbolWithMessage(UChar32 codepoint) { | 12 testing::AssertionResult isCJKIdeographOrSymbolWithMessage(UChar32 codepoint) { |
| 77 const size_t formatBufferSize = 10; | 13 const size_t formatBufferSize = 10; |
| 78 char formattedAsHex[formatBufferSize]; | 14 char formattedAsHex[formatBufferSize]; |
| 79 snprintf(formattedAsHex, formatBufferSize, "0x%x", codepoint); | 15 snprintf(formattedAsHex, formatBufferSize, "0x%x", codepoint); |
| 80 | 16 |
| 81 if (Character::isCJKIdeographOrSymbol(codepoint)) { | 17 if (Character::isCJKIdeographOrSymbol(codepoint)) { |
| 82 return testing::AssertionSuccess() << "Codepoint " << formattedAsHex | 18 return testing::AssertionSuccess() << "Codepoint " << formattedAsHex |
| 83 << " is a CJKIdeographOrSymbol."; | 19 << " is a CJKIdeographOrSymbol."; |
| 84 } | 20 } |
| 85 | 21 |
| 86 return testing::AssertionFailure() << "Codepoint " << formattedAsHex | 22 return testing::AssertionFailure() << "Codepoint " << formattedAsHex |
| 87 << " is not a CJKIdeographOrSymbol."; | 23 << " is not a CJKIdeographOrSymbol."; |
| 88 } | 24 } |
| 89 | 25 |
| 90 TEST(CharacterTest, HammerEmojiVsCJKIdeographOrSymbol) { | 26 TEST(CharacterTest, HammerEmojiVsCJKIdeographOrSymbol) { |
| 91 for (UChar32 testChar = 0; testChar < kMaxCodepoint; testChar++) { | 27 for (UChar32 testChar = 0; testChar < kMaxCodepoint; testChar++) { |
| 92 if (Character::isEmojiEmojiDefault(testChar)) { | 28 if (Character::isEmojiEmojiDefault(testChar)) { |
| 93 EXPECT_TRUE(isCJKIdeographOrSymbolWithMessage(testChar)); | 29 EXPECT_TRUE(isCJKIdeographOrSymbolWithMessage(testChar)); |
| 94 } | 30 } |
| 95 } | 31 } |
| 96 } | 32 } |
| 97 | 33 |
| 98 TEST(CharacterTest, TestCharacterRangeCodePathSurrogate1) { | |
| 99 /* To be surrogate ... */ | |
| 100 /* 1st character must be 0xD800 .. 0xDBFF */ | |
| 101 /* 2nd character must be 0xdc00 .. 0xdfff */ | |
| 102 | |
| 103 /* The following 5 should all be Simple because they are not surrogate. */ | |
| 104 static UChar c1[] = {0xD800, 0xDBFE}; | |
| 105 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c1, 2)); | |
| 106 static UChar c2[] = {0xD800, 0xE000}; | |
| 107 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c2, 2)); | |
| 108 static UChar c3[] = {0xDBFF, 0xDBFE}; | |
| 109 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c3, 2)); | |
| 110 static UChar c4[] = {0xDBFF, 0xE000}; | |
| 111 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c4, 2)); | |
| 112 static UChar c5[] = {0xDC00, 0xDBFF}; | |
| 113 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c5, 2)); | |
| 114 | |
| 115 /* To be Complex, the Supplementary Character must be in either */ | |
| 116 /* U+1F1E6 through U+1F1FF or U+E0100 through U+E01EF. */ | |
| 117 /* That is, a lead of 0xD83C with trail 0xDDE6 .. 0xDDFF or */ | |
| 118 /* a lead of 0xDB40 with trail 0xDD00 .. 0xDDEF. */ | |
| 119 static UChar c6[] = {0xD83C, 0xDDE5}; | |
| 120 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c6, 2)); | |
| 121 static UChar c7[] = {0xD83C, 0xDDE6}; | |
| 122 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c7, 2)); | |
| 123 static UChar c8[] = {0xD83C, 0xDDF0}; | |
| 124 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c8, 2)); | |
| 125 static UChar c9[] = {0xD83C, 0xDDFF}; | |
| 126 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c9, 2)); | |
| 127 static UChar c10[] = {0xD83C, 0xDE00}; | |
| 128 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c10, 2)); | |
| 129 | |
| 130 static UChar c11[] = {0xDB40, 0xDCFF}; | |
| 131 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c11, 2)); | |
| 132 static UChar c12[] = {0xDB40, 0xDD00}; | |
| 133 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c12, 2)); | |
| 134 static UChar c13[] = {0xDB40, 0xDDED}; | |
| 135 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c13, 2)); | |
| 136 static UChar c14[] = {0xDB40, 0xDDEF}; | |
| 137 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c14, 2)); | |
| 138 static UChar c15[] = {0xDB40, 0xDDF0}; | |
| 139 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c15, 2)); | |
| 140 | |
| 141 // Eye + Speech Bubble | |
| 142 static UChar c16[] = {0xD83D, 0xDC40}; | |
| 143 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c16, 2)); | |
| 144 static UChar c17[] = {0xD83D, 0xDC41}; | |
| 145 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c17, 2)); | |
| 146 static UChar c18[] = {0xD83D, 0xDC42}; | |
| 147 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c18, 2)); | |
| 148 static UChar c19[] = {0xD83D, 0xDDE7}; | |
| 149 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c19, 2)); | |
| 150 static UChar c20[] = {0xD83D, 0xDDE8}; | |
| 151 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c20, 2)); | |
| 152 static UChar c21[] = {0xD83D, 0xDDE9}; | |
| 153 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c21, 2)); | |
| 154 } | |
| 155 | |
| 156 TEST(CharacterTest, TestCharacterRangeCodePathString) { | |
| 157 // Simple-Simple is still simple | |
| 158 static UChar c1[] = {0x2FF, 0x2FF}; | |
| 159 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c1, 2)); | |
| 160 // Complex-Simple is Complex | |
| 161 static UChar c2[] = {0x300, 0x2FF}; | |
| 162 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c2, 2)); | |
| 163 // Simple-Complex is Complex | |
| 164 static UChar c3[] = {0x2FF, 0x330}; | |
| 165 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c3, 2)); | |
| 166 // Complex-Complex is Complex | |
| 167 static UChar c4[] = {0x36F, 0x330}; | |
| 168 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c4, 2)); | |
| 169 // Surrogate-Complex is Complex | |
| 170 static UChar c5[] = {0xD83C, 0xDDE5, 0x330}; | |
| 171 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c5, 3)); | |
| 172 // Complex-Surrogate is Complex | |
| 173 static UChar c6[] = {0x330, 0xD83C, 0xDDE5}; | |
| 174 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c6, 3)); | |
| 175 } | |
| 176 | |
| 177 static void TestSpecificUChar32RangeIdeograph(UChar32 rangeStart, | 34 static void TestSpecificUChar32RangeIdeograph(UChar32 rangeStart, |
| 178 UChar32 rangeEnd, | 35 UChar32 rangeEnd, |
| 179 bool before = true) { | 36 bool before = true) { |
| 180 if (before) | 37 if (before) |
| 181 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(rangeStart - 1)); | 38 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(rangeStart - 1)); |
| 182 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(rangeStart)); | 39 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(rangeStart)); |
| 183 EXPECT_TRUE(Character::isCJKIdeographOrSymbol( | 40 EXPECT_TRUE(Character::isCJKIdeographOrSymbol( |
| 184 (UChar32)((uint64_t)rangeStart + (uint64_t)rangeEnd) / 2)); | 41 (UChar32)((uint64_t)rangeStart + (uint64_t)rangeEnd) / 2)); |
| 185 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(rangeEnd)); | 42 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(rangeEnd)); |
| 186 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(rangeEnd + 1)); | 43 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(rangeEnd + 1)); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 testChar = base + objectReplacementCharacter; | 299 testChar = base + objectReplacementCharacter; |
| 443 EXPECT_FALSE(Character::treatAsZeroWidthSpaceInComplexScript(testChar)); | 300 EXPECT_FALSE(Character::treatAsZeroWidthSpaceInComplexScript(testChar)); |
| 444 | 301 |
| 445 testChar = base + 0xA; | 302 testChar = base + 0xA; |
| 446 EXPECT_FALSE(Character::isNormalizedCanvasSpaceCharacter(testChar)); | 303 EXPECT_FALSE(Character::isNormalizedCanvasSpaceCharacter(testChar)); |
| 447 testChar = base + 0x9; | 304 testChar = base + 0x9; |
| 448 EXPECT_FALSE(Character::isNormalizedCanvasSpaceCharacter(testChar)); | 305 EXPECT_FALSE(Character::isNormalizedCanvasSpaceCharacter(testChar)); |
| 449 } | 306 } |
| 450 | 307 |
| 451 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |