1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/textformatting/test/src/TLINEPAG.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,318 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Class to test the line paginator.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#include <basched.h>
1.24 +#include <frmpage.h>
1.25 +#include <frmconst.h>
1.26 +#include <bautils.h>
1.27 +#include <e32test.h>
1.28 +#include "tlinepag.h"
1.29 +
1.30 +namespace LocalToTLinePag
1.31 +{
1.32 +_LIT(KTLinePag, "TLinePag");
1.33 +CTLinePagStep* TestStep = NULL;
1.34 +#define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
1.35 +#define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
1.36 +}
1.37 +using namespace LocalToTLinePag;
1.38 +///////////////////////////////////////////////////////////////////////////////////////
1.39 +///////////////////////////////////////////////////////////////////////////////////////
1.40 +//Test macroses and functions
1.41 +
1.42 +LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
1.43 + {
1.44 + if(aValue != aExpected)
1.45 + {
1.46 + TBuf<256> buf;
1.47 + buf.AppendFormat(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.48 + TestStep->print(buf,(TText8*)__FILE__,aLine);
1.49 + TestStep->testpoint(EFalse,(TText8*)__FILE__,aLine);
1.50 + }
1.51 + }
1.52 +
1.53 +class CLinePaginatorTest : public CBase
1.54 + {
1.55 +public:
1.56 + static CLinePaginatorTest* NewL();
1.57 + ~CLinePaginatorTest();
1.58 + void OpenTestFileL();
1.59 + void StartPaginateL();
1.60 + TBool CompareArrays();
1.61 +private:
1.62 + void ConstructL();
1.63 + CLinePaginatorTest();
1.64 + TBool PaginateSectionL();
1.65 + TBool ReadTestFile(TPageLine& aline);
1.66 + void WriteOutputFile(TPageLine aLine);
1.67 + void StorePageBreakL(TInt aDocPos);
1.68 +private:
1.69 + CArrayFixFlat<TInt>* iCharsPerPage;
1.70 + TLinePaginator iPaginator;
1.71 + CArrayFixFlat<TInt>* iTestChars;
1.72 + TInt iNumPages;
1.73 + RFile iTestFile;
1.74 + RFs ifsClient;
1.75 + TInt iFilePos;
1.76 + TBool iTestPageBreak;
1.77 + };
1.78 +
1.79 +
1.80 +#define TEST_FILE _L("z:\\test\\app-framework\\form\\input\\page.txt")
1.81 +
1.82 +const TInt KGranularity = 10;
1.83 +
1.84 +CLinePaginatorTest* CLinePaginatorTest::NewL()
1.85 + {
1.86 + CLinePaginatorTest* self=new(ELeave) CLinePaginatorTest();
1.87 + self->ConstructL();
1.88 + return self;
1.89 + }
1.90 +
1.91 +CLinePaginatorTest::CLinePaginatorTest()
1.92 + {}
1.93 +
1.94 +CLinePaginatorTest::~CLinePaginatorTest()
1.95 + {
1.96 + iTestFile.Close();
1.97 + ifsClient.Close();
1.98 + delete iTestChars;
1.99 + delete iCharsPerPage;
1.100 + }
1.101 +
1.102 +void CLinePaginatorTest::ConstructL()
1.103 + {
1.104 + iCharsPerPage=new(ELeave) CArrayFixFlat<TInt>(KGranularity);
1.105 + iTestChars=new(ELeave) CArrayFixFlat<TInt>(KGranularity);
1.106 +
1.107 + iFilePos=0;
1.108 + iNumPages=0;
1.109 +
1.110 + iPaginator.SetArray(iCharsPerPage);
1.111 + }
1.112 +
1.113 +
1.114 +void CLinePaginatorTest::StartPaginateL(/*parameters*/)
1.115 + {
1.116 + // do initialisation stuff
1.117 + while(PaginateSectionL())
1.118 + {
1.119 + }
1.120 + TBool success=CompareArrays();
1.121 + CheckL(success, ETrue,__LINE__);
1.122 + }
1.123 +
1.124 +
1.125 +TBool CLinePaginatorTest::PaginateSectionL()
1.126 + {
1.127 + TPageLine line;
1.128 +
1.129 + while (ReadTestFile(line))
1.130 + {
1.131 + iPaginator.AppendLineL(line);
1.132 + if (iTestPageBreak)
1.133 + StorePageBreakL(line.iDocPos);
1.134 + WriteOutputFile(line);
1.135 + }
1.136 +
1.137 + iPaginator.FlushL(line.iDocPos);
1.138 + StorePageBreakL(line.iDocPos);
1.139 +
1.140 + return(EFalse);
1.141 + }
1.142 +
1.143 +void CLinePaginatorTest::OpenTestFileL()
1.144 + {
1.145 + TBuf8<128> text;
1.146 + TInt err=ifsClient.Connect();
1.147 + err=iTestFile.Open(ifsClient,TEST_FILE,EFileStream|EFileRead|EFileShareReadersOnly);
1.148 +
1.149 +
1.150 + iTestFile.Read(0,text,128);
1.151 + TInt startNum=text.Locate('<')+1;
1.152 + text.Delete(0,startNum);
1.153 + TLex8 lex=text;
1.154 + TInt pageHeight;
1.155 + lex.Val(pageHeight);
1.156 + iPaginator.SetPageHeight(pageHeight);
1.157 +
1.158 + TBuf<254> buf;
1.159 + buf.AppendFormat(_L("DocPos\tHeight\tKeep\tStart\tHeight of Pages = <%d>\n"), pageHeight);
1.160 + TESTPRINT(buf);
1.161 + }
1.162 +
1.163 +TBool CLinePaginatorTest::ReadTestFile(TPageLine& aLine)
1.164 + {
1.165 + TLex8 lex;
1.166 + TBuf8<128> textBuffer;
1.167 + TBuf8<128> numBuffer;
1.168 + TInt startNum;
1.169 +
1.170 + iTestFile.Read(iFilePos,textBuffer,128);
1.171 + if (textBuffer.Locate('X') != KErrNotFound && textBuffer.Locate('X') < textBuffer.Locate('\r'))
1.172 + {
1.173 + startNum=textBuffer.Locate('\n')+1;
1.174 + textBuffer.Delete(0,startNum);
1.175 + iFilePos+=startNum;
1.176 + lex=textBuffer;
1.177 + lex.Val(aLine.iDocPos);
1.178 + TBuf<254> buf;
1.179 + buf.AppendFormat(_L("%d\tX\n"), aLine.iDocPos);
1.180 + TESTPRINT(buf);
1.181 + return EFalse;
1.182 + }
1.183 +
1.184 + startNum=textBuffer.Locate('\n')+1;
1.185 + textBuffer.Delete(0,startNum);
1.186 + iFilePos+=startNum;
1.187 + lex=textBuffer;
1.188 + lex.Val(aLine.iDocPos);
1.189 +
1.190 + startNum=textBuffer.Locate('\t')+1;
1.191 + textBuffer.Delete(0,startNum);
1.192 + iFilePos+=startNum;
1.193 + lex=textBuffer;
1.194 + lex.Val(aLine.iLineHeight);
1.195 +
1.196 + startNum=textBuffer.Locate('\t')+1;
1.197 + textBuffer.Delete(0,startNum);
1.198 + iFilePos+=startNum;
1.199 + lex=textBuffer;
1.200 + lex.Val(aLine.iKeepWithNext);
1.201 +
1.202 + startNum=textBuffer.Locate('\t')+1;
1.203 + textBuffer.Delete(0,startNum);
1.204 + iFilePos+=startNum;
1.205 + lex=textBuffer;
1.206 + lex.Val(aLine.iStartNewPage);
1.207 +
1.208 + if (textBuffer.Locate('\t')<textBuffer.Locate('\r')
1.209 + && textBuffer.Locate('B')!=KErrNotFound
1.210 + && textBuffer.Locate('B')<textBuffer.Locate('\r'))
1.211 + iTestPageBreak=ETrue;
1.212 + else
1.213 + iTestPageBreak=EFalse;
1.214 +
1.215 + iFilePos+=textBuffer.Locate('\r')+1;
1.216 + return ETrue;
1.217 + }
1.218 +
1.219 +void CLinePaginatorTest::WriteOutputFile(TPageLine aLine)
1.220 + {
1.221 + TBuf<256> buf;
1.222 + if (iTestPageBreak)
1.223 + {
1.224 + buf.AppendFormat(_L("%d\t%d\t%d\t%d\tBREAK\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
1.225 + TESTPRINT(buf);
1.226 + }
1.227 + else
1.228 + {
1.229 + buf.Zero();
1.230 + buf.AppendFormat(_L("%d\t%d\t%d\t%d\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
1.231 + TESTPRINT(buf);
1.232 + }
1.233 +
1.234 + }
1.235 +
1.236 +void CLinePaginatorTest::StorePageBreakL(TInt aDocPos)
1.237 + {
1.238 + iNumPages++;
1.239 + iTestChars->AppendL(aDocPos);
1.240 + }
1.241 +
1.242 +//#pragma warning( disable : 4701 ) //local variable 'docPosError' may be used without having been initialized
1.243 +TBool CLinePaginatorTest::CompareArrays()
1.244 + {
1.245 + TInt numPages=iCharsPerPage->Count();
1.246 + TInt numTestPages=iTestChars->Count();
1.247 + TInt numChars;
1.248 + TInt numTestChars;
1.249 + TBool pagesSame=EFalse;
1.250 + TBuf8<128> text;
1.251 + TInt prevDocPos=0;
1.252 + TInt docPosError=0;
1.253 +
1.254 + TBuf<256> buf;
1.255 + if (numPages==numTestPages)
1.256 + {
1.257 + buf.AppendFormat(_L("Correct Number of Pages = %d\n"), numPages);
1.258 + TESTPRINT(buf);
1.259 + pagesSame=ETrue;
1.260 + for (TInt i=0; i<numPages; i++)
1.261 + {
1.262 + numChars=(*iCharsPerPage)[i];
1.263 + numTestChars=(*iTestChars)[i]-prevDocPos;
1.264 + if(numChars!=numTestChars)
1.265 + {
1.266 + if (pagesSame)
1.267 + docPosError=(*iTestChars)[i];
1.268 + pagesSame=EFalse;
1.269 + }
1.270 + prevDocPos=(*iTestChars)[i];
1.271 + }
1.272 + if (pagesSame)
1.273 + {
1.274 + TESTPRINT(_L("Correct Number of Characters on Pages -- PASSED\n"));
1.275 + }
1.276 + else
1.277 + {
1.278 + TESTPRINT(_L("Incorrect Number of Characters on Pages -- FAILED\n"));
1.279 + buf.Zero();
1.280 + buf.AppendFormat(_L("First Error Occurs at Position = %d"), docPosError);
1.281 + TESTPRINT(buf);
1.282 + }
1.283 + }
1.284 + else
1.285 + {
1.286 + TESTPRINT(_L("Incorrect Number of Pages -- FAILED\n"));
1.287 + buf.Zero();
1.288 + buf.AppendFormat(_L("Number Calculated by LinePaginator = %d\n"), numPages);
1.289 + buf.AppendFormat(_L("Number Contained in File = %d\n"), numTestPages);
1.290 + TESTPRINT(buf);
1.291 + }
1.292 +
1.293 + iTestFile.Close();
1.294 + return pagesSame;
1.295 + }
1.296 +
1.297 +
1.298 +void LinePaginateL()
1.299 + {
1.300 + CLinePaginatorTest* linePaginate=CLinePaginatorTest::NewL();
1.301 + linePaginate->OpenTestFileL();
1.302 + linePaginate->StartPaginateL();
1.303 + delete linePaginate;
1.304 + }
1.305 +
1.306 +TVerdict CTLinePagStep::doTestStepL()
1.307 + {
1.308 + SetTestStepResult(EPass);
1.309 + TestStep = this;
1.310 + TESTPRINT(KTLinePag);
1.311 + TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-LINEPAG-0001 CLinePaginatorTest tests "));
1.312 + TRAPD(error, LinePaginateL());
1.313 + TESTPOINT(error == KErrNone);
1.314 + return TestStepResult();
1.315 + }
1.316 +
1.317 +void FormPanic(TFormPanic aPanic)
1.318 + {
1.319 + User::Panic(_L("Form"),aPanic);
1.320 + }
1.321 +