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