OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 // Include the implementation so we can make an appropriate template instance. | 10 // Include the implementation so we can make an appropriate template instance. |
11 #include "SkAdvancedTypefaceMetrics.h" | 11 #include "SkAdvancedTypefaceMetrics.h" |
12 | 12 |
13 using namespace skia_advanced_typeface_metrics_utils; | |
14 | |
15 // Negative values and zeros in a range plus trailing zeros. | 13 // Negative values and zeros in a range plus trailing zeros. |
16 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 14 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
17 static const int16_t data1[] = {-1, 0, -3, 4, 5, 6, 7, 0, 0, 0, 8, 0, 0, 0, 0}; | 15 static const int16_t data1[] = {-1, 0, -3, 4, 5, 6, 7, 0, 0, 0, 8, 0, 0, 0, 0}; |
18 static const char* expected1 = "0[-1 0 -3 4 5 6 7 0 0 0 8]"; | 16 static const char* expected1 = "0[-1 0 -3 4 5 6 7 0 0 0 8]"; |
19 | 17 |
20 // Run with leading and trailing zeros. | 18 // Run with leading and trailing zeros. |
21 // Test rules: d 0 1 2 3 4 5 6 7 8 9 10 11 | 19 // Test rules: d 0 1 2 3 4 5 6 7 8 9 10 11 |
22 static const int16_t data2[] = {0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 0, 0
}; | 20 static const int16_t data2[] = {0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 0, 0
}; |
23 static const char* expected2 = "3 9 100"; | 21 static const char* expected2 = "3 9 100"; |
24 | 22 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 static const uint32_t subset13[] = {0, 3, 4, 7}; | 89 static const uint32_t subset13[] = {0, 3, 4, 7}; |
92 static const char* expectedSubset13 = "0[1] 1 6 2 7[3]"; | 90 static const char* expectedSubset13 = "0[1] 1 6 2 7[3]"; |
93 | 91 |
94 // Enough don't cares to breakup something. | 92 // Enough don't cares to breakup something. |
95 // Test rules: a 0 1 2 3 4 5 | 93 // Test rules: a 0 1 2 3 4 5 |
96 static const int16_t data14[] = {1, 0, 0, 0, 0, 2}; | 94 static const int16_t data14[] = {1, 0, 0, 0, 0, 2}; |
97 static const char* expected14 = "0[1] 5[2]"; | 95 static const char* expected14 = "0[1] 5[2]"; |
98 static const uint32_t subset14[] = {0, 5}; | 96 static const uint32_t subset14[] = {0, 5}; |
99 static const char* expectedSubset14 = "0[1] 5[2]"; | 97 static const char* expectedSubset14 = "0[1] 5[2]"; |
100 | 98 |
101 static SkString stringify_advance_data(SkAdvancedTypefaceMetrics::AdvanceMetric<
int16_t>* data) { | 99 static SkString stringify_advance_data(const SkSinglyLinkedList< |
| 100 SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>>& list) { |
102 SkString result; | 101 SkString result; |
103 bool leadingSpace = false; | 102 bool leadingSpace = false; |
104 while (data != nullptr) { | 103 for (const SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>& data : list) { |
105 if (leadingSpace) { | 104 if (leadingSpace) { |
106 result.append(" "); | 105 result.append(" "); |
107 } else { | 106 } else { |
108 leadingSpace = true; | 107 leadingSpace = true; |
109 } | 108 } |
110 switch(data->fType) { | 109 switch (data.fType) { |
111 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kRun: | 110 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kRun: |
112 result.appendf("%d %d %d", data->fStartId, data->fEndId, data->fAdvanc
e[0]); | 111 result.appendf("%d %d %d", data.fStartId, data.fEndId, |
113 break; | 112 data.fAdvance[0]); |
114 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kRange: | 113 break; |
115 result.appendf("%d[", data->fStartId); | 114 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kRange: |
116 for (int i = 0; i < data->fAdvance.count(); ++i) { | 115 result.appendf("%d[", data.fStartId); |
117 if (i > 0) { | 116 for (int i = 0; i < data.fAdvance.count(); ++i) { |
118 result.append(" "); | 117 if (i > 0) { |
119 } | 118 result.append(" "); |
120 result.appendf("%d", data->fAdvance[i]); | 119 } |
121 } | 120 result.appendf("%d", data.fAdvance[i]); |
122 result.append("]"); | 121 } |
123 break; | 122 result.append("]"); |
124 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kDefault: | 123 break; |
125 result.appendf("<Default=%d>", data->fAdvance[0]); | 124 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kDefault: |
126 break; | 125 result.appendf("<Default=%d>", data.fAdvance[0]); |
127 } | 126 break; |
128 data = data->fNext.get(); | 127 } |
129 } | 128 } |
130 return result; | 129 return result; |
131 } | 130 } |
132 | 131 |
133 class TestWData { | 132 class TestWData { |
134 public: | 133 public: |
135 TestWData(skiatest::Reporter* reporter, | 134 TestWData(skiatest::Reporter* reporter, |
136 const int16_t advances[], int advanceLen, | 135 const int16_t advances[], int advanceLen, |
137 const uint32_t subset[], int subsetLen, | 136 const uint32_t subset[], int subsetLen, |
138 const char* expected) | 137 const char* expected) |
(...skipping 15 matching lines...) Expand all Loading... |
154 static bool getAdvance(void* tc, int gId, int16_t* advance) { | 153 static bool getAdvance(void* tc, int gId, int16_t* advance) { |
155 TestWData* testCase = (TestWData*)tc; | 154 TestWData* testCase = (TestWData*)tc; |
156 if (gId >= 0 && gId < testCase->fAdvancesLen) { | 155 if (gId >= 0 && gId < testCase->fAdvancesLen) { |
157 *advance = testCase->fAdvances[gId]; | 156 *advance = testCase->fAdvances[gId]; |
158 return true; | 157 return true; |
159 } | 158 } |
160 return false; | 159 return false; |
161 } | 160 } |
162 | 161 |
163 void runTest(skiatest::Reporter* reporter) { | 162 void runTest(skiatest::Reporter* reporter) { |
164 SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t> > result
; | 163 SkAdvancedTypefaceMetrics metrics; |
165 result.reset(getAdvanceData((void*)this, fAdvancesLen, fSubset, fSubsetL
en, getAdvance)); | 164 metrics.setGlyphWidths((void*)this, fAdvancesLen, fSubset, fSubsetLen, |
| 165 getAdvance); |
166 | 166 |
167 SkString stringResult = stringify_advance_data(result); | 167 SkString stringResult = stringify_advance_data(metrics.fGlyphWidths); |
168 if (!stringResult.equals(fExpected)) { | 168 if (!stringResult.equals(fExpected)) { |
169 ERRORF(reporter, "Expected: %s\n Result: %s\n", fExpected, stringRe
sult.c_str()); | 169 ERRORF(reporter, "Expected: %s\n Result: %s\n", fExpected, stringRe
sult.c_str()); |
170 } | 170 } |
171 } | 171 } |
172 }; | 172 }; |
173 | 173 |
174 DEF_TEST(WArray, reporter) { | 174 DEF_TEST(WArray, reporter) { |
175 TestWData(reporter, data1, SK_ARRAY_COUNT(data1), nullptr, 0, expected1); | 175 TestWData(reporter, data1, SK_ARRAY_COUNT(data1), nullptr, 0, expected1); |
176 TestWData(reporter, data2, SK_ARRAY_COUNT(data2), nullptr, 0, expected2); | 176 TestWData(reporter, data2, SK_ARRAY_COUNT(data2), nullptr, 0, expected2); |
177 TestWData(reporter, data3, SK_ARRAY_COUNT(data3), nullptr, 0, expected3); | 177 TestWData(reporter, data3, SK_ARRAY_COUNT(data3), nullptr, 0, expected3); |
(...skipping 18 matching lines...) Expand all Loading... |
196 TestWData(reporter, data12, SK_ARRAY_COUNT(data12), nullptr, 0, expected12); | 196 TestWData(reporter, data12, SK_ARRAY_COUNT(data12), nullptr, 0, expected12); |
197 TestWData(reporter, data12, SK_ARRAY_COUNT(data12), subset12, | 197 TestWData(reporter, data12, SK_ARRAY_COUNT(data12), subset12, |
198 SK_ARRAY_COUNT(subset12), expectedSubset12); | 198 SK_ARRAY_COUNT(subset12), expectedSubset12); |
199 TestWData(reporter, data13, SK_ARRAY_COUNT(data13), nullptr, 0, expected13); | 199 TestWData(reporter, data13, SK_ARRAY_COUNT(data13), nullptr, 0, expected13); |
200 TestWData(reporter, data13, SK_ARRAY_COUNT(data13), subset13, | 200 TestWData(reporter, data13, SK_ARRAY_COUNT(data13), subset13, |
201 SK_ARRAY_COUNT(subset13), expectedSubset13); | 201 SK_ARRAY_COUNT(subset13), expectedSubset13); |
202 TestWData(reporter, data14, SK_ARRAY_COUNT(data14), nullptr, 0, expected14); | 202 TestWData(reporter, data14, SK_ARRAY_COUNT(data14), nullptr, 0, expected14); |
203 TestWData(reporter, data14, SK_ARRAY_COUNT(data14), subset14, | 203 TestWData(reporter, data14, SK_ARRAY_COUNT(data14), subset14, |
204 SK_ARRAY_COUNT(subset14), expectedSubset14); | 204 SK_ARRAY_COUNT(subset14), expectedSubset14); |
205 } | 205 } |
OLD | NEW |