os/textandloc/textrendering/texthandling/ttext/TRICHOOM.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/texthandling/ttext/TRICHOOM.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1033 @@
     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 <txtrich.h>
    1.23 +#include "TSTCLIPB.H"
    1.24 +#include <txtstyle.h>
    1.25 +#include <gdi.h>
    1.26 +#include <conpics.h>											   						 
    1.27 +#include <flddef.h>
    1.28 +#include <fldbltin.h>
    1.29 +#include <s32mem.h>
    1.30 +#include <s32file.h>
    1.31 +#include "../incp/T_PMLPAR.H"
    1.32 +#include "T_RICHOOM.h"
    1.33 +
    1.34 +#define test(cond)											\
    1.35 +	{														\
    1.36 +	TBool __bb = (cond);									\
    1.37 +	TEST(__bb);												\
    1.38 +	if (!__bb)												\
    1.39 +		{													\
    1.40 +		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
    1.41 +		User::Leave(1);										\
    1.42 +		}													\
    1.43 +	}
    1.44 +
    1.45 +const TInt KTestCleanupStack=0x500;
    1.46 +
    1.47 +LOCAL_D RFs theFs;
    1.48 +LOCAL_D CParaFormatLayer* GlobalParaFormatLayer;
    1.49 +LOCAL_D CCharFormatLayer* GlobalCharFormatLayer;
    1.50 +LOCAL_D MPictureFactory* GlobalPictureFactory;
    1.51 +LOCAL_D CTrapCleanup* TheTrapCleanup;
    1.52 +LOCAL_D CParser* TheParser;
    1.53 +LOCAL_D RFs TheSession;
    1.54 +
    1.55 +
    1.56 +CRichText* CT_RICHOOM::LoadIntoTextL(TFileName& aFileName)
    1.57 +//
    1.58 +	{
    1.59 +	TRAPD(ret,
    1.60 +	TheParser=CParser::NewL());
    1.61 +	CRichText* text=NULL;
    1.62 +	TRAP(ret,
    1.63 +	text=TheParser->ParseL(aFileName));
    1.64 +	delete GlobalParaFormatLayer;
    1.65 +	delete GlobalCharFormatLayer;
    1.66 +	GlobalParaFormatLayer=(CParaFormatLayer*)text->GlobalParaFormatLayer();
    1.67 +	GlobalCharFormatLayer=(CCharFormatLayer*)text->GlobalCharFormatLayer();
    1.68 +	delete TheParser;
    1.69 +	TheParser=NULL;
    1.70 +	return text;
    1.71 +	}
    1.72 +
    1.73 +
    1.74 +void CT_RICHOOM::ConstructOOM()
    1.75 +// Test CRichText construction, (and index), forcing a leave error at each
    1.76 +// possible stage of the process.
    1.77 +//
    1.78 +	{
    1.79 +	INFO_PRINTF1(_L("Construction under low memory conditions"));
    1.80 +	
    1.81 +	CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
    1.82 +	CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
    1.83 +	TInt failRate=0;
    1.84 +	CRichText* doc=NULL;
    1.85 +	for (failRate=1;;failRate++)
    1.86 +		{
    1.87 +		__UHEAP_RESET;
    1.88 +		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
    1.89 +		__UHEAP_MARK;
    1.90 +		TRAPD(ret,doc=CRichText::NewL(paraLayer,charLayer));
    1.91 +		if (ret!=KErrNone)
    1.92 +			{
    1.93 +			__UHEAP_MARKEND;
    1.94 +			test(doc==NULL);
    1.95 +			}
    1.96 +		else
    1.97 +			{
    1.98 +			test(doc!=NULL);
    1.99 +//			test(!doc->HasMarkupData());
   1.100 +			delete doc;
   1.101 +			__UHEAP_MARKEND;
   1.102 +			break;
   1.103 +			}
   1.104 +		}
   1.105 +	__UHEAP_RESET;
   1.106 +	delete paraLayer;
   1.107 +	delete charLayer;
   1.108 +	TBuf<36> answer;
   1.109 +	answer.Format(_L("        #allocs for full c'tion: %d\n"),failRate-1);
   1.110 +	INFO_PRINTF1(answer);
   1.111 +	}
   1.112 +
   1.113 +
   1.114 +void CT_RICHOOM::CopyPasteOOM()
   1.115 +	{
   1.116 +// Set up the framework
   1.117 +	INFO_PRINTF1(_L("Copy/Paste OOM"));
   1.118 +	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.119 +	TFileName file=_L("z:\\test\\app-framework\\etext\\climb.txt");
   1.120 +	/*TInt count=*/richText1->ImportTextFileL(0,file,CPlainText::EOrganiseByParagraph);
   1.121 +	//
   1.122 +	// Insert some picture components
   1.123 +	CXzePicture* pic1=CXzePicture::NewL('p');
   1.124 +	CXzePicture* pic2=CXzePicture::NewL('l');
   1.125 +	CXzePicture* pic3=CXzePicture::NewL('l');
   1.126 +	TPictureHeader hdr1;
   1.127 +	TPictureHeader hdr2;
   1.128 +	TPictureHeader hdr3;
   1.129 +	hdr1.iPictureType = KUidXzePictureType;
   1.130 +	hdr2.iPictureType = KUidXzePictureType;
   1.131 +	hdr3.iPictureType = KUidXzePictureType;
   1.132 +	hdr1.iPicture = pic1;
   1.133 +	hdr2.iPicture = pic2;
   1.134 +	hdr3.iPicture = pic3;
   1.135 +	richText1->InsertL(richText1->DocumentLength(),hdr3);
   1.136 +	richText1->InsertL(richText1->DocumentLength(),hdr2);
   1.137 +	richText1->InsertL(richText1->DocumentLength(),hdr1);
   1.138 +	//
   1.139 +	// Apply some random formatting
   1.140 +	TCharFormat charFormat; TCharFormatMask charMask;
   1.141 +	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   1.142 +	charMask.SetAttrib(EAttFontStrokeWeight);
   1.143 +	richText1->ApplyCharFormatL(charFormat,charMask,10,37);
   1.144 +//
   1.145 +// Copy to clipboard normally.
   1.146 +	INFO_PRINTF1(_L("Copy Normally"));
   1.147 +	User::LeaveIfError(TheSession.Connect());
   1.148 +	CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession);
   1.149 +	richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),0,richText1->DocumentLength()-1);  // forces virtual trailing phrase
   1.150 +	writeBoard->CommitL();
   1.151 +	CleanupStack::PopAndDestroy();  // writeboard
   1.152 +	writeBoard=NULL;
   1.153 +	delete richText1;
   1.154 +	richText1=NULL;
   1.155 +//
   1.156 +// Paste from clipboard normally.
   1.157 +	INFO_PRINTF1(_L("Paste Normally"));
   1.158 +	__UHEAP_MARK;
   1.159 +	CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.160 +	MDemPictureFactory pictureFactory;
   1.161 +	empty->SetPictureFactory(&pictureFactory,NULL);
   1.162 +	CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession);
   1.163 +	TRAPD(ret,
   1.164 +	empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),0));
   1.165 +	test(ret==KErrNone);
   1.166 +	delete empty;
   1.167 +	empty=NULL;
   1.168 +	CleanupStack::PopAndDestroy();  // readBoard
   1.169 +	readBoard=NULL;
   1.170 +	__UHEAP_MARKEND;
   1.171 +//
   1.172 +// Paste from clipboard with OOM
   1.173 +	INFO_PRINTF1(_L("Paste with OOM"));
   1.174 +	INFO_PRINTF1(_L("...please wait"));
   1.175 +	__UHEAP_MARK;
   1.176 +	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.177 +	for (TInt ii=1; ;ii++)
   1.178 +		{
   1.179 +		readBoard=CClipboard::NewForReadingLC(TheSession);
   1.180 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.181 +		TRAP(ret,empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),0));
   1.182 +		__UHEAP_RESET;
   1.183 +		empty->Reset();
   1.184 +		CleanupStack::PopAndDestroy();
   1.185 +		if (ret==KErrNone)
   1.186 +			break;
   1.187 +		}
   1.188 +	readBoard=NULL;
   1.189 +
   1.190 +	//
   1.191 +	delete empty;
   1.192 +	empty=NULL;
   1.193 +	TheSession.Close();
   1.194 +	__UHEAP_MARKEND;
   1.195 +	}
   1.196 +
   1.197 +
   1.198 +void CT_RICHOOM::CopyPasteOOM2()
   1.199 +// Test case for defect HA-282 - simple case
   1.200 +//
   1.201 +	{
   1.202 +	__UHEAP_MARK;
   1.203 +// Set up the framework
   1.204 +	INFO_PRINTF1(_L("Copy/Paste OOM 2"));
   1.205 +	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.206 +	richText1->InsertL(0,_L("HelloHello"));
   1.207 +	richText1->InsertL(5,CEditableText::EParagraphDelimiter);
   1.208 +	//
   1.209 +	// Format the first paragraph
   1.210 +	TCharFormat charFormat; TCharFormatMask charMask;
   1.211 +	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   1.212 +	charMask.SetAttrib(EAttFontStrokeWeight);
   1.213 +	richText1->ApplyCharFormatL(charFormat,charMask,0,6);
   1.214 +//
   1.215 +// Copy to clipboard normally.
   1.216 +	INFO_PRINTF1(_L("Copy Normally"));
   1.217 +	User::LeaveIfError(TheSession.Connect());
   1.218 +	CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession);
   1.219 +	richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),2,6);  // forces virtual trailing phrase
   1.220 +	writeBoard->CommitL();
   1.221 +	CleanupStack::PopAndDestroy();  // writeboard
   1.222 +	writeBoard=NULL;
   1.223 +//
   1.224 +// Paste from clipboard normally.
   1.225 +	INFO_PRINTF1(_L("Paste Normally"));
   1.226 +//	__UHEAP_MARK;
   1.227 +	CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.228 +	empty->AppendTakingSolePictureOwnershipL(*richText1);
   1.229 +	CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession);
   1.230 +	TRAPD(ret,
   1.231 +	empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),empty->DocumentLength()));
   1.232 +	test(ret==KErrNone);
   1.233 +	delete empty;
   1.234 +	empty=NULL;
   1.235 +	CleanupStack::PopAndDestroy();  // readBoard
   1.236 +	readBoard=NULL;
   1.237 +//	__UHEAP_MARKEND;
   1.238 +//
   1.239 +// Paste from clipboard with OOM
   1.240 +	INFO_PRINTF1(_L("Paste with OOM"));
   1.241 +	INFO_PRINTF1(_L("...please wait"));
   1.242 +	__UHEAP_MARK;
   1.243 +	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.244 +	empty->AppendTakingSolePictureOwnershipL(*richText1);
   1.245 +	delete richText1;
   1.246 +	richText1=NULL;
   1.247 +	for (TInt ii=1; ;ii++)
   1.248 +		{
   1.249 +		readBoard=CClipboard::NewForReadingLC(TheSession);
   1.250 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.251 +		TRAP(ret,empty->PasteFromStoreL(readBoard->Store(),readBoard->StreamDictionary(),empty->DocumentLength()));
   1.252 +		__UHEAP_RESET;
   1.253 +//		empty->Reset();
   1.254 +		CleanupStack::PopAndDestroy();
   1.255 +		if (ret==KErrNone)
   1.256 +			break;
   1.257 +		}
   1.258 +	readBoard=NULL;
   1.259 +	//
   1.260 +	delete empty;
   1.261 +	empty=NULL;
   1.262 +	__UHEAP_MARKEND;
   1.263 +	TheSession.Close();
   1.264 +	__UHEAP_MARKEND;
   1.265 +	}
   1.266 +
   1.267 +
   1.268 +void CT_RICHOOM::WriteInlineL(RWriteStream& aStream,CRichText* aRichText)
   1.269 +	{
   1.270 +	aRichText->ExternalizeStyleDataL(aStream);
   1.271 +	aRichText->ExternalizeMarkupDataL(aStream);	
   1.272 +	aRichText->ExternalizePlainTextL(aStream);
   1.273 +	}
   1.274 +
   1.275 +void CT_RICHOOM::ReadInlineL(RReadStream& aStream,CRichText* aRichText)
   1.276 +	{
   1.277 +	aRichText->InternalizeStyleDataL(aStream);
   1.278 +	aRichText->InternalizeMarkupDataL(aStream);	
   1.279 +	aRichText->InternalizePlainTextL(aStream);
   1.280 +	}
   1.281 +
   1.282 +
   1.283 +CStyleList* CT_RICHOOM::CreatePopulatedStyleList()
   1.284 +//
   1.285 +	{
   1.286 +	//
   1.287 +	// Create style aswell.
   1.288 +	CStyleList* list=CStyleList::NewL();
   1.289 +	CParagraphStyle* style1=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer);
   1.290 +	CParagraphStyle* style2=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer);
   1.291 +	CParagraphStyle* style3=CParagraphStyle::NewL(*GlobalParaFormatLayer,*GlobalCharFormatLayer);
   1.292 +	RParagraphStyleInfo info1(style1);
   1.293 +	RParagraphStyleInfo info2(style2);
   1.294 +	RParagraphStyleInfo info3(style3);
   1.295 +	list->AppendL(&info1);
   1.296 +	list->AppendL(&info2);
   1.297 +	list->AppendL(&info3);
   1.298 +	return list;
   1.299 +	}
   1.300 +_LIT(KTRichOutputFile,"c:\\etext\\TRICH.DAT");
   1.301 +
   1.302 +void CT_RICHOOM::SaveLoadOOM()
   1.303 +	{
   1.304 +// Set up the framework
   1.305 +	theFs.Delete(KTRichOutputFile);
   1.306 +	theFs.MkDirAll(KTRichOutputFile);
   1.307 +	CFileStore* store = CPermanentFileStore::CreateLC(theFs,KTRichOutputFile,EFileRead|EFileWrite);
   1.308 +	store->SetTypeL(store->Layout());
   1.309 +	CStyleList* list=CreatePopulatedStyleList();
   1.310 +	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   1.311 +	TBool hasMarkupData=richText1->HasMarkupData();
   1.312 +	test(hasMarkupData);  // because of owned style list.
   1.313 +	richText1->InsertL(0,_L("hello"));
   1.314 +	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   1.315 +	richText1->InsertL(richText1->DocumentLength(),_L("there"));
   1.316 +
   1.317 +	RStoreWriteStream out;
   1.318 +	TStreamId id1 =  out.CreateLC(*store);
   1.319 +	
   1.320 +	INFO_PRINTF1(_L("Store/Restore OOM"));
   1.321 +	INFO_PRINTF1(_L("Writing Inline noramlly"));
   1.322 +// Write out inline normally
   1.323 +	WriteInlineL(out,richText1);
   1.324 +	delete richText1;
   1.325 +	out.CommitL();
   1.326 +	CleanupStack::PopAndDestroy();  // out
   1.327 +	store->CommitL();
   1.328 +	RStoreReadStream in;
   1.329 +	in.OpenLC(*store,id1);
   1.330 +	CRichText* empty = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.331 +
   1.332 +	INFO_PRINTF1(_L("Reading Inline noramlly"));
   1.333 +// Read in inline normally:
   1.334 +	TRAPD(ret,ReadInlineL(in,empty));
   1.335 +	test(ret==KErrNone);
   1.336 +	CleanupStack::PopAndDestroy();  // in
   1.337 +	delete empty;
   1.338 +	empty=NULL;
   1.339 +
   1.340 +	INFO_PRINTF1(_L("Reading Inline with OOM"));
   1.341 +// Read in inline with OOM:
   1.342 +	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.343 +
   1.344 +	for (TInt jj = 1; ;++jj)
   1.345 +		{
   1.346 +		RStoreReadStream in2;
   1.347 +		in2.OpenLC(*store,id1);
   1.348 +		__UHEAP_SETFAIL(RHeap::EDeterministic,jj);
   1.349 +		TRAPD(ret,ReadInlineL(in2,empty));
   1.350 +		__UHEAP_RESET;
   1.351 +		CleanupStack::PopAndDestroy();  // in2
   1.352 +		if (ret!=KErrNone)
   1.353 +			empty->Reset();
   1.354 +		else
   1.355 +			{
   1.356 +			test(empty->HasMarkupData());
   1.357 +			break;
   1.358 +			}
   1.359 +		}
   1.360 +
   1.361 +	INFO_PRINTF1(_L("Writing Inline with OOM"));
   1.362 +// Write out inline with OOM:
   1.363 +	CStyleList* list2=CreatePopulatedStyleList();
   1.364 +	CRichText* richText2 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list2);
   1.365 +	richText2->InsertL(0,_L("hello"));
   1.366 +	TStreamId i = store->ExtendL();
   1.367 +	for (TInt ii = 1; ;++ii)
   1.368 +		{
   1.369 +		RStoreWriteStream out2;
   1.370 +		out2.ReplaceLC(*store,i);	
   1.371 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.372 +		TRAP(ret,WriteInlineL(out2,richText2));
   1.373 +		__UHEAP_RESET;
   1.374 +		if (ret==KErrNone)
   1.375 +			{
   1.376 +			out2.CommitL();
   1.377 +			CleanupStack::PopAndDestroy();  // out2
   1.378 +			delete richText2;
   1.379 +			break;		
   1.380 +			}
   1.381 +		else
   1.382 +			CleanupStack::PopAndDestroy();  // out2
   1.383 +		}
   1.384 +	store->CommitL();
   1.385 +
   1.386 +	INFO_PRINTF1(_L("Reading Inline after OOM write"));
   1.387 +// Read in inline normally following a write out with OOM
   1.388 +	RStoreReadStream in3;
   1.389 +	in3.OpenLC(*store,i);
   1.390 +	empty->Reset();
   1.391 +	TRAP(ret,ReadInlineL(in3,empty));	// unhandled exception
   1.392 +	test(ret==KErrNone);
   1.393 +	CleanupStack::PopAndDestroy();
   1.394 +	empty->Reset();
   1.395 +
   1.396 +//
   1.397 +//
   1.398 +//
   1.399 +
   1.400 +	// Set up new component framework
   1.401 +	CXzePicture* pic1=CXzePicture::NewL('p');
   1.402 +	CXzePicture* pic2=CXzePicture::NewL('l');
   1.403 +	CXzePicture* pic3=CXzePicture::NewL('l');
   1.404 +	TPictureHeader hdr1;
   1.405 +	TPictureHeader hdr2;
   1.406 +	TPictureHeader hdr3;
   1.407 +	hdr1.iPictureType = KUidXzePictureType;
   1.408 +	hdr2.iPictureType = KUidXzePictureType;
   1.409 +	hdr3.iPictureType = KUidXzePictureType;
   1.410 +	hdr1.iPicture = pic1;
   1.411 +	hdr2.iPicture = pic2;
   1.412 +	hdr3.iPicture = pic3;
   1.413 +	CRichText* richText3 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.414 +	richText3->InsertL(0,hdr3);
   1.415 +	richText3->InsertL(0,hdr2);
   1.416 +	richText3->InsertL(0,hdr1);
   1.417 +	richText3->InsertL(2,_L("hello"));
   1.418 +
   1.419 +	INFO_PRINTF1(_L("Writing Outline noramlly"));
   1.420 +// Write outline normally:
   1.421 +	TStreamId id2 = richText3->StoreL(*store);
   1.422 +	store->CommitL();
   1.423 +	delete richText3;
   1.424 +
   1.425 +	INFO_PRINTF1(_L("Reading Outline noramlly"));
   1.426 +// Read outline normally:
   1.427 +	empty->Reset();
   1.428 +	TRAP(ret,empty->RestoreL(*store,id2));
   1.429 +	test(ret==KErrNone);
   1.430 +	empty->Reset();
   1.431 +
   1.432 +	INFO_PRINTF1(_L("Reading Outline with OOM"));
   1.433 +// Read outline with OOM:
   1.434 +	CRichText* inText2=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.435 +	for (TInt kk = 1; ;++kk)
   1.436 +		{
   1.437 +		__UHEAP_SETFAIL(RHeap::EDeterministic,kk);
   1.438 +		//
   1.439 +		TRAP(ret,inText2->RestoreL(*store,id2));
   1.440 +		//
   1.441 +		__UHEAP_RESET;
   1.442 +		if (ret!=KErrNone)
   1.443 +			inText2->Reset();
   1.444 +		else
   1.445 +			{
   1.446 +			delete inText2;
   1.447 +			break;
   1.448 +			}
   1.449 +		}
   1.450 +
   1.451 +	CRichText* richText4 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.452 +	CXzePicture* pic4=CXzePicture::NewL('P');
   1.453 +	CXzePicture* pic5=CXzePicture::NewL('P');
   1.454 +	CXzePicture* pic6=CXzePicture::NewL('P');
   1.455 +	TPictureHeader hdr4;
   1.456 +	TPictureHeader hdr5;
   1.457 +	TPictureHeader hdr6;
   1.458 +	hdr4.iPictureType=KUidXzePictureType;
   1.459 +	hdr5.iPictureType=KUidXzePictureType;
   1.460 +	hdr6.iPictureType=KUidXzePictureType;
   1.461 +	hdr4.iPicture=pic4;
   1.462 +	hdr5.iPicture=pic5;
   1.463 +	hdr6.iPicture=pic6;
   1.464 +	richText4->InsertL(0,hdr4);
   1.465 +	richText4->InsertL(0,hdr5);
   1.466 +	richText4->InsertL(0,hdr6);
   1.467 +	richText4->InsertL(1,_L("hello"));
   1.468 +	
   1.469 +	INFO_PRINTF1(_L("Writing Outline with OOM"));
   1.470 +// Wtite outline with OOM:
   1.471 +	TStreamId id3(0);
   1.472 +	for (TInt mm=1; ;++mm)
   1.473 +		{
   1.474 +		__UHEAP_SETFAIL(RHeap::EDeterministic,mm);
   1.475 +		TRAPD(ret,id3 = richText4->StoreL(*store));
   1.476 +		if (ret==KErrNone)
   1.477 +			{
   1.478 +			__UHEAP_RESET;
   1.479 +			delete richText4;
   1.480 +			store->CommitL();
   1.481 +			break;		
   1.482 +			}
   1.483 +		}
   1.484 +
   1.485 +	INFO_PRINTF1(_L("Reading Outline after OOM write"));
   1.486 +// Read outline normally folliwng a write with OOM:
   1.487 +	empty->Reset();
   1.488 +	TRAP(ret,empty->RestoreL(*store,id3));
   1.489 +	test(ret==KErrNone);
   1.490 +		
   1.491 +	CleanupStack::PopAndDestroy();  // store
   1.492 +	delete empty;
   1.493 +	}
   1.494 +
   1.495 +
   1.496 +void CT_RICHOOM::CheckTextIntegrity(const CRichText* aText)
   1.497 +// Simply invokes a method to run the text (& component's) onvariants.
   1.498 +//
   1.499 +	{
   1.500 +	__UHEAP_RESET;
   1.501 +	CParaFormat* paraFormat=CParaFormat::NewLC();
   1.502 +	aText->GetParagraphFormatL(paraFormat,0);  // forces CRichTextIndex::__DbgTextInvariant() to run.
   1.503 +	CleanupStack::PopAndDestroy();  // paraFormat
   1.504 +	}
   1.505 +	
   1.506 +	
   1.507 +void CT_RICHOOM::BasicEditOOM()
   1.508 +// Tests basic editing functions under OOM conditions.
   1.509 +//
   1.510 +	{
   1.511 +	INFO_PRINTF1(_L("Basic Editing methods under OOM"));
   1.512 +	INFO_PRINTF1(_L("InsertL(TChar)"));
   1.513 +//
   1.514 +//	Insert a single character
   1.515 +	const TInt insertCharLoop=10;
   1.516 +	const TInt KSmallTextBufferSize=1;
   1.517 +	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.518 +	richText1->SetPictureFactory(NULL,NULL);  // forces index generation
   1.519 +	for (TInt mm=1;mm<=insertCharLoop;mm++)
   1.520 +		{
   1.521 +		__UHEAP_SETFAIL(RHeap::EDeterministic,mm);
   1.522 +		for (TInt nn=1;nn<=insertCharLoop;nn++)
   1.523 +			{
   1.524 +			TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),'x'));
   1.525 +			if (ret!=KErrNone)
   1.526 +				{
   1.527 +				test(richText1->DocumentLength()+1==nn);
   1.528 +				CheckTextIntegrity(richText1);
   1.529 +				break;
   1.530 +				}
   1.531 +			}
   1.532 +		__UHEAP_RESET;
   1.533 +		richText1->Reset();
   1.534 +		}
   1.535 +	__UHEAP_RESET;
   1.536 +	delete richText1;
   1.537 +//
   1.538 +//
   1.539 +	INFO_PRINTF1(_L("InsertL(TDesC&)"));
   1.540 +//
   1.541 +//	Insert a descriptor
   1.542 +	const TInt insertDescriptorLoop=10;
   1.543 +	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.544 +	richText1->SetPictureFactory(NULL,NULL);  // forces index generation
   1.545 +	TPtrC buf(_L("1234567890"));
   1.546 +
   1.547 +	for (TInt nn=1;nn<=insertDescriptorLoop+1;nn++)
   1.548 +		{
   1.549 +		__UHEAP_SETFAIL(RHeap::EDeterministic,nn);
   1.550 +		TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),buf));
   1.551 +		if (ret!=KErrNone)
   1.552 +			{
   1.553 +			test(richText1->DocumentLength()==0);
   1.554 +			}
   1.555 +		else
   1.556 +			{
   1.557 +			test(richText1->DocumentLength()==buf.Length());
   1.558 +			}
   1.559 +		CheckTextIntegrity(richText1);
   1.560 +		richText1->Reset();
   1.561 +		}
   1.562 +	__UHEAP_RESET;
   1.563 +	delete richText1;
   1.564 +
   1.565 +//
   1.566 +//
   1.567 +	INFO_PRINTF1(_L("InsertL(TPictureHeader&)"));
   1.568 +//
   1.569 +//	Insert a picture header
   1.570 +	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.571 +	//
   1.572 +	for (TInt ii=18; ;ii++)
   1.573 +		{
   1.574 +		// create the picture header
   1.575 +		__UHEAP_RESET;
   1.576 +		CXzePicture* pic1=CXzePicture::NewL('o');
   1.577 +		TPictureHeader hdr1;
   1.578 +		hdr1.iPictureType=KUidXzePictureType;
   1.579 +		hdr1.iPicture=pic1;
   1.580 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.581 +		TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),hdr1));
   1.582 +		if (ret!=KErrNone)
   1.583 +			{
   1.584 +			test(richText1->DocumentLength()==0);
   1.585 +//			if (ii<19)
   1.586 +//				delete pic1;
   1.587 +/*
   1.588 +	THE ABOVE 2 LINES ARE WRONG NOW, SINCE THE PICTURE IS DELETED AUTOMATICALLY, IF THE INSERTION FAILS.
   1.589 +
   1.590 +*/
   1.591 +			richText1->Reset();
   1.592 +			}
   1.593 +		else
   1.594 +			{
   1.595 +			test(richText1->DocumentLength()==1);
   1.596 +			break;
   1.597 +			}
   1.598 +		}
   1.599 +	__UHEAP_RESET;
   1.600 +	delete richText1;
   1.601 +
   1.602 +	__UHEAP_RESET;
   1.603 +//	delete richText1;
   1.604 +	}
   1.605 +
   1.606 +
   1.607 +void CT_RICHOOM::AppendTest1L()
   1.608 +	{
   1.609 +//	Insert a single character
   1.610 +	const TInt insertDescriptorLoop=10;
   1.611 +	const TInt KSmallTextBufferSize=1;
   1.612 +	CRichText* source=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.613 +	CRichText* target=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.614 +	source->InsertL(source->DocumentLength(),_L("1234567890"));	
   1.615 +	target->InsertL(target->DocumentLength(),_L("abcdef"));
   1.616 +	TInt targetStartLength=target->DocumentLength();
   1.617 +	for (TInt nn=1;nn<=insertDescriptorLoop+2;nn++) // +1 for the last para delim, +1 to force a suceed
   1.618 +		{
   1.619 +		__UHEAP_SETFAIL(RHeap::EDeterministic,nn);
   1.620 +		TRAPD(ret,target->AppendTakingSolePictureOwnershipL(*source));
   1.621 +		if (ret!=KErrNone)
   1.622 +			{
   1.623 +			test(target->DocumentLength()==targetStartLength);
   1.624 +			}
   1.625 +		else
   1.626 +			{
   1.627 +			TInt targetLength=target->DocumentLength();
   1.628 +			test(targetLength==targetStartLength+source->DocumentLength()+1);
   1.629 +			break;
   1.630 +			}
   1.631 +		CheckTextIntegrity(target);
   1.632 +		}
   1.633 +	__UHEAP_RESET;
   1.634 +	delete target;
   1.635 +	delete source;
   1.636 +	}
   1.637 +
   1.638 +
   1.639 +void CT_RICHOOM::AppendTest2L(CRichText* aTarget)
   1.640 +	{
   1.641 +	__UHEAP_RESET;
   1.642 +	const TInt KSmallTextBufferSize=1;
   1.643 +	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   1.644 +	CRichText* source=LoadIntoTextL(filename);
   1.645 +	if (!aTarget)
   1.646 +		aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.647 +	TInt targetStartLength=aTarget->DocumentLength();
   1.648 +	for (TInt ii = 1; ;++ii)
   1.649 +		{
   1.650 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.651 +		TRAPD(ret,
   1.652 +			aTarget->AppendTakingSolePictureOwnershipL(*source));
   1.653 +		__UHEAP_RESET;
   1.654 +		if (ret!=KErrNone)
   1.655 +			{
   1.656 +			test(aTarget->DocumentLength()==targetStartLength);
   1.657 +			}
   1.658 +		else
   1.659 +			{// We have succeeded in appending the document.
   1.660 +			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   1.661 +			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   1.662 +			break;
   1.663 +			}
   1.664 +		}
   1.665 +	delete source;
   1.666 +	delete aTarget;
   1.667 +	}
   1.668 +
   1.669 +
   1.670 +void CT_RICHOOM::AppendTestNewL(CRichText* aTarget)
   1.671 +	{
   1.672 +	const TInt KSmallTextBufferSize=4;
   1.673 +	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   1.674 +	CRichText* source=LoadIntoTextL(filename);
   1.675 +	if (!aTarget)
   1.676 +		{
   1.677 +		aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.678 +		aTarget->InsertL(0,_L("This is paragraph number one"));
   1.679 +		aTarget->InsertL(1,CEditableText::EParagraphDelimiter);
   1.680 +		}
   1.681 +	TInt targetStartLength=aTarget->DocumentLength();
   1.682 +	for (TInt ii = 1; ;++ii)
   1.683 +		{
   1.684 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.685 +		TRAPD(ret,
   1.686 +			aTarget->AppendTakingSolePictureOwnershipL(*source));
   1.687 +		__UHEAP_RESET;
   1.688 +		if (ret!=KErrNone)
   1.689 +			{
   1.690 +			test(aTarget->DocumentLength()==targetStartLength);
   1.691 +			}
   1.692 +		else
   1.693 +			{// We have succeeded in appending the document.
   1.694 +			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   1.695 +			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   1.696 +			break;
   1.697 +			}
   1.698 +		}
   1.699 +	delete source;
   1.700 +	delete aTarget;
   1.701 +	}
   1.702 +
   1.703 +
   1.704 +void CT_RICHOOM::AppendTest3L(CRichText* aTarget)
   1.705 +	{
   1.706 +	const TInt KSmallTextBufferSize=31;
   1.707 +	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   1.708 +	CRichText* source=LoadIntoTextL(filename);
   1.709 +	if (!aTarget)
   1.710 +		aTarget=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   1.711 +	TInt targetStartLength=aTarget->DocumentLength();
   1.712 +	for (TInt ii = 1; ;++ii)
   1.713 +		{
   1.714 +		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   1.715 +		TRAPD(ret,
   1.716 +			aTarget->AppendTakingSolePictureOwnershipL(*source));
   1.717 +		__UHEAP_RESET;
   1.718 +		if (ret!=KErrNone)
   1.719 +			{
   1.720 +			test(aTarget->DocumentLength()==targetStartLength);
   1.721 +			}
   1.722 +		else
   1.723 +			{// We have succeeded in appending the document.
   1.724 +			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   1.725 +			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   1.726 +			break;
   1.727 +			}
   1.728 +		}
   1.729 +	delete source;
   1.730 +	delete aTarget;
   1.731 +	}
   1.732 +
   1.733 +
   1.734 +void CT_RICHOOM::AppendTakingSolePictureOwnershipOOM()
   1.735 +//
   1.736 +	{
   1.737 +	INFO_PRINTF1(_L("AppendTakingSolePictureOwnershipL() under OOM"));
   1.738 +	//
   1.739 +	INFO_PRINTF1(_L("Plain text only"));
   1.740 +	TRAPD(ret,
   1.741 +	AppendTest1L());
   1.742 +	test(ret==KErrNone);
   1.743 +	//
   1.744 +	INFO_PRINTF1(_L("Plain text + phrase markup, with empty target"));
   1.745 +	TRAP(ret,
   1.746 +	AppendTest2L(STATIC_CAST(CRichText*,NULL)));
   1.747 +	test(ret==KErrNone);
   1.748 +	//
   1.749 +	INFO_PRINTF1(_L("Plain text + phrase markup, with non-empty target"));
   1.750 +	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   1.751 +	CRichText* target=LoadIntoTextL(filename);
   1.752 +	TRAP(ret,
   1.753 +	AppendTest2L(target));
   1.754 +	test(ret==KErrNone);
   1.755 +	//
   1.756 +//	INFO_PRINTF1(_L("Plain text + shared markup, with empty target"));
   1.757 +//	TRAP(ret,
   1.758 +//	AppendTest3L(STATIC_CAST(CRichText*,NULL)));
   1.759 +//	test(ret==KErrNone);
   1.760 +	//
   1.761 +	INFO_PRINTF1(_L("Plain text + shared markup, non-empty target"));
   1.762 +	TRAP(ret,
   1.763 +	AppendTestNewL(STATIC_CAST(CRichText*,NULL)));
   1.764 +	test(ret==KErrNone);
   1.765 +	//
   1.766 +	INFO_PRINTF1(_L("Plain text + shared markup, with non-empty target"));
   1.767 +	filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   1.768 +	target=LoadIntoTextL(filename);
   1.769 +	TRAP(ret,
   1.770 +	AppendTest3L(target));
   1.771 +	test(ret==KErrNone);
   1.772 +	}
   1.773 +
   1.774 +
   1.775 +void CT_RICHOOM::DoAppendParagraphOOM(CRichText* aRichText,TBool aUnderOOM,TInt aReplicas)
   1.776 +	{
   1.777 +	if (!aUnderOOM)
   1.778 +		{
   1.779 +		aRichText->AppendParagraphL(aReplicas);
   1.780 +		return;
   1.781 +		}
   1.782 +//
   1.783 +// Append testing for OOM
   1.784 +	TInt charCount=aRichText->DocumentLength();
   1.785 +	TInt paraCount=aRichText->ParagraphCount();
   1.786 +	for (TInt jj = 1; ;++jj)
   1.787 +		{
   1.788 +		__UHEAP_SETFAIL(RHeap::EDeterministic,jj);
   1.789 +		TRAPD(ret,
   1.790 +		aRichText->AppendParagraphL(aReplicas));
   1.791 +		__UHEAP_RESET;
   1.792 +		TInt newCharCount=aRichText->DocumentLength();
   1.793 +		TInt newParaCount=aRichText->ParagraphCount();
   1.794 +		if (ret!=KErrNone)
   1.795 +			{
   1.796 +			test(newCharCount==charCount);
   1.797 +			test(newParaCount==paraCount);
   1.798 +			}
   1.799 +		else
   1.800 +			{
   1.801 +			test(newCharCount==charCount+aReplicas);
   1.802 +			test(newParaCount==paraCount+aReplicas);
   1.803 +			TBuf<30> buf;
   1.804 +			buf.Format(_L("   allocs=%d\n"),jj);
   1.805 +			INFO_PRINTF1(buf);
   1.806 +			break;
   1.807 +			}
   1.808 +		}
   1.809 +	}
   1.810 +
   1.811 +
   1.812 +void CT_RICHOOM::AppendParagraphOOM()
   1.813 +//	
   1.814 +	{
   1.815 +	TInt manyParas=5;
   1.816 +	TInt singlePara=1;
   1.817 +	INFO_PRINTF1(_L("AppendParagraphL() under OOM"));
   1.818 +//
   1.819 +	INFO_PRINTF1(_L("appending normally - text has markup - single para"));
   1.820 +	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   1.821 +	CRichText* text=LoadIntoTextL(filename);
   1.822 +	DoAppendParagraphOOM(text,EFalse,singlePara);
   1.823 +	delete text;
   1.824 +	text=NULL;
   1.825 +
   1.826 +	INFO_PRINTF1(_L("appending with OOM - text has markup - single para"));
   1.827 +	text=LoadIntoTextL(filename);
   1.828 +	DoAppendParagraphOOM(text,ETrue,singlePara);
   1.829 +	delete text;
   1.830 +	text=NULL;
   1.831 +
   1.832 +	INFO_PRINTF1(_L("appending normally - text has markup - many paras"));
   1.833 +	text=LoadIntoTextL(filename);
   1.834 +	DoAppendParagraphOOM(text,EFalse,manyParas);
   1.835 +	delete text;
   1.836 +	text=NULL;
   1.837 +
   1.838 +	INFO_PRINTF1(_L("appending with OOM - text has markup - many paras"));
   1.839 +	text=LoadIntoTextL(filename);
   1.840 +	DoAppendParagraphOOM(text,ETrue,manyParas);
   1.841 +	delete text;
   1.842 +	text=NULL;
   1.843 +	}
   1.844 +
   1.845 +
   1.846 +void CT_RICHOOM::ApplyCharFormatOOM1()
   1.847 +	{
   1.848 +// Set up the framework
   1.849 +	INFO_PRINTF1(_L("ApplyCharFormatL() OOM - no markup"));
   1.850 +	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.851 +	richText1->InsertL(0,_L("SOME VERY FINE TEXT"));
   1.852 +
   1.853 +// Apply some random formatting
   1.854 +	TCharFormat charFormat; TCharFormatMask charMask;
   1.855 +	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   1.856 +	charMask.SetAttrib(EAttFontStrokeWeight);
   1.857 +
   1.858 +	for (TInt jj=1; ;jj++)
   1.859 +		{
   1.860 +		__UHEAP_SETFAIL(RHeap::EDeterministic,jj);
   1.861 +		TRAPD(ret,
   1.862 +		richText1->ApplyCharFormatL(charFormat,charMask,5,11));
   1.863 +		__UHEAP_RESET;
   1.864 +		TPtrC buf;
   1.865 +		if (ret==KErrNone)
   1.866 +			{
   1.867 +			TCharFormat newFormat;
   1.868 +			richText1->GetChars(buf,newFormat,5);
   1.869 +			test(newFormat.IsEqual(charFormat,charMask));
   1.870 +			test(buf.Length() < richText1->DocumentLength());
   1.871 +			break;
   1.872 +			}
   1.873 +		else
   1.874 +			{
   1.875 +
   1.876 +			}
   1.877 +
   1.878 +		}
   1.879 +	delete richText1;
   1.880 +	richText1=NULL;
   1.881 +	}
   1.882 +
   1.883 +
   1.884 +void CT_RICHOOM::ApplyCharFormatOOM2()
   1.885 +	{
   1.886 +// Set up the framework
   1.887 +	INFO_PRINTF1(_L("ApplyCharFormatL() OOM - with markup"));
   1.888 +	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   1.889 +	richText1->InsertL(0,_L("SOME TEXT"));
   1.890 +
   1.891 +// Generate some markup
   1.892 +	TCharFormat cF;
   1.893 +	TCharFormatMask cM;
   1.894 +	cF.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
   1.895 +	cM.SetAttrib(EAttFontPosture);
   1.896 +	richText1->ApplyCharFormatL(cF,cM,3,3);
   1.897 +
   1.898 +// Apply some random formatting
   1.899 +	TCharFormat charFormat; TCharFormatMask charMask;
   1.900 +	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   1.901 +	charMask.SetAttrib(EAttFontStrokeWeight);
   1.902 +
   1.903 +	for (TInt jj=1; ;jj++)
   1.904 +		{
   1.905 +		__UHEAP_SETFAIL(RHeap::EDeterministic,jj);
   1.906 +		TRAPD(ret,
   1.907 +		richText1->ApplyCharFormatL(charFormat,charMask,3,3));
   1.908 +		__UHEAP_RESET;
   1.909 +		TPtrC buf;
   1.910 +		if (ret==KErrNone)
   1.911 +			{
   1.912 +			TCharFormat newFormat;
   1.913 +			richText1->GetChars(buf,newFormat,3);
   1.914 +			test(newFormat.iFontSpec.iFontStyle.Posture()==EPostureItalic);
   1.915 +			test(newFormat.iFontSpec.iFontStyle.StrokeWeight()==EStrokeWeightBold);
   1.916 +			test(buf.Length()==3);
   1.917 +			break;
   1.918 +			}
   1.919 +		else
   1.920 +			{
   1.921 +
   1.922 +			}
   1.923 +
   1.924 +		}
   1.925 +	delete richText1;
   1.926 +	richText1=NULL;
   1.927 +	}
   1.928 +
   1.929 +
   1.930 +void CT_RICHOOM::doMainL()
   1.931 +	{
   1.932 + 
   1.933 +	GlobalPictureFactory=new(ELeave) MDemPictureFactory;
   1.934 +	GlobalParaFormatLayer=CParaFormatLayer::NewL();
   1.935 +	GlobalCharFormatLayer=CCharFormatLayer::NewL();
   1.936 +	theFs.Connect();
   1.937 +	//
   1.938 +	TRAPD(ret,ConstructOOM());
   1.939 +		test(ret==KErrNone);
   1.940 +	TRAP(ret,SaveLoadOOM());
   1.941 +		test(ret==KErrNone);
   1.942 +	TRAP(ret,CopyPasteOOM());
   1.943 +		test(ret==KErrNone);
   1.944 +	TRAP(ret,BasicEditOOM());
   1.945 +		test(ret==KErrNone);
   1.946 +	TRAP(ret,AppendTakingSolePictureOwnershipOOM());
   1.947 +		test(ret==KErrNone);
   1.948 +	TRAP(ret,CopyPasteOOM2());
   1.949 +		test(ret==KErrNone);
   1.950 +	TRAP(ret,AppendParagraphOOM());
   1.951 +		test(ret==KErrNone);
   1.952 +	TRAP(ret,ApplyCharFormatOOM1());
   1.953 +		test(ret==KErrNone);
   1.954 +	TRAP(ret,ApplyCharFormatOOM2());
   1.955 +		test(ret==KErrNone);
   1.956 +	//
   1.957 +	delete GlobalPictureFactory;
   1.958 +	delete GlobalParaFormatLayer;
   1.959 +	delete GlobalCharFormatLayer;
   1.960 +	theFs.Close();
   1.961 +	}
   1.962 +
   1.963 +
   1.964 +void CT_RICHOOM::setupCleanup()
   1.965 +//
   1.966 +// Initialise the cleanup stack.
   1.967 +//
   1.968 +    {
   1.969 +	TheTrapCleanup=CTrapCleanup::New();
   1.970 +	test(TheTrapCleanup!=NULL);
   1.971 +	TRAPD(r,\
   1.972 +		{\
   1.973 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.974 +			CleanupStack::PushL((TAny*)0);\
   1.975 +		CleanupStack::Pop(KTestCleanupStack);\
   1.976 +		});
   1.977 +	test(r==KErrNone);
   1.978 +	}
   1.979 +
   1.980 +
   1.981 +void CT_RICHOOM::DeleteDataFile(const TDesC& aFullName)
   1.982 +	{
   1.983 +	RFs fsSession;
   1.984 +	TInt err = fsSession.Connect();
   1.985 +	if(err == KErrNone)
   1.986 +		{
   1.987 +		TEntry entry;
   1.988 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.989 +			{
   1.990 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   1.991 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.992 +			if(err != KErrNone) 
   1.993 +				{
   1.994 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   1.995 +				}
   1.996 +			err = fsSession.Delete(aFullName);
   1.997 +			if(err != KErrNone) 
   1.998 +				{
   1.999 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
  1.1000 +				}
  1.1001 +			}
  1.1002 +		fsSession.Close();
  1.1003 +		}
  1.1004 +	else
  1.1005 +		{
  1.1006 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
  1.1007 +		}
  1.1008 +	}
  1.1009 +
  1.1010 +CT_RICHOOM::CT_RICHOOM()
  1.1011 +    {
  1.1012 +    SetTestStepName(KTestStep_T_RICHOOM);
  1.1013 +    }
  1.1014 +
  1.1015 +TVerdict CT_RICHOOM::doTestStepL()
  1.1016 +    {
  1.1017 +    SetTestStepResult(EFail);
  1.1018 +
  1.1019 +    __UHEAP_MARK;
  1.1020 +
  1.1021 +	setupCleanup();
  1.1022 +    
  1.1023 +	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRICHOOM-0001 RichText OOM Testing "));
  1.1024 +    TRAPD(error1, doMainL());
  1.1025 +
  1.1026 +	delete TheTrapCleanup;
  1.1027 +
  1.1028 +    __UHEAP_MARKEND;
  1.1029 +
  1.1030 +    if(error1 == KErrNone)
  1.1031 +        {
  1.1032 +        SetTestStepResult(EPass);
  1.1033 +        }
  1.1034 +
  1.1035 +    return TestStepResult();
  1.1036 +    }