| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2011 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "Test.h" | |
| 9 | |
| 10 // Include the implementation so we can make an appropriate template instance. | |
| 11 #include "SkAdvancedTypefaceMetrics.h" | |
| 12 | |
| 13 // Negative values and zeros in a range plus trailing zeros. | |
| 14 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
| 15 static const int16_t data1[] = {-1, 0, -3, 4, 5, 6, 7, 0, 0, 0, 8, 0, 0, 0, 0}; | |
| 16 static const char* expected1 = "0[-1 0 -3 4 5 6 7 0 0 0 8]"; | |
| 17 | |
| 18 // Run with leading and trailing zeros. | |
| 19 // Test rules: d 0 1 2 3 4 5 6 7 8 9 10 11 | |
| 20 static const int16_t data2[] = {0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 0, 0
}; | |
| 21 static const char* expected2 = "3 9 100"; | |
| 22 | |
| 23 // Removing 0's from a range. | |
| 24 // Test rules: a 0 1 2 3 4 5 6 7 8 9 10 11 | |
| 25 static const int16_t data3[] = {1, 2, 0, 0, 0, 3, 4, 0, 0, 0, 0, 5}; | |
| 26 static const char* expected3 = "0[1 2 0 0 0 3 4] 11[5]"; | |
| 27 | |
| 28 // Removing 0's from a run/range and between runs. | |
| 29 // Test rules: a, b 0 1 2 3 4 5 6 7 8 9 10 11 12 14 15 | |
| 30 static const int16_t data4[] = {1, 0, 0, 0, 1, 2, 2, 2, 3, 0, 0, 0, 0, 3, 4}; | |
| 31 static const char* expected4 = "0[1 0 0 0 1] 5 7 2 8[3] 13[3 4]"; | |
| 32 | |
| 33 // Runs that starts outside a range. | |
| 34 // Test rules: a, e 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
| 35 static const int16_t data5[] = {1, 1, 2, 3, 0, 0, 0, 0, 5, 5, 6, 7, 0, 0, 0, 0,
8, 0}; | |
| 36 static const char* expected5 = "0 1 1 2[2 3] 8 9 5 10[6 7] 16[8]"; | |
| 37 | |
| 38 // Zeros and runs that should be broken out. | |
| 39 // Test rules: a, b, e 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | |
| 40 static const int16_t data6[] = {1, 0, 0, 0, 0, 1, 2, 3, 3, 4, 5, 5, 5, 6}; | |
| 41 static const char* expected6 = "0[1] 5[1 2 3 3 4] 10 12 5 13[6]"; | |
| 42 | |
| 43 // Don't cares that aren't enough to break out a run. | |
| 44 // Test rules: c 0 1 2 3 4 5 | |
| 45 static const int16_t data7[] = {1, 2, 10, 11, 2, 3}; | |
| 46 static const char* expected7 = "0[1 2 10 11 2 3]"; | |
| 47 static const uint32_t subset7[] = {0, 1, 4, 5}; | |
| 48 static const char* expectedSubset7 = "0[1 2 0 0 2 3]"; | |
| 49 | |
| 50 // Don't cares that are enough to break out a run. | |
| 51 // Test rules: c 0 1 2 3 4 5 6 | |
| 52 static const int16_t data8[] = {1, 2, 10, 11, 12, 2, 3}; | |
| 53 static const char* expected8 = "0[1 2 10 11 12 2 3]"; | |
| 54 static const uint32_t subset8[] = {0, 1, 5, 6}; | |
| 55 static const char* expectedSubset8 = "0[1] 1 5 2 6[3]"; | |
| 56 | |
| 57 // Leading don't cares. | |
| 58 // Test rules: d 0 1 2 3 4 | |
| 59 static const int16_t data9[] = {1, 1, 10, 2, 3}; | |
| 60 static const char* expected9 = "0 1 1 2[10 2 3]"; | |
| 61 static const uint32_t subset9[] = {0, 1, 3, 4}; | |
| 62 static const char* expectedSubset9 = "0 1 1 3[2 3]"; | |
| 63 | |
| 64 // Almost run of don't cares inside a range. | |
| 65 // Test rules: c 0 1 2 3 4 5 | |
| 66 static const int16_t data10[] = {1, 2, 10, 11, 12, 3}; | |
| 67 static const char* expected10 = "0[1 2 10 11 12 3]"; | |
| 68 static const uint32_t subset10[] = {0, 1, 5}; | |
| 69 static const char* expectedSubset10 = "0[1 2 0 0 0 3]"; | |
| 70 | |
| 71 // Run of don't cares inside a range. | |
| 72 // Test rules: c 0 1 2 3 4 5 6 | |
| 73 static const int16_t data11[] = {1, 2, 10, 11, 12, 13, 3}; | |
| 74 static const char* expected11 = "0[1 2 10 11 12 13 3]"; | |
| 75 static const uint32_t subset11[] = {0, 1, 6}; | |
| 76 static const char* expectedSubset11 = "0[1 2] 6[3]"; | |
| 77 | |
| 78 // Almost run within a range with leading don't cares. | |
| 79 // Test rules: c 0 1 2 3 4 5 6 | |
| 80 static const int16_t data12[] = {1, 10, 11, 2, 12, 13, 3}; | |
| 81 static const char* expected12 = "0[1 10 11 2 12 13 3]"; | |
| 82 static const uint32_t subset12[] = {0, 3, 6}; | |
| 83 static const char* expectedSubset12 = "0[1 0 0 2 0 0 3]"; | |
| 84 | |
| 85 // Run within a range with leading don't cares. | |
| 86 // Test rules: c 0 1 2 3 4 5 6 7 | |
| 87 static const int16_t data13[] = {1, 10, 11, 2, 2, 12, 13, 3}; | |
| 88 static const char* expected13 = "0[1 10 11 2 2 12 13 3]"; | |
| 89 static const uint32_t subset13[] = {0, 3, 4, 7}; | |
| 90 static const char* expectedSubset13 = "0[1] 1 6 2 7[3]"; | |
| 91 | |
| 92 // Enough don't cares to breakup something. | |
| 93 // Test rules: a 0 1 2 3 4 5 | |
| 94 static const int16_t data14[] = {1, 0, 0, 0, 0, 2}; | |
| 95 static const char* expected14 = "0[1] 5[2]"; | |
| 96 static const uint32_t subset14[] = {0, 5}; | |
| 97 static const char* expectedSubset14 = "0[1] 5[2]"; | |
| 98 | |
| 99 static SkString stringify_advance_data(const SkSinglyLinkedList< | |
| 100 SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>>& list) { | |
| 101 SkString result; | |
| 102 bool leadingSpace = false; | |
| 103 for (const SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>& data : list) { | |
| 104 if (leadingSpace) { | |
| 105 result.append(" "); | |
| 106 } else { | |
| 107 leadingSpace = true; | |
| 108 } | |
| 109 switch (data.fType) { | |
| 110 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kRun: | |
| 111 result.appendf("%d %d %d", data.fStartId, data.fEndId, | |
| 112 data.fAdvance[0]); | |
| 113 break; | |
| 114 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kRange: | |
| 115 result.appendf("%d[", data.fStartId); | |
| 116 for (int i = 0; i < data.fAdvance.count(); ++i) { | |
| 117 if (i > 0) { | |
| 118 result.append(" "); | |
| 119 } | |
| 120 result.appendf("%d", data.fAdvance[i]); | |
| 121 } | |
| 122 result.append("]"); | |
| 123 break; | |
| 124 case SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t>::kDefault: | |
| 125 result.appendf("<Default=%d>", data.fAdvance[0]); | |
| 126 break; | |
| 127 } | |
| 128 } | |
| 129 return result; | |
| 130 } | |
| 131 | |
| 132 class TestWData { | |
| 133 public: | |
| 134 TestWData(skiatest::Reporter* reporter, | |
| 135 const int16_t advances[], int advanceLen, | |
| 136 const uint32_t subset[], int subsetLen, | |
| 137 const char* expected) | |
| 138 : fAdvances(advances) | |
| 139 , fAdvancesLen(advanceLen) | |
| 140 , fSubset(subset) | |
| 141 , fSubsetLen(subsetLen) | |
| 142 , fExpected(expected) { | |
| 143 this->runTest(reporter); | |
| 144 } | |
| 145 | |
| 146 private: | |
| 147 const int16_t* fAdvances; | |
| 148 const int fAdvancesLen; | |
| 149 const uint32_t* fSubset; | |
| 150 const int fSubsetLen; | |
| 151 const char* fExpected; | |
| 152 | |
| 153 void runTest(skiatest::Reporter* reporter) { | |
| 154 SkAdvancedTypefaceMetrics metrics; | |
| 155 metrics.setGlyphWidths( | |
| 156 fAdvancesLen, fSubset, fSubsetLen, | |
| 157 std::function<bool(int, int16_t*)>([this](int gId, int16_t* adva
nce) { | |
| 158 if (gId >= 0 && gId < fAdvancesLen) { | |
| 159 *advance = fAdvances[gId]; | |
| 160 return true; | |
| 161 } | |
| 162 return false; | |
| 163 })); | |
| 164 | |
| 165 SkString stringResult = stringify_advance_data(metrics.fGlyphWidths); | |
| 166 if (!stringResult.equals(fExpected)) { | |
| 167 ERRORF(reporter, "Expected: %s\n Result: %s\n", fExpected, stringRe
sult.c_str()); | |
| 168 } | |
| 169 } | |
| 170 }; | |
| 171 | |
| 172 DEF_TEST(WArray, reporter) { | |
| 173 TestWData(reporter, data1, SK_ARRAY_COUNT(data1), nullptr, 0, expected1); | |
| 174 TestWData(reporter, data2, SK_ARRAY_COUNT(data2), nullptr, 0, expected2); | |
| 175 TestWData(reporter, data3, SK_ARRAY_COUNT(data3), nullptr, 0, expected3); | |
| 176 TestWData(reporter, data4, SK_ARRAY_COUNT(data4), nullptr, 0, expected4); | |
| 177 TestWData(reporter, data5, SK_ARRAY_COUNT(data5), nullptr, 0, expected5); | |
| 178 TestWData(reporter, data6, SK_ARRAY_COUNT(data6), nullptr, 0, expected6); | |
| 179 TestWData(reporter, data7, SK_ARRAY_COUNT(data7), nullptr, 0, expected7); | |
| 180 TestWData(reporter, data7, SK_ARRAY_COUNT(data7), subset7, | |
| 181 SK_ARRAY_COUNT(subset7), expectedSubset7); | |
| 182 TestWData(reporter, data8, SK_ARRAY_COUNT(data8), nullptr, 0, expected8); | |
| 183 TestWData(reporter, data8, SK_ARRAY_COUNT(data8), subset8, | |
| 184 SK_ARRAY_COUNT(subset8), expectedSubset8); | |
| 185 TestWData(reporter, data9, SK_ARRAY_COUNT(data9), nullptr, 0, expected9); | |
| 186 TestWData(reporter, data9, SK_ARRAY_COUNT(data9), subset9, | |
| 187 SK_ARRAY_COUNT(subset9), expectedSubset9); | |
| 188 TestWData(reporter, data10, SK_ARRAY_COUNT(data10), nullptr, 0, expected10); | |
| 189 TestWData(reporter, data10, SK_ARRAY_COUNT(data10), subset10, | |
| 190 SK_ARRAY_COUNT(subset10), expectedSubset10); | |
| 191 TestWData(reporter, data11, SK_ARRAY_COUNT(data11), nullptr, 0, expected11); | |
| 192 TestWData(reporter, data11, SK_ARRAY_COUNT(data11), subset11, | |
| 193 SK_ARRAY_COUNT(subset11), expectedSubset11); | |
| 194 TestWData(reporter, data12, SK_ARRAY_COUNT(data12), nullptr, 0, expected12); | |
| 195 TestWData(reporter, data12, SK_ARRAY_COUNT(data12), subset12, | |
| 196 SK_ARRAY_COUNT(subset12), expectedSubset12); | |
| 197 TestWData(reporter, data13, SK_ARRAY_COUNT(data13), nullptr, 0, expected13); | |
| 198 TestWData(reporter, data13, SK_ARRAY_COUNT(data13), subset13, | |
| 199 SK_ARRAY_COUNT(subset13), expectedSubset13); | |
| 200 TestWData(reporter, data14, SK_ARRAY_COUNT(data14), nullptr, 0, expected14); | |
| 201 TestWData(reporter, data14, SK_ARRAY_COUNT(data14), subset14, | |
| 202 SK_ARRAY_COUNT(subset14), expectedSubset14); | |
| 203 } | |
| OLD | NEW |