Update contrib.
2 * Copyright (c) 1997-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 * Class to test the line paginator.
27 namespace LocalToTLinePag
29 _LIT(KTLinePag, "TLinePag");
30 CTLinePagStep* TestStep = NULL;
31 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
32 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
34 using namespace LocalToTLinePag;
35 ///////////////////////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////////////////
37 //Test macroses and functions
39 LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
41 if(aValue != aExpected)
44 buf.AppendFormat(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
45 TestStep->print(buf,(TText8*)__FILE__,aLine);
46 TestStep->testpoint(EFalse,(TText8*)__FILE__,aLine);
50 class CLinePaginatorTest : public CBase
53 static CLinePaginatorTest* NewL();
54 ~CLinePaginatorTest();
56 void StartPaginateL();
57 TBool CompareArrays();
61 TBool PaginateSectionL();
62 TBool ReadTestFile(TPageLine& aline);
63 void WriteOutputFile(TPageLine aLine);
64 void StorePageBreakL(TInt aDocPos);
66 CArrayFixFlat<TInt>* iCharsPerPage;
67 TLinePaginator iPaginator;
68 CArrayFixFlat<TInt>* iTestChars;
77 #define TEST_FILE _L("z:\\test\\app-framework\\form\\input\\page.txt")
79 const TInt KGranularity = 10;
81 CLinePaginatorTest* CLinePaginatorTest::NewL()
83 CLinePaginatorTest* self=new(ELeave) CLinePaginatorTest();
88 CLinePaginatorTest::CLinePaginatorTest()
91 CLinePaginatorTest::~CLinePaginatorTest()
99 void CLinePaginatorTest::ConstructL()
101 iCharsPerPage=new(ELeave) CArrayFixFlat<TInt>(KGranularity);
102 iTestChars=new(ELeave) CArrayFixFlat<TInt>(KGranularity);
107 iPaginator.SetArray(iCharsPerPage);
111 void CLinePaginatorTest::StartPaginateL(/*parameters*/)
113 // do initialisation stuff
114 while(PaginateSectionL())
117 TBool success=CompareArrays();
118 CheckL(success, ETrue,__LINE__);
122 TBool CLinePaginatorTest::PaginateSectionL()
126 while (ReadTestFile(line))
128 iPaginator.AppendLineL(line);
130 StorePageBreakL(line.iDocPos);
131 WriteOutputFile(line);
134 iPaginator.FlushL(line.iDocPos);
135 StorePageBreakL(line.iDocPos);
140 void CLinePaginatorTest::OpenTestFileL()
143 TInt err=ifsClient.Connect();
144 err=iTestFile.Open(ifsClient,TEST_FILE,EFileStream|EFileRead|EFileShareReadersOnly);
147 iTestFile.Read(0,text,128);
148 TInt startNum=text.Locate('<')+1;
149 text.Delete(0,startNum);
153 iPaginator.SetPageHeight(pageHeight);
156 buf.AppendFormat(_L("DocPos\tHeight\tKeep\tStart\tHeight of Pages = <%d>\n"), pageHeight);
160 TBool CLinePaginatorTest::ReadTestFile(TPageLine& aLine)
163 TBuf8<128> textBuffer;
164 TBuf8<128> numBuffer;
167 iTestFile.Read(iFilePos,textBuffer,128);
168 if (textBuffer.Locate('X') != KErrNotFound && textBuffer.Locate('X') < textBuffer.Locate('\r'))
170 startNum=textBuffer.Locate('\n')+1;
171 textBuffer.Delete(0,startNum);
174 lex.Val(aLine.iDocPos);
176 buf.AppendFormat(_L("%d\tX\n"), aLine.iDocPos);
181 startNum=textBuffer.Locate('\n')+1;
182 textBuffer.Delete(0,startNum);
185 lex.Val(aLine.iDocPos);
187 startNum=textBuffer.Locate('\t')+1;
188 textBuffer.Delete(0,startNum);
191 lex.Val(aLine.iLineHeight);
193 startNum=textBuffer.Locate('\t')+1;
194 textBuffer.Delete(0,startNum);
197 lex.Val(aLine.iKeepWithNext);
199 startNum=textBuffer.Locate('\t')+1;
200 textBuffer.Delete(0,startNum);
203 lex.Val(aLine.iStartNewPage);
205 if (textBuffer.Locate('\t')<textBuffer.Locate('\r')
206 && textBuffer.Locate('B')!=KErrNotFound
207 && textBuffer.Locate('B')<textBuffer.Locate('\r'))
208 iTestPageBreak=ETrue;
210 iTestPageBreak=EFalse;
212 iFilePos+=textBuffer.Locate('\r')+1;
216 void CLinePaginatorTest::WriteOutputFile(TPageLine aLine)
221 buf.AppendFormat(_L("%d\t%d\t%d\t%d\tBREAK\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
227 buf.AppendFormat(_L("%d\t%d\t%d\t%d\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
233 void CLinePaginatorTest::StorePageBreakL(TInt aDocPos)
236 iTestChars->AppendL(aDocPos);
239 //#pragma warning( disable : 4701 ) //local variable 'docPosError' may be used without having been initialized
240 TBool CLinePaginatorTest::CompareArrays()
242 TInt numPages=iCharsPerPage->Count();
243 TInt numTestPages=iTestChars->Count();
246 TBool pagesSame=EFalse;
252 if (numPages==numTestPages)
254 buf.AppendFormat(_L("Correct Number of Pages = %d\n"), numPages);
257 for (TInt i=0; i<numPages; i++)
259 numChars=(*iCharsPerPage)[i];
260 numTestChars=(*iTestChars)[i]-prevDocPos;
261 if(numChars!=numTestChars)
264 docPosError=(*iTestChars)[i];
267 prevDocPos=(*iTestChars)[i];
271 TESTPRINT(_L("Correct Number of Characters on Pages -- PASSED\n"));
275 TESTPRINT(_L("Incorrect Number of Characters on Pages -- FAILED\n"));
277 buf.AppendFormat(_L("First Error Occurs at Position = %d"), docPosError);
283 TESTPRINT(_L("Incorrect Number of Pages -- FAILED\n"));
285 buf.AppendFormat(_L("Number Calculated by LinePaginator = %d\n"), numPages);
286 buf.AppendFormat(_L("Number Contained in File = %d\n"), numTestPages);
297 CLinePaginatorTest* linePaginate=CLinePaginatorTest::NewL();
298 linePaginate->OpenTestFileL();
299 linePaginate->StartPaginateL();
303 TVerdict CTLinePagStep::doTestStepL()
305 SetTestStepResult(EPass);
307 TESTPRINT(KTLinePag);
308 TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-LINEPAG-0001 CLinePaginatorTest tests "));
309 TRAPD(error, LinePaginateL());
310 TESTPOINT(error == KErrNone);
311 return TestStepResult();
314 void FormPanic(TFormPanic aPanic)
316 User::Panic(_L("Form"),aPanic);