sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-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 |
* Class to test the line paginator.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <basched.h>
|
sl@0
|
21 |
#include <frmpage.h>
|
sl@0
|
22 |
#include <frmconst.h>
|
sl@0
|
23 |
#include <bautils.h>
|
sl@0
|
24 |
#include <e32test.h>
|
sl@0
|
25 |
#include "tlinepag.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
namespace LocalToTLinePag
|
sl@0
|
28 |
{
|
sl@0
|
29 |
_LIT(KTLinePag, "TLinePag");
|
sl@0
|
30 |
CTLinePagStep* TestStep = NULL;
|
sl@0
|
31 |
#define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
|
sl@0
|
32 |
#define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
|
sl@0
|
33 |
}
|
sl@0
|
34 |
using namespace LocalToTLinePag;
|
sl@0
|
35 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
36 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
37 |
//Test macroses and functions
|
sl@0
|
38 |
|
sl@0
|
39 |
LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
if(aValue != aExpected)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
TBuf<256> buf;
|
sl@0
|
44 |
buf.AppendFormat(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
45 |
TestStep->print(buf,(TText8*)__FILE__,aLine);
|
sl@0
|
46 |
TestStep->testpoint(EFalse,(TText8*)__FILE__,aLine);
|
sl@0
|
47 |
}
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
class CLinePaginatorTest : public CBase
|
sl@0
|
51 |
{
|
sl@0
|
52 |
public:
|
sl@0
|
53 |
static CLinePaginatorTest* NewL();
|
sl@0
|
54 |
~CLinePaginatorTest();
|
sl@0
|
55 |
void OpenTestFileL();
|
sl@0
|
56 |
void StartPaginateL();
|
sl@0
|
57 |
TBool CompareArrays();
|
sl@0
|
58 |
private:
|
sl@0
|
59 |
void ConstructL();
|
sl@0
|
60 |
CLinePaginatorTest();
|
sl@0
|
61 |
TBool PaginateSectionL();
|
sl@0
|
62 |
TBool ReadTestFile(TPageLine& aline);
|
sl@0
|
63 |
void WriteOutputFile(TPageLine aLine);
|
sl@0
|
64 |
void StorePageBreakL(TInt aDocPos);
|
sl@0
|
65 |
private:
|
sl@0
|
66 |
CArrayFixFlat<TInt>* iCharsPerPage;
|
sl@0
|
67 |
TLinePaginator iPaginator;
|
sl@0
|
68 |
CArrayFixFlat<TInt>* iTestChars;
|
sl@0
|
69 |
TInt iNumPages;
|
sl@0
|
70 |
RFile iTestFile;
|
sl@0
|
71 |
RFs ifsClient;
|
sl@0
|
72 |
TInt iFilePos;
|
sl@0
|
73 |
TBool iTestPageBreak;
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
#define TEST_FILE _L("z:\\test\\app-framework\\form\\input\\page.txt")
|
sl@0
|
78 |
|
sl@0
|
79 |
const TInt KGranularity = 10;
|
sl@0
|
80 |
|
sl@0
|
81 |
CLinePaginatorTest* CLinePaginatorTest::NewL()
|
sl@0
|
82 |
{
|
sl@0
|
83 |
CLinePaginatorTest* self=new(ELeave) CLinePaginatorTest();
|
sl@0
|
84 |
self->ConstructL();
|
sl@0
|
85 |
return self;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
CLinePaginatorTest::CLinePaginatorTest()
|
sl@0
|
89 |
{}
|
sl@0
|
90 |
|
sl@0
|
91 |
CLinePaginatorTest::~CLinePaginatorTest()
|
sl@0
|
92 |
{
|
sl@0
|
93 |
iTestFile.Close();
|
sl@0
|
94 |
ifsClient.Close();
|
sl@0
|
95 |
delete iTestChars;
|
sl@0
|
96 |
delete iCharsPerPage;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
void CLinePaginatorTest::ConstructL()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
iCharsPerPage=new(ELeave) CArrayFixFlat<TInt>(KGranularity);
|
sl@0
|
102 |
iTestChars=new(ELeave) CArrayFixFlat<TInt>(KGranularity);
|
sl@0
|
103 |
|
sl@0
|
104 |
iFilePos=0;
|
sl@0
|
105 |
iNumPages=0;
|
sl@0
|
106 |
|
sl@0
|
107 |
iPaginator.SetArray(iCharsPerPage);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
void CLinePaginatorTest::StartPaginateL(/*parameters*/)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
// do initialisation stuff
|
sl@0
|
114 |
while(PaginateSectionL())
|
sl@0
|
115 |
{
|
sl@0
|
116 |
}
|
sl@0
|
117 |
TBool success=CompareArrays();
|
sl@0
|
118 |
CheckL(success, ETrue,__LINE__);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
|
sl@0
|
122 |
TBool CLinePaginatorTest::PaginateSectionL()
|
sl@0
|
123 |
{
|
sl@0
|
124 |
TPageLine line;
|
sl@0
|
125 |
|
sl@0
|
126 |
while (ReadTestFile(line))
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iPaginator.AppendLineL(line);
|
sl@0
|
129 |
if (iTestPageBreak)
|
sl@0
|
130 |
StorePageBreakL(line.iDocPos);
|
sl@0
|
131 |
WriteOutputFile(line);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
iPaginator.FlushL(line.iDocPos);
|
sl@0
|
135 |
StorePageBreakL(line.iDocPos);
|
sl@0
|
136 |
|
sl@0
|
137 |
return(EFalse);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
void CLinePaginatorTest::OpenTestFileL()
|
sl@0
|
141 |
{
|
sl@0
|
142 |
TBuf8<128> text;
|
sl@0
|
143 |
TInt err=ifsClient.Connect();
|
sl@0
|
144 |
err=iTestFile.Open(ifsClient,TEST_FILE,EFileStream|EFileRead|EFileShareReadersOnly);
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
iTestFile.Read(0,text,128);
|
sl@0
|
148 |
TInt startNum=text.Locate('<')+1;
|
sl@0
|
149 |
text.Delete(0,startNum);
|
sl@0
|
150 |
TLex8 lex=text;
|
sl@0
|
151 |
TInt pageHeight;
|
sl@0
|
152 |
lex.Val(pageHeight);
|
sl@0
|
153 |
iPaginator.SetPageHeight(pageHeight);
|
sl@0
|
154 |
|
sl@0
|
155 |
TBuf<254> buf;
|
sl@0
|
156 |
buf.AppendFormat(_L("DocPos\tHeight\tKeep\tStart\tHeight of Pages = <%d>\n"), pageHeight);
|
sl@0
|
157 |
TESTPRINT(buf);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
TBool CLinePaginatorTest::ReadTestFile(TPageLine& aLine)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
TLex8 lex;
|
sl@0
|
163 |
TBuf8<128> textBuffer;
|
sl@0
|
164 |
TBuf8<128> numBuffer;
|
sl@0
|
165 |
TInt startNum;
|
sl@0
|
166 |
|
sl@0
|
167 |
iTestFile.Read(iFilePos,textBuffer,128);
|
sl@0
|
168 |
if (textBuffer.Locate('X') != KErrNotFound && textBuffer.Locate('X') < textBuffer.Locate('\r'))
|
sl@0
|
169 |
{
|
sl@0
|
170 |
startNum=textBuffer.Locate('\n')+1;
|
sl@0
|
171 |
textBuffer.Delete(0,startNum);
|
sl@0
|
172 |
iFilePos+=startNum;
|
sl@0
|
173 |
lex=textBuffer;
|
sl@0
|
174 |
lex.Val(aLine.iDocPos);
|
sl@0
|
175 |
TBuf<254> buf;
|
sl@0
|
176 |
buf.AppendFormat(_L("%d\tX\n"), aLine.iDocPos);
|
sl@0
|
177 |
TESTPRINT(buf);
|
sl@0
|
178 |
return EFalse;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
startNum=textBuffer.Locate('\n')+1;
|
sl@0
|
182 |
textBuffer.Delete(0,startNum);
|
sl@0
|
183 |
iFilePos+=startNum;
|
sl@0
|
184 |
lex=textBuffer;
|
sl@0
|
185 |
lex.Val(aLine.iDocPos);
|
sl@0
|
186 |
|
sl@0
|
187 |
startNum=textBuffer.Locate('\t')+1;
|
sl@0
|
188 |
textBuffer.Delete(0,startNum);
|
sl@0
|
189 |
iFilePos+=startNum;
|
sl@0
|
190 |
lex=textBuffer;
|
sl@0
|
191 |
lex.Val(aLine.iLineHeight);
|
sl@0
|
192 |
|
sl@0
|
193 |
startNum=textBuffer.Locate('\t')+1;
|
sl@0
|
194 |
textBuffer.Delete(0,startNum);
|
sl@0
|
195 |
iFilePos+=startNum;
|
sl@0
|
196 |
lex=textBuffer;
|
sl@0
|
197 |
lex.Val(aLine.iKeepWithNext);
|
sl@0
|
198 |
|
sl@0
|
199 |
startNum=textBuffer.Locate('\t')+1;
|
sl@0
|
200 |
textBuffer.Delete(0,startNum);
|
sl@0
|
201 |
iFilePos+=startNum;
|
sl@0
|
202 |
lex=textBuffer;
|
sl@0
|
203 |
lex.Val(aLine.iStartNewPage);
|
sl@0
|
204 |
|
sl@0
|
205 |
if (textBuffer.Locate('\t')<textBuffer.Locate('\r')
|
sl@0
|
206 |
&& textBuffer.Locate('B')!=KErrNotFound
|
sl@0
|
207 |
&& textBuffer.Locate('B')<textBuffer.Locate('\r'))
|
sl@0
|
208 |
iTestPageBreak=ETrue;
|
sl@0
|
209 |
else
|
sl@0
|
210 |
iTestPageBreak=EFalse;
|
sl@0
|
211 |
|
sl@0
|
212 |
iFilePos+=textBuffer.Locate('\r')+1;
|
sl@0
|
213 |
return ETrue;
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
void CLinePaginatorTest::WriteOutputFile(TPageLine aLine)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
TBuf<256> buf;
|
sl@0
|
219 |
if (iTestPageBreak)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
buf.AppendFormat(_L("%d\t%d\t%d\t%d\tBREAK\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
|
sl@0
|
222 |
TESTPRINT(buf);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
else
|
sl@0
|
225 |
{
|
sl@0
|
226 |
buf.Zero();
|
sl@0
|
227 |
buf.AppendFormat(_L("%d\t%d\t%d\t%d\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
|
sl@0
|
228 |
TESTPRINT(buf);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
void CLinePaginatorTest::StorePageBreakL(TInt aDocPos)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
iNumPages++;
|
sl@0
|
236 |
iTestChars->AppendL(aDocPos);
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
//#pragma warning( disable : 4701 ) //local variable 'docPosError' may be used without having been initialized
|
sl@0
|
240 |
TBool CLinePaginatorTest::CompareArrays()
|
sl@0
|
241 |
{
|
sl@0
|
242 |
TInt numPages=iCharsPerPage->Count();
|
sl@0
|
243 |
TInt numTestPages=iTestChars->Count();
|
sl@0
|
244 |
TInt numChars;
|
sl@0
|
245 |
TInt numTestChars;
|
sl@0
|
246 |
TBool pagesSame=EFalse;
|
sl@0
|
247 |
TBuf8<128> text;
|
sl@0
|
248 |
TInt prevDocPos=0;
|
sl@0
|
249 |
TInt docPosError=0;
|
sl@0
|
250 |
|
sl@0
|
251 |
TBuf<256> buf;
|
sl@0
|
252 |
if (numPages==numTestPages)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
buf.AppendFormat(_L("Correct Number of Pages = %d\n"), numPages);
|
sl@0
|
255 |
TESTPRINT(buf);
|
sl@0
|
256 |
pagesSame=ETrue;
|
sl@0
|
257 |
for (TInt i=0; i<numPages; i++)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
numChars=(*iCharsPerPage)[i];
|
sl@0
|
260 |
numTestChars=(*iTestChars)[i]-prevDocPos;
|
sl@0
|
261 |
if(numChars!=numTestChars)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
if (pagesSame)
|
sl@0
|
264 |
docPosError=(*iTestChars)[i];
|
sl@0
|
265 |
pagesSame=EFalse;
|
sl@0
|
266 |
}
|
sl@0
|
267 |
prevDocPos=(*iTestChars)[i];
|
sl@0
|
268 |
}
|
sl@0
|
269 |
if (pagesSame)
|
sl@0
|
270 |
{
|
sl@0
|
271 |
TESTPRINT(_L("Correct Number of Characters on Pages -- PASSED\n"));
|
sl@0
|
272 |
}
|
sl@0
|
273 |
else
|
sl@0
|
274 |
{
|
sl@0
|
275 |
TESTPRINT(_L("Incorrect Number of Characters on Pages -- FAILED\n"));
|
sl@0
|
276 |
buf.Zero();
|
sl@0
|
277 |
buf.AppendFormat(_L("First Error Occurs at Position = %d"), docPosError);
|
sl@0
|
278 |
TESTPRINT(buf);
|
sl@0
|
279 |
}
|
sl@0
|
280 |
}
|
sl@0
|
281 |
else
|
sl@0
|
282 |
{
|
sl@0
|
283 |
TESTPRINT(_L("Incorrect Number of Pages -- FAILED\n"));
|
sl@0
|
284 |
buf.Zero();
|
sl@0
|
285 |
buf.AppendFormat(_L("Number Calculated by LinePaginator = %d\n"), numPages);
|
sl@0
|
286 |
buf.AppendFormat(_L("Number Contained in File = %d\n"), numTestPages);
|
sl@0
|
287 |
TESTPRINT(buf);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
iTestFile.Close();
|
sl@0
|
291 |
return pagesSame;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
|
sl@0
|
295 |
void LinePaginateL()
|
sl@0
|
296 |
{
|
sl@0
|
297 |
CLinePaginatorTest* linePaginate=CLinePaginatorTest::NewL();
|
sl@0
|
298 |
linePaginate->OpenTestFileL();
|
sl@0
|
299 |
linePaginate->StartPaginateL();
|
sl@0
|
300 |
delete linePaginate;
|
sl@0
|
301 |
}
|
sl@0
|
302 |
|
sl@0
|
303 |
TVerdict CTLinePagStep::doTestStepL()
|
sl@0
|
304 |
{
|
sl@0
|
305 |
SetTestStepResult(EPass);
|
sl@0
|
306 |
TestStep = this;
|
sl@0
|
307 |
TESTPRINT(KTLinePag);
|
sl@0
|
308 |
TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-LINEPAG-0001 CLinePaginatorTest tests "));
|
sl@0
|
309 |
TRAPD(error, LinePaginateL());
|
sl@0
|
310 |
TESTPOINT(error == KErrNone);
|
sl@0
|
311 |
return TestStepResult();
|
sl@0
|
312 |
}
|
sl@0
|
313 |
|
sl@0
|
314 |
void FormPanic(TFormPanic aPanic)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
User::Panic(_L("Form"),aPanic);
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|