1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/texthandling/ttext/T_INDTER.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,285 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2010 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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <e32base.h>
1.24 +
1.25 +#include <txtfrmat.h>
1.26 +#include <txtfmlyr.h>
1.27 +#include <txtrich.h>
1.28 +#include <gdi.h>
1.29 +
1.30 +#include "../incp/T_PMLPAR.H"
1.31 +#include "T_INDTER.h"
1.32 +
1.33 +LOCAL_D CTestStep *pTestStep = NULL;
1.34 +#define test(cond) \
1.35 + { \
1.36 + TBool __bb = (cond); \
1.37 + pTestStep->TEST(__bb); \
1.38 + if (!__bb) \
1.39 + { \
1.40 + pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed")); \
1.41 + User::Leave(1); \
1.42 + } \
1.43 + }
1.44 +#undef INFO_PRINTF1
1.45 +#undef INFO_PRINTF2
1.46 +// copy from tefexportconst.h
1.47 +#define INFO_PRINTF1(p1) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
1.48 +#define INFO_PRINTF2(p1, p2) pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
1.49 +
1.50 +#define UNUSED_VAR(a) a = a
1.51 +
1.52 +const TInt KTestCleanupStack=0x40;
1.53 +
1.54 +LOCAL_D CTrapCleanup* TheTrapCleanup=NULL;
1.55 +LOCAL_D CRichText* TheText=NULL;
1.56 +LOCAL_D CParaFormatLayer* TheGlobalParaLayer=NULL;
1.57 +LOCAL_D CCharFormatLayer* TheGlobalCharLayer=NULL;
1.58 +LOCAL_D CParser* TheParser;
1.59 +
1.60 +
1.61 +LOCAL_C void SetRichTextL(TFileName& aFileName)
1.62 +//
1.63 + {
1.64 + delete TheText;
1.65 + delete TheGlobalParaLayer;
1.66 + delete TheGlobalCharLayer;
1.67 + TheParser=CParser::NewL();
1.68 + CleanupStack::PushL(TheParser);
1.69 + TheText=TheParser->ParseL(aFileName);
1.70 + CleanupStack::PopAndDestroy();
1.71 + TheGlobalParaLayer=(CParaFormatLayer*)TheText->GlobalParaFormatLayer();
1.72 + TheGlobalCharLayer=(CCharFormatLayer*)TheText->GlobalCharFormatLayer();
1.73 + }
1.74 +
1.75 +
1.76 +LOCAL_C void CreateRichTextL()
1.77 +//
1.78 + {
1.79 + TParaFormatMask paraMask;
1.80 + TheGlobalParaLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraMask);
1.81 + CleanupStack::PushL(TheGlobalParaLayer);
1.82 + TCharFormat charFormat;
1.83 + TCharFormatMask charMask;
1.84 + TheGlobalCharLayer=CCharFormatLayer::NewL(charFormat,charMask);
1.85 + CleanupStack::PushL(TheGlobalCharLayer);
1.86 + TheText=CRichText::NewL(TheGlobalParaLayer,TheGlobalCharLayer);
1.87 + CleanupStack::Pop(2);
1.88 + }
1.89 +
1.90 +
1.91 +LOCAL_C void DestroyRichText()
1.92 +//
1.93 + {
1.94 + delete TheText;
1.95 + delete TheGlobalParaLayer;
1.96 + delete TheGlobalCharLayer;
1.97 + }
1.98 +
1.99 +
1.100 +LOCAL_C void ResetTextL()
1.101 +// Initialise the rich text.
1.102 +//
1.103 + {
1.104 + TheText->Reset();
1.105 + TBuf<512> buf(_L("This is paragraph one"));
1.106 + buf.Append(CEditableText::EParagraphDelimiter);
1.107 + buf.Append(_L("This is paragraph two"));
1.108 + buf.Append(CEditableText::EParagraphDelimiter);
1.109 + buf.Append(_L("This is paragraph 333"));
1.110 + // Editable text already has the terminating paragraph delimter.
1.111 + TheText->InsertL(0,buf);
1.112 + }
1.113 +
1.114 +
1.115 +LOCAL_C TParaBorder BorderValues(TParaBorder::TLineStyle aLineStyle,TInt aThickness)
1.116 +//
1.117 + {
1.118 + TParaBorder border;
1.119 + border.iLineStyle=aLineStyle;
1.120 + border.iThickness=aThickness;
1.121 + return border;
1.122 + }
1.123 +
1.124 +
1.125 +LOCAL_C void PerformTestParaBordersL(CParaFormat& aApplyFormat,TParaFormatMask& aApplyMask,
1.126 + TTextFormatAttribute anAttribute,CParaFormat::TParaBorderSide aSide,
1.127 + TParaBorder& aBorder,
1.128 + CParaFormat& aSensedFormat,TParaFormatMask& aSensedMask)
1.129 +//
1.130 + {
1.131 + aApplyMask.SetAttrib(anAttribute);
1.132 + aApplyFormat.SetParaBorderL(aSide,aBorder);
1.133 + TheText->ApplyParaFormatL(&aApplyFormat,aApplyMask,0,1);
1.134 + TheText->GetParaFormatL(&aSensedFormat,aSensedMask,0,TheText->DocumentLength());
1.135 + }
1.136 +
1.137 +
1.138 +LOCAL_C void TestParaBordersL()
1.139 +// Tests the indeterminate state of paragraph borders.
1.140 +//
1.141 + {
1.142 + ResetTextL();
1.143 + CParaFormat* sensedFormat=CParaFormat::NewLC();
1.144 + TParaFormatMask undeterminedMask;
1.145 + TheText->GetParaFormatL(sensedFormat,undeterminedMask,0,TheText->DocumentLength());
1.146 + test(undeterminedMask.IsNull());
1.147 + //
1.148 + CParaFormat* applyFormat=CParaFormat::NewLC();
1.149 + TParaFormatMask applyMask;
1.150 + //
1.151 + TParaBorder border=BorderValues(TParaBorder::ESolid,1);
1.152 + //
1.153 + PerformTestParaBordersL(*applyFormat,applyMask,EAttTopBorder,CParaFormat::EParaBorderTop,border,*sensedFormat,undeterminedMask);
1.154 + test(undeterminedMask.AttribIsSet(EAttTopBorder));
1.155 + test(!(undeterminedMask.AttribIsSet(EAttBottomBorder)));
1.156 + test(!(undeterminedMask.AttribIsSet(EAttLeftBorder)));
1.157 + test(!(undeterminedMask.AttribIsSet(EAttRightBorder)));
1.158 + //
1.159 + PerformTestParaBordersL(*applyFormat,applyMask,EAttBottomBorder,CParaFormat::EParaBorderBottom,border,*sensedFormat,undeterminedMask);
1.160 + test(undeterminedMask.AttribIsSet(EAttTopBorder));
1.161 + test(undeterminedMask.AttribIsSet(EAttBottomBorder));
1.162 + test(!(undeterminedMask.AttribIsSet(EAttLeftBorder)));
1.163 + test(!(undeterminedMask.AttribIsSet(EAttRightBorder)));
1.164 + //
1.165 + PerformTestParaBordersL(*applyFormat,applyMask,EAttLeftBorder,CParaFormat::EParaBorderLeft,border,*sensedFormat,undeterminedMask);
1.166 + test(undeterminedMask.AttribIsSet(EAttTopBorder));
1.167 + test(undeterminedMask.AttribIsSet(EAttBottomBorder));
1.168 + test(undeterminedMask.AttribIsSet(EAttLeftBorder));
1.169 + test(!(undeterminedMask.AttribIsSet(EAttRightBorder)));
1.170 + //
1.171 + PerformTestParaBordersL(*applyFormat,applyMask,EAttRightBorder,CParaFormat::EParaBorderRight,border,*sensedFormat,undeterminedMask);
1.172 + test(undeterminedMask.AttribIsSet(EAttTopBorder));
1.173 + test(undeterminedMask.AttribIsSet(EAttBottomBorder));
1.174 + test(undeterminedMask.AttribIsSet(EAttLeftBorder));
1.175 + test(undeterminedMask.AttribIsSet(EAttRightBorder));
1.176 + //
1.177 + CleanupStack::PopAndDestroy(2); // applyFormat & sensedFormat
1.178 + }
1.179 +
1.180 +
1.181 +LOCAL_C void TestParaFormatL()
1.182 +// Test the indeterminate state of paragraph format attributes.
1.183 +//
1.184 + {
1.185 + INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_INDTER-0001 Paragraph format attributes "));
1.186 + TestParaBordersL();
1.187 + }
1.188 +
1.189 +
1.190 +LOCAL_C void TestCharFormatL()
1.191 +// Test the indeterminate state of character format attributes.
1.192 +//
1.193 + {
1.194 + INFO_PRINTF1(_L("Character format attributes"));
1.195 + //
1.196 + ResetTextL();
1.197 + TCharFormat applyFormat;
1.198 + TCharFormatMask applyMask;
1.199 + //
1.200 + TCharFormat sensedFormat;
1.201 + TCharFormatMask sensedMask;
1.202 + // Make para 2 bold
1.203 + applyFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
1.204 + applyMask.SetAttrib(EAttFontStrokeWeight);
1.205 + TheText->ApplyCharFormatL(applyFormat,applyMask,22,22);
1.206 + // Make para 3 italic
1.207 + applyFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
1.208 + applyMask.ClearAll(); applyMask.SetAttrib(EAttFontPosture);
1.209 + TheText->ApplyCharFormatL(applyFormat,applyMask,44,21);
1.210 + //
1.211 + TheText->GetCharFormat(sensedFormat,sensedMask,0,TheText->DocumentLength());
1.212 + test(sensedMask.AttribIsSet(EAttFontStrokeWeight));
1.213 + test(sensedMask.AttribIsSet(EAttFontPosture));
1.214 + //
1.215 + TheText->GetCharFormat(sensedFormat,sensedMask,50,1);
1.216 + test(sensedMask.IsNull());
1.217 + //
1.218 + TheText->GetCharFormat(sensedFormat,sensedMask,44,21);
1.219 + test(sensedMask.IsNull());
1.220 + //
1.221 + TFileName file=_L("z:\\test\\app-framework\\etext\\t_indter.pml");
1.222 + SetRichTextL(file);
1.223 +
1.224 + TheText->GetCharFormat(sensedFormat,sensedMask,4,1);
1.225 + //
1.226 + TheText->GetCharFormat(sensedFormat,sensedMask,0,TheText->DocumentLength());
1.227 + test(sensedMask.AttribIsSet(EAttFontStrokeWeight));
1.228 + test(sensedMask.AttribIsSet(EAttFontPosture));
1.229 + test(sensedMask.AttribIsSet(EAttFontUnderline));
1.230 + test(sensedMask.AttribIsSet(EAttFontStrikethrough));
1.231 + test(sensedMask.AttribIsSet(EAttFontPrintPos));
1.232 + }
1.233 +
1.234 +
1.235 +LOCAL_C void DoTestL()
1.236 +// Main routine
1.237 +//
1.238 + {
1.239 + CreateRichTextL();
1.240 + TestParaFormatL();
1.241 + TestCharFormatL();
1.242 +
1.243 + DestroyRichText();
1.244 + }
1.245 +
1.246 +
1.247 +LOCAL_C void setupCleanup()
1.248 +// Initialise the cleanup stack.
1.249 +//
1.250 + {
1.251 +
1.252 + TheTrapCleanup=CTrapCleanup::New();
1.253 + TRAPD(r,\
1.254 + {\
1.255 + for (TInt i=KTestCleanupStack;i>0;i--)\
1.256 + CleanupStack::PushL((TAny*)1);\
1.257 + test(r==KErrNone);\
1.258 + CleanupStack::Pop(KTestCleanupStack);\
1.259 + });
1.260 + }
1.261 +
1.262 +CT_INDTER::CT_INDTER()
1.263 + {
1.264 + SetTestStepName(KTestStep_T_INDTER);
1.265 + pTestStep = this;
1.266 + }
1.267 +
1.268 +TVerdict CT_INDTER::doTestStepL()
1.269 + {
1.270 + SetTestStepResult(EFail);
1.271 +
1.272 + INFO_PRINTF1(_L("Rich Text Format attribute Indeterminate State tests"));
1.273 + __UHEAP_MARK;
1.274 + setupCleanup();
1.275 + TRAPD(r, DoTestL());
1.276 + test(r == KErrNone);
1.277 +
1.278 + delete TheTrapCleanup;
1.279 +
1.280 + __UHEAP_MARKEND;
1.281 +
1.282 + if (r == KErrNone)
1.283 + {
1.284 + SetTestStepResult(EPass);
1.285 + }
1.286 +
1.287 + return TestStepResult();
1.288 + }