Update contrib.
2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
30 #include "tformhindi.h"
32 namespace LocalToTFormHindi {
34 _LIT(KTformhindi, "tformhindi");
35 const TInt KDisplayWidth = 100;
36 const TInt KDisplayHeight = 100;
37 _LIT(KDevanagariFontName, "Devanagari OT Eval");
39 CTFormHindiStep* TestStep = NULL;
40 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
41 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
44 using namespace LocalToTFormHindi;
46 _LIT(KTestDeva, "|\x915\x94d\x92b|\x907|\x920\x94d\x920|");
47 _LIT(KTestBidi, "|\x915|\x644|\x920|");
48 _LIT(KTestDeva2, "|\x917|\x91c|\x92f\x93f|\x924\x94d\x932\x940|\x917|");
50 static const TInt KZeroWidthJoiner = 0x200d;
52 /** Test that the deletions occur in expected places.
53 Expected places should be marked by '|' (pipe character).
54 These will be removed prior to the test.
57 void TestDeletePosition(const TDesC& aTestText, CRichText* aRichText,
62 TInt positionCount = 0;
64 TInt ttlen = aTestText.Length();
65 for (TInt i = 0; i != ttlen; ++i)
67 TInt c = aTestText[i];
70 positions[positionCount] = text.Length();
78 aRichText->InsertL(0, text);
79 TCharFormat format(KDevanagariFontName, 200);
81 mask.SetAttrib(EAttFontTypeface);
82 aRichText->ApplyCharFormatL(format, mask, 0, text.Length());
83 aTextView->FormatTextL();
85 for (TInt j = 0; j < positionCount - 1; ++j)
87 aTextView->SetDocPosL(positions[j], EFalse);
88 TInt pos = aTextView->GetForwardDeletePositionL().HigherPos();
89 TESTPOINT(pos == positions[j + 1]);
90 aTextView->SetDocPosL(positions[j], ETrue);
91 pos = aTextView->GetForwardDeletePositionL().HigherPos();
92 TESTPOINT(pos == positions[j + 1]);
93 aTextView->SetDocPosL(positions[j + 1], EFalse);
94 pos = aTextView->GetBackwardDeletePositionL().LowerPos();
95 TESTPOINT(pos == positions[j]);
96 aTextView->SetDocPosL(positions[j + 1], ETrue);
97 pos = aTextView->GetBackwardDeletePositionL().LowerPos();
98 TESTPOINT(pos == positions[j]);
105 // DEF101191: FORM always splits chunks at ZWJ character
107 class CPDEF_101617_CustomDraw : public MFormCustomDraw
110 CPDEF_101617_CustomDraw() :
116 virtual ~CPDEF_101617_CustomDraw() {}
118 void setExpectedChunk(const TDesC& aChunk)
124 void setExpectedChunks(const TDesC& aLeftChunk, const TDesC& aRightChunk)
126 iLeftChunk = aLeftChunk;
127 iRightChunk = aRightChunk;
132 virtual void DrawText(const TParam& /*aParam*/, const TLineInfo& /*aLineInfo*/, const TCharFormat& /*aFormat*/,
133 const TDesC& aText, const TPoint& /*aTextOrigin*/, TInt /*aExtraPixels*/) const
135 TBool containsZWJ = EFalse;
138 TInt len = aText.Length();
139 for (TInt i = 0; i < len; i++)
142 if (0xffff != aText[i])
144 text.Append(aText[i]);
145 if (KZeroWidthJoiner == aText[i])
152 // check that the text was splitted as expected
153 if (containsZWJ || iChunk > 0)
155 // the first chunk with a LZW should be equal to iLeftChunk
158 TESTPOINT(text == iLeftChunk);
161 // the following chunk should be equal to iRightChunk, if it is not-null.
162 else if (1 == iChunk && iRightChunk.Size() > 0)
164 TESTPOINT(text == iRightChunk);
167 // just ignore the following chunks
172 TBuf<100> iLeftChunk;
173 TBuf<100> iRightChunk;
174 mutable TInt iChunk; // modified in a const method
177 void PDEF_101617_DefectL(CRichText* aRichText, CTextView* aTextView)
179 TCharFormat format(KDevanagariFontName, 200);
180 TCharFormatMask mask;
181 mask.SetAttrib(EAttFontTypeface);
183 CPDEF_101617_CustomDraw* customDrawer = new CPDEF_101617_CustomDraw;
184 CleanupStack::PushL(customDrawer);
186 CTextLayout* layout = const_cast<CTextLayout*>(aTextView->Layout());
187 layout->SetCustomDraw(customDrawer);
189 TRect rect(0, 0, 300, 100);
191 // 1. test the sequence Sha, Virama, ZWJ, Va,Sha, EndOfParagraph
192 _LIT(KTestDevaZWJ1, "\x0936\x094d\x200d\x0935\x0936\x2029");
193 TPtrC text1(KTestDevaZWJ1().Ptr(), KTestDevaZWJ1().Length());
195 // the text should not be split and should remain a single chunk...
196 _LIT(KTestDevaZWJ1_LeftChunk, "\x0936\x094d\x200d\x0935\x0936");
198 customDrawer->setExpectedChunk(KTestDevaZWJ1_LeftChunk);
201 aRichText->InsertL(0, text1);
202 aRichText->ApplyCharFormatL(format, mask, 0, text1.Length());
203 aTextView->FormatTextL();
204 aTextView->DrawL(rect);
207 // 2. test the sequence Sha,ZWJ,Virama, Va, EndOfParagraph
208 _LIT(KTestDevaZWJ2, "\x0936\x200d\x094d\x0935\x2029");
209 TPtrC text2(KTestDevaZWJ2().Ptr(), KTestDevaZWJ2().Length());
211 // the text should be split at the bidirectionality change
212 _LIT(KTestDevaZWJ2_LeftChunk, "\x0936\x200d\x094d\x0935");
214 customDrawer->setExpectedChunk(KTestDevaZWJ2_LeftChunk);
217 aRichText->InsertL(0, text2);
218 aRichText->ApplyCharFormatL(format, mask, 0, text2.Length());
219 aTextView->FormatTextL();
220 aTextView->DrawL(rect);
222 // 3. test the sequence Sha, Virama, ZWJ,Alef(Hebrew) EndOfParagraph
223 _LIT(KTestDevaZWJ3, "\x0936\x094d\x200d\x05D0\x2029");
224 TPtrC text3(KTestDevaZWJ3().Ptr(), KTestDevaZWJ3().Length());
226 // the text should be split keeping ZWJ (0x200d) at the end of the first chunk...
227 _LIT(KTestDevaZWJ3_LeftChunk, "\x0936\x094d\x200d");
228 // ... and placing another ZWJ at the start of the second chunk (right to left text)
229 _LIT(KTestDevaZWJ3_RightChunk, "\x05D0\x200d");
231 customDrawer->setExpectedChunks(KTestDevaZWJ3_LeftChunk, KTestDevaZWJ3_RightChunk);
234 aRichText->InsertL(0, text3);
235 aRichText->ApplyCharFormatL(format, mask, 0, text3.Length());
236 aTextView->FormatTextL();
237 aTextView->DrawL(rect);
239 // 4. test the sequence Sha, Virama, ZWJ, Va,Alef(Hebrew) EndOfParagraph
240 _LIT(KTestDevaZWJ4, "\x0936\x094d\x200d\x0935\x05D0\x2029");
241 TPtrC text4(KTestDevaZWJ4().Ptr(), KTestDevaZWJ4().Length());
243 // the text should be split at the bidirectionality change
244 _LIT(KTestDevaZWJ4_LeftChunk, "\x0936\x094d\x200d\x0935");
245 _LIT(KTestDevaZWJ4_RightChunk, "\x05D0");
247 customDrawer->setExpectedChunks(KTestDevaZWJ4_LeftChunk, KTestDevaZWJ4_RightChunk);
250 aRichText->InsertL(0, text4);
251 aRichText->ApplyCharFormatL(format, mask, 0, text4.Length());
252 aTextView->FormatTextL();
253 aTextView->DrawL(rect);
257 layout->SetCustomDraw(NULL);
258 CleanupStack::PopAndDestroy(customDrawer);
262 /** @SYMTestCaseID SYSLIB-FORM-UT-1532
264 Test delete-by-syllable within Hindi text.
265 @SYMTestPriority High
267 Format some Devanagari, test result of calling GetForwardDeletePositionL
268 and GetBackwardDeletePositionL for various inputs.
269 @SYMTestExpectedResults
270 Success if the font "Devanagari OT Eval" is present, Not Run if it is not.
271 This font is licensed to Symbian by Monotype Imaging Ltd. for internal
272 testing only and so is not distributed with the SDK. Therefore users
273 outside of Symbian will experience Not Run unless they have also
276 void TestTextViewL(CRichText* aRichText,
277 CTextView* aTextView)
279 // Test devanagari delete-by-syllable
280 TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1532 Test some simple Hindi "));
281 TestDeletePosition(KTestDeva, aRichText, aTextView);
284 // The Arabic character is not present in this font, not even
285 // as a fallback glyph. This allows us to exercise a fixes for
287 TESTPRINT(_L("Test with characters not in font"));
288 TestDeletePosition(KTestBidi, aRichText, aTextView);
290 // Test sample suggested by customer
291 TESTPRINT(_L("Test Hindi #2"));
292 TestDeletePosition(KTestDeva2, aRichText, aTextView);
294 // regression test for PDEF101617: FORM always splits chunks at ZWJ character
295 TESTPRINT(_L("Regression test: PDEF101617"));
296 PDEF_101617_DefectL(aRichText, aTextView);
300 void TestL(CFbsScreenDevice* aDevice)
302 CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
303 CleanupStack::PushL(paraFormat);
304 CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
305 CleanupStack::PushL(charFormat);
306 CRichText* text = CRichText::NewL(paraFormat, charFormat);
307 CleanupStack::PushL(text);
308 TRect displayRect(0, 0, KDisplayWidth, KDisplayHeight);
309 CTextLayout* layout = CTextLayout::NewL(text, displayRect.Width());
310 CleanupStack::PushL(layout);
311 CTextView* view = CTextView::NewL(layout, displayRect,
312 aDevice, aDevice, 0, 0, 0);
313 CleanupStack::PushL(view);
314 TestTextViewL(text, view);
315 CleanupStack::PopAndDestroy(view);
316 CleanupStack::PopAndDestroy(layout);
317 CleanupStack::PopAndDestroy(text);
318 CleanupStack::PopAndDestroy(charFormat);
319 CleanupStack::PopAndDestroy(paraFormat);
322 TVerdict CTFormHindiStep::doTestStepL()
324 SetTestStepResult(EPass);
326 TESTPRINT(KTformhindi);
328 TInt error = RFbsSession::Connect();
329 if (error == KErrNotFound)
332 User::LeaveIfError(RFbsSession::Connect());
334 CFbsScreenDevice* screenDevice = 0;
336 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor16M));
337 if (error == KErrNotSupported)
338 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor16MA));
339 if (error == KErrNotSupported)
340 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor16MU));
341 if (error == KErrNotSupported)
342 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor64K));
343 if (error == KErrNotSupported)
344 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor4K));
345 if (error == KErrNotSupported)
346 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor256));
347 if (error == KErrNotSupported)
348 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EColor16));
349 if (error == KErrNotSupported)
350 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EGray256));
351 if (error == KErrNotSupported)
352 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EGray16));
353 if (error == KErrNotSupported)
354 TRAP(error, screenDevice = CFbsScreenDevice::NewL(0,EGray4));
355 if (error == KErrNotSupported)
356 screenDevice = CFbsScreenDevice::NewL(0,EGray2);
358 CleanupStack::PushL(screenDevice);
359 screenDevice->ChangeScreenDevice(0);
360 screenDevice->SetAutoUpdate(ETrue);
361 CGraphicsContext* gc;
362 User::LeaveIfError(screenDevice->CreateContext(gc));
363 CleanupStack::PushL(gc);
364 TFontSpec fs(KDevanagariFontName, 16);
366 User::LeaveIfError(screenDevice->GetNearestFontInPixels(devaFont, fs));
367 TFontSpec fontSpec = devaFont->FontSpecInTwips();
368 if(0 != fontSpec.iTypeface.iName.Compare(KDevanagariFontName))
370 // Test font not found.
371 User::Leave(KErrNotFound);
373 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
374 CleanupStack::PushL(scheduler);
375 CActiveScheduler::Install(scheduler);
377 // We know that we have everything we need now, so we'll start the test!
378 // A failure before this point would show up in the logs as "not run" rather
380 TESTPRINT(_L("Test forward/backward delete for Hindi"));
381 TRAP(error, TestL(screenDevice));
382 CleanupStack::PopAndDestroy(scheduler);
383 CleanupStack::PopAndDestroy(gc);
384 CleanupStack::PopAndDestroy(screenDevice);
385 RFbsSession::Disconnect();
386 User::LeaveIfError(error);
387 return TestStepResult();