First public contribution.
2 * Copyright (c) 2003-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.
15 * TInterpreter.cpp unit tests for RTmBoundingRectInterpreter
20 #include "TestPicture.h"
21 #include "TestLayout.h"
22 #include "TGraphicsContext.h"
24 #include "tinterpreter.h"
29 namespace LocalToTInterpreter
31 _LIT(KLeftToRight1, "abc \x5D0 def abc \x5D0\x5D1\x5D2 \x5D0\x5D1\x5D2 xyz abc a\tb\tc\td\te.");
32 _LIT(KLeftToRight2, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
33 _LIT(KContingentBreak, "\xFFFC");
35 CTInterpreterStep* TestStep = NULL;
36 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
37 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
40 using namespace LocalToTInterpreter;
44 Checks if one region is a subset of another.
46 The potential superset.
47 @param aPotentialSubset
50 ETrue if and only if aPotentialSubset is contained within aRegion.
53 TBool IsSubsetL(const TRegion& aRegion, const TRegion& aPotentialSubset)
56 sub.Copy(aPotentialSubset);
57 sub.SubRegion(aRegion);
59 User::Leave(KErrNoMemory);
64 Checks if two regions are equal.
65 @param aA First region.
66 @param aB Second region.
68 ETrue if the regions are equal, false otherwise.
71 TBool RegionsEqualL(const TRegion& aA, const TRegion& aB)
73 return IsSubsetL(aA, aB) && IsSubsetL(aB, aA);
77 Gets the region corresponding to the selection. Builds it up by adding
78 selections together. The selections are at (n * aStartStep, aEnd + n *
79 aEndStep) for n <- {0, 1, 2...}. The iteration ends when either the start would
80 be beyond the length of the document or when the start is at 0 and the end is
81 beyond the length of the document.
82 @param aRegion Returns the region.
83 @param aLayout The layout to get the selection of.
84 @param aStartStep How different the starts of successive selections are.
85 @param aEnd The end of the first selection.
86 @param aEndStep How different the ends of the successive selections are.
90 void GetSelectionL(TRegion& aRegion, CTestTmTextLayout& aLayout,
91 TInt aStartStep, TInt aEnd, TInt aEndStep)
95 TInt documentLength = aLayout.Source().DocumentLength();
97 while (start < documentLength && !(documentLength < aEnd && start == 0))
99 TTmInterpreterParam param(aLayout.Layout());
100 RTmBoundingRectInterpreter interp(aLayout.Source(), param);
101 if (interp.FirstRect(start, aEnd, rect))
103 aRegion.AddRect(rect);
104 while (interp.NextRect(rect))
105 aRegion.AddRect(rect);
111 if (aRegion.CheckError())
112 User::Leave(KErrNoMemory);
116 Tests RTmBoundingRectInterpreter for a particular piece of text.
119 void TestTextL(CTestTmTextLayout& aLayout)
124 CleanupClosePushL(region1);
125 CleanupClosePushL(region2);
126 CleanupClosePushL(region3);
128 GetSelectionL(region1, aLayout, 1, 1, 1);
129 GetSelectionL(region2, aLayout, 0, 1, 1);
130 GetSelectionL(region3, aLayout, 0, aLayout.Source().DocumentLength(), 1);
132 TESTPOINT(RegionsEqualL(region1, region2));
133 TESTPOINT(RegionsEqualL(region1, region3));
135 CleanupStack::PopAndDestroy(®ion3);
136 CleanupStack::PopAndDestroy(®ion2);
137 CleanupStack::PopAndDestroy(®ion1);
143 CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
144 CleanupStack::PushL(paraLayer);
145 CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
146 CleanupStack::PushL(charLayer);
147 CRichText* richText = CRichText::NewL(paraLayer, charLayer);
148 CleanupStack::PushL(richText);
150 TESTPRINT(_L("RTmBoundingRectInterpreter consistency of coverage"));
152 richText->InsertL(0, KLeftToRight1);
153 CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
154 TSize pictureSize(15, 15);
155 CTestPicture* picture = new (ELeave) CTestPicture;
156 picture->SetSizeInPixels( pictureSize, text1->Device() );
157 TPictureHeader pictureHeader;
158 pictureHeader.iPicture = picture;
159 pictureHeader.iSize = pictureSize;
160 richText->InsertL(19, pictureHeader);
161 TTmReformatParam param;
162 param.iStartChar = 19;
163 param.iOldLength = 0;
164 param.iNewLength = 1;
165 param.iMaxExtraLines = KMaxTInt;
166 param.iParFormatChanged = ETrue;
167 param.iParInvalid = EFalse;
168 TTmReformatResult out;
169 text1->FormatL(param, out);
172 //Test for finding text chunks adjoining a given document position
173 text1->TestAdjacentChunks();
175 CleanupStack::PopAndDestroy(text1);
176 CleanupStack::PopAndDestroy(richText);
177 CleanupStack::PopAndDestroy(charLayer);
178 CleanupStack::PopAndDestroy(paraLayer);
183 @SYMTestCaseID SYSLIB-FORM-UT-1591
184 @SYMTestCaseDesc Tests to make sure when contingent line breaks, "\xFFFC", are inserted into richtext
185 (with and without a picture attached) and FormatL is called it does not lead to a
186 panic in 'IsLegalBreakBeforeL' or 'IsLegalBreakAfterL'.
187 @SYMTestPriority High
188 @SYMTestActions Insert some richtext, then insert a TPictureHeader into the text (which inserts a
189 contingent line break), then call FormatL. Then insert just a contingent line break,
190 with no TPictureHeader associated with it and call FormatL (for IsLegalBreakAfterL).
191 Then repeat the process, but making sure the text is scanned in the opposite
192 direction, so IsLegalBreakBeforeL is called.
193 @SYMTestExpectedResults Test must not fail
199 TInt testStartLength = 52;
200 TInt testEndLength = 56;
202 CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
203 CleanupStack::PushL(paraLayer);
204 CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
205 CleanupStack::PushL(charLayer);
206 CRichText* richText = CRichText::NewL(paraLayer, charLayer);
207 CleanupStack::PushL(richText);
209 TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1591 DEF077884: TSourcePictureBreaker crashes when picture not found. "));
214 richText->InsertL(0, KLeftToRight2);
216 TESTPOINT(testStartLength == richText->DocumentLength());
218 CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
220 TTmReformatResult out;
221 TTmReformatParam param;
222 param.iStartChar = 0;
223 param.iOldLength = 0;
224 param.iNewLength = 1;
225 param.iMaxExtraLines = KMaxTInt;
226 param.iParFormatChanged = ETrue;
227 param.iParInvalid = EFalse;
229 richText->InsertL(14, KContingentBreak); // Insert a contingent linebreak with no picture
231 text1->FormatL(param, out); // Scans the text from right to left.
234 TSize pictureSize(100, 100);
235 CTestPicture* picture = new (ELeave) CTestPicture;
236 picture->SetSizeInPixels(pictureSize, text1->Device());
238 TPictureHeader pictureHeader;
239 pictureHeader.iPicture = picture;
240 pictureHeader.iSize = pictureSize;
242 richText->InsertL(15, pictureHeader); // Insert a contingent linebreak with picture
244 param.iOldLength = 1;
245 param.iNewLength = 2;
247 text1->FormatL(param, out); // Scans the text from right to left.
250 TTmFormatParam formatParam;
251 formatParam.iFlags = 0;
252 // iFlags now need to be set to make sure the text is scanned in the opposite direction when
253 // FormatL is called.
254 formatParam.iFlags = formatParam.iFlags | TTmFormatParamBase::ELegalLineBreaksOnly;
255 formatParam.iFlags = formatParam.iFlags | TTmFormatParamBase::EWrap;
256 formatParam.iWrapWidth = 12;
257 formatParam.iMaxHeight = 100;
258 formatParam.iMaxLines = 10;
259 formatParam.iEllipsis = 0xFFFF;
260 formatParam.iStartChar = 0;
261 formatParam.iEndChar = 50;
262 formatParam.iLineInPar = 0;
264 param.iOldLength = 2;
265 param.iNewLength = 3;
267 CTmTextLayout* text2 = new (ELeave) CTmTextLayout;
269 text2->SetTextL(text1->Source(),formatParam);
271 richText->InsertL(28, KContingentBreak); // Insert a contingent linebreak with no picture
273 text2->FormatL(formatParam, param, out); // Scans the text from left to right.
276 CTestPicture* picture2 = new (ELeave) CTestPicture;
277 picture2->SetSizeInPixels( pictureSize, text1->Device() );
279 TPictureHeader pictureHeader2;
280 pictureHeader2.iPicture = picture2;
281 pictureHeader2.iSize = pictureSize;
283 richText->InsertL(34, pictureHeader2); // Insert a contingent linebreak with picture
285 param.iOldLength = 3;
286 param.iNewLength = 4;
288 text2->FormatL(formatParam, param, out); // Scans the text from left to right.
293 TESTPOINT(testEndLength == richText->DocumentLength());
295 CleanupStack::PopAndDestroy(text1);
296 CleanupStack::PopAndDestroy(richText);
297 CleanupStack::PopAndDestroy(charLayer);
298 CleanupStack::PopAndDestroy(paraLayer);
302 Tests RTmBoundingRectInterpreter.
305 TVerdict CTInterpreterStep::doTestStepL()
307 SetTestStepResult(EPass);
309 TESTPRINT(_L("TInterpreter unit"));
310 TESTPRINT(_L("Start TInterpreter.exe Tests"));
313 return TestStepResult();