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 30 matching lines...) Expand all Loading... |
41 bool hasStrongDirectionality; | 41 bool hasStrongDirectionality; |
42 String value("foo"); | 42 String value("foo"); |
43 TextRun run(value); | 43 TextRun run(value); |
44 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; | 44 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; |
45 bidiResolver.setStatus( | 45 bidiResolver.setStatus( |
46 BidiStatus(run.direction(), run.directionalOverride())); | 46 BidiStatus(run.direction(), run.directionalOverride())); |
47 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); | 47 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); |
48 TextDirection direction = | 48 TextDirection direction = |
49 bidiResolver.determineParagraphDirectionality(&hasStrongDirectionality); | 49 bidiResolver.determineParagraphDirectionality(&hasStrongDirectionality); |
50 EXPECT_TRUE(hasStrongDirectionality); | 50 EXPECT_TRUE(hasStrongDirectionality); |
51 EXPECT_EQ(TextDirection::Ltr, direction); | 51 EXPECT_EQ(TextDirection::kLtr, direction); |
52 } | 52 } |
53 | 53 |
54 TextDirection determineParagraphDirectionality( | 54 TextDirection determineParagraphDirectionality( |
55 const TextRun& textRun, | 55 const TextRun& textRun, |
56 bool* hasStrongDirectionality = 0) { | 56 bool* hasStrongDirectionality = 0) { |
57 BidiResolver<TextRunIterator, BidiCharacterRun> resolver; | 57 BidiResolver<TextRunIterator, BidiCharacterRun> resolver; |
58 resolver.setStatus(BidiStatus(TextDirection::Ltr, false)); | 58 resolver.setStatus(BidiStatus(TextDirection::kLtr, false)); |
59 resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); | 59 resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); |
60 return resolver.determineParagraphDirectionality(hasStrongDirectionality); | 60 return resolver.determineParagraphDirectionality(hasStrongDirectionality); |
61 } | 61 } |
62 | 62 |
63 struct TestData { | 63 struct TestData { |
64 UChar text[3]; | 64 UChar text[3]; |
65 size_t length; | 65 size_t length; |
66 TextDirection expectedDirection; | 66 TextDirection expectedDirection; |
67 bool expectedStrong; | 67 bool expectedStrong; |
68 }; | 68 }; |
69 | 69 |
70 void testDirectionality(const TestData& entry) { | 70 void testDirectionality(const TestData& entry) { |
71 bool hasStrongDirectionality; | 71 bool hasStrongDirectionality; |
72 String data(entry.text, entry.length); | 72 String data(entry.text, entry.length); |
73 TextRun run(data); | 73 TextRun run(data); |
74 TextDirection direction = | 74 TextDirection direction = |
75 determineParagraphDirectionality(run, &hasStrongDirectionality); | 75 determineParagraphDirectionality(run, &hasStrongDirectionality); |
76 EXPECT_EQ(entry.expectedStrong, hasStrongDirectionality); | 76 EXPECT_EQ(entry.expectedStrong, hasStrongDirectionality); |
77 EXPECT_EQ(entry.expectedDirection, direction); | 77 EXPECT_EQ(entry.expectedDirection, direction); |
78 } | 78 } |
79 | 79 |
80 TEST(BidiResolver, ParagraphDirectionSurrogates) { | 80 TEST(BidiResolver, ParagraphDirectionSurrogates) { |
81 const TestData testData[] = { | 81 const TestData testData[] = { |
82 // Test strong RTL, non-BMP. (U+10858 Imperial | 82 // Test strong RTL, non-BMP. (U+10858 Imperial |
83 // Aramaic number one, strong RTL) | 83 // Aramaic number one, strong RTL) |
84 {{0xD802, 0xDC58}, 2, TextDirection::Rtl, true}, | 84 {{0xD802, 0xDC58}, 2, TextDirection::kRtl, true}, |
85 | 85 |
86 // Test strong LTR, non-BMP. (U+1D15F Musical | 86 // Test strong LTR, non-BMP. (U+1D15F Musical |
87 // symbol quarter note, strong LTR) | 87 // symbol quarter note, strong LTR) |
88 {{0xD834, 0xDD5F}, 2, TextDirection::Ltr, true}, | 88 {{0xD834, 0xDD5F}, 2, TextDirection::kLtr, true}, |
89 | 89 |
90 // Test broken surrogate: valid leading, invalid | 90 // Test broken surrogate: valid leading, invalid |
91 // trail. (Lead of U+10858, space) | 91 // trail. (Lead of U+10858, space) |
92 {{0xD802, ' '}, 2, TextDirection::Ltr, false}, | 92 {{0xD802, ' '}, 2, TextDirection::kLtr, false}, |
93 | 93 |
94 // Test broken surrogate: invalid leading. (Trail | 94 // Test broken surrogate: invalid leading. (Trail |
95 // of U+10858, U+05D0 Hebrew Alef) | 95 // of U+10858, U+05D0 Hebrew Alef) |
96 {{0xDC58, 0x05D0}, 2, TextDirection::Rtl, true}, | 96 {{0xDC58, 0x05D0}, 2, TextDirection::kRtl, true}, |
97 | 97 |
98 // Test broken surrogate: valid leading, invalid | 98 // Test broken surrogate: valid leading, invalid |
99 // trail/valid lead, valid trail. | 99 // trail/valid lead, valid trail. |
100 {{0xD802, 0xD802, 0xDC58}, 3, TextDirection::Rtl, true}, | 100 {{0xD802, 0xD802, 0xDC58}, 3, TextDirection::kRtl, true}, |
101 | 101 |
102 // Test broken surrogate: valid leading, no trail | 102 // Test broken surrogate: valid leading, no trail |
103 // (string too short). (Lead of U+10858) | 103 // (string too short). (Lead of U+10858) |
104 {{0xD802, 0xDC58}, 1, TextDirection::Ltr, false}, | 104 {{0xD802, 0xDC58}, 1, TextDirection::kLtr, false}, |
105 | 105 |
106 // Test broken surrogate: trail appearing before | 106 // Test broken surrogate: trail appearing before |
107 // lead. (U+10858 units reversed) | 107 // lead. (U+10858 units reversed) |
108 {{0xDC58, 0xD802}, 2, TextDirection::Ltr, false}}; | 108 {{0xDC58, 0xD802}, 2, TextDirection::kLtr, false}}; |
109 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testData); ++i) | 109 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testData); ++i) |
110 testDirectionality(testData[i]); | 110 testDirectionality(testData[i]); |
111 } | 111 } |
112 | 112 |
113 class BidiTestRunner { | 113 class BidiTestRunner { |
114 public: | 114 public: |
115 BidiTestRunner() | 115 BidiTestRunner() |
116 : m_testsRun(0), | 116 : m_testsRun(0), |
117 m_testsSkipped(0), | 117 m_testsSkipped(0), |
118 m_ignoredCharFailures(0), | 118 m_ignoredCharFailures(0), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 | 179 |
180 m_testsRun++; | 180 m_testsRun++; |
181 | 181 |
182 TextRun textRun(input.data(), input.size()); | 182 TextRun textRun(input.data(), input.size()); |
183 switch (paragraphDirection) { | 183 switch (paragraphDirection) { |
184 case bidi_test::DirectionAutoLTR: | 184 case bidi_test::DirectionAutoLTR: |
185 textRun.setDirection(determineParagraphDirectionality(textRun)); | 185 textRun.setDirection(determineParagraphDirectionality(textRun)); |
186 break; | 186 break; |
187 case bidi_test::DirectionLTR: | 187 case bidi_test::DirectionLTR: |
188 textRun.setDirection(TextDirection::Ltr); | 188 textRun.setDirection(TextDirection::kLtr); |
189 break; | 189 break; |
190 case bidi_test::DirectionRTL: | 190 case bidi_test::DirectionRTL: |
191 textRun.setDirection(TextDirection::Rtl); | 191 textRun.setDirection(TextDirection::kRtl); |
192 break; | 192 break; |
193 } | 193 } |
194 BidiResolver<TextRunIterator, BidiCharacterRun> resolver; | 194 BidiResolver<TextRunIterator, BidiCharacterRun> resolver; |
195 resolver.setStatus( | 195 resolver.setStatus( |
196 BidiStatus(textRun.direction(), textRun.directionalOverride())); | 196 BidiStatus(textRun.direction(), textRun.directionalOverride())); |
197 resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); | 197 resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); |
198 | 198 |
199 BidiRunList<BidiCharacterRun>& runs = resolver.runs(); | 199 BidiRunList<BidiCharacterRun>& runs = resolver.runs(); |
200 resolver.createBidiRunsForLine(TextRunIterator(&textRun, textRun.length())); | 200 resolver.createBidiRunsForLine(TextRunIterator(&textRun, textRun.length())); |
201 | 201 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // The unittest harness only pays attention to GTest output, so we verify | 292 // The unittest harness only pays attention to GTest output, so we verify |
293 // that the tests behaved as expected: | 293 // that the tests behaved as expected: |
294 EXPECT_EQ(352098u, runner.m_testsRun); | 294 EXPECT_EQ(352098u, runner.m_testsRun); |
295 EXPECT_EQ(418143u, runner.m_testsSkipped); | 295 EXPECT_EQ(418143u, runner.m_testsSkipped); |
296 EXPECT_EQ(0u, runner.m_ignoredCharFailures); | 296 EXPECT_EQ(0u, runner.m_ignoredCharFailures); |
297 EXPECT_EQ(44882u, runner.m_levelFailures); | 297 EXPECT_EQ(44882u, runner.m_levelFailures); |
298 EXPECT_EQ(19151u, runner.m_orderFailures); | 298 EXPECT_EQ(19151u, runner.m_orderFailures); |
299 } | 299 } |
300 | 300 |
301 } // namespace blink | 301 } // namespace blink |
OLD | NEW |