textrendering/textformatting/test/src/TInterpreter.cpp
branchRCL_3
changeset 17 336bee5c2d35
parent 16 748ec5531811
equal deleted inserted replaced
16:748ec5531811 17:336bee5c2d35
     1 /*
     1 /*
     2 * Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2003-2009 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".
    19 
    19 
    20 #include "TestPicture.h"
    20 #include "TestPicture.h"
    21 #include "TestLayout.h"
    21 #include "TestLayout.h"
    22 #include "TGraphicsContext.h"
    22 #include "TGraphicsContext.h"
    23 #include "TMINTERP.H"
    23 #include "TMINTERP.H"
    24 #include "tinterpreter.h"
    24 
    25 #include <txtrich.h>
    25 #include <txtrich.h>
    26 #include <e32test.h>
    26 #include <e32test.h>
    27 
    27 
    28 
       
    29 namespace LocalToTInterpreter
       
    30 {
       
    31 _LIT(KLeftToRight1, "abc \x5D0 def abc \x5D0\x5D1\x5D2 \x5D0\x5D1\x5D2 xyz abc a\tb\tc\td\te.");
    28 _LIT(KLeftToRight1, "abc \x5D0 def abc \x5D0\x5D1\x5D2 \x5D0\x5D1\x5D2 xyz abc a\tb\tc\td\te.");
    32 _LIT(KLeftToRight2, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    29 _LIT(KLeftToRight2, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    33 _LIT(KContingentBreak, "\xFFFC");
    30 _LIT(KContingentBreak, "\xFFFC");
    34 
       
    35 CTInterpreterStep* TestStep = NULL;
       
    36 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
       
    37 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
       
    38 
       
    39 }
       
    40 using namespace LocalToTInterpreter;
       
    41 
       
    42 
    31 
    43 /**
    32 /**
    44 Checks if one region is a subset of another.
    33 Checks if one region is a subset of another.
    45 @param aRegion
    34 @param aRegion
    46 	The potential superset.
    35 	The potential superset.
   114 
   103 
   115 /**
   104 /**
   116 Tests RTmBoundingRectInterpreter for a particular piece of text.
   105 Tests RTmBoundingRectInterpreter for a particular piece of text.
   117 @internalComponent
   106 @internalComponent
   118 */
   107 */
   119 void TestTextL(CTestTmTextLayout& aLayout)
   108 void TestTextL(RTest& aTest, CTestTmTextLayout& aLayout)
   120 	{
   109 	{
   121 	RRegion region1;
   110 	RRegion region1;
   122 	RRegion region2;
   111 	RRegion region2;
   123 	RRegion region3;
   112 	RRegion region3;
   124 	CleanupClosePushL(region1);
   113 	CleanupClosePushL(region1);
   127 
   116 
   128 	GetSelectionL(region1, aLayout, 1, 1, 1);
   117 	GetSelectionL(region1, aLayout, 1, 1, 1);
   129 	GetSelectionL(region2, aLayout, 0, 1, 1);
   118 	GetSelectionL(region2, aLayout, 0, 1, 1);
   130 	GetSelectionL(region3, aLayout, 0, aLayout.Source().DocumentLength(), 1);
   119 	GetSelectionL(region3, aLayout, 0, aLayout.Source().DocumentLength(), 1);
   131 
   120 
   132 	TESTPOINT(RegionsEqualL(region1, region2));
   121 	aTest(RegionsEqualL(region1, region2));
   133 	TESTPOINT(RegionsEqualL(region1, region3));
   122 	aTest(RegionsEqualL(region1, region3));
   134 
   123 
   135 	CleanupStack::PopAndDestroy(&region3);
   124 	CleanupStack::PopAndDestroy(&region3);
   136 	CleanupStack::PopAndDestroy(&region2);
   125 	CleanupStack::PopAndDestroy(&region2);
   137 	CleanupStack::PopAndDestroy(&region1);
   126 	CleanupStack::PopAndDestroy(&region1);
   138 	}
   127 	}
   139 
   128 
   140 
   129 
   141 void TestsL()
   130 void TestsL(RTest& aTest)
   142 	{
   131 	{
   143 	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
   132 	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
   144 	CleanupStack::PushL(paraLayer);
   133 	CleanupStack::PushL(paraLayer);
   145 	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
   134 	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
   146 	CleanupStack::PushL(charLayer);
   135 	CleanupStack::PushL(charLayer);
   147 	CRichText* richText = CRichText::NewL(paraLayer, charLayer);
   136 	CRichText* richText = CRichText::NewL(paraLayer, charLayer);
   148 	CleanupStack::PushL(richText);
   137 	CleanupStack::PushL(richText);
   149 
   138 
   150 	TESTPRINT(_L("RTmBoundingRectInterpreter consistency of coverage"));
   139 	aTest.Next(_L("RTmBoundingRectInterpreter consistency of coverage"));
   151 	richText->Reset();
   140 	richText->Reset();
   152 	richText->InsertL(0, KLeftToRight1);
   141 	richText->InsertL(0, KLeftToRight1);
   153 	CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
   142 	CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
   154 	TSize pictureSize(15, 15);
   143 	TSize pictureSize(15, 15);
   155 	CTestPicture* picture = new (ELeave) CTestPicture;
   144 	CTestPicture* picture = new (ELeave) CTestPicture;
   165 	param.iMaxExtraLines = KMaxTInt;
   154 	param.iMaxExtraLines = KMaxTInt;
   166 	param.iParFormatChanged = ETrue;
   155 	param.iParFormatChanged = ETrue;
   167 	param.iParInvalid = EFalse;
   156 	param.iParInvalid = EFalse;
   168 	TTmReformatResult out;
   157 	TTmReformatResult out;
   169 	text1->FormatL(param, out);
   158 	text1->FormatL(param, out);
   170 	TestTextL(*text1);
   159 	TestTextL(aTest, *text1);
   171 
   160 
   172 	//Test for finding text chunks adjoining a given document position
   161 	//Test for finding text chunks adjoining a given document position
   173 	text1->TestAdjacentChunks();
   162 	text1->TestAdjacentChunks();
   174 
   163 
   175 	CleanupStack::PopAndDestroy(text1);
   164 	CleanupStack::PopAndDestroy(text1);
   192 						direction, so IsLegalBreakBeforeL is called.
   181 						direction, so IsLegalBreakBeforeL is called.
   193 @SYMTestExpectedResults Test must not fail
   182 @SYMTestExpectedResults Test must not fail
   194 @SYMDEF                 DEF077884
   183 @SYMDEF                 DEF077884
   195 */
   184 */
   196 
   185 
   197 void Def077884L()
   186 void Def077884L(RTest& aTest)
   198 	{
   187 	{
   199 	TInt testStartLength = 52;
   188 	TInt testStartLength = 52;
   200 	TInt testEndLength = 56;
   189 	TInt testEndLength = 56;
   201 
   190 
   202 	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
   191 	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
   204 	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
   193 	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
   205 	CleanupStack::PushL(charLayer);
   194 	CleanupStack::PushL(charLayer);
   206 	CRichText* richText = CRichText::NewL(paraLayer, charLayer);
   195 	CRichText* richText = CRichText::NewL(paraLayer, charLayer);
   207 	CleanupStack::PushL(richText);
   196 	CleanupStack::PushL(richText);
   208 
   197 
   209 	TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1591 DEF077884: TSourcePictureBreaker crashes when picture not found. "));
   198 	aTest.Next(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1591 DEF077884: TSourcePictureBreaker crashes when picture not found. "));
   210 
   199 
   211 
   200 
   212 	richText->Reset();
   201 	richText->Reset();
   213 
   202 
   214 	richText->InsertL(0, KLeftToRight2);
   203 	richText->InsertL(0, KLeftToRight2);
   215 
   204 
   216 	TESTPOINT(testStartLength == richText->DocumentLength());
   205 	aTest(testStartLength == richText->DocumentLength());
   217 
   206 
   218 	CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
   207 	CTestTmTextLayout* text1 = CTestTmTextLayout::NewLC(*richText, 100);
   219 
   208 
   220 	TTmReformatResult out;
   209 	TTmReformatResult out;
   221 	TTmReformatParam param;
   210 	TTmReformatParam param;
   286 	param.iNewLength = 4;
   275 	param.iNewLength = 4;
   287 
   276 
   288 	text2->FormatL(formatParam, param, out); // Scans the text from left to right.
   277 	text2->FormatL(formatParam, param, out); // Scans the text from left to right.
   289 
   278 
   290 
   279 
   291 	TestTextL(*text1);
   280 	TestTextL(aTest, *text1);
   292 
   281 
   293 	TESTPOINT(testEndLength == richText->DocumentLength());
   282 	aTest(testEndLength == richText->DocumentLength());
   294 
   283 
   295 	CleanupStack::PopAndDestroy(text1);
   284 	CleanupStack::PopAndDestroy(text1);
   296 	CleanupStack::PopAndDestroy(richText);
   285 	CleanupStack::PopAndDestroy(richText);
   297 	CleanupStack::PopAndDestroy(charLayer);
   286 	CleanupStack::PopAndDestroy(charLayer);
   298 	CleanupStack::PopAndDestroy(paraLayer);
   287 	CleanupStack::PopAndDestroy(paraLayer);
   300 
   289 
   301 /**
   290 /**
   302 Tests RTmBoundingRectInterpreter.
   291 Tests RTmBoundingRectInterpreter.
   303 @internalComponent
   292 @internalComponent
   304 */
   293 */
   305 TVerdict CTInterpreterStep::doTestStepL()
   294 void RunTestsL(RTest& aTest)
   306 	{
   295 	{
   307     SetTestStepResult(EPass);
   296 	TestsL(aTest);
   308     TestStep = this;
   297 	Def077884L(aTest);
   309     TESTPRINT(_L("TInterpreter unit"));
   298 	}
   310     TESTPRINT(_L("Start TInterpreter.exe Tests"));
   299 
   311 	TestsL();
   300 /**
   312 	Def077884L();
   301 Tests RTmBoundingRectInterpreter.
   313 	return TestStepResult();
   302 @internalComponent
   314 	}
   303 */
   315 
   304 TInt E32Main()
   316 
   305 	{
       
   306 	RTest rtest(_L("TInterpreter unit"));
       
   307 	CTrapCleanup* TrapCleanup = CTrapCleanup::New();
       
   308 	rtest.Start(_L("Start TInterpreter.exe Tests"));
       
   309 	TRAPD(err, RunTestsL(rtest));
       
   310 	rtest.End();
       
   311 	delete TrapCleanup;
       
   312 	return err;
       
   313 	}
       
   314