1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/textformatting/test/src/TestLayout.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,237 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 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 +* TestLayout.cpp test jig for CTmTextLayout
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#include "TestLayout.h"
1.24 +#include "TGraphicsContext.h"
1.25 +#include "TMINTERP.H"
1.26 +
1.27 +#include <txtrich.h>
1.28 +
1.29 +#include <e32test.h>
1.30 +/**
1.31 +Constructor.
1.32 +@param aRichText
1.33 + Text to be formatted.
1.34 +@param aDeviceMap
1.35 + Formatting and drawing device.
1.36 +@internalComponent
1.37 +*/
1.38 +CETextSource::CETextSource(const CRichText& aRichText,
1.39 + MGraphicsDeviceMap* aDeviceMap)
1.40 + : iRichText(&aRichText), iDeviceMap(aDeviceMap)
1.41 + {
1.42 + }
1.43 +
1.44 +/**
1.45 +Gets the length of the document.
1.46 +@return
1.47 + The number of Unicode UTF16 codes in the document.
1.48 +@internalComponent
1.49 +*/
1.50 +TInt CETextSource::DocumentLength() const
1.51 + {
1.52 + return iRichText->DocumentLength();
1.53 + }
1.54 +
1.55 +/**
1.56 +Gets a run of text of constant formatting.
1.57 +@param aPos
1.58 + Start of the text to get.
1.59 +@param aText
1.60 + Segment of text to return.
1.61 +@param aFormat
1.62 + Format of the segment of text.
1.63 +@internalComponent
1.64 +*/
1.65 +void CETextSource::GetText(TInt aPos, TPtrC& aText, TTmCharFormat& aFormat) const
1.66 + {
1.67 + TCharFormat characterFormat;
1.68 + iRichText->GetChars(aText, characterFormat, aPos);
1.69 + aFormat = characterFormat;
1.70 + }
1.71 +
1.72 +/**
1.73 +Gets the format of the paragraph at aPos.
1.74 +@param aPos
1.75 + Character index.
1.76 +@param aFormat
1.77 + Returns the format.
1.78 +@internalComponent
1.79 +*/
1.80 +void CETextSource::GetParagraphFormatL(TInt aPos, RTmParFormat& aFormat) const
1.81 + {
1.82 + CParaFormat* format = CParaFormat::NewLC();
1.83 + iRichText->GetParagraphFormatL(format, aPos);
1.84 + aFormat.CopyL(*format);
1.85 + CleanupStack::PopAndDestroy(format);
1.86 + }
1.87 +
1.88 +/**
1.89 +Returns the start of the paragraph containing aPos.
1.90 +@param aPos
1.91 + Character index.
1.92 +@return
1.93 + Character index of the start of the paragraph.
1.94 +@internalComponent
1.95 +*/
1.96 +TInt CETextSource::ParagraphStart(TInt aPos) const
1.97 + {
1.98 + iRichText->ParagraphNumberForPos(aPos);
1.99 + return aPos;
1.100 + }
1.101 +
1.102 +/**
1.103 +Gets a pointer to the picture at aPos.
1.104 +@param aPos
1.105 + Character index.
1.106 +@return
1.107 + A pointer to the picture at aPos if there is one. 0 otherwise.
1.108 +@internalComponent
1.109 +*/
1.110 +CPicture* CETextSource::PictureL(TInt aPos) const
1.111 + {
1.112 + return iRichText->PictureHandleL(aPos);
1.113 + }
1.114 +
1.115 +/**
1.116 +Creates a new CTestTmTextLayout.
1.117 +@param aText
1.118 + Text to format.
1.119 +@param aWrapWidth
1.120 + Width to format at.
1.121 +@return
1.122 + The newly constructed object.
1.123 +@internalComponent
1.124 +*/
1.125 +CTestTmTextLayout* CTestTmTextLayout::NewLC(
1.126 + const CRichText& aText, TInt aWrapWidth)
1.127 + {
1.128 + CTestTmTextLayout* r = new CTestTmTextLayout;
1.129 + CleanupStack::PushL(r);
1.130 + r->ConstructL(aText, aWrapWidth);
1.131 + return r;
1.132 + }
1.133 +
1.134 +/**
1.135 +Creates a new CTestTmTextLayout.
1.136 +@param aText
1.137 + Text to format.
1.138 +@param aWrapWidth
1.139 + Width to format at.
1.140 +@param aTransliterate
1.141 + Function to transform aText with if required. 0 if no transformation is to
1.142 + take place.
1.143 +@return
1.144 + The newly constructed object.
1.145 +@internalComponent
1.146 +*/
1.147 +CTestTmTextLayout* CTestTmTextLayout::NewLC(
1.148 + const TDesC& aText, TInt aWrapWidth, TransliterationFn* aTransliterate)
1.149 + {
1.150 + CTestTmTextLayout* r = new CTestTmTextLayout;
1.151 + CleanupStack::PushL(r);
1.152 + r->iParagraphFormatLayer = CParaFormatLayer::NewL();
1.153 + r->iCharacterFormatLayer = CCharFormatLayer::NewL();
1.154 + HBufC* buf = HBufC::NewLC(aText.Length());
1.155 + TPtr des = buf->Des();
1.156 + if (aTransliterate)
1.157 + aTransliterate(aText, des);
1.158 + else
1.159 + des.Copy(aText);
1.160 + r->iRichText = CRichText::NewL(
1.161 + r->iParagraphFormatLayer, r->iCharacterFormatLayer);
1.162 + r->iRichText->InsertL(0, *buf);
1.163 + CleanupStack::PopAndDestroy(buf);
1.164 + r->ConstructL(*r->iRichText, aWrapWidth);
1.165 + return r;
1.166 + }
1.167 +
1.168 +/**
1.169 +Destructor.
1.170 +@internalComponent
1.171 +*/
1.172 +CTestTmTextLayout::~CTestTmTextLayout()
1.173 + {
1.174 + delete iLayout;
1.175 + delete iSource;
1.176 + delete iDevice;
1.177 + delete iRichText;
1.178 + delete iCharacterFormatLayer;
1.179 + delete iParagraphFormatLayer;
1.180 + }
1.181 +
1.182 +/**
1.183 +Constructs a new CTestTmTextLayout.
1.184 +@param aText
1.185 + Text to format.
1.186 +@param aWrapWidth
1.187 + Width to format at.
1.188 +@return
1.189 + The newly constructed object.
1.190 +@internalComponent
1.191 +*/
1.192 +void CTestTmTextLayout::ConstructL(const CRichText& aText, TInt aWrapWidth)
1.193 + {
1.194 + iLayout = new (ELeave) CTmTextLayout;
1.195 + TSize screen(aWrapWidth, 100);
1.196 + iDevice = CTestGraphicsDevice::NewL(screen, 0);
1.197 + iSource = new (ELeave) CETextSource(aText, iDevice);
1.198 + iFormatParam.iWrapWidth = aWrapWidth;
1.199 + iFormatParam.iFlags = TTmFormatParamBase::EWrap;
1.200 + iLayout->SetTextL(*iSource, iFormatParam);
1.201 + }
1.202 +
1.203 +/**
1.204 +Reformats the text.
1.205 +@param aIn
1.206 + Reformatting parameters.
1.207 +@param aOut
1.208 + Reformatting result.
1.209 +@internalComponent
1.210 +*/
1.211 +void CTestTmTextLayout::FormatL(const TTmReformatParam& aIn, TTmReformatResult& aOut)
1.212 + {
1.213 + iLayout->FormatL(iFormatParam, aIn, aOut);
1.214 + }
1.215 +
1.216 +/**
1.217 +@SYMTestCaseID SYSLIB-FORM-UT-1887
1.218 +@SYMTestCaseDesc Testing CTmTextLayout::FindAdjacentChunks() API
1.219 +@SYMTestPriority Low
1.220 +@SYMTestActions Tests by finding the text chunks adjoining a given document position. When pos=-1,FindAdjacentChunks() returns false
1.221 +@SYMTestExpectedResults Tests must not fail
1.222 +@SYMREQ REQ0000
1.223 +*/
1.224 +void CTestTmTextLayout::TestAdjacentChunks()
1.225 + {
1.226 + RTest test(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1887 FindAdjacentChunks"));
1.227 + for (TInt pos = -1; pos != 4; ++pos)
1.228 + {
1.229 + for (TInt type = 0; type != 4; ++type)
1.230 + {
1.231 + TTmDocPosSpec posSpec(pos,static_cast<TTmDocPosSpec::TType>(type));
1.232 + CTmTextLayout::TTmChunkDescription left;
1.233 + CTmTextLayout::TTmChunkDescription right;
1.234 + TBool result = iLayout->FindAdjacentChunks(posSpec,left,right);
1.235 + if(pos==-1)
1.236 + test(result==0);
1.237 + }
1.238 + }
1.239 + test.Close();
1.240 + }