sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* TInterpreter.cpp unit tests for RTmBoundingRectInterpreter
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "TestPicture.h"
|
sl@0
|
21 |
#include "TestLayout.h"
|
sl@0
|
22 |
#include "TGraphicsContext.h"
|
sl@0
|
23 |
#include "TMINTERP.H"
|
sl@0
|
24 |
#include "tinterpreter.h"
|
sl@0
|
25 |
#include <txtrich.h>
|
sl@0
|
26 |
#include <e32test.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
namespace LocalToTInterpreter
|
sl@0
|
30 |
{
|
sl@0
|
31 |
_LIT(KLeftToRight1, "abc \x5D0 def abc \x5D0\x5D1\x5D2 \x5D0\x5D1\x5D2 xyz abc a\tb\tc\td\te.");
|
sl@0
|
32 |
_LIT(KLeftToRight2, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
sl@0
|
33 |
_LIT(KContingentBreak, "\xFFFC");
|
sl@0
|
34 |
|
sl@0
|
35 |
CTInterpreterStep* TestStep = NULL;
|
sl@0
|
36 |
#define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
|
sl@0
|
37 |
#define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
|
sl@0
|
38 |
|
sl@0
|
39 |
}
|
sl@0
|
40 |
using namespace LocalToTInterpreter;
|
sl@0
|
41 |
|
sl@0
|
42 |
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
Checks if one region is a subset of another.
|
sl@0
|
45 |
@param aRegion
|
sl@0
|
46 |
The potential superset.
|
sl@0
|
47 |
@param aPotentialSubset
|
sl@0
|
48 |
The potential subset.
|
sl@0
|
49 |
@return
|
sl@0
|
50 |
ETrue if and only if aPotentialSubset is contained within aRegion.
|
sl@0
|
51 |
@internalComponent
|
sl@0
|
52 |
*/
|
sl@0
|
53 |
TBool IsSubsetL(const TRegion& aRegion, const TRegion& aPotentialSubset)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
RRegion sub;
|
sl@0
|
56 |
sub.Copy(aPotentialSubset);
|
sl@0
|
57 |
sub.SubRegion(aRegion);
|
sl@0
|
58 |
if (sub.CheckError())
|
sl@0
|
59 |
User::Leave(KErrNoMemory);
|
sl@0
|
60 |
return sub.IsEmpty();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
/**
|
sl@0
|
64 |
Checks if two regions are equal.
|
sl@0
|
65 |
@param aA First region.
|
sl@0
|
66 |
@param aB Second region.
|
sl@0
|
67 |
@return
|
sl@0
|
68 |
ETrue if the regions are equal, false otherwise.
|
sl@0
|
69 |
@internalComponent
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
TBool RegionsEqualL(const TRegion& aA, const TRegion& aB)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
return IsSubsetL(aA, aB) && IsSubsetL(aB, aA);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
Gets the region corresponding to the selection. Builds it up by adding
|
sl@0
|
78 |
selections together. The selections are at (n * aStartStep, aEnd + n *
|
sl@0
|
79 |
aEndStep) for n <- {0, 1, 2...}. The iteration ends when either the start would
|
sl@0
|
80 |
be beyond the length of the document or when the start is at 0 and the end is
|
sl@0
|
81 |
beyond the length of the document.
|
sl@0
|
82 |
@param aRegion Returns the region.
|
sl@0
|
83 |
@param aLayout The layout to get the selection of.
|
sl@0
|
84 |
@param aStartStep How different the starts of successive selections are.
|
sl@0
|
85 |
@param aEnd The end of the first selection.
|
sl@0
|
86 |
@param aEndStep How different the ends of the successive selections are.
|
sl@0
|
87 |
|
sl@0
|
88 |
@internalComponent
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
void GetSelectionL(TRegion& aRegion, CTestTmTextLayout& aLayout,
|
sl@0
|
91 |
TInt aStartStep, TInt aEnd, TInt aEndStep)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
aRegion.Clear();
|
sl@0
|
94 |
TRect rect;
|
sl@0
|
95 |
TInt documentLength = aLayout.Source().DocumentLength();
|
sl@0
|
96 |
TInt start = 0;
|
sl@0
|
97 |
while (start < documentLength && !(documentLength < aEnd && start == 0))
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TTmInterpreterParam param(aLayout.Layout());
|
sl@0
|
100 |
RTmBoundingRectInterpreter interp(aLayout.Source(), param);
|
sl@0
|
101 |
if (interp.FirstRect(start, aEnd, rect))
|
sl@0
|
102 |
{
|
sl@0
|
103 |
aRegion.AddRect(rect);
|
sl@0
|
104 |
while (interp.NextRect(rect))
|
sl@0
|
105 |
aRegion.AddRect(rect);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
start += aStartStep;
|
sl@0
|
108 |
aEnd += aEndStep;
|
sl@0
|
109 |
interp.Close();
|
sl@0
|
110 |
}
|
sl@0
|
111 |
if (aRegion.CheckError())
|
sl@0
|
112 |
User::Leave(KErrNoMemory);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
/**
|
sl@0
|
116 |
Tests RTmBoundingRectInterpreter for a particular piece of text.
|
sl@0
|
117 |
@internalComponent
|
sl@0
|
118 |
*/
|
sl@0
|
119 |
void TestTextL(CTestTmTextLayout& aLayout)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
RRegion region1;
|
sl@0
|
122 |
RRegion region2;
|
sl@0
|
123 |
RRegion region3;
|
sl@0
|
124 |
CleanupClosePushL(region1);
|
sl@0
|
125 |
CleanupClosePushL(region2);
|
sl@0
|
126 |
CleanupClosePushL(region3);
|
sl@0
|
127 |
|
sl@0
|
128 |
GetSelectionL(region1, aLayout, 1, 1, 1);
|
sl@0
|
129 |
GetSelectionL(region2, aLayout, 0, 1, 1);
|
sl@0
|
130 |
GetSelectionL(region3, aLayout, 0, aLayout.Source().DocumentLength(), 1);
|
sl@0
|
131 |
|
sl@0
|
132 |
TESTPOINT(RegionsEqualL(region1, region2));
|
sl@0
|
133 |
TESTPOINT(RegionsEqualL(region1, region3));
|
sl@0
|
134 |
|
sl@0
|
135 |
CleanupStack::PopAndDestroy(®ion3);
|
sl@0
|
136 |
CleanupStack::PopAndDestroy(®ion2);
|
sl@0
|
137 |
CleanupStack::PopAndDestroy(®ion1);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
|
sl@0
|
141 |
void TestsL()
|
sl@0
|
142 |
{
|
sl@0
|
143 |
CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
|
sl@0
|
144 |
CleanupStack::PushL(paraLayer);
|
sl@0
|
145 |
CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
|
sl@0
|
146 |
CleanupStack::PushL(charLayer);
|
sl@0
|
147 |
CRichText* richText = CRichText::NewL(paraLayer, charLayer);
|
sl@0
|
148 |
CleanupStack::PushL(richText);
|
sl@0
|
149 |
|
sl@0
|
150 |
TESTPRINT(_L("RTmBoundingRectInterpreter consistency of coverage"));
|
sl@0
|
151 |
richText->Reset();
|
sl@0
|
152 |
richText->InsertL(0, KLeftToRight1);
|
sl@0
|
153 |
CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
|
sl@0
|
154 |
TSize pictureSize(15, 15);
|
sl@0
|
155 |
CTestPicture* picture = new (ELeave) CTestPicture;
|
sl@0
|
156 |
picture->SetSizeInPixels( pictureSize, text1->Device() );
|
sl@0
|
157 |
TPictureHeader pictureHeader;
|
sl@0
|
158 |
pictureHeader.iPicture = picture;
|
sl@0
|
159 |
pictureHeader.iSize = pictureSize;
|
sl@0
|
160 |
richText->InsertL(19, pictureHeader);
|
sl@0
|
161 |
TTmReformatParam param;
|
sl@0
|
162 |
param.iStartChar = 19;
|
sl@0
|
163 |
param.iOldLength = 0;
|
sl@0
|
164 |
param.iNewLength = 1;
|
sl@0
|
165 |
param.iMaxExtraLines = KMaxTInt;
|
sl@0
|
166 |
param.iParFormatChanged = ETrue;
|
sl@0
|
167 |
param.iParInvalid = EFalse;
|
sl@0
|
168 |
TTmReformatResult out;
|
sl@0
|
169 |
text1->FormatL(param, out);
|
sl@0
|
170 |
TestTextL(*text1);
|
sl@0
|
171 |
|
sl@0
|
172 |
//Test for finding text chunks adjoining a given document position
|
sl@0
|
173 |
text1->TestAdjacentChunks();
|
sl@0
|
174 |
|
sl@0
|
175 |
CleanupStack::PopAndDestroy(text1);
|
sl@0
|
176 |
CleanupStack::PopAndDestroy(richText);
|
sl@0
|
177 |
CleanupStack::PopAndDestroy(charLayer);
|
sl@0
|
178 |
CleanupStack::PopAndDestroy(paraLayer);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
|
sl@0
|
182 |
/**
|
sl@0
|
183 |
@SYMTestCaseID SYSLIB-FORM-UT-1591
|
sl@0
|
184 |
@SYMTestCaseDesc Tests to make sure when contingent line breaks, "\xFFFC", are inserted into richtext
|
sl@0
|
185 |
(with and without a picture attached) and FormatL is called it does not lead to a
|
sl@0
|
186 |
panic in 'IsLegalBreakBeforeL' or 'IsLegalBreakAfterL'.
|
sl@0
|
187 |
@SYMTestPriority High
|
sl@0
|
188 |
@SYMTestActions Insert some richtext, then insert a TPictureHeader into the text (which inserts a
|
sl@0
|
189 |
contingent line break), then call FormatL. Then insert just a contingent line break,
|
sl@0
|
190 |
with no TPictureHeader associated with it and call FormatL (for IsLegalBreakAfterL).
|
sl@0
|
191 |
Then repeat the process, but making sure the text is scanned in the opposite
|
sl@0
|
192 |
direction, so IsLegalBreakBeforeL is called.
|
sl@0
|
193 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
194 |
@SYMDEF DEF077884
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
|
sl@0
|
197 |
void Def077884L()
|
sl@0
|
198 |
{
|
sl@0
|
199 |
TInt testStartLength = 52;
|
sl@0
|
200 |
TInt testEndLength = 56;
|
sl@0
|
201 |
|
sl@0
|
202 |
CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
|
sl@0
|
203 |
CleanupStack::PushL(paraLayer);
|
sl@0
|
204 |
CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
|
sl@0
|
205 |
CleanupStack::PushL(charLayer);
|
sl@0
|
206 |
CRichText* richText = CRichText::NewL(paraLayer, charLayer);
|
sl@0
|
207 |
CleanupStack::PushL(richText);
|
sl@0
|
208 |
|
sl@0
|
209 |
TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1591 DEF077884: TSourcePictureBreaker crashes when picture not found. "));
|
sl@0
|
210 |
|
sl@0
|
211 |
|
sl@0
|
212 |
richText->Reset();
|
sl@0
|
213 |
|
sl@0
|
214 |
richText->InsertL(0, KLeftToRight2);
|
sl@0
|
215 |
|
sl@0
|
216 |
TESTPOINT(testStartLength == richText->DocumentLength());
|
sl@0
|
217 |
|
sl@0
|
218 |
CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
|
sl@0
|
219 |
|
sl@0
|
220 |
TTmReformatResult out;
|
sl@0
|
221 |
TTmReformatParam param;
|
sl@0
|
222 |
param.iStartChar = 0;
|
sl@0
|
223 |
param.iOldLength = 0;
|
sl@0
|
224 |
param.iNewLength = 1;
|
sl@0
|
225 |
param.iMaxExtraLines = KMaxTInt;
|
sl@0
|
226 |
param.iParFormatChanged = ETrue;
|
sl@0
|
227 |
param.iParInvalid = EFalse;
|
sl@0
|
228 |
|
sl@0
|
229 |
richText->InsertL(14, KContingentBreak); // Insert a contingent linebreak with no picture
|
sl@0
|
230 |
|
sl@0
|
231 |
text1->FormatL(param, out); // Scans the text from right to left.
|
sl@0
|
232 |
|
sl@0
|
233 |
|
sl@0
|
234 |
TSize pictureSize(100, 100);
|
sl@0
|
235 |
CTestPicture* picture = new (ELeave) CTestPicture;
|
sl@0
|
236 |
picture->SetSizeInPixels(pictureSize, text1->Device());
|
sl@0
|
237 |
|
sl@0
|
238 |
TPictureHeader pictureHeader;
|
sl@0
|
239 |
pictureHeader.iPicture = picture;
|
sl@0
|
240 |
pictureHeader.iSize = pictureSize;
|
sl@0
|
241 |
|
sl@0
|
242 |
richText->InsertL(15, pictureHeader); // Insert a contingent linebreak with picture
|
sl@0
|
243 |
|
sl@0
|
244 |
param.iOldLength = 1;
|
sl@0
|
245 |
param.iNewLength = 2;
|
sl@0
|
246 |
|
sl@0
|
247 |
text1->FormatL(param, out); // Scans the text from right to left.
|
sl@0
|
248 |
|
sl@0
|
249 |
|
sl@0
|
250 |
TTmFormatParam formatParam;
|
sl@0
|
251 |
formatParam.iFlags = 0;
|
sl@0
|
252 |
// iFlags now need to be set to make sure the text is scanned in the opposite direction when
|
sl@0
|
253 |
// FormatL is called.
|
sl@0
|
254 |
formatParam.iFlags = formatParam.iFlags | TTmFormatParamBase::ELegalLineBreaksOnly;
|
sl@0
|
255 |
formatParam.iFlags = formatParam.iFlags | TTmFormatParamBase::EWrap;
|
sl@0
|
256 |
formatParam.iWrapWidth = 12;
|
sl@0
|
257 |
formatParam.iMaxHeight = 100;
|
sl@0
|
258 |
formatParam.iMaxLines = 10;
|
sl@0
|
259 |
formatParam.iEllipsis = 0xFFFF;
|
sl@0
|
260 |
formatParam.iStartChar = 0;
|
sl@0
|
261 |
formatParam.iEndChar = 50;
|
sl@0
|
262 |
formatParam.iLineInPar = 0;
|
sl@0
|
263 |
|
sl@0
|
264 |
param.iOldLength = 2;
|
sl@0
|
265 |
param.iNewLength = 3;
|
sl@0
|
266 |
|
sl@0
|
267 |
CTmTextLayout* text2 = new (ELeave) CTmTextLayout;
|
sl@0
|
268 |
|
sl@0
|
269 |
text2->SetTextL(text1->Source(),formatParam);
|
sl@0
|
270 |
|
sl@0
|
271 |
richText->InsertL(28, KContingentBreak); // Insert a contingent linebreak with no picture
|
sl@0
|
272 |
|
sl@0
|
273 |
text2->FormatL(formatParam, param, out); // Scans the text from left to right.
|
sl@0
|
274 |
|
sl@0
|
275 |
|
sl@0
|
276 |
CTestPicture* picture2 = new (ELeave) CTestPicture;
|
sl@0
|
277 |
picture2->SetSizeInPixels( pictureSize, text1->Device() );
|
sl@0
|
278 |
|
sl@0
|
279 |
TPictureHeader pictureHeader2;
|
sl@0
|
280 |
pictureHeader2.iPicture = picture2;
|
sl@0
|
281 |
pictureHeader2.iSize = pictureSize;
|
sl@0
|
282 |
|
sl@0
|
283 |
richText->InsertL(34, pictureHeader2); // Insert a contingent linebreak with picture
|
sl@0
|
284 |
|
sl@0
|
285 |
param.iOldLength = 3;
|
sl@0
|
286 |
param.iNewLength = 4;
|
sl@0
|
287 |
|
sl@0
|
288 |
text2->FormatL(formatParam, param, out); // Scans the text from left to right.
|
sl@0
|
289 |
|
sl@0
|
290 |
|
sl@0
|
291 |
TestTextL(*text1);
|
sl@0
|
292 |
|
sl@0
|
293 |
TESTPOINT(testEndLength == richText->DocumentLength());
|
sl@0
|
294 |
|
sl@0
|
295 |
CleanupStack::PopAndDestroy(text1);
|
sl@0
|
296 |
CleanupStack::PopAndDestroy(richText);
|
sl@0
|
297 |
CleanupStack::PopAndDestroy(charLayer);
|
sl@0
|
298 |
CleanupStack::PopAndDestroy(paraLayer);
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
/**
|
sl@0
|
302 |
Tests RTmBoundingRectInterpreter.
|
sl@0
|
303 |
@internalComponent
|
sl@0
|
304 |
*/
|
sl@0
|
305 |
TVerdict CTInterpreterStep::doTestStepL()
|
sl@0
|
306 |
{
|
sl@0
|
307 |
SetTestStepResult(EPass);
|
sl@0
|
308 |
TestStep = this;
|
sl@0
|
309 |
TESTPRINT(_L("TInterpreter unit"));
|
sl@0
|
310 |
TESTPRINT(_L("Start TInterpreter.exe Tests"));
|
sl@0
|
311 |
TestsL();
|
sl@0
|
312 |
Def077884L();
|
sl@0
|
313 |
return TestStepResult();
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
|