OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 String value("foo"); | 48 String value("foo"); |
49 TextRun run(value); | 49 TextRun run(value); |
50 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; | 50 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; |
51 bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride()
)); | 51 bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride()
)); |
52 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); | 52 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); |
53 TextDirection direction = bidiResolver.determineParagraphDirectionality(&has
StrongDirectionality); | 53 TextDirection direction = bidiResolver.determineParagraphDirectionality(&has
StrongDirectionality); |
54 EXPECT_TRUE(hasStrongDirectionality); | 54 EXPECT_TRUE(hasStrongDirectionality); |
55 EXPECT_EQ(LTR, direction); | 55 EXPECT_EQ(LTR, direction); |
56 } | 56 } |
57 | 57 |
| 58 TextDirection determineParagraphDirectionality(const TextRun& textRun, bool* has
StrongDirectionality = 0) |
| 59 { |
| 60 BidiResolver<TextRunIterator, BidiCharacterRun> resolver; |
| 61 resolver.setStatus(BidiStatus(LTR, false)); |
| 62 resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); |
| 63 return resolver.determineParagraphDirectionality(hasStrongDirectionality); |
| 64 } |
| 65 |
| 66 struct TestData { |
| 67 UChar text[3]; |
| 68 size_t length; |
| 69 TextDirection expectedDirection; |
| 70 bool expectedStrong; |
| 71 }; |
| 72 |
| 73 void testDirectionality(const TestData& entry) |
| 74 { |
| 75 bool hasStrongDirectionality; |
| 76 String data(entry.text, entry.length); |
| 77 TextRun run(data); |
| 78 TextDirection direction = determineParagraphDirectionality(run, &hasStrongDi
rectionality); |
| 79 EXPECT_EQ(entry.expectedStrong, hasStrongDirectionality); |
| 80 EXPECT_EQ(entry.expectedDirection, direction); |
| 81 } |
| 82 |
| 83 TEST(BidiResolver, ParagraphDirectionSurrogates) |
| 84 { |
| 85 const TestData testData[] = { |
| 86 // Test strong RTL, non-BMP. (U+10858 Imperial Aramaic number one, stron
g RTL) |
| 87 { { 0xD802, 0xDC58 }, 2, RTL, true }, |
| 88 |
| 89 // Test strong LTR, non-BMP. (U+1D15F Musical symbol quarter note, stron
g LTR) |
| 90 { { 0xD834, 0xDD5F }, 2, LTR, true }, |
| 91 |
| 92 // Test broken surrogate: valid leading, invalid trail. (Lead of U+10858
, space) |
| 93 { { 0xD802, ' ' }, 2, LTR, false }, |
| 94 |
| 95 // Test broken surrogate: invalid leading. (Trail of U+10858, U+05D0 Heb
rew Alef) |
| 96 { { 0xDC58, 0x05D0 }, 2, RTL, true }, |
| 97 |
| 98 // Test broken surrogate: valid leading, invalid trail/valid lead, valid
trail. |
| 99 { { 0xD802, 0xD802, 0xDC58 }, 3, RTL, true }, |
| 100 |
| 101 // Test broken surrogate: valid leading, no trail (string too short). (L
ead of U+10858) |
| 102 { { 0xD802, 0xDC58 }, 1, LTR, false }, |
| 103 |
| 104 // Test broken surrogate: trail appearing before lead. (U+10858 units re
versed) |
| 105 { { 0xDC58, 0xD802 }, 2, LTR, false } |
| 106 }; |
| 107 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testData); ++i) |
| 108 testDirectionality(testData[i]); |
| 109 } |
| 110 |
58 class BidiTestRunner { | 111 class BidiTestRunner { |
59 public: | 112 public: |
60 BidiTestRunner() | 113 BidiTestRunner() |
61 : m_testsRun(0) | 114 : m_testsRun(0) |
62 , m_testsSkipped(0) | 115 , m_testsSkipped(0) |
63 , m_ignoredCharFailures(0) | 116 , m_ignoredCharFailures(0) |
64 , m_levelFailures(0) | 117 , m_levelFailures(0) |
65 , m_orderFailures(0) | 118 , m_orderFailures(0) |
66 { | 119 { |
67 } | 120 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 { | 153 { |
101 std::ostringstream diff; | 154 std::ostringstream diff; |
102 diff << "actual: "; | 155 diff << "actual: "; |
103 // This is the magical way to print a vector to a stream, clear, right? | 156 // This is the magical way to print a vector to a stream, clear, right? |
104 std::copy(actual.begin(), actual.end(), std::ostream_iterator<int>(diff, " "
)); | 157 std::copy(actual.begin(), actual.end(), std::ostream_iterator<int>(diff, " "
)); |
105 diff << " expected: "; | 158 diff << " expected: "; |
106 std::copy(expected.begin(), expected.end(), std::ostream_iterator<int>(diff,
" ")); | 159 std::copy(expected.begin(), expected.end(), std::ostream_iterator<int>(diff,
" ")); |
107 return diff.str(); | 160 return diff.str(); |
108 } | 161 } |
109 | 162 |
110 TextDirection determineParagraphDirectionality(const TextRun& textRun) | |
111 { | |
112 BidiResolver<TextRunIterator, BidiCharacterRun> resolver; | |
113 resolver.setStatus(BidiStatus(LTR, false)); | |
114 resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); | |
115 return resolver.determineParagraphDirectionality(); | |
116 } | |
117 | |
118 void BidiTestRunner::runTest(const std::basic_string<UChar>& input, const std::v
ector<int>& expectedOrder, | 163 void BidiTestRunner::runTest(const std::basic_string<UChar>& input, const std::v
ector<int>& expectedOrder, |
119 const std::vector<int>& expectedLevels, bidi_test::ParagraphDirection paragr
aphDirection, | 164 const std::vector<int>& expectedLevels, bidi_test::ParagraphDirection paragr
aphDirection, |
120 const std::string& line, size_t lineNumber) | 165 const std::string& line, size_t lineNumber) |
121 { | 166 { |
122 if (!m_skippedCodePoints.empty()) { | 167 if (!m_skippedCodePoints.empty()) { |
123 for (size_t i = 0; i < input.size(); i++) { | 168 for (size_t i = 0; i < input.size(); i++) { |
124 if (m_skippedCodePoints.count(input[i])) { | 169 if (m_skippedCodePoints.count(input[i])) { |
125 m_testsSkipped++; | 170 m_testsSkipped++; |
126 return; | 171 return; |
127 } | 172 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // The unittest harness only pays attention to GTest output, so we verify | 284 // The unittest harness only pays attention to GTest output, so we verify |
240 // that the tests behaved as expected: | 285 // that the tests behaved as expected: |
241 EXPECT_EQ(352098u, runner.m_testsRun); | 286 EXPECT_EQ(352098u, runner.m_testsRun); |
242 EXPECT_EQ(418143u, runner.m_testsSkipped); | 287 EXPECT_EQ(418143u, runner.m_testsSkipped); |
243 EXPECT_EQ(0u, runner.m_ignoredCharFailures); | 288 EXPECT_EQ(0u, runner.m_ignoredCharFailures); |
244 EXPECT_EQ(44882u, runner.m_levelFailures); | 289 EXPECT_EQ(44882u, runner.m_levelFailures); |
245 EXPECT_EQ(19151u, runner.m_orderFailures); | 290 EXPECT_EQ(19151u, runner.m_orderFailures); |
246 } | 291 } |
247 | 292 |
248 } | 293 } |
OLD | NEW |