os/textandloc/textrendering/textformatting/test/src/TestLayout.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* TestLayout.cpp test jig for CTmTextLayout
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#include "TestLayout.h"
sl@0
    21
#include "TGraphicsContext.h"
sl@0
    22
#include "TMINTERP.H"
sl@0
    23
sl@0
    24
#include <txtrich.h>
sl@0
    25
sl@0
    26
#include <e32test.h>
sl@0
    27
/**
sl@0
    28
Constructor.
sl@0
    29
@param aRichText
sl@0
    30
	Text to be formatted.
sl@0
    31
@param aDeviceMap
sl@0
    32
	Formatting and drawing device.
sl@0
    33
@internalComponent
sl@0
    34
*/
sl@0
    35
CETextSource::CETextSource(const CRichText& aRichText,
sl@0
    36
	MGraphicsDeviceMap* aDeviceMap)
sl@0
    37
	: iRichText(&aRichText), iDeviceMap(aDeviceMap)
sl@0
    38
	{
sl@0
    39
	}
sl@0
    40
sl@0
    41
/**
sl@0
    42
Gets the length of the document.
sl@0
    43
@return
sl@0
    44
	The number of Unicode UTF16 codes in the document.
sl@0
    45
@internalComponent
sl@0
    46
*/
sl@0
    47
TInt CETextSource::DocumentLength() const
sl@0
    48
	{
sl@0
    49
	return iRichText->DocumentLength();
sl@0
    50
	}
sl@0
    51
sl@0
    52
/**
sl@0
    53
Gets a run of text of constant formatting.
sl@0
    54
@param aPos
sl@0
    55
	Start of the text to get.
sl@0
    56
@param aText
sl@0
    57
	Segment of text to return.
sl@0
    58
@param aFormat
sl@0
    59
	Format of the segment of text.
sl@0
    60
@internalComponent
sl@0
    61
*/
sl@0
    62
void CETextSource::GetText(TInt aPos, TPtrC& aText, TTmCharFormat& aFormat) const
sl@0
    63
	{
sl@0
    64
	TCharFormat characterFormat;
sl@0
    65
	iRichText->GetChars(aText, characterFormat, aPos);
sl@0
    66
	aFormat = characterFormat;
sl@0
    67
	}
sl@0
    68
sl@0
    69
/**
sl@0
    70
Gets the format of the paragraph at aPos.
sl@0
    71
@param aPos
sl@0
    72
	Character index.
sl@0
    73
@param aFormat
sl@0
    74
	Returns the format.
sl@0
    75
@internalComponent
sl@0
    76
*/
sl@0
    77
void CETextSource::GetParagraphFormatL(TInt aPos, RTmParFormat& aFormat) const
sl@0
    78
	{
sl@0
    79
	CParaFormat* format = CParaFormat::NewLC();
sl@0
    80
	iRichText->GetParagraphFormatL(format, aPos);
sl@0
    81
	aFormat.CopyL(*format);
sl@0
    82
	CleanupStack::PopAndDestroy(format);
sl@0
    83
	}
sl@0
    84
sl@0
    85
/**
sl@0
    86
Returns the start of the paragraph containing aPos.
sl@0
    87
@param aPos
sl@0
    88
	Character index.
sl@0
    89
@return
sl@0
    90
	Character index of the start of the paragraph.
sl@0
    91
@internalComponent
sl@0
    92
*/
sl@0
    93
TInt CETextSource::ParagraphStart(TInt aPos) const
sl@0
    94
	{
sl@0
    95
	iRichText->ParagraphNumberForPos(aPos);
sl@0
    96
	return aPos;
sl@0
    97
	}
sl@0
    98
sl@0
    99
/**
sl@0
   100
Gets a pointer to the picture at aPos.
sl@0
   101
@param aPos
sl@0
   102
	Character index.
sl@0
   103
@return
sl@0
   104
	A pointer to the picture at aPos if there is one. 0 otherwise.
sl@0
   105
@internalComponent
sl@0
   106
*/
sl@0
   107
CPicture* CETextSource::PictureL(TInt aPos) const
sl@0
   108
	{
sl@0
   109
	return iRichText->PictureHandleL(aPos);
sl@0
   110
	}
sl@0
   111
sl@0
   112
/**
sl@0
   113
Creates a new CTestTmTextLayout.
sl@0
   114
@param aText
sl@0
   115
	Text to format.
sl@0
   116
@param aWrapWidth
sl@0
   117
	Width to format at.
sl@0
   118
@return
sl@0
   119
	The newly constructed object.
sl@0
   120
@internalComponent
sl@0
   121
*/
sl@0
   122
CTestTmTextLayout* CTestTmTextLayout::NewLC(
sl@0
   123
	const CRichText& aText, TInt aWrapWidth)
sl@0
   124
	{
sl@0
   125
	CTestTmTextLayout* r = new CTestTmTextLayout;
sl@0
   126
	CleanupStack::PushL(r);
sl@0
   127
	r->ConstructL(aText, aWrapWidth);
sl@0
   128
	return r;
sl@0
   129
	}
sl@0
   130
sl@0
   131
/**
sl@0
   132
Creates a new CTestTmTextLayout.
sl@0
   133
@param aText
sl@0
   134
	Text to format.
sl@0
   135
@param aWrapWidth
sl@0
   136
	Width to format at.
sl@0
   137
@param aTransliterate
sl@0
   138
	Function to transform aText with if required. 0 if no transformation is to
sl@0
   139
	take place.
sl@0
   140
@return
sl@0
   141
	The newly constructed object.
sl@0
   142
@internalComponent
sl@0
   143
*/
sl@0
   144
CTestTmTextLayout* CTestTmTextLayout::NewLC(
sl@0
   145
	const TDesC& aText, TInt aWrapWidth, TransliterationFn* aTransliterate)
sl@0
   146
	{
sl@0
   147
	CTestTmTextLayout* r = new CTestTmTextLayout;
sl@0
   148
	CleanupStack::PushL(r);
sl@0
   149
	r->iParagraphFormatLayer = CParaFormatLayer::NewL();
sl@0
   150
	r->iCharacterFormatLayer = CCharFormatLayer::NewL();
sl@0
   151
	HBufC* buf = HBufC::NewLC(aText.Length());
sl@0
   152
	TPtr des = buf->Des();
sl@0
   153
	if (aTransliterate)
sl@0
   154
		aTransliterate(aText, des);
sl@0
   155
	else
sl@0
   156
		des.Copy(aText);
sl@0
   157
	r->iRichText = CRichText::NewL(
sl@0
   158
		r->iParagraphFormatLayer, r->iCharacterFormatLayer);
sl@0
   159
	r->iRichText->InsertL(0, *buf);
sl@0
   160
	CleanupStack::PopAndDestroy(buf);
sl@0
   161
	r->ConstructL(*r->iRichText, aWrapWidth);
sl@0
   162
	return r;
sl@0
   163
	}
sl@0
   164
sl@0
   165
/**
sl@0
   166
Destructor.
sl@0
   167
@internalComponent
sl@0
   168
*/
sl@0
   169
CTestTmTextLayout::~CTestTmTextLayout()
sl@0
   170
	{
sl@0
   171
	delete iLayout;
sl@0
   172
	delete iSource;
sl@0
   173
	delete iDevice;
sl@0
   174
	delete iRichText;
sl@0
   175
	delete iCharacterFormatLayer;
sl@0
   176
	delete iParagraphFormatLayer;
sl@0
   177
	}
sl@0
   178
sl@0
   179
/**
sl@0
   180
Constructs a new CTestTmTextLayout.
sl@0
   181
@param aText
sl@0
   182
	Text to format.
sl@0
   183
@param aWrapWidth
sl@0
   184
	Width to format at.
sl@0
   185
@return
sl@0
   186
	The newly constructed object.
sl@0
   187
@internalComponent
sl@0
   188
*/
sl@0
   189
void CTestTmTextLayout::ConstructL(const CRichText& aText, TInt aWrapWidth)
sl@0
   190
	{
sl@0
   191
	iLayout = new (ELeave) CTmTextLayout;
sl@0
   192
	TSize screen(aWrapWidth, 100);
sl@0
   193
	iDevice = CTestGraphicsDevice::NewL(screen, 0);
sl@0
   194
	iSource = new (ELeave) CETextSource(aText, iDevice);
sl@0
   195
	iFormatParam.iWrapWidth = aWrapWidth;
sl@0
   196
	iFormatParam.iFlags = TTmFormatParamBase::EWrap;
sl@0
   197
	iLayout->SetTextL(*iSource, iFormatParam);
sl@0
   198
	}
sl@0
   199
sl@0
   200
/**
sl@0
   201
Reformats the text.
sl@0
   202
@param aIn
sl@0
   203
	Reformatting parameters.
sl@0
   204
@param aOut
sl@0
   205
	Reformatting result.
sl@0
   206
@internalComponent
sl@0
   207
*/
sl@0
   208
void CTestTmTextLayout::FormatL(const TTmReformatParam& aIn, TTmReformatResult& aOut)
sl@0
   209
	{
sl@0
   210
	iLayout->FormatL(iFormatParam, aIn, aOut);
sl@0
   211
	}
sl@0
   212
	
sl@0
   213
/**
sl@0
   214
@SYMTestCaseID          SYSLIB-FORM-UT-1887
sl@0
   215
@SYMTestCaseDesc        Testing CTmTextLayout::FindAdjacentChunks() API
sl@0
   216
@SYMTestPriority        Low
sl@0
   217
@SYMTestActions         Tests by finding the text chunks adjoining a given document position. When pos=-1,FindAdjacentChunks() returns false
sl@0
   218
@SYMTestExpectedResults Tests must not fail
sl@0
   219
@SYMREQ                 REQ0000
sl@0
   220
*/
sl@0
   221
void CTestTmTextLayout::TestAdjacentChunks()
sl@0
   222
	{
sl@0
   223
	RTest test(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1887  FindAdjacentChunks"));
sl@0
   224
	for (TInt pos = -1; pos != 4; ++pos)
sl@0
   225
		{
sl@0
   226
		for (TInt type = 0; type != 4; ++type)
sl@0
   227
			{
sl@0
   228
			TTmDocPosSpec posSpec(pos,static_cast<TTmDocPosSpec::TType>(type));
sl@0
   229
			CTmTextLayout::TTmChunkDescription left;
sl@0
   230
			CTmTextLayout::TTmChunkDescription right;
sl@0
   231
			TBool result = iLayout->FindAdjacentChunks(posSpec,left,right);
sl@0
   232
			if(pos==-1)
sl@0
   233
			test(result==0);
sl@0
   234
			}
sl@0
   235
		}
sl@0
   236
		test.Close();
sl@0
   237
	}