os/textandloc/textrendering/texthandling/ttext/T_INDTER.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <e32std.h>
    20 #include <e32base.h>
    21 
    22 #include <txtfrmat.h>
    23 #include <txtfmlyr.h>
    24 #include <txtrich.h>
    25 #include <gdi.h>
    26 
    27 #include "../incp/T_PMLPAR.H"
    28 #include "T_INDTER.h"
    29 
    30 LOCAL_D CTestStep *pTestStep = NULL;
    31 #define test(cond)											\
    32 	{														\
    33 	TBool __bb = (cond);									\
    34 	pTestStep->TEST(__bb);									\
    35 	if (!__bb)												\
    36 		{													\
    37 		pTestStep->ERR_PRINTF1(_L("ERROR: Test Failed"));	\
    38 		User::Leave(1);										\
    39 		}													\
    40 	}
    41 #undef INFO_PRINTF1
    42 #undef INFO_PRINTF2
    43 // copy from tefexportconst.h
    44 #define INFO_PRINTF1(p1)        pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1))
    45 #define INFO_PRINTF2(p1, p2)    pTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2))
    46 
    47 #define UNUSED_VAR(a) a = a
    48 
    49 const TInt KTestCleanupStack=0x40;
    50 
    51 LOCAL_D CTrapCleanup* TheTrapCleanup=NULL;
    52 LOCAL_D CRichText* TheText=NULL;
    53 LOCAL_D CParaFormatLayer* TheGlobalParaLayer=NULL;
    54 LOCAL_D CCharFormatLayer* TheGlobalCharLayer=NULL;
    55 LOCAL_D CParser* TheParser;
    56 
    57 
    58 LOCAL_C void SetRichTextL(TFileName& aFileName)
    59 //
    60 	{
    61 	delete TheText;
    62 	delete TheGlobalParaLayer;
    63 	delete TheGlobalCharLayer;
    64 	TheParser=CParser::NewL();
    65 	CleanupStack::PushL(TheParser);
    66 	TheText=TheParser->ParseL(aFileName);
    67 	CleanupStack::PopAndDestroy();
    68 	TheGlobalParaLayer=(CParaFormatLayer*)TheText->GlobalParaFormatLayer();
    69 	TheGlobalCharLayer=(CCharFormatLayer*)TheText->GlobalCharFormatLayer();
    70 	}
    71 
    72 
    73 LOCAL_C void CreateRichTextL()
    74 //
    75 	{
    76 	TParaFormatMask paraMask;
    77 	TheGlobalParaLayer=CParaFormatLayer::NewL((CParaFormat*)NULL,paraMask);
    78 	CleanupStack::PushL(TheGlobalParaLayer);
    79 	TCharFormat charFormat;
    80 	TCharFormatMask charMask;
    81 	TheGlobalCharLayer=CCharFormatLayer::NewL(charFormat,charMask);
    82 	CleanupStack::PushL(TheGlobalCharLayer);
    83 	TheText=CRichText::NewL(TheGlobalParaLayer,TheGlobalCharLayer);
    84 	CleanupStack::Pop(2);
    85 	}
    86 
    87 
    88 LOCAL_C void DestroyRichText()
    89 //
    90 	{
    91 	delete TheText;
    92 	delete TheGlobalParaLayer;
    93 	delete TheGlobalCharLayer;
    94 	}
    95 
    96 
    97 LOCAL_C void ResetTextL()
    98 // Initialise the rich text.
    99 //
   100 	{
   101 	TheText->Reset();
   102 	TBuf<512> buf(_L("This is paragraph one"));
   103 	buf.Append(CEditableText::EParagraphDelimiter);
   104 	buf.Append(_L("This is paragraph two"));
   105 	buf.Append(CEditableText::EParagraphDelimiter);
   106 	buf.Append(_L("This is paragraph 333"));
   107 	// Editable text already has the terminating paragraph delimter.
   108 	TheText->InsertL(0,buf);
   109 	}
   110 
   111 
   112 LOCAL_C TParaBorder BorderValues(TParaBorder::TLineStyle aLineStyle,TInt aThickness)
   113 //
   114 	{
   115 	TParaBorder border;
   116 	border.iLineStyle=aLineStyle;
   117 	border.iThickness=aThickness;
   118 	return border;
   119 	}
   120 
   121 
   122 LOCAL_C void PerformTestParaBordersL(CParaFormat& aApplyFormat,TParaFormatMask& aApplyMask,
   123 									 TTextFormatAttribute anAttribute,CParaFormat::TParaBorderSide aSide,
   124 									 TParaBorder& aBorder,
   125 									 CParaFormat& aSensedFormat,TParaFormatMask& aSensedMask)
   126 //
   127 	{
   128 	aApplyMask.SetAttrib(anAttribute);
   129 	aApplyFormat.SetParaBorderL(aSide,aBorder);
   130 	TheText->ApplyParaFormatL(&aApplyFormat,aApplyMask,0,1);
   131 	TheText->GetParaFormatL(&aSensedFormat,aSensedMask,0,TheText->DocumentLength());
   132 	}
   133 
   134 
   135 LOCAL_C void TestParaBordersL()
   136 // Tests the indeterminate state of paragraph borders.
   137 //
   138 	{
   139 	ResetTextL();
   140 	CParaFormat* sensedFormat=CParaFormat::NewLC();
   141 	TParaFormatMask undeterminedMask;
   142 	TheText->GetParaFormatL(sensedFormat,undeterminedMask,0,TheText->DocumentLength());
   143 	test(undeterminedMask.IsNull());
   144 	//
   145 	CParaFormat* applyFormat=CParaFormat::NewLC();
   146 	TParaFormatMask applyMask;
   147 	//
   148 	TParaBorder border=BorderValues(TParaBorder::ESolid,1);
   149 	//
   150 	PerformTestParaBordersL(*applyFormat,applyMask,EAttTopBorder,CParaFormat::EParaBorderTop,border,*sensedFormat,undeterminedMask);
   151 	test(undeterminedMask.AttribIsSet(EAttTopBorder));
   152 	test(!(undeterminedMask.AttribIsSet(EAttBottomBorder)));
   153 	test(!(undeterminedMask.AttribIsSet(EAttLeftBorder)));
   154 	test(!(undeterminedMask.AttribIsSet(EAttRightBorder)));
   155 	//
   156 	PerformTestParaBordersL(*applyFormat,applyMask,EAttBottomBorder,CParaFormat::EParaBorderBottom,border,*sensedFormat,undeterminedMask);	
   157 	test(undeterminedMask.AttribIsSet(EAttTopBorder));
   158 	test(undeterminedMask.AttribIsSet(EAttBottomBorder));
   159 	test(!(undeterminedMask.AttribIsSet(EAttLeftBorder)));
   160 	test(!(undeterminedMask.AttribIsSet(EAttRightBorder)));
   161 	//
   162 	PerformTestParaBordersL(*applyFormat,applyMask,EAttLeftBorder,CParaFormat::EParaBorderLeft,border,*sensedFormat,undeterminedMask);
   163 	test(undeterminedMask.AttribIsSet(EAttTopBorder));
   164 	test(undeterminedMask.AttribIsSet(EAttBottomBorder));
   165 	test(undeterminedMask.AttribIsSet(EAttLeftBorder));
   166 	test(!(undeterminedMask.AttribIsSet(EAttRightBorder)));
   167 	//
   168 	PerformTestParaBordersL(*applyFormat,applyMask,EAttRightBorder,CParaFormat::EParaBorderRight,border,*sensedFormat,undeterminedMask);	
   169 	test(undeterminedMask.AttribIsSet(EAttTopBorder));
   170 	test(undeterminedMask.AttribIsSet(EAttBottomBorder));
   171 	test(undeterminedMask.AttribIsSet(EAttLeftBorder));
   172 	test(undeterminedMask.AttribIsSet(EAttRightBorder));
   173 	//
   174 	CleanupStack::PopAndDestroy(2);  // applyFormat & sensedFormat
   175 	}
   176 
   177 
   178 LOCAL_C void TestParaFormatL()
   179 // Test the indeterminate state of paragraph format attributes.
   180 //
   181 	{
   182 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_INDTER-0001 Paragraph format attributes "));
   183 	TestParaBordersL();
   184 	}
   185 
   186 
   187 LOCAL_C void TestCharFormatL()
   188 // Test the indeterminate state of character format attributes.
   189 //
   190 	{
   191 	INFO_PRINTF1(_L("Character format attributes"));
   192 	//
   193 	ResetTextL();
   194 	TCharFormat applyFormat;
   195 	TCharFormatMask applyMask;
   196 	//
   197 	TCharFormat sensedFormat;
   198 	TCharFormatMask sensedMask;
   199 	// Make para 2 bold
   200 	applyFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   201 	applyMask.SetAttrib(EAttFontStrokeWeight);
   202 	TheText->ApplyCharFormatL(applyFormat,applyMask,22,22);
   203 	// Make para 3 italic
   204 	applyFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
   205 	applyMask.ClearAll();  applyMask.SetAttrib(EAttFontPosture);
   206 	TheText->ApplyCharFormatL(applyFormat,applyMask,44,21);
   207 	//	
   208 	TheText->GetCharFormat(sensedFormat,sensedMask,0,TheText->DocumentLength());
   209 	test(sensedMask.AttribIsSet(EAttFontStrokeWeight));
   210 	test(sensedMask.AttribIsSet(EAttFontPosture));
   211 	//
   212 	TheText->GetCharFormat(sensedFormat,sensedMask,50,1);
   213 	test(sensedMask.IsNull());
   214 	//
   215 	TheText->GetCharFormat(sensedFormat,sensedMask,44,21);
   216 	test(sensedMask.IsNull());
   217 	//
   218 	TFileName file=_L("z:\\test\\app-framework\\etext\\t_indter.pml");
   219 	SetRichTextL(file);
   220 
   221 	TheText->GetCharFormat(sensedFormat,sensedMask,4,1);
   222 	//
   223 	TheText->GetCharFormat(sensedFormat,sensedMask,0,TheText->DocumentLength());
   224 	test(sensedMask.AttribIsSet(EAttFontStrokeWeight));
   225 	test(sensedMask.AttribIsSet(EAttFontPosture));
   226 	test(sensedMask.AttribIsSet(EAttFontUnderline));
   227 	test(sensedMask.AttribIsSet(EAttFontStrikethrough));
   228 	test(sensedMask.AttribIsSet(EAttFontPrintPos));
   229 	}
   230 
   231 
   232 LOCAL_C void DoTestL()
   233 // Main routine
   234 //
   235     {
   236 	CreateRichTextL();
   237 	TestParaFormatL();
   238 	TestCharFormatL();
   239 	
   240 	DestroyRichText();
   241     }
   242 
   243 
   244 LOCAL_C void setupCleanup()
   245 // Initialise the cleanup stack.
   246 //
   247     {
   248 
   249 	TheTrapCleanup=CTrapCleanup::New();
   250 	TRAPD(r,\
   251 		{\
   252 		for (TInt i=KTestCleanupStack;i>0;i--)\
   253 			CleanupStack::PushL((TAny*)1);\
   254 		test(r==KErrNone);\
   255 		CleanupStack::Pop(KTestCleanupStack);\
   256 		});
   257 	}
   258 
   259 CT_INDTER::CT_INDTER()
   260     {
   261     SetTestStepName(KTestStep_T_INDTER);
   262     pTestStep = this;
   263     }
   264 
   265 TVerdict CT_INDTER::doTestStepL()
   266     {
   267     SetTestStepResult(EFail);
   268 
   269     INFO_PRINTF1(_L("Rich Text Format attribute Indeterminate State tests"));
   270     __UHEAP_MARK;
   271     setupCleanup();
   272     TRAPD(r, DoTestL());
   273     test(r == KErrNone);
   274 
   275     delete TheTrapCleanup;
   276     
   277     __UHEAP_MARKEND;
   278     
   279     if (r == KErrNone)
   280         {
   281         SetTestStepResult(EPass);
   282         }
   283 
   284     return TestStepResult();
   285     }