Flutter Engine
The Flutter Engine
Macros | Functions
SkUnicodeTest.cpp File Reference
#include "include/core/SkSpan.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "src/base/SkBitmaskEnum.h"
#include "tests/Test.h"
#include "modules/skunicode/include/SkUnicode.h"
#include <vector>

Go to the source code of this file.

Macros

#define DEF_TEST_ICU(name, reporter)
 
#define DEF_TEST_ICU4X(name, reporter)
 
#define DEF_TEST_LIBGRAPHEME(name, reporter)
 
#define DEF_TEST_NOIMPL(name, reporter)
 
#define DEF_TEST_UNICODES(name, reporter)
 
#define DEF_TEST_ICU_UNICODES(name, reporter)
 

Functions

bool hasWordFlag (SkUnicode::CodeUnitFlags flags)
 
 DEF_TEST_ICU_UNICODES (SkUnicode_GetBidiRegionsLTR, reporter)
 
 DEF_TEST_ICU_UNICODES (SkUnicode_GetBidiRegionsRTL, reporter)
 
 DEF_TEST_ICU_UNICODES (SkUnicode_GetBidiRegionsMix1, reporter)
 
 DEF_TEST_ICU_UNICODES (SkUnicode_GetBidiRegionsMix2, reporter)
 
 DEF_TEST_ICU_UNICODES (SkUnicode_ToUpper, reporter)
 
 DEF_TEST_ICU_UNICODES (SkUnicode_ComputeCodeUnitFlags, reporter)
 
 DEF_TEST_UNICODES (SkUnicode_ReorderVisual, reporter)
 
static void SkUnicode_Emoji (SkUnicode *icu, skiatest::Reporter *reporter)
 
static void SkUnicode_Ideographic (SkUnicode *icu, skiatest::Reporter *reporter)
 

Macro Definition Documentation

◆ DEF_TEST_ICU

#define DEF_TEST_ICU (   name,
  reporter 
)

Definition at line 36 of file SkUnicodeTest.cpp.

◆ DEF_TEST_ICU4X

#define DEF_TEST_ICU4X (   name,
  reporter 
)

Definition at line 43 of file SkUnicodeTest.cpp.

◆ DEF_TEST_ICU_UNICODES

#define DEF_TEST_ICU_UNICODES (   name,
  reporter 
)
Value:
DEF_TEST_ICU(name, reporter) \
DEF_TEST_ICU4X(name, reporter) \
DEF_TEST_NOIMPL(name, reporter) \
reporter
Definition: FontMgrTest.cpp:39
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

Definition at line 63 of file SkUnicodeTest.cpp.

◆ DEF_TEST_LIBGRAPHEME

#define DEF_TEST_LIBGRAPHEME (   name,
  reporter 
)

Definition at line 50 of file SkUnicodeTest.cpp.

◆ DEF_TEST_NOIMPL

#define DEF_TEST_NOIMPL (   name,
  reporter 
)

Definition at line 53 of file SkUnicodeTest.cpp.

◆ DEF_TEST_UNICODES

#define DEF_TEST_UNICODES (   name,
  reporter 
)
Value:
DEF_TEST_ICU(name, reporter) \
DEF_TEST_ICU4X(name, reporter) \
DEF_TEST_LIBGRAPHEME(name, reporter) \
DEF_TEST_NOIMPL(name, reporter) \

Definition at line 55 of file SkUnicodeTest.cpp.

Function Documentation

◆ DEF_TEST_ICU_UNICODES() [1/6]

DEF_TEST_ICU_UNICODES ( SkUnicode_ComputeCodeUnitFlags  ,
reporter   
)

Definition at line 251 of file SkUnicodeTest.cpp.

251 {
252 if (!unicode) {
253 return;
254 }
255 //SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
256 SkString text("1\n22 333 4444 55555 666666 7777777");
257 // 4 8 13 19 24
259 auto result = unicode->computeCodeUnitFlags(text.data(),
260 text.size(),
261 /*replaceTabs=*/true,
262 &results);
264 REPORTER_ASSERT(reporter, results.size() == SkToS16(text.size() + 1));
265 for (auto i = 0; i < results.size(); ++i) {
266 auto flags = results[i];
267 auto expected = SkUnicode::CodeUnitFlags::kGraphemeStart;
268 if (i == 1) {
270 }
271 if (i == 2) {
272 expected |= SkUnicode::CodeUnitFlags::kHardLineBreakBefore;
273 }
274 if (i == 1 || i == 4 || i == 8 || i == 13 || i == 19 || i == 26) {
275 expected |= SkUnicode::CodeUnitFlags::kPartOfWhiteSpaceBreak;
276 expected |= SkUnicode::CodeUnitFlags::kPartOfIntraWordBreak;
277 }
278 if (i == 0 || i == 2 || i == 5 || i == 9 || i == 14 || i == 20
279 || i == 27 || i == 34) {
280 expected |= SkUnicode::CodeUnitFlags::kSoftLineBreakBefore;
281 }
282 REPORTER_ASSERT(reporter, flags == expected);
283 }
284}
constexpr int16_t SkToS16(S x)
Definition: SkTo.h:23
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int size() const
Definition: SkTArray.h:421
FlutterSemanticsFlag flags
GAsyncResult * result
std::u16string text
constexpr int kControl

◆ DEF_TEST_ICU_UNICODES() [2/6]

DEF_TEST_ICU_UNICODES ( SkUnicode_GetBidiRegionsLTR  ,
reporter   
)

Definition at line 143 of file SkUnicodeTest.cpp.

143 {
144 if (!unicode) {
145 return;
146 }
147 SkString text("1 22 333 4444 55555 666666 7777777");
148 std::vector<SkUnicode::BidiRegion> results;
149 auto result = unicode->getBidiRegions(text.data(),
150 text.size(),
152 &results);
154 REPORTER_ASSERT(reporter, results.size() == 1);
155 REPORTER_ASSERT(reporter, results[0].start == 0 &&
156 results[0].end == text.size() &&
157 results[0].level == 0);
158}
glong glong end

◆ DEF_TEST_ICU_UNICODES() [3/6]

DEF_TEST_ICU_UNICODES ( SkUnicode_GetBidiRegionsMix1  ,
reporter   
)

Definition at line 177 of file SkUnicodeTest.cpp.

177 {
178 if (!unicode) {
179 return;
180 }
181 // Spaces become Arabic (RTL) but numbers remain English (LTR)
182 SkString text("1 22 333 4444 55555 666666 7777777");
183 std::vector<SkUnicode::BidiRegion> expected = {
184 {0, 1, 2},
185 {1, 2, 1},
186 {2, 4, 2},
187 {4, 5, 1},
188 {5, 8, 2},
189 {8, 9, 1},
190 {9, 13, 2},
191 {13, 14, 1},
192 {14, 19, 2},
193 {19, 20, 1},
194 {20, 26, 2},
195 {26, 27, 1},
196 {27, 34, 2},
197 };
198 std::vector<SkUnicode::BidiRegion> results;
199 auto result = unicode->getBidiRegions(text.data(),
200 text.size(),
202 &results);
204 REPORTER_ASSERT(reporter, results.size() == expected.size());
205 for (auto i = 0ul; i < results.size(); ++i) {
206 REPORTER_ASSERT(reporter, results[i].start == expected[i].start &&
207 results[i].end == expected[i].end &&
208 results[i].level == expected[i].level);
209 }
210}

◆ DEF_TEST_ICU_UNICODES() [4/6]

DEF_TEST_ICU_UNICODES ( SkUnicode_GetBidiRegionsMix2  ,
reporter   
)

Definition at line 212 of file SkUnicodeTest.cpp.

212 {
213 if (!unicode) {
214 return;
215 }
216 // Few Russian/English words (ЛТР) in the mix
217 SkString text("World ЛТР Domination هي عبارة قبيحة ، أفضل أن أسميها World ЛТР Optimization.");
218 std::vector<SkUnicode::BidiRegion> expected = {
219 { 0, 24, 0},
220 { 24, 80, 1},
221 { 80, 107, 0},
222 };
223 std::vector<SkUnicode::BidiRegion> results;
224 auto result = unicode->getBidiRegions(text.data(),
225 text.size(),
227 &results);
229 REPORTER_ASSERT(reporter, results.size() == expected.size());
230 for (auto i = 0ul; i < results.size(); ++i) {
231 REPORTER_ASSERT(reporter, results[i].start == expected[i].start &&
232 results[i].end == expected[i].end &&
233 results[i].level == expected[i].level);
234 }
235}

◆ DEF_TEST_ICU_UNICODES() [5/6]

DEF_TEST_ICU_UNICODES ( SkUnicode_GetBidiRegionsRTL  ,
reporter   
)

Definition at line 160 of file SkUnicodeTest.cpp.

160 {
161 if (!unicode) {
162 return;
163 }
164 SkString text("الهيمنة على العالم عبارة قبيحة ، أفضل أن أسميها تحسين العالم.");
165 std::vector<SkUnicode::BidiRegion> results;
166 auto result = unicode->getBidiRegions(text.data(),
167 text.size(),
169 &results);
171 REPORTER_ASSERT(reporter, results.size() == 1);
172 REPORTER_ASSERT(reporter, results[0].start == 0 &&
173 results[0].end == text.size() &&
174 results[0].level == 1);
175}

◆ DEF_TEST_ICU_UNICODES() [6/6]

DEF_TEST_ICU_UNICODES ( SkUnicode_ToUpper  ,
reporter   
)

Definition at line 239 of file SkUnicodeTest.cpp.

239 {
240 if (!unicode) {
241 return;
242 }
243 SkString lower("abcdefghijklmnopqrstuvwxyz");
244 SkString upper("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
245 auto icu_result1 = unicode->toUpper(lower);
246 REPORTER_ASSERT(reporter, icu_result1.equals(upper));
247 auto icu_result2 = unicode->toUpper(upper);
248 REPORTER_ASSERT(reporter, icu_result2.equals(upper));
249}

◆ DEF_TEST_UNICODES()

DEF_TEST_UNICODES ( SkUnicode_ReorderVisual  ,
reporter   
)

Definition at line 286 of file SkUnicodeTest.cpp.

286 {
287 if (!unicode) {
288 return;
289 }
290 auto reorder = [&](std::vector<SkUnicode::BidiLevel> levels,
291 std::vector<int32_t> expected) {
292 std::vector<int32_t> logicalOrder(levels.size());
293 unicode->reorderVisual(levels.data(), levels.size(), logicalOrder.data());
294 for (auto i = 0ul; i < levels.size(); ++i) {
295 REPORTER_ASSERT(reporter, expected[i] == logicalOrder[i]);
296 }
297 };
298 reorder({}, {});
299 reorder({0}, {0});
300 reorder({1}, {0});
301 reorder({0, 1, 0, 1}, {0, 1, 2, 3});
302}

◆ hasWordFlag()

bool hasWordFlag ( SkUnicode::CodeUnitFlags  flags)

Definition at line 138 of file SkUnicodeTest.cpp.

138 {
140}
@ kWordBreak
Definition: SkUnicode.h:91

◆ SkUnicode_Emoji()

static void SkUnicode_Emoji ( SkUnicode icu,
skiatest::Reporter reporter 
)
static

Definition at line 304 of file SkUnicodeTest.cpp.

304 {
305 std::u32string emojis(U"😄😁😆😅😂🤣");
306 std::u32string not_emojis(U"満毎行昼本可");
307 for (auto e : emojis) {
309 }
310 for (auto n: not_emojis) {
312 }
313}
virtual bool isEmoji(SkUnichar utf8)=0

◆ SkUnicode_Ideographic()

static void SkUnicode_Ideographic ( SkUnicode icu,
skiatest::Reporter reporter 
)
static

Definition at line 337 of file SkUnicodeTest.cpp.

337 {
338 std::u32string ideographic(U"満毎行昼本可");
339 std::u32string not_ideographic(U"😄😁😆😅😂🤣");
340 for (auto i : ideographic) {
342 }
343 for (auto n: not_ideographic) {
345 }
346}
virtual bool isIdeographic(SkUnichar utf8)=0