textrendering/textformatting/test/src/TLINEPAG.CPP
changeset 51 a7c938434754
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
44:601ab138ba0b 51:a7c938434754
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include <basched.h>
    20 #include <basched.h>
    21 #include <frmpage.h>
    21 #include <frmpage.h>
    22 #include <frmconst.h>
    22 #include <frmconst.h>
    23 #include <bautils.h>
    23 #include <bautils.h>
    24 #include <e32test.h>
    24 #include <e32test.h>
    25 
    25 #include "tlinepag.h"
       
    26 
       
    27 namespace LocalToTLinePag
       
    28 {
    26 _LIT(KTLinePag, "TLinePag");
    29 _LIT(KTLinePag, "TLinePag");
    27 RTest TheTest(KTLinePag);
    30 CTLinePagStep*  TestStep = NULL;
    28 
    31 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
       
    32 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
       
    33 }
       
    34 using namespace LocalToTLinePag;
    29 ///////////////////////////////////////////////////////////////////////////////////////
    35 ///////////////////////////////////////////////////////////////////////////////////////
    30 ///////////////////////////////////////////////////////////////////////////////////////
    36 ///////////////////////////////////////////////////////////////////////////////////////
    31 //Test macroses and functions
    37 //Test macroses and functions
    32 
    38 
    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)
    39 LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
    41 	{
    40 	{
    42 	if(aValue != aExpected)
    41 	if(aValue != aExpected)
    43 		{
    42 		{
    44 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    43         TBuf<256> buf;
    45 		TheTest(EFalse, aLine);
    44         buf.AppendFormat(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    46 		}
    45         TestStep->print(buf,(TText8*)__FILE__,aLine);
    47 	}
    46 		TestStep->testpoint(EFalse,(TText8*)__FILE__,aLine);
    48 #define TEST(arg) ::CheckL((arg), __LINE__)
    47 		}
    49 #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
    48 	}
    50 
    49 
    51 class CLinePaginatorTest : public CBase
    50 class CLinePaginatorTest : public CBase
    52 	{
    51 	{
    53 public:
    52 public:
    54 	static CLinePaginatorTest* NewL();
    53 	static CLinePaginatorTest* NewL();
   114 	// do initialisation stuff
   113 	// do initialisation stuff
   115 	while(PaginateSectionL())
   114 	while(PaginateSectionL())
   116 		{
   115 		{
   117 		}
   116 		}
   118 	TBool success=CompareArrays();
   117 	TBool success=CompareArrays();
   119 	TEST2(success, ETrue);
   118 	CheckL(success, ETrue,__LINE__);
   120 	}
   119 	}
   121 
   120 
   122 
   121 
   123 TBool CLinePaginatorTest::PaginateSectionL()
   122 TBool CLinePaginatorTest::PaginateSectionL()
   124 	{
   123 	{
   151 	TLex8 lex=text;
   150 	TLex8 lex=text;
   152 	TInt pageHeight;
   151 	TInt pageHeight;
   153 	lex.Val(pageHeight);
   152 	lex.Val(pageHeight);
   154 	iPaginator.SetPageHeight(pageHeight);
   153 	iPaginator.SetPageHeight(pageHeight);
   155 
   154 
   156 	TheTest.Printf(_L("DocPos\tHeight\tKeep\tStart\tHeight of Pages = <%d>\n"), pageHeight);
   155 	TBuf<254> buf;
       
   156 	buf.AppendFormat(_L("DocPos\tHeight\tKeep\tStart\tHeight of Pages = <%d>\n"), pageHeight);
       
   157 	TESTPRINT(buf);
   157 	}
   158 	}
   158 
   159 
   159 TBool CLinePaginatorTest::ReadTestFile(TPageLine& aLine)
   160 TBool CLinePaginatorTest::ReadTestFile(TPageLine& aLine)
   160 	{
   161 	{
   161 	TLex8 lex;
   162 	TLex8 lex;
   169 		startNum=textBuffer.Locate('\n')+1;
   170 		startNum=textBuffer.Locate('\n')+1;
   170   		textBuffer.Delete(0,startNum);
   171   		textBuffer.Delete(0,startNum);
   171 		iFilePos+=startNum;
   172 		iFilePos+=startNum;
   172 		lex=textBuffer;
   173 		lex=textBuffer;
   173 		lex.Val(aLine.iDocPos);
   174 		lex.Val(aLine.iDocPos);
   174 		TheTest.Printf(_L("%d\tX\n"), aLine.iDocPos);
   175 		TBuf<254> buf;
       
   176 		buf.AppendFormat(_L("%d\tX\n"), aLine.iDocPos);
       
   177 		TESTPRINT(buf);
   175 		return EFalse;
   178 		return EFalse;
   176 		}
   179 		}
   177 
   180 
   178 	startNum=textBuffer.Locate('\n')+1;
   181 	startNum=textBuffer.Locate('\n')+1;
   179 	textBuffer.Delete(0,startNum);
   182 	textBuffer.Delete(0,startNum);
   210 	return ETrue;
   213 	return ETrue;
   211 	}
   214 	}
   212 
   215 
   213 void CLinePaginatorTest::WriteOutputFile(TPageLine aLine)
   216 void CLinePaginatorTest::WriteOutputFile(TPageLine aLine)
   214 	{
   217 	{
       
   218     TBuf<256> buf;
   215 	if (iTestPageBreak)
   219 	if (iTestPageBreak)
   216 		{
   220 		{
   217 		TheTest.Printf(_L("%d\t%d\t%d\t%d\tBREAK\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
   221 		buf.AppendFormat(_L("%d\t%d\t%d\t%d\tBREAK\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
       
   222 		TESTPRINT(buf);		
   218 		}
   223 		}
   219 	else
   224 	else
   220 		{
   225 		{
   221 		TheTest.Printf(_L("%d\t%d\t%d\t%d\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
   226         buf.Zero();        
       
   227 		buf.AppendFormat(_L("%d\t%d\t%d\t%d\n"), aLine.iDocPos, aLine.iLineHeight, aLine.iKeepWithNext, aLine.iStartNewPage);
       
   228 		TESTPRINT(buf);
   222 		}
   229 		}
   223 
   230 
   224 	}
   231 	}
   225 
   232 
   226 void CLinePaginatorTest::StorePageBreakL(TInt aDocPos)
   233 void CLinePaginatorTest::StorePageBreakL(TInt aDocPos)
   239 	TBool pagesSame=EFalse;
   246 	TBool pagesSame=EFalse;
   240 	TBuf8<128> text;
   247 	TBuf8<128> text;
   241 	TInt prevDocPos=0;
   248 	TInt prevDocPos=0;
   242 	TInt docPosError=0;
   249 	TInt docPosError=0;
   243 
   250 
       
   251 	TBuf<256> buf;
   244 	if (numPages==numTestPages)
   252 	if (numPages==numTestPages)
   245 		{
   253 		{
   246  		TheTest.Printf(_L("Correct Number of Pages = %d\n"), numPages);
   254  		buf.AppendFormat(_L("Correct Number of Pages = %d\n"), numPages);
       
   255  		TESTPRINT(buf);
   247 		pagesSame=ETrue;
   256 		pagesSame=ETrue;
   248 		for (TInt i=0; i<numPages; i++)
   257 		for (TInt i=0; i<numPages; i++)
   249 			{
   258 			{
   250 			numChars=(*iCharsPerPage)[i];
   259 			numChars=(*iCharsPerPage)[i];
   251 			numTestChars=(*iTestChars)[i]-prevDocPos;
   260 			numTestChars=(*iTestChars)[i]-prevDocPos;
   256 				pagesSame=EFalse;
   265 				pagesSame=EFalse;
   257 				}
   266 				}
   258 			prevDocPos=(*iTestChars)[i];
   267 			prevDocPos=(*iTestChars)[i];
   259 			}
   268 			}
   260 		if (pagesSame)
   269 		if (pagesSame)
   261 			{
   270 			{            
   262  			TheTest.Printf(_L("Correct Number of Characters on Pages -- PASSED\n"));
   271  			TESTPRINT(_L("Correct Number of Characters on Pages -- PASSED\n"));
   263 			}
   272 			}
   264 		else
   273 		else
   265 			{
   274 			{
   266 			TheTest.Printf(_L("Incorrect Number of Characters on Pages -- FAILED\n"));
   275             TESTPRINT(_L("Incorrect Number of Characters on Pages -- FAILED\n"));            
   267 			TheTest.Printf(_L("First Error Occurs at Position = %d"), docPosError);
   276             buf.Zero();
       
   277 			buf.AppendFormat(_L("First Error Occurs at Position = %d"), docPosError);
       
   278 			TESTPRINT(buf);
   268 			}
   279 			}
   269 		}
   280 		}
   270 	else
   281 	else
   271 		{
   282 		{
   272  		TheTest.Printf(_L("Incorrect Number of Pages  -- FAILED\n"));
   283         TESTPRINT(_L("Incorrect Number of Pages  -- FAILED\n"));
   273 		TheTest.Printf(_L("Number Calculated	by LinePaginator = %d\n"), numPages);
   284         buf.Zero();
   274 		TheTest.Printf(_L("Number Contained in File = %d\n"), numTestPages);
   285 		buf.AppendFormat(_L("Number Calculated	by LinePaginator = %d\n"), numPages);		
       
   286 		buf.AppendFormat(_L("Number Contained in File = %d\n"), numTestPages);
       
   287 		TESTPRINT(buf);
   275 		}
   288 		}
   276 
   289 
   277 	iTestFile.Close();
   290 	iTestFile.Close();
   278 	return pagesSame;
   291 	return pagesSame;
   279 	}
   292 	}
   285 	linePaginate->OpenTestFileL();
   298 	linePaginate->OpenTestFileL();
   286 	linePaginate->StartPaginateL();
   299 	linePaginate->StartPaginateL();
   287 	delete linePaginate;
   300 	delete linePaginate;
   288 	}
   301 	}
   289 
   302 
   290 TInt E32Main()
   303 TVerdict CTLinePagStep::doTestStepL()
   291 	{
   304 	{
   292 	TheTest.Title();
   305     SetTestStepResult(EPass);
   293 	static CTrapCleanup* TrapCleanup = CTrapCleanup::New();
   306     TestStep = this;
   294 
   307 	TESTPRINT(KTLinePag);
   295 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-LINEPAG-0001 CLinePaginatorTest tests "));
   308 	TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-LINEPAG-0001 CLinePaginatorTest tests "));
   296 	TRAPD(error, LinePaginateL());
   309 	TRAPD(error, LinePaginateL());
   297 	TEST(error == KErrNone);
   310 	TESTPOINT(error == KErrNone);
   298 	delete TrapCleanup;
   311 	return TestStepResult();
   299 	TheTest.End();
       
   300 	TheTest.Close();
       
   301 	return error;
       
   302 	}
   312 	}
   303 
   313 
   304 void FormPanic(TFormPanic aPanic)
   314 void FormPanic(TFormPanic aPanic)
   305 	{
   315 	{
   306 	User::Panic(_L("Form"),aPanic);
   316 	User::Panic(_L("Form"),aPanic);