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