| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/fonts/ScriptRunIterator.h" | 5 #include "platform/fonts/ScriptRunIterator.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "wtf/Assertions.h" | 8 #include "wtf/Assertions.h" |
| 9 #include "wtf/Threading.h" | 9 #include "wtf/Threading.h" |
| 10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 for (int i = 0; i < 16; ++i) { | 102 for (int i = 0; i < 16; ++i) { |
| 103 if (kTable[i] == value) { | 103 if (kTable[i] == value) { |
| 104 return i; | 104 return i; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 DLOG(ERROR) << "Table does not contain value 0x" << std::hex << value; | 107 DLOG(ERROR) << "Table does not contain value 0x" << std::hex << value; |
| 108 return 0; | 108 return 0; |
| 109 } | 109 } |
| 110 | 110 |
| 111 static String ToTestString(const std::string& input) { | 111 static String ToTestString(const std::string& input) { |
| 112 String result(emptyString16Bit()); | 112 String result(emptyString16Bit); |
| 113 bool inSet = false; | 113 bool inSet = false; |
| 114 int seen = 0; | 114 int seen = 0; |
| 115 int code = 0; | 115 int code = 0; |
| 116 int list = 0; | 116 int list = 0; |
| 117 int currentShift = 0; | 117 int currentShift = 0; |
| 118 for (char c : input) { | 118 for (char c : input) { |
| 119 if (inSet) { | 119 if (inSet) { |
| 120 switch (c) { | 120 switch (c) { |
| 121 case '(': | 121 case '(': |
| 122 ASSERT(seen == 0); | 122 ASSERT(seen == 0); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 kLatin3 + kGreek2 + kHan, | 281 kLatin3 + kGreek2 + kHan, |
| 282 kHan3 + kLatin2 + kGreek, | 282 kHan3 + kLatin2 + kGreek, |
| 283 kHan3 + kGreek2 + kLatin, | 283 kHan3 + kGreek2 + kLatin, |
| 284 kGreek3 + kLatin2 + kHan, | 284 kGreek3 + kLatin2 + kHan, |
| 285 kGreek3 + kHan2 + kLatin, | 285 kGreek3 + kHan2 + kLatin, |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 class ScriptRunIteratorTest : public testing::Test { | 288 class ScriptRunIteratorTest : public testing::Test { |
| 289 protected: | 289 protected: |
| 290 void CheckRuns(const Vector<TestRun>& runs) { | 290 void CheckRuns(const Vector<TestRun>& runs) { |
| 291 String text(emptyString16Bit()); | 291 String text(emptyString16Bit); |
| 292 Vector<ExpectedRun> expect; | 292 Vector<ExpectedRun> expect; |
| 293 for (auto& run : runs) { | 293 for (auto& run : runs) { |
| 294 text.append(String::fromUTF8(run.text.c_str())); | 294 text.append(String::fromUTF8(run.text.c_str())); |
| 295 expect.push_back(ExpectedRun(text.length(), run.code)); | 295 expect.push_back(ExpectedRun(text.length(), run.code)); |
| 296 } | 296 } |
| 297 ScriptRunIterator scriptRunIterator(text.characters16(), text.length()); | 297 ScriptRunIterator scriptRunIterator(text.characters16(), text.length()); |
| 298 VerifyRuns(&scriptRunIterator, expect); | 298 VerifyRuns(&scriptRunIterator, expect); |
| 299 } | 299 } |
| 300 | 300 |
| 301 // FIXME crbug.com/527329 - CheckMockRuns should be replaced by finding | 301 // FIXME crbug.com/527329 - CheckMockRuns should be replaced by finding |
| 302 // suitable equivalent real codepoint sequences instead. | 302 // suitable equivalent real codepoint sequences instead. |
| 303 void CheckMockRuns(const Vector<TestRun>& runs) { | 303 void CheckMockRuns(const Vector<TestRun>& runs) { |
| 304 String text(emptyString16Bit()); | 304 String text(emptyString16Bit); |
| 305 Vector<ExpectedRun> expect; | 305 Vector<ExpectedRun> expect; |
| 306 for (const TestRun& run : runs) { | 306 for (const TestRun& run : runs) { |
| 307 text.append(MockScriptData::ToTestString(run.text)); | 307 text.append(MockScriptData::ToTestString(run.text)); |
| 308 expect.push_back(ExpectedRun(text.length(), run.code)); | 308 expect.push_back(ExpectedRun(text.length(), run.code)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 ScriptRunIterator scriptRunIterator(text.characters16(), text.length(), | 311 ScriptRunIterator scriptRunIterator(text.characters16(), text.length(), |
| 312 MockScriptData::instance()); | 312 MockScriptData::instance()); |
| 313 VerifyRuns(&scriptRunIterator, expect); | 313 VerifyRuns(&scriptRunIterator, expect); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void VerifyRuns(ScriptRunIterator* scriptRunIterator, | 316 void VerifyRuns(ScriptRunIterator* scriptRunIterator, |
| 317 const Vector<ExpectedRun>& expect) { | 317 const Vector<ExpectedRun>& expect) { |
| 318 unsigned limit; | 318 unsigned limit; |
| 319 UScriptCode code; | 319 UScriptCode code; |
| 320 unsigned long runCount = 0; | 320 unsigned long runCount = 0; |
| 321 while (scriptRunIterator->consume(limit, code)) { | 321 while (scriptRunIterator->consume(limit, code)) { |
| 322 ASSERT_LT(runCount, expect.size()); | 322 ASSERT_LT(runCount, expect.size()); |
| 323 ASSERT_EQ(expect[runCount].limit, limit); | 323 ASSERT_EQ(expect[runCount].limit, limit); |
| 324 ASSERT_EQ(expect[runCount].code, code); | 324 ASSERT_EQ(expect[runCount].code, code); |
| 325 ++runCount; | 325 ++runCount; |
| 326 } | 326 } |
| 327 ASSERT_EQ(expect.size(), runCount); | 327 ASSERT_EQ(expect.size(), runCount); |
| 328 } | 328 } |
| 329 }; | 329 }; |
| 330 | 330 |
| 331 TEST_F(ScriptRunIteratorTest, Empty) { | 331 TEST_F(ScriptRunIteratorTest, Empty) { |
| 332 String empty(emptyString16Bit()); | 332 String empty(emptyString16Bit); |
| 333 ScriptRunIterator scriptRunIterator(empty.characters16(), empty.length()); | 333 ScriptRunIterator scriptRunIterator(empty.characters16(), empty.length()); |
| 334 unsigned limit = 0; | 334 unsigned limit = 0; |
| 335 UScriptCode code = USCRIPT_INVALID_CODE; | 335 UScriptCode code = USCRIPT_INVALID_CODE; |
| 336 ASSERT(!scriptRunIterator.consume(limit, code)); | 336 ASSERT(!scriptRunIterator.consume(limit, code)); |
| 337 ASSERT_EQ(limit, 0u); | 337 ASSERT_EQ(limit, 0u); |
| 338 ASSERT_EQ(code, USCRIPT_INVALID_CODE); | 338 ASSERT_EQ(code, USCRIPT_INVALID_CODE); |
| 339 } | 339 } |
| 340 | 340 |
| 341 // Some of our compilers cannot initialize a vector from an array yet. | 341 // Some of our compilers cannot initialize a vector from an array yet. |
| 342 #define DECLARE_RUNSVECTOR(...) \ | 342 #define DECLARE_RUNSVECTOR(...) \ |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 679 } |
| 680 } | 680 } |
| 681 } | 681 } |
| 682 | 682 |
| 683 // ZWJ is \u200D Cf (Format, other) and its script is inherited. I'm going to | 683 // ZWJ is \u200D Cf (Format, other) and its script is inherited. I'm going to |
| 684 // ignore this for now, as I think it shouldn't matter which run it ends up | 684 // ignore this for now, as I think it shouldn't matter which run it ends up |
| 685 // in. HarfBuzz needs to be able to use it as context and shape each | 685 // in. HarfBuzz needs to be able to use it as context and shape each |
| 686 // neighboring character appropriately no matter what run it got assigned to. | 686 // neighboring character appropriately no matter what run it got assigned to. |
| 687 | 687 |
| 688 } // namespace blink | 688 } // namespace blink |
| OLD | NEW |