Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkShaperJSONWriterTest.cpp File Reference
#include "modules/skparagraph/tests/SkShaperJSONWriter.h"
#include "tests/Test.h"
#include "include/core/SkSpan.h"
#include "src/base/SkUTF.h"
#include "src/utils/SkJSONWriter.h"

Go to the source code of this file.

Functions

 DEF_TEST (SkShaperTest_cluster, reporter)
 
 DEF_TEST (SkShaperTest_VisualizeCluster, reporter)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( SkShaperTest_cluster  ,
reporter   
)

Definition at line 16 of file SkShaperJSONWriterTest.cpp.

16 {
17
18 struct Answer {
19 size_t glyphStartIndex, glyphEndIndex;
20 uint32_t utf8StartIndex, utf8EndIndex;
21 };
22
23 struct TestCase {
24 size_t utf8Len;
25 std::vector<uint32_t> clusters;
26 std::vector<Answer> answers;
27 };
28
29 std::vector<TestCase> cases = {
30 /*1:1*/ { 1, {0}, {{0, 1, 0, 1}} },
31 /*1:2*/ { 1, {0, 0}, {{0, 2, 0, 1}} },
32 /*2:1*/ { 2, {0}, {{0, 1, 0, 2}} },
33 /*2:3*/ { 2, {0, 0, 0}, {{0, 3, 0, 2}} },
34 /*3:2*/ { 3, {0, 0}, {{0, 2, 0, 3}} },
35
36 // cluster runs
37 { 2, {0, 1}, {{0, 1, 0, 1}, {1, 2, 1, 2}} },
38 { 2, {1, 0}, {{0, 1, 1, 2}, {1, 2, 0, 1}} },
39 { 2, {0, 0, 1}, {{0, 2, 0, 1}, {2, 3, 1, 2}} },
40 { 2, {1, 0, 0}, {{0, 1, 1, 2}, {1, 3, 0, 1}} },
41 { 2, {0, 1, 1}, {{0, 1, 0, 1}, {1, 3, 1, 2}} },
42 { 2, {1, 1, 0}, {{0, 2, 1, 2}, {2, 3, 0, 1}} },
43 { 3, {0, 0, 1}, {{0, 2, 0, 1}, {2, 3, 1, 3}} },
44 { 3, {1, 0, 0}, {{0, 1, 1, 3}, {1, 3, 0, 1}} },
45 { 3, {0, 1, 1}, {{0, 1, 0, 1}, {1, 3, 1, 3}} },
46 { 3, {1, 1, 0}, {{0, 2, 1, 3}, {2, 3, 0, 1}} },
47 { 4, {3, 2, 1, 0}, {{0, 1, 3, 4}, {1, 2, 2, 3}, {2, 3, 1, 2}, {3, 4, 0, 1}} },
48 };
49
50 for (auto& oneCase : cases) {
51 size_t answerCount = 0;
52 auto checker = [&](size_t glyphStartIndex, size_t glyphEndIndex,
53 uint32_t utf8StartIndex, uint32_t utf8EndIndex) {
54 if (answerCount < oneCase.answers.size()) {
55 Answer a = oneCase.answers[answerCount];
56 REPORTER_ASSERT(reporter, a.glyphStartIndex == glyphStartIndex);
57 REPORTER_ASSERT(reporter, a.glyphEndIndex == glyphEndIndex );
58 REPORTER_ASSERT(reporter, a.utf8StartIndex == utf8StartIndex );
59 REPORTER_ASSERT(reporter, a.utf8EndIndex == utf8EndIndex );
60
61 } else {
62 REPORTER_ASSERT(reporter, false, "Too many clusters");
63 }
64 answerCount++;
65 };
66
68 0, oneCase.utf8Len, SkSpan(oneCase.clusters), checker);
69 REPORTER_ASSERT(reporter, answerCount == oneCase.answers.size());
70 }
71}
reporter
static const double answers[][2]
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static void BreakupClusters(size_t utf8Begin, size_t utf8End, SkSpan< const uint32_t > clusters, const BreakupClustersCallback &processMToN)
struct MyStruct a[10]

◆ DEF_TEST() [2/2]

DEF_TEST ( SkShaperTest_VisualizeCluster  ,
reporter   
)

Definition at line 73 of file SkShaperJSONWriterTest.cpp.

73 {
74
75 struct Answer {
76 std::string utf8;
77 std::vector<SkGlyphID> glyphIDs;
78 };
79 struct TestCase {
80 std::string utf8;
81 std::vector<SkGlyphID> glyphIDs;
82 std::vector<uint32_t> clusters;
83 std::vector<Answer> answers;
84 };
85
86 std::vector<TestCase> cases = {
87 { "A", {7}, {0}, {{"A", {7}}} },
88 { "ABCD", {7, 8, 9, 10}, {0, 1, 2, 3}, {{"ABCD", {7, 8, 9, 10}}} },
89 { "A", {7, 8}, {0, 0}, {{"A", {7, 8}}} },
90 { "AB", {7}, {0}, {{"AB", {7}}} },
91 { "AB", {7, 8, 9}, {0, 0, 0}, {{"AB", {7, 8, 9}}} },
92 { "ABC", {7, 8}, {0, 0}, {{"ABC", {7, 8}}} },
93 { "ABCD", {7, 8, 9, 10}, {3, 2, 1, 0}, {{"ABCD", {7, 8, 9, 10}}} },
94 { "المادة", {246, 268, 241, 205, 240}, {10, 8, 6, 2, 0},
95 {{"ادة", {246, 268, 241}}, {"لم", {205}}, {"ا", {240}}} },
96 };
97
98 for (auto& oneCase : cases) {
99 size_t answerCount = 0;
100 auto checker = [&](
101 int codePointCount, SkSpan<const char> utf1to1, SkSpan<const SkGlyphID> glyph1to1) {
102 if (answerCount < oneCase.answers.size()) {
103 Answer a = oneCase.answers[answerCount];
104 std::string toCheckUtf8{utf1to1.data(), utf1to1.size()};
105 REPORTER_ASSERT(reporter, a.utf8 == toCheckUtf8);
106 std::vector<SkGlyphID> toCheckGlyphIDs{glyph1to1.begin(), glyph1to1.end()};
107 REPORTER_ASSERT(reporter, a.glyphIDs == toCheckGlyphIDs);
108
109 } else {
110 REPORTER_ASSERT(reporter, false, "Too many clusters");
111 }
112 answerCount++;
113 };
114
115 SkShaperJSONWriter::VisualizeClusters(oneCase.utf8.c_str(),
116 0, oneCase.utf8.size(),
117 SkSpan(oneCase.glyphIDs),
118 SkSpan(oneCase.clusters),
119 checker);
120 }
121}
static void VisualizeClusters(const char utf8[], size_t utf8Begin, size_t utf8End, SkSpan< const SkGlyphID > glyphIDs, SkSpan< const uint32_t > clusters, const VisualizeClustersCallback &processMToN)