198 TBool r = MTmSource::GetLineBreakL(aText, aDocPos, |
206 TBool r = MTmSource::GetLineBreakL(aText, aDocPos, |
199 aMinBreakPos, aMaxBreakPos, aForwards, |
207 aMinBreakPos, aMaxBreakPos, aForwards, |
200 aBreakPos, aHangingChars, aBreakPosAfterSpaces); |
208 aBreakPos, aHangingChars, aBreakPosAfterSpaces); |
201 if (r) |
209 if (r) |
202 { |
210 { |
203 test(aMinBreakPos <= aBreakPos); |
211 TESTPOINT(aMinBreakPos <= aBreakPos); |
204 test(0 < aBreakPos); |
212 TESTPOINT(0 < aBreakPos); |
205 test(aBreakPos <= aHangingChars); |
213 TESTPOINT(aBreakPos <= aHangingChars); |
206 test(aHangingChars <= aBreakPosAfterSpaces); |
214 TESTPOINT(aHangingChars <= aBreakPosAfterSpaces); |
207 test(aBreakPos <= aMaxBreakPos); |
215 TESTPOINT(aBreakPos <= aMaxBreakPos); |
208 test(aHangingChars == aBreakPos || iHangingChar); |
216 TESTPOINT(aHangingChars == aBreakPos || iHangingChar); |
209 // If the direction was backwards, the algorithm should have |
217 // If the direction was backwards, the algorithm should have |
210 // checked if a hanging character was allowed. |
218 // checked if a hanging character was allowed. |
211 // This condition could be relaxed to allow it not to be checked |
219 // This condition could be relaxed to allow it not to be checked |
212 // if there is no break allowed between the possible hanging |
220 // if there is no break allowed between the possible hanging |
213 // character and the previous character. |
221 // character and the previous character. |
214 test(!aForwards || aText.Length() == aMaxBreakPos |
222 TESTPOINT(!aForwards || aText.Length() == aMaxBreakPos |
215 || 0 < iHangingCharRequestCount); |
223 || 0 < iHangingCharRequestCount); |
216 // If the maximum break point was chosen or exceeded, the algorithm |
224 // If the maximum break point was chosen or exceeded, the algorithm |
217 // should have checked to find out whether a hanging character is |
225 // should have checked to find out whether a hanging character is |
218 // allowed. |
226 // allowed. |
219 test(aHangingChars < aMaxBreakPos |
227 TESTPOINT(aHangingChars < aMaxBreakPos |
220 || 0 < iHangingCharRequestCount); |
228 || 0 < iHangingCharRequestCount); |
221 // Check that only spaces exist between aHangingChars and |
229 // Check that only spaces exist between aHangingChars and |
222 // aMaxBreakPos |
230 // aMaxBreakPos |
223 for (TInt i = aHangingChars; i != aBreakPosAfterSpaces; ++i) |
231 for (TInt i = aHangingChars; i != aBreakPosAfterSpaces; ++i) |
224 { |
232 { |
225 TUint n; |
233 TUint n; |
226 test(ESpLineBreakClass == LineBreakClass(aText[i], n, n)); |
234 TESTPOINT(ESpLineBreakClass == LineBreakClass(aText[i], n, n)); |
227 } |
235 } |
228 // Check that all the spaces were counted |
236 // Check that all the spaces were counted |
229 test(aBreakPosAfterSpaces == aText.Length() |
237 TESTPOINT(aBreakPosAfterSpaces == aText.Length() |
230 || aText[aBreakPosAfterSpaces] != ' '); |
238 || aText[aBreakPosAfterSpaces] != ' '); |
231 } |
239 } |
232 // Find out how many runs of two or more Sa there are, and check that |
240 // Find out how many runs of two or more Sa there are, and check that |
233 // this matches the number of times that it was requested. |
241 // this matches the number of times that it was requested. |
234 TInt minChecked = aMinBreakPos - 1; |
242 TInt minChecked = aMinBreakPos - 1; |
330 b2 = KMaxTInt; |
338 b2 = KMaxTInt; |
331 return t.GetLineBreakL(aText, 0, aMin, aMax, aForwards, b0, b1, b2)? |
339 return t.GetLineBreakL(aText, 0, aMin, aMax, aForwards, b0, b1, b2)? |
332 b1 : -1; |
340 b1 : -1; |
333 } |
341 } |
334 |
342 |
335 void RunTests() |
343 CTTmSourceStep::CTTmSourceStep() |
336 { |
344 { |
337 test.Title(); |
345 |
338 test.Start(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMSOURCE-0001 Line-Break Tests: ")); |
346 } |
339 |
347 |
340 test(-1 == TestLineBreak(_L(""), 0, 0, 0, 0, 0)); |
348 |
341 test(-1 == TestLineBreak(_L("5"), 0, 0, 0, 0, 0)); |
349 TVerdict CTTmSourceStep::doTestStepL() |
342 test(-1 == TestLineBreak(_L("5"), 0, 0, 0, 0, 1)); |
350 { |
343 test(-1 == TestLineBreak(_L("@"), 1, 0, 0, 0, 0)); |
351 SetTestStepResult(EPass); |
344 test(1 == TestLineBreak(_L("a b"), 0, 0, 0, 0, 0)); |
352 TestStep = this; |
345 test(-1 == TestLineBreak(_L("0 0 0 9 9"), 0, 0, 0, 0, 0)); |
353 TESTPRINT(_L("TTmSource - MTmSource tests")); |
346 test(-1 == TestLineBreak(_L("0 0 0 9 9"), 0, 0, 0, 0, 1)); |
354 TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMSOURCE-0001 Line-Break Tests: ")); |
347 test(9 == TestLineBreak(_L("4242454445"), 0, 0, 0, 0, 0)); |
355 |
348 test(5 == TestLineBreak(_L("4242454445"), 0, 0, 0, 0, 1)); |
356 TEST(-1 == TestLineBreak(_L(""), 0, 0, 0, 0, 0)); |
349 test(5 == TestLineBreak(_L("hello there"), 0, 0, 0, 0, 0)); |
357 TEST(-1 == TestLineBreak(_L("5"), 0, 0, 0, 0, 0)); |
350 test(5 == TestLineBreak(_L("hello there"), 0, 0, 0, 0, 1)); |
358 TEST(-1 == TestLineBreak(_L("5"), 0, 0, 0, 0, 1)); |
351 test(-1 == TestLineBreak(_L("hel the re"), 0, 0, 5, 7, 0)); |
359 TEST(-1 == TestLineBreak(_L("@"), 1, 0, 0, 0, 0)); |
352 test(-1 == TestLineBreak(_L("hel the re"), 0, 0, 5, 7, 1)); |
360 TEST(1 == TestLineBreak(_L("a b"), 0, 0, 0, 0, 0)); |
353 test(8 == TestLineBreak(_L("hel the re"), 0, 1, 5, 7, 0)); |
361 TEST(-1 == TestLineBreak(_L("0 0 0 9 9"), 0, 0, 0, 0, 0)); |
354 test(8 == TestLineBreak(_L("hel the re"), 0, 1, 6, 7, 1)); |
362 TEST(-1 == TestLineBreak(_L("0 0 0 9 9"), 0, 0, 0, 0, 1)); |
355 test(3 == TestLineBreak(_L("@@@@@"), 3, 0, 0, 0, 0)); |
363 TEST(9 == TestLineBreak(_L("4242454445"), 0, 0, 0, 0, 0)); |
356 test(3 == TestLineBreak(_L("@@@@@"), 3, 0, 0, 0, 1)); |
364 TEST(5 == TestLineBreak(_L("4242454445"), 0, 0, 0, 0, 1)); |
357 test(5 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 5, 0, 5, 0, 0)); |
365 TEST(5 == TestLineBreak(_L("hello there"), 0, 0, 0, 0, 0)); |
358 test(5 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 5, 0, 5, 0, 1)); |
366 TEST(5 == TestLineBreak(_L("hello there"), 0, 0, 0, 0, 1)); |
359 test(16 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 16, 0, 0, 0, 0)); |
367 TEST(-1 == TestLineBreak(_L("hel the re"), 0, 0, 5, 7, 0)); |
360 test(16 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 16, 0, 0, 0, 1)); |
368 TEST(-1 == TestLineBreak(_L("hel the re"), 0, 0, 5, 7, 1)); |
361 test(5 == TestLineBreak(_L("55@@@55"), 0, 0, 0, 0, 0)); |
369 TEST(8 == TestLineBreak(_L("hel the re"), 0, 1, 5, 7, 0)); |
362 test(2 == TestLineBreak(_L("55@@@55"), 0, 0, 0, 0, 1)); |
370 TEST(8 == TestLineBreak(_L("hel the re"), 0, 1, 6, 7, 1)); |
363 test(3 == TestLineBreak(_L("55@55"), 0, 0, 0, 0, 0)); |
371 TEST(3 == TestLineBreak(_L("@@@@@"), 3, 0, 0, 0, 0)); |
364 test(2 == TestLineBreak(_L("55@55"), 0, 0, 0, 0, 1)); |
372 TEST(3 == TestLineBreak(_L("@@@@@"), 3, 0, 0, 0, 1)); |
|
373 TEST(5 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 5, 0, 5, 0, 0)); |
|
374 TEST(5 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 5, 0, 5, 0, 1)); |
|
375 TEST(16 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 16, 0, 0, 0, 0)); |
|
376 TEST(16 == TestLineBreak(_L("9999@@@@@00099@@@@gfra"), 16, 0, 0, 0, 1)); |
|
377 TEST(5 == TestLineBreak(_L("55@@@55"), 0, 0, 0, 0, 0)); |
|
378 TEST(2 == TestLineBreak(_L("55@@@55"), 0, 0, 0, 0, 1)); |
|
379 TEST(3 == TestLineBreak(_L("55@55"), 0, 0, 0, 0, 0)); |
|
380 TEST(2 == TestLineBreak(_L("55@55"), 0, 0, 0, 0, 1)); |
365 |
381 |
366 // Test for DEF046468, which was caused by the TLineBreakIterator constructor accessing past the end of a string |
382 // Test for DEF046468, which was caused by the TLineBreakIterator constructor accessing past the end of a string |
367 test.Next(_L("Line-Break DEF046468 Test:")); |
383 TESTPRINT(_L("Line-Break DEF046468 Test:")); |
368 // Create a string of 16 chars with a picture code at the 17th position |
384 // Create a string of 16 chars with a picture code at the 17th position |
369 _LIT(KLarsString, "dolor sit amet, \xFFFC"); |
385 _LIT(KLarsString, "dolor sit amet, \xFFFC"); |
370 // Create a TPtrC for the 16 character string ( with the picture code after the string in memory ) |
386 // Create a TPtrC for the 16 character string ( with the picture code after the string in memory ) |
371 TBufC<20> KTestBuffer(KLarsString); |
387 TBufC<20> KTestBuffer(KLarsString); |
372 TPtrC KTestString( reinterpret_cast<const TUint16*>(KTestBuffer.Ptr()), 16); |
388 TPtrC KTestString( reinterpret_cast<const TUint16*>(KTestBuffer.Ptr()), 16); |
373 // Test the iterator overrun. If iterator accesses past the end of the array, it'll get picture code and crash |
389 // Test the iterator overrun. If iterator accesses past the end of the array, it'll get picture code and crash |
374 test(9 == TestLineBreak(KTestString,0,0,1,15,0)); |
390 TEST(9 == TestLineBreak(KTestString,0,0,1,15,0)); |
375 |
391 |
376 test.End(); |
392 return TestStepResult(); |
377 test.Close(); |
|
378 |
|
379 } |
393 } |
380 |
|
381 TInt E32Main() |
|
382 { |
|
383 TrapCleanup = CTrapCleanup::New(); |
|
384 TRAPD(err, RunTests()); |
|
385 test(err == KErrNone); |
|
386 delete TrapCleanup; |
|
387 return 0; |
|
388 } |
|