Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / fonts / FontTest.cpp
blob9d8a17be8f86e2157ad2f3dcd44fd315201dcf38
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // Tests for the Font class.
28 #include "config.h"
30 #include "platform/fonts/Character.h"
31 #include "platform/fonts/Font.h"
33 #include <gtest/gtest.h>
35 namespace blink {
37 static void TestSpecificUCharRange(UChar rangeStart, UChar rangeEnd)
39 UChar below[1];
40 UChar start[1];
41 UChar midway[1];
42 UChar end[1];
43 UChar above[1];
45 below[0] = rangeStart - 1;
46 start[0] = rangeStart;
47 midway[0] = ((int)rangeStart + (int)rangeEnd) / 2;
48 end[0] = rangeEnd;
49 above[0] = rangeEnd + 1;
51 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(below, 1));
52 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(start, 1));
53 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(midway, 1));
54 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(end, 1));
55 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(above, 1));
58 TEST(FontTest, TestCharacterRangeCodePath)
60 static UChar c1[] = { 0x0 };
61 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c1, 1));
63 TestSpecificUCharRange(0x2E5, 0x2E9);
64 TestSpecificUCharRange(0x300, 0x36F);
65 TestSpecificUCharRange(0x0591, 0x05BD);
66 TestSpecificUCharRange(0x05BF, 0x05CF);
67 TestSpecificUCharRange(0x0600, 0x109F);
68 TestSpecificUCharRange(0x1100, 0x11FF);
69 TestSpecificUCharRange(0x135D, 0x135F);
70 TestSpecificUCharRange(0x1700, 0x18AF);
71 TestSpecificUCharRange(0x1900, 0x194F);
72 TestSpecificUCharRange(0x1980, 0x19DF);
73 TestSpecificUCharRange(0x1A00, 0x1CFF);
75 static UChar c2[] = { 0x1DBF };
76 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c2, 1));
77 static UChar c3[] = { 0x1DC0 };
78 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c3, 1));
79 static UChar c4[] = { 0x1DD0 };
80 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c4, 1));
81 static UChar c5[] = { 0x1DFF };
82 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c5, 1));
83 static UChar c6[] = { 0x1E00 };
84 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c6, 1));
85 static UChar c7[] = { 0x2000 };
86 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c7, 1));
87 static UChar c8[] = { 0x2001 };
88 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c8, 1));
90 TestSpecificUCharRange(0x20D0, 0x20FF);
91 TestSpecificUCharRange(0x2CEF, 0x2CF1);
92 TestSpecificUCharRange(0x302A, 0x302F);
94 TestSpecificUCharRange(0xA67C, 0xA67D);
95 TestSpecificUCharRange(0xA6F0, 0xA6F1);
96 TestSpecificUCharRange(0xA800, 0xABFF);
98 TestSpecificUCharRange(0xD7B0, 0xD7FF);
99 TestSpecificUCharRange(0xFE00, 0xFE0F);
100 TestSpecificUCharRange(0xFE20, 0xFE2F);
103 TEST(FontTest, TestCharacterRangeCodePathSurrogate1)
105 /* To be surrogate ... */
106 /* 1st character must be 0xD800 .. 0xDBFF */
107 /* 2nd character must be 0xdc00 .. 0xdfff */
109 /* The following 5 should all be Simple because they are not surrogate. */
110 static UChar c1[] = { 0xD800, 0xDBFE };
111 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c1, 2));
112 static UChar c2[] = { 0xD800, 0xE000 };
113 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c2, 2));
114 static UChar c3[] = { 0xDBFF, 0xDBFE };
115 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c3, 2));
116 static UChar c4[] = { 0xDBFF, 0xE000 };
117 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c4, 2));
118 static UChar c5[] = { 0xDC00, 0xDBFF };
119 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c5, 2));
121 /* To be Complex, the Supplementary Character must be in either */
122 /* U+1F1E6 through U+1F1FF or U+E0100 through U+E01EF. */
123 /* That is, a lead of 0xD83C with trail 0xDDE6 .. 0xDDFF or */
124 /* a lead of 0xDB40 with trail 0xDD00 .. 0xDDEF. */
125 static UChar c6[] = { 0xD83C, 0xDDE5 };
126 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c6, 2));
127 static UChar c7[] = { 0xD83C, 0xDDE6 };
128 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c7, 2));
129 static UChar c8[] = { 0xD83C, 0xDDF0 };
130 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c8, 2));
131 static UChar c9[] = { 0xD83C, 0xDDFF };
132 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c9, 2));
133 static UChar c10[] = { 0xD83C, 0xDE00 };
134 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c10, 2));
136 static UChar c11[] = { 0xDB40, 0xDCFF };
137 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c11, 2));
138 static UChar c12[] = { 0xDB40, 0xDD00 };
139 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c12, 2));
140 static UChar c13[] = { 0xDB40, 0xDDED };
141 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c13, 2));
142 static UChar c14[] = { 0xDB40, 0xDDEF };
143 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c14, 2));
144 static UChar c15[] = { 0xDB40, 0xDDF0 };
145 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c15, 2));
148 TEST(FontTest, TestCharacterRangeCodePathString)
150 // Simple-Simple is still simple
151 static UChar c1[] = { 0x2FF, 0x2FF };
152 EXPECT_EQ(SimplePath, Character::characterRangeCodePath(c1, 2));
153 // Complex-Simple is Complex
154 static UChar c2[] = { 0x300, 0x2FF };
155 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c2, 2));
156 // Simple-Complex is Complex
157 static UChar c3[] = { 0x2FF, 0x330 };
158 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c3, 2));
159 // Complex-Complex is Complex
160 static UChar c4[] = { 0x36F, 0x330 };
161 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c4, 2));
162 // Surrogate-Complex is Complex
163 static UChar c5[] = { 0xD83C, 0xDDE5, 0x330 };
164 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c5, 3));
165 // Complex-Surrogate is Complex
166 static UChar c6[] = { 0x330, 0xD83C, 0xDDE5 };
167 EXPECT_EQ(ComplexPath, Character::characterRangeCodePath(c6, 3));
170 static void TestSpecificUChar32RangeIdeograph(UChar32 rangeStart, UChar32 rangeEnd)
172 EXPECT_FALSE(Character::isCJKIdeograph(rangeStart - 1));
173 EXPECT_TRUE(Character::isCJKIdeograph(rangeStart));
174 EXPECT_TRUE(Character::isCJKIdeograph((UChar32)((uint64_t)rangeStart + (uint64_t)rangeEnd) / 2));
175 EXPECT_TRUE(Character::isCJKIdeograph(rangeEnd));
176 EXPECT_FALSE(Character::isCJKIdeograph(rangeEnd + 1));
179 TEST(FontTest, TestIsCJKIdeograph)
181 // The basic CJK Unified Ideographs block.
182 TestSpecificUChar32RangeIdeograph(0x4E00, 0x9FFF);
183 // CJK Unified Ideographs Extension A.
184 TestSpecificUChar32RangeIdeograph(0x3400, 0x4DBF);
185 // CJK Unified Ideographs Extension A and Kangxi Radicals.
186 TestSpecificUChar32RangeIdeograph(0x2E80, 0x2FDF);
187 // CJK Strokes.
188 TestSpecificUChar32RangeIdeograph(0x31C0, 0x31EF);
189 // CJK Compatibility Ideographs.
190 TestSpecificUChar32RangeIdeograph(0xF900, 0xFAFF);
191 // CJK Unified Ideographs Extension B.
192 TestSpecificUChar32RangeIdeograph(0x20000, 0x2A6DF);
193 // CJK Unified Ideographs Extension C.
194 // CJK Unified Ideographs Extension D.
195 TestSpecificUChar32RangeIdeograph(0x2A700, 0x2B81F);
196 // CJK Compatibility Ideographs Supplement.
197 TestSpecificUChar32RangeIdeograph(0x2F800, 0x2FA1F);
200 static void TestSpecificUChar32RangeIdeographSymbol(UChar32 rangeStart, UChar32 rangeEnd)
202 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(rangeStart - 1));
203 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(rangeStart));
204 EXPECT_TRUE(Character::isCJKIdeographOrSymbol((UChar32)((uint64_t)rangeStart + (uint64_t)rangeEnd) / 2));
205 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(rangeEnd));
206 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(rangeEnd + 1));
209 TEST(FontTest, TestIsCJKIdeographOrSymbol)
211 // CJK Compatibility Ideographs Supplement.
212 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2C7));
213 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2CA));
214 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2CB));
215 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2D9));
217 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2020));
218 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2021));
219 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2030));
220 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x203B));
221 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x203C));
222 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2042));
223 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2047));
224 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2048));
225 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2049));
226 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2051));
227 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x20DD));
228 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x20DE));
229 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2100));
230 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2103));
231 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2105));
232 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2109));
233 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x210A));
234 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2113));
235 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2116));
236 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2121));
237 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x212B));
238 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x213B));
239 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2150));
240 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2151));
241 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2152));
243 TestSpecificUChar32RangeIdeographSymbol(0x2156, 0x215A);
244 TestSpecificUChar32RangeIdeographSymbol(0x2160, 0x216B);
245 TestSpecificUChar32RangeIdeographSymbol(0x2170, 0x217B);
247 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x217F));
248 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2189));
249 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2307));
250 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2312));
252 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0x23BD));
253 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x23BE));
254 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x23C4));
255 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x23CC));
256 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0x23CD));
257 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x23CE));
258 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2423));
260 TestSpecificUChar32RangeIdeographSymbol(0x2460, 0x2492);
261 TestSpecificUChar32RangeIdeographSymbol(0x249C, 0x24FF);
263 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25A0));
264 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25A1));
265 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25A2));
266 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25AA));
267 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25AB));
268 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25B1));
269 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25B2));
270 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25B3));
271 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25B6));
272 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25B7));
273 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25BC));
274 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25BD));
275 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25C0));
276 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25C1));
277 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25C6));
278 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25C7));
279 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25C9));
280 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25CB));
281 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25CC));
283 TestSpecificUChar32RangeIdeographSymbol(0x25CE, 0x25D3);
284 TestSpecificUChar32RangeIdeographSymbol(0x25E2, 0x25E6);
286 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x25EF));
288 TestSpecificUChar32RangeIdeographSymbol(0x2600, 0x2603);
290 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2605));
291 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2606));
292 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x260E));
293 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2616));
294 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2617));
295 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2640));
296 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2642));
298 TestSpecificUChar32RangeIdeographSymbol(0x2660, 0x266F);
299 TestSpecificUChar32RangeIdeographSymbol(0x2672, 0x267D);
301 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x26A0));
302 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x26BD));
303 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x26BE));
304 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2713));
305 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x271A));
306 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x273F));
307 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2740));
308 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2756));
310 TestSpecificUChar32RangeIdeographSymbol(0x2776, 0x277F);
312 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x2B1A));
314 TestSpecificUChar32RangeIdeographSymbol(0x2FF0, 0x302F);
315 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x3031));
316 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x312F));
317 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0x3130));
319 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0x318F));
320 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x3190));
321 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x319F));
322 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x31BF));
324 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0x31FF));
325 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x3200));
326 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x3300));
327 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x33FF));
329 TestSpecificUChar32RangeIdeographSymbol(0xF860, 0xF862);
330 TestSpecificUChar32RangeIdeographSymbol(0xFE30, 0xFE4F);
332 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0xFE10));
333 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0xFE11));
334 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0xFE12));
335 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0xFE19));
337 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0xFF0D));
338 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0xFF1B));
339 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0xFF1C));
340 EXPECT_FALSE(Character::isCJKIdeographOrSymbol(0xFF1E));
342 TestSpecificUChar32RangeIdeographSymbol(0xFF00, 0xFFEF);
344 EXPECT_TRUE(Character::isCJKIdeographOrSymbol(0x1F100));
346 TestSpecificUChar32RangeIdeographSymbol(0x1F110, 0x1F129);
347 TestSpecificUChar32RangeIdeographSymbol(0x1F130, 0x1F149);
348 TestSpecificUChar32RangeIdeographSymbol(0x1F150, 0x1F169);
349 TestSpecificUChar32RangeIdeographSymbol(0x1F170, 0x1F189);
350 TestSpecificUChar32RangeIdeographSymbol(0x1F200, 0x1F6FF);
353 } // namespace blink