textrendering/texthandling/ttext/TRICHOOM.CPP
changeset 51 a7c938434754
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
44:601ab138ba0b 51:a7c938434754
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    17 
    17 
    18 
    18 
    19 #include <txtrich.h>
    19 #include <txtrich.h>
    20 #include "TSTCLIPB.H"
    20 #include "TSTCLIPB.H"
    21 #include <txtstyle.h>
    21 #include <txtstyle.h>
    22 #include <e32test.h>
       
    23 #include <gdi.h>
    22 #include <gdi.h>
    24 #include <conpics.h>											   						 
    23 #include <conpics.h>											   						 
    25 #include <flddef.h>
    24 #include <flddef.h>
    26 #include <fldbltin.h>
    25 #include <fldbltin.h>
    27 #include <s32mem.h>
    26 #include <s32mem.h>
    28 #include <s32file.h>
    27 #include <s32file.h>
    29 #include "../incp/T_PMLPAR.H"
    28 #include "../incp/T_PMLPAR.H"
       
    29 #include "T_RICHOOM.h"
       
    30 
       
    31 #define test(cond)											\
       
    32 	{														\
       
    33 	TBool __bb = (cond);									\
       
    34 	TEST(__bb);												\
       
    35 	if (!__bb)												\
       
    36 		{													\
       
    37 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
       
    38 		User::Leave(1);										\
       
    39 		}													\
       
    40 	}
    30 
    41 
    31 const TInt KTestCleanupStack=0x500;
    42 const TInt KTestCleanupStack=0x500;
    32 GLDEF_C RTest test(_L("TRICHOOM"));
    43 
    33 LOCAL_D RFs theFs;
    44 LOCAL_D RFs theFs;
    34 LOCAL_D CParaFormatLayer* GlobalParaFormatLayer;
    45 LOCAL_D CParaFormatLayer* GlobalParaFormatLayer;
    35 LOCAL_D CCharFormatLayer* GlobalCharFormatLayer;
    46 LOCAL_D CCharFormatLayer* GlobalCharFormatLayer;
    36 LOCAL_D MPictureFactory* GlobalPictureFactory;
    47 LOCAL_D MPictureFactory* GlobalPictureFactory;
    37 LOCAL_D CTrapCleanup* TheTrapCleanup;
    48 LOCAL_D CTrapCleanup* TheTrapCleanup;
    38 LOCAL_D CParser* TheParser;
    49 LOCAL_D CParser* TheParser;
    39 LOCAL_D RFs TheSession;
    50 LOCAL_D RFs TheSession;
    40 
    51 
    41 
    52 
    42 LOCAL_C CRichText* LoadIntoTextL(TFileName& aFileName)
    53 CRichText* CT_RICHOOM::LoadIntoTextL(TFileName& aFileName)
    43 //
    54 //
    44 	{
    55 	{
    45 	TRAPD(ret,
    56 	TRAPD(ret,
    46 	TheParser=CParser::NewL());
    57 	TheParser=CParser::NewL());
    47 	CRichText* text=NULL;
    58 	CRichText* text=NULL;
    55 	TheParser=NULL;
    66 	TheParser=NULL;
    56 	return text;
    67 	return text;
    57 	}
    68 	}
    58 
    69 
    59 
    70 
    60 LOCAL_D void ConstructOOM()
    71 void CT_RICHOOM::ConstructOOM()
    61 // Test CRichText construction, (and index), forcing a leave error at each
    72 // Test CRichText construction, (and index), forcing a leave error at each
    62 // possible stage of the process.
    73 // possible stage of the process.
    63 //
    74 //
    64 	{
    75 	{
    65 	test.Start(_L("Construction under low memory conditions"));
    76 	INFO_PRINTF1(_L("Construction under low memory conditions"));
    66 	
    77 	
    67 	CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
    78 	CParaFormatLayer* paraLayer=CParaFormatLayer::NewL();
    68 	CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
    79 	CCharFormatLayer* charLayer=CCharFormatLayer::NewL();
    69 	TInt failRate=0;
    80 	TInt failRate=0;
    70 	CRichText* doc=NULL;
    81 	CRichText* doc=NULL;
    91 	__UHEAP_RESET;
   102 	__UHEAP_RESET;
    92 	delete paraLayer;
   103 	delete paraLayer;
    93 	delete charLayer;
   104 	delete charLayer;
    94 	TBuf<36> answer;
   105 	TBuf<36> answer;
    95 	answer.Format(_L("        #allocs for full c'tion: %d\n"),failRate-1);
   106 	answer.Format(_L("        #allocs for full c'tion: %d\n"),failRate-1);
    96 	test.Printf(answer);
   107 	INFO_PRINTF1(answer);
    97 	}
   108 	}
    98 
   109 
    99 
   110 
   100 LOCAL_D void CopyPasteOOM()
   111 void CT_RICHOOM::CopyPasteOOM()
   101 	{
   112 	{
   102 // Set up the framework
   113 // Set up the framework
   103 	test.Next(_L("Copy/Paste OOM"));
   114 	INFO_PRINTF1(_L("Copy/Paste OOM"));
   104 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   115 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   105 	TFileName file=_L("z:\\test\\app-framework\\etext\\climb.txt");
   116 	TFileName file=_L("z:\\test\\app-framework\\etext\\climb.txt");
   106 	/*TInt count=*/richText1->ImportTextFileL(0,file,CPlainText::EOrganiseByParagraph);
   117 	/*TInt count=*/richText1->ImportTextFileL(0,file,CPlainText::EOrganiseByParagraph);
   107 	//
   118 	//
   108 	// Insert some picture components
   119 	// Insert some picture components
   127 	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   138 	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   128 	charMask.SetAttrib(EAttFontStrokeWeight);
   139 	charMask.SetAttrib(EAttFontStrokeWeight);
   129 	richText1->ApplyCharFormatL(charFormat,charMask,10,37);
   140 	richText1->ApplyCharFormatL(charFormat,charMask,10,37);
   130 //
   141 //
   131 // Copy to clipboard normally.
   142 // Copy to clipboard normally.
   132 	test.Start(_L("Copy Normally"));
   143 	INFO_PRINTF1(_L("Copy Normally"));
   133 	User::LeaveIfError(TheSession.Connect());
   144 	User::LeaveIfError(TheSession.Connect());
   134 	CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession);
   145 	CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession);
   135 	richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),0,richText1->DocumentLength()-1);  // forces virtual trailing phrase
   146 	richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),0,richText1->DocumentLength()-1);  // forces virtual trailing phrase
   136 	writeBoard->CommitL();
   147 	writeBoard->CommitL();
   137 	CleanupStack::PopAndDestroy();  // writeboard
   148 	CleanupStack::PopAndDestroy();  // writeboard
   138 	writeBoard=NULL;
   149 	writeBoard=NULL;
   139 	delete richText1;
   150 	delete richText1;
   140 	richText1=NULL;
   151 	richText1=NULL;
   141 //
   152 //
   142 // Paste from clipboard normally.
   153 // Paste from clipboard normally.
   143 	test.Next(_L("Paste Normally"));
   154 	INFO_PRINTF1(_L("Paste Normally"));
   144 	__UHEAP_MARK;
   155 	__UHEAP_MARK;
   145 	CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   156 	CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   146 	MDemPictureFactory pictureFactory;
   157 	MDemPictureFactory pictureFactory;
   147 	empty->SetPictureFactory(&pictureFactory,NULL);
   158 	empty->SetPictureFactory(&pictureFactory,NULL);
   148 	CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession);
   159 	CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession);
   154 	CleanupStack::PopAndDestroy();  // readBoard
   165 	CleanupStack::PopAndDestroy();  // readBoard
   155 	readBoard=NULL;
   166 	readBoard=NULL;
   156 	__UHEAP_MARKEND;
   167 	__UHEAP_MARKEND;
   157 //
   168 //
   158 // Paste from clipboard with OOM
   169 // Paste from clipboard with OOM
   159 	test.Next(_L("Paste with OOM"));
   170 	INFO_PRINTF1(_L("Paste with OOM"));
   160 	test.Next(_L("...please wait"));
   171 	INFO_PRINTF1(_L("...please wait"));
   161 	__UHEAP_MARK;
   172 	__UHEAP_MARK;
   162 	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   173 	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   163 	for (TInt ii=1; ;ii++)
   174 	for (TInt ii=1; ;ii++)
   164 		{
   175 		{
   165 		readBoard=CClipboard::NewForReadingLC(TheSession);
   176 		readBoard=CClipboard::NewForReadingLC(TheSession);
   176 	//
   187 	//
   177 	delete empty;
   188 	delete empty;
   178 	empty=NULL;
   189 	empty=NULL;
   179 	TheSession.Close();
   190 	TheSession.Close();
   180 	__UHEAP_MARKEND;
   191 	__UHEAP_MARKEND;
   181 	test.End();
   192 	}
   182 	}
   193 
   183 
   194 
   184 
   195 void CT_RICHOOM::CopyPasteOOM2()
   185 LOCAL_D void CopyPasteOOM2()
       
   186 // Test case for defect HA-282 - simple case
   196 // Test case for defect HA-282 - simple case
   187 //
   197 //
   188 	{
   198 	{
   189 	__UHEAP_MARK;
   199 	__UHEAP_MARK;
   190 // Set up the framework
   200 // Set up the framework
   191 	test.Next(_L("Copy/Paste OOM 2"));
   201 	INFO_PRINTF1(_L("Copy/Paste OOM 2"));
   192 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   202 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   193 	richText1->InsertL(0,_L("HelloHello"));
   203 	richText1->InsertL(0,_L("HelloHello"));
   194 	richText1->InsertL(5,CEditableText::EParagraphDelimiter);
   204 	richText1->InsertL(5,CEditableText::EParagraphDelimiter);
   195 	//
   205 	//
   196 	// Format the first paragraph
   206 	// Format the first paragraph
   198 	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   208 	charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   199 	charMask.SetAttrib(EAttFontStrokeWeight);
   209 	charMask.SetAttrib(EAttFontStrokeWeight);
   200 	richText1->ApplyCharFormatL(charFormat,charMask,0,6);
   210 	richText1->ApplyCharFormatL(charFormat,charMask,0,6);
   201 //
   211 //
   202 // Copy to clipboard normally.
   212 // Copy to clipboard normally.
   203 	test.Start(_L("Copy Normally"));
   213 	INFO_PRINTF1(_L("Copy Normally"));
   204 	User::LeaveIfError(TheSession.Connect());
   214 	User::LeaveIfError(TheSession.Connect());
   205 	CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession);
   215 	CClipboard* writeBoard=CClipboard::NewForWritingLC(TheSession);
   206 	richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),2,6);  // forces virtual trailing phrase
   216 	richText1->CopyToStoreL(writeBoard->Store(),writeBoard->StreamDictionary(),2,6);  // forces virtual trailing phrase
   207 	writeBoard->CommitL();
   217 	writeBoard->CommitL();
   208 	CleanupStack::PopAndDestroy();  // writeboard
   218 	CleanupStack::PopAndDestroy();  // writeboard
   209 	writeBoard=NULL;
   219 	writeBoard=NULL;
   210 //
   220 //
   211 // Paste from clipboard normally.
   221 // Paste from clipboard normally.
   212 	test.Next(_L("Paste Normally"));
   222 	INFO_PRINTF1(_L("Paste Normally"));
   213 //	__UHEAP_MARK;
   223 //	__UHEAP_MARK;
   214 	CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   224 	CRichText* empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   215 	empty->AppendTakingSolePictureOwnershipL(*richText1);
   225 	empty->AppendTakingSolePictureOwnershipL(*richText1);
   216 	CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession);
   226 	CClipboard* readBoard=CClipboard::NewForReadingLC(TheSession);
   217 	TRAPD(ret,
   227 	TRAPD(ret,
   222 	CleanupStack::PopAndDestroy();  // readBoard
   232 	CleanupStack::PopAndDestroy();  // readBoard
   223 	readBoard=NULL;
   233 	readBoard=NULL;
   224 //	__UHEAP_MARKEND;
   234 //	__UHEAP_MARKEND;
   225 //
   235 //
   226 // Paste from clipboard with OOM
   236 // Paste from clipboard with OOM
   227 	test.Next(_L("Paste with OOM"));
   237 	INFO_PRINTF1(_L("Paste with OOM"));
   228 	test.Next(_L("...please wait"));
   238 	INFO_PRINTF1(_L("...please wait"));
   229 	__UHEAP_MARK;
   239 	__UHEAP_MARK;
   230 	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   240 	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   231 	empty->AppendTakingSolePictureOwnershipL(*richText1);
   241 	empty->AppendTakingSolePictureOwnershipL(*richText1);
   232 	delete richText1;
   242 	delete richText1;
   233 	richText1=NULL;
   243 	richText1=NULL;
   247 	delete empty;
   257 	delete empty;
   248 	empty=NULL;
   258 	empty=NULL;
   249 	__UHEAP_MARKEND;
   259 	__UHEAP_MARKEND;
   250 	TheSession.Close();
   260 	TheSession.Close();
   251 	__UHEAP_MARKEND;
   261 	__UHEAP_MARKEND;
   252 	test.End();
   262 	}
   253 	}
   263 
   254 
   264 
   255 
   265 void CT_RICHOOM::WriteInlineL(RWriteStream& aStream,CRichText* aRichText)
   256 LOCAL_D void WriteInlineL(RWriteStream& aStream,CRichText* aRichText)
       
   257 	{
   266 	{
   258 	aRichText->ExternalizeStyleDataL(aStream);
   267 	aRichText->ExternalizeStyleDataL(aStream);
   259 	aRichText->ExternalizeMarkupDataL(aStream);	
   268 	aRichText->ExternalizeMarkupDataL(aStream);	
   260 	aRichText->ExternalizePlainTextL(aStream);
   269 	aRichText->ExternalizePlainTextL(aStream);
   261 	}
   270 	}
   262 
   271 
   263 LOCAL_D void ReadInlineL(RReadStream& aStream,CRichText* aRichText)
   272 void CT_RICHOOM::ReadInlineL(RReadStream& aStream,CRichText* aRichText)
   264 	{
   273 	{
   265 	aRichText->InternalizeStyleDataL(aStream);
   274 	aRichText->InternalizeStyleDataL(aStream);
   266 	aRichText->InternalizeMarkupDataL(aStream);	
   275 	aRichText->InternalizeMarkupDataL(aStream);	
   267 	aRichText->InternalizePlainTextL(aStream);
   276 	aRichText->InternalizePlainTextL(aStream);
   268 	}
   277 	}
   269 
   278 
   270 
   279 
   271 LOCAL_C CStyleList* CreatePopulatedStyleList()
   280 CStyleList* CT_RICHOOM::CreatePopulatedStyleList()
   272 //
   281 //
   273 	{
   282 	{
   274 	//
   283 	//
   275 	// Create style aswell.
   284 	// Create style aswell.
   276 	CStyleList* list=CStyleList::NewL();
   285 	CStyleList* list=CStyleList::NewL();
   285 	list->AppendL(&info3);
   294 	list->AppendL(&info3);
   286 	return list;
   295 	return list;
   287 	}
   296 	}
   288 _LIT(KTRichOutputFile,"c:\\etext\\TRICH.DAT");
   297 _LIT(KTRichOutputFile,"c:\\etext\\TRICH.DAT");
   289 
   298 
   290 LOCAL_C void SaveLoadOOM()
   299 void CT_RICHOOM::SaveLoadOOM()
   291 	{
   300 	{
   292 // Set up the framework
   301 // Set up the framework
   293 	theFs.Delete(KTRichOutputFile);
   302 	theFs.Delete(KTRichOutputFile);
   294 	theFs.MkDirAll(KTRichOutputFile);
   303 	theFs.MkDirAll(KTRichOutputFile);
   295 	CFileStore* store = CPermanentFileStore::CreateLC(theFs,KTRichOutputFile,EFileRead|EFileWrite);
   304 	CFileStore* store = CPermanentFileStore::CreateLC(theFs,KTRichOutputFile,EFileRead|EFileWrite);
   303 	richText1->InsertL(richText1->DocumentLength(),_L("there"));
   312 	richText1->InsertL(richText1->DocumentLength(),_L("there"));
   304 
   313 
   305 	RStoreWriteStream out;
   314 	RStoreWriteStream out;
   306 	TStreamId id1 =  out.CreateLC(*store);
   315 	TStreamId id1 =  out.CreateLC(*store);
   307 	
   316 	
   308 	test.Next(_L("Store/Restore OOM"));
   317 	INFO_PRINTF1(_L("Store/Restore OOM"));
   309 	test.Start(_L("Writing Inline noramlly"));
   318 	INFO_PRINTF1(_L("Writing Inline noramlly"));
   310 // Write out inline normally
   319 // Write out inline normally
   311 	WriteInlineL(out,richText1);
   320 	WriteInlineL(out,richText1);
   312 	delete richText1;
   321 	delete richText1;
   313 	out.CommitL();
   322 	out.CommitL();
   314 	CleanupStack::PopAndDestroy();  // out
   323 	CleanupStack::PopAndDestroy();  // out
   315 	store->CommitL();
   324 	store->CommitL();
   316 	RStoreReadStream in;
   325 	RStoreReadStream in;
   317 	in.OpenLC(*store,id1);
   326 	in.OpenLC(*store,id1);
   318 	CRichText* empty = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   327 	CRichText* empty = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   319 
   328 
   320 	test.Next(_L("Reading Inline noramlly"));
   329 	INFO_PRINTF1(_L("Reading Inline noramlly"));
   321 // Read in inline normally:
   330 // Read in inline normally:
   322 	TRAPD(ret,ReadInlineL(in,empty));
   331 	TRAPD(ret,ReadInlineL(in,empty));
   323 	test(ret==KErrNone);
   332 	test(ret==KErrNone);
   324 	CleanupStack::PopAndDestroy();  // in
   333 	CleanupStack::PopAndDestroy();  // in
   325 	delete empty;
   334 	delete empty;
   326 	empty=NULL;
   335 	empty=NULL;
   327 
   336 
   328 	test.Next(_L("Reading Inline with OOM"));
   337 	INFO_PRINTF1(_L("Reading Inline with OOM"));
   329 // Read in inline with OOM:
   338 // Read in inline with OOM:
   330 	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   339 	empty=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   331 
   340 
   332 	for (TInt jj = 1; ;++jj)
   341 	for (TInt jj = 1; ;++jj)
   333 		{
   342 		{
   344 			test(empty->HasMarkupData());
   353 			test(empty->HasMarkupData());
   345 			break;
   354 			break;
   346 			}
   355 			}
   347 		}
   356 		}
   348 
   357 
   349 	test.Next(_L("Writing Inline with OOM"));
   358 	INFO_PRINTF1(_L("Writing Inline with OOM"));
   350 // Write out inline with OOM:
   359 // Write out inline with OOM:
   351 	CStyleList* list2=CreatePopulatedStyleList();
   360 	CStyleList* list2=CreatePopulatedStyleList();
   352 	CRichText* richText2 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list2);
   361 	CRichText* richText2 = CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list2);
   353 	richText2->InsertL(0,_L("hello"));
   362 	richText2->InsertL(0,_L("hello"));
   354 	TStreamId i = store->ExtendL();
   363 	TStreamId i = store->ExtendL();
   369 		else
   378 		else
   370 			CleanupStack::PopAndDestroy();  // out2
   379 			CleanupStack::PopAndDestroy();  // out2
   371 		}
   380 		}
   372 	store->CommitL();
   381 	store->CommitL();
   373 
   382 
   374 	test.Next(_L("Reading Inline after OOM write"));
   383 	INFO_PRINTF1(_L("Reading Inline after OOM write"));
   375 // Read in inline normally following a write out with OOM
   384 // Read in inline normally following a write out with OOM
   376 	RStoreReadStream in3;
   385 	RStoreReadStream in3;
   377 	in3.OpenLC(*store,i);
   386 	in3.OpenLC(*store,i);
   378 	empty->Reset();
   387 	empty->Reset();
   379 	TRAP(ret,ReadInlineL(in3,empty));	// unhandled exception
   388 	TRAP(ret,ReadInlineL(in3,empty));	// unhandled exception
   402 	richText3->InsertL(0,hdr3);
   411 	richText3->InsertL(0,hdr3);
   403 	richText3->InsertL(0,hdr2);
   412 	richText3->InsertL(0,hdr2);
   404 	richText3->InsertL(0,hdr1);
   413 	richText3->InsertL(0,hdr1);
   405 	richText3->InsertL(2,_L("hello"));
   414 	richText3->InsertL(2,_L("hello"));
   406 
   415 
   407 	test.Next(_L("Writing Outline noramlly"));
   416 	INFO_PRINTF1(_L("Writing Outline noramlly"));
   408 // Write outline normally:
   417 // Write outline normally:
   409 	TStreamId id2 = richText3->StoreL(*store);
   418 	TStreamId id2 = richText3->StoreL(*store);
   410 	store->CommitL();
   419 	store->CommitL();
   411 	delete richText3;
   420 	delete richText3;
   412 
   421 
   413 	test.Next(_L("Reading Outline noramlly"));
   422 	INFO_PRINTF1(_L("Reading Outline noramlly"));
   414 // Read outline normally:
   423 // Read outline normally:
   415 	empty->Reset();
   424 	empty->Reset();
   416 	TRAP(ret,empty->RestoreL(*store,id2));
   425 	TRAP(ret,empty->RestoreL(*store,id2));
   417 	test(ret==KErrNone);
   426 	test(ret==KErrNone);
   418 	empty->Reset();
   427 	empty->Reset();
   419 
   428 
   420 	test.Next(_L("Reading Outline with OOM"));
   429 	INFO_PRINTF1(_L("Reading Outline with OOM"));
   421 // Read outline with OOM:
   430 // Read outline with OOM:
   422 	CRichText* inText2=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   431 	CRichText* inText2=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   423 	for (TInt kk = 1; ;++kk)
   432 	for (TInt kk = 1; ;++kk)
   424 		{
   433 		{
   425 		__UHEAP_SETFAIL(RHeap::EDeterministic,kk);
   434 		__UHEAP_SETFAIL(RHeap::EDeterministic,kk);
   452 	richText4->InsertL(0,hdr4);
   461 	richText4->InsertL(0,hdr4);
   453 	richText4->InsertL(0,hdr5);
   462 	richText4->InsertL(0,hdr5);
   454 	richText4->InsertL(0,hdr6);
   463 	richText4->InsertL(0,hdr6);
   455 	richText4->InsertL(1,_L("hello"));
   464 	richText4->InsertL(1,_L("hello"));
   456 	
   465 	
   457 	test.Next(_L("Writing Outline with OOM"));
   466 	INFO_PRINTF1(_L("Writing Outline with OOM"));
   458 // Wtite outline with OOM:
   467 // Wtite outline with OOM:
   459 	TStreamId id3(0);
   468 	TStreamId id3(0);
   460 	for (TInt mm=1; ;++mm)
   469 	for (TInt mm=1; ;++mm)
   461 		{
   470 		{
   462 		__UHEAP_SETFAIL(RHeap::EDeterministic,mm);
   471 		__UHEAP_SETFAIL(RHeap::EDeterministic,mm);
   468 			store->CommitL();
   477 			store->CommitL();
   469 			break;		
   478 			break;		
   470 			}
   479 			}
   471 		}
   480 		}
   472 
   481 
   473 	test.Next(_L("Reading Outline after OOM write"));
   482 	INFO_PRINTF1(_L("Reading Outline after OOM write"));
   474 // Read outline normally folliwng a write with OOM:
   483 // Read outline normally folliwng a write with OOM:
   475 	empty->Reset();
   484 	empty->Reset();
   476 	TRAP(ret,empty->RestoreL(*store,id3));
   485 	TRAP(ret,empty->RestoreL(*store,id3));
   477 	test(ret==KErrNone);
   486 	test(ret==KErrNone);
   478 		
   487 		
   479 	CleanupStack::PopAndDestroy();  // store
   488 	CleanupStack::PopAndDestroy();  // store
   480 	delete empty;
   489 	delete empty;
   481 	test.End();
   490 	}
   482 	}
   491 
   483 
   492 
   484 
   493 void CT_RICHOOM::CheckTextIntegrity(const CRichText* aText)
   485 LOCAL_C void CheckTextIntegrity(const CRichText* aText)
       
   486 // Simply invokes a method to run the text (& component's) onvariants.
   494 // Simply invokes a method to run the text (& component's) onvariants.
   487 //
   495 //
   488 	{
   496 	{
   489 	__UHEAP_RESET;
   497 	__UHEAP_RESET;
   490 	CParaFormat* paraFormat=CParaFormat::NewLC();
   498 	CParaFormat* paraFormat=CParaFormat::NewLC();
   491 	aText->GetParagraphFormatL(paraFormat,0);  // forces CRichTextIndex::__DbgTextInvariant() to run.
   499 	aText->GetParagraphFormatL(paraFormat,0);  // forces CRichTextIndex::__DbgTextInvariant() to run.
   492 	CleanupStack::PopAndDestroy();  // paraFormat
   500 	CleanupStack::PopAndDestroy();  // paraFormat
   493 	}
   501 	}
   494 	
   502 	
   495 	
   503 	
   496 LOCAL_C void BasicEditOOM()
   504 void CT_RICHOOM::BasicEditOOM()
   497 // Tests basic editing functions under OOM conditions.
   505 // Tests basic editing functions under OOM conditions.
   498 //
   506 //
   499 	{
   507 	{
   500 	test.Next(_L("Basic Editing methods under OOM"));
   508 	INFO_PRINTF1(_L("Basic Editing methods under OOM"));
   501 	test.Start(_L("InsertL(TChar)"));
   509 	INFO_PRINTF1(_L("InsertL(TChar)"));
   502 //
   510 //
   503 //	Insert a single character
   511 //	Insert a single character
   504 	const TInt insertCharLoop=10;
   512 	const TInt insertCharLoop=10;
   505 	const TInt KSmallTextBufferSize=1;
   513 	const TInt KSmallTextBufferSize=1;
   506 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   514 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   523 		}
   531 		}
   524 	__UHEAP_RESET;
   532 	__UHEAP_RESET;
   525 	delete richText1;
   533 	delete richText1;
   526 //
   534 //
   527 //
   535 //
   528 	test.Next(_L("InsertL(TDesC&)"));
   536 	INFO_PRINTF1(_L("InsertL(TDesC&)"));
   529 //
   537 //
   530 //	Insert a descriptor
   538 //	Insert a descriptor
   531 	const TInt insertDescriptorLoop=10;
   539 	const TInt insertDescriptorLoop=10;
   532 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   540 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   533 	richText1->SetPictureFactory(NULL,NULL);  // forces index generation
   541 	richText1->SetPictureFactory(NULL,NULL);  // forces index generation
   536 	for (TInt nn=1;nn<=insertDescriptorLoop+1;nn++)
   544 	for (TInt nn=1;nn<=insertDescriptorLoop+1;nn++)
   537 		{
   545 		{
   538 		__UHEAP_SETFAIL(RHeap::EDeterministic,nn);
   546 		__UHEAP_SETFAIL(RHeap::EDeterministic,nn);
   539 		TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),buf));
   547 		TRAPD(ret,richText1->InsertL(richText1->DocumentLength(),buf));
   540 		if (ret!=KErrNone)
   548 		if (ret!=KErrNone)
       
   549 			{
   541 			test(richText1->DocumentLength()==0);
   550 			test(richText1->DocumentLength()==0);
   542 		else
   551 			}
       
   552 		else
       
   553 			{
   543 			test(richText1->DocumentLength()==buf.Length());
   554 			test(richText1->DocumentLength()==buf.Length());
       
   555 			}
   544 		CheckTextIntegrity(richText1);
   556 		CheckTextIntegrity(richText1);
   545 		richText1->Reset();
   557 		richText1->Reset();
   546 		}
   558 		}
   547 	__UHEAP_RESET;
   559 	__UHEAP_RESET;
   548 	delete richText1;
   560 	delete richText1;
   549 
   561 
   550 //
   562 //
   551 //
   563 //
   552 	test.Next(_L("InsertL(TPictureHeader&)"));
   564 	INFO_PRINTF1(_L("InsertL(TPictureHeader&)"));
   553 //
   565 //
   554 //	Insert a picture header
   566 //	Insert a picture header
   555 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   567 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   556 	//
   568 	//
   557 	for (TInt ii=18; ;ii++)
   569 	for (TInt ii=18; ;ii++)
   581 			break;
   593 			break;
   582 			}
   594 			}
   583 		}
   595 		}
   584 	__UHEAP_RESET;
   596 	__UHEAP_RESET;
   585 	delete richText1;
   597 	delete richText1;
   586 	
   598 
   587 
       
   588 	test.End();	
       
   589 	__UHEAP_RESET;
   599 	__UHEAP_RESET;
   590 //	delete richText1;
   600 //	delete richText1;
   591 	}
   601 	}
   592 
   602 
   593 
   603 
   594 LOCAL_C void AppendTest1L()
   604 void CT_RICHOOM::AppendTest1L()
   595 	{
   605 	{
   596 //	Insert a single character
   606 //	Insert a single character
   597 	const TInt insertDescriptorLoop=10;
   607 	const TInt insertDescriptorLoop=10;
   598 	const TInt KSmallTextBufferSize=1;
   608 	const TInt KSmallTextBufferSize=1;
   599 	CRichText* source=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   609 	CRichText* source=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,CEditableText::ESegmentedStorage,KSmallTextBufferSize);
   604 	for (TInt nn=1;nn<=insertDescriptorLoop+2;nn++) // +1 for the last para delim, +1 to force a suceed
   614 	for (TInt nn=1;nn<=insertDescriptorLoop+2;nn++) // +1 for the last para delim, +1 to force a suceed
   605 		{
   615 		{
   606 		__UHEAP_SETFAIL(RHeap::EDeterministic,nn);
   616 		__UHEAP_SETFAIL(RHeap::EDeterministic,nn);
   607 		TRAPD(ret,target->AppendTakingSolePictureOwnershipL(*source));
   617 		TRAPD(ret,target->AppendTakingSolePictureOwnershipL(*source));
   608 		if (ret!=KErrNone)
   618 		if (ret!=KErrNone)
       
   619 			{
   609 			test(target->DocumentLength()==targetStartLength);
   620 			test(target->DocumentLength()==targetStartLength);
       
   621 			}
   610 		else
   622 		else
   611 			{
   623 			{
   612 			TInt targetLength=target->DocumentLength();
   624 			TInt targetLength=target->DocumentLength();
   613 			test(targetLength==targetStartLength+source->DocumentLength()+1);
   625 			test(targetLength==targetStartLength+source->DocumentLength()+1);
   614 			break;
   626 			break;
   616 		CheckTextIntegrity(target);
   628 		CheckTextIntegrity(target);
   617 		}
   629 		}
   618 	__UHEAP_RESET;
   630 	__UHEAP_RESET;
   619 	delete target;
   631 	delete target;
   620 	delete source;
   632 	delete source;
   621 //	test.End();
   633 	}
   622 	}
   634 
   623 
   635 
   624 
   636 void CT_RICHOOM::AppendTest2L(CRichText* aTarget)
   625 LOCAL_C void AppendTest2L(CRichText* aTarget)
       
   626 	{
   637 	{
   627 	__UHEAP_RESET;
   638 	__UHEAP_RESET;
   628 	const TInt KSmallTextBufferSize=1;
   639 	const TInt KSmallTextBufferSize=1;
   629 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   640 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   630 	CRichText* source=LoadIntoTextL(filename);
   641 	CRichText* source=LoadIntoTextL(filename);
   636 		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   647 		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   637 		TRAPD(ret,
   648 		TRAPD(ret,
   638 			aTarget->AppendTakingSolePictureOwnershipL(*source));
   649 			aTarget->AppendTakingSolePictureOwnershipL(*source));
   639 		__UHEAP_RESET;
   650 		__UHEAP_RESET;
   640 		if (ret!=KErrNone)
   651 		if (ret!=KErrNone)
       
   652 			{
   641 			test(aTarget->DocumentLength()==targetStartLength);
   653 			test(aTarget->DocumentLength()==targetStartLength);
       
   654 			}
   642 		else
   655 		else
   643 			{// We have succeeded in appending the document.
   656 			{// We have succeeded in appending the document.
   644 			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   657 			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   645 			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   658 			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   646 			break;
   659 			break;
   649 	delete source;
   662 	delete source;
   650 	delete aTarget;
   663 	delete aTarget;
   651 	}
   664 	}
   652 
   665 
   653 
   666 
   654 LOCAL_C void AppendTestNewL(CRichText* aTarget)
   667 void CT_RICHOOM::AppendTestNewL(CRichText* aTarget)
   655 	{
   668 	{
   656 	const TInt KSmallTextBufferSize=4;
   669 	const TInt KSmallTextBufferSize=4;
   657 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   670 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   658 	CRichText* source=LoadIntoTextL(filename);
   671 	CRichText* source=LoadIntoTextL(filename);
   659 	if (!aTarget)
   672 	if (!aTarget)
   668 		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   681 		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   669 		TRAPD(ret,
   682 		TRAPD(ret,
   670 			aTarget->AppendTakingSolePictureOwnershipL(*source));
   683 			aTarget->AppendTakingSolePictureOwnershipL(*source));
   671 		__UHEAP_RESET;
   684 		__UHEAP_RESET;
   672 		if (ret!=KErrNone)
   685 		if (ret!=KErrNone)
       
   686 			{
   673 			test(aTarget->DocumentLength()==targetStartLength);
   687 			test(aTarget->DocumentLength()==targetStartLength);
       
   688 			}
   674 		else
   689 		else
   675 			{// We have succeeded in appending the document.
   690 			{// We have succeeded in appending the document.
   676 			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   691 			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   677 			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   692 			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   678 			break;
   693 			break;
   681 	delete source;
   696 	delete source;
   682 	delete aTarget;
   697 	delete aTarget;
   683 	}
   698 	}
   684 
   699 
   685 
   700 
   686 LOCAL_C void AppendTest3L(CRichText* aTarget)
   701 void CT_RICHOOM::AppendTest3L(CRichText* aTarget)
   687 	{
   702 	{
   688 	const TInt KSmallTextBufferSize=31;
   703 	const TInt KSmallTextBufferSize=31;
   689 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   704 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   690 	CRichText* source=LoadIntoTextL(filename);
   705 	CRichText* source=LoadIntoTextL(filename);
   691 	if (!aTarget)
   706 	if (!aTarget)
   696 		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   711 		__UHEAP_SETFAIL(RHeap::EDeterministic,ii);
   697 		TRAPD(ret,
   712 		TRAPD(ret,
   698 			aTarget->AppendTakingSolePictureOwnershipL(*source));
   713 			aTarget->AppendTakingSolePictureOwnershipL(*source));
   699 		__UHEAP_RESET;
   714 		__UHEAP_RESET;
   700 		if (ret!=KErrNone)
   715 		if (ret!=KErrNone)
       
   716 			{
   701 			test(aTarget->DocumentLength()==targetStartLength);
   717 			test(aTarget->DocumentLength()==targetStartLength);
       
   718 			}
   702 		else
   719 		else
   703 			{// We have succeeded in appending the document.
   720 			{// We have succeeded in appending the document.
   704 			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   721 			TInt paraDelimiter=(targetStartLength>0) ? 1 : 0;
   705 			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   722 			test(aTarget->DocumentLength()==targetStartLength+paraDelimiter+source->DocumentLength());
   706 			break;
   723 			break;
   709 	delete source;
   726 	delete source;
   710 	delete aTarget;
   727 	delete aTarget;
   711 	}
   728 	}
   712 
   729 
   713 
   730 
   714 LOCAL_C void AppendTakingSolePictureOwnershipOOM()
   731 void CT_RICHOOM::AppendTakingSolePictureOwnershipOOM()
   715 //
   732 //
   716 	{
   733 	{
   717 	test.Next(_L("AppendTakingSolePictureOwnershipL() under OOM"));
   734 	INFO_PRINTF1(_L("AppendTakingSolePictureOwnershipL() under OOM"));
   718 	//
   735 	//
   719 	test.Start(_L("Plain text only"));
   736 	INFO_PRINTF1(_L("Plain text only"));
   720 	TRAPD(ret,
   737 	TRAPD(ret,
   721 	AppendTest1L());
   738 	AppendTest1L());
   722 	test(ret==KErrNone);
   739 	test(ret==KErrNone);
   723 	//
   740 	//
   724 	test.Next(_L("Plain text + phrase markup, with empty target"));
   741 	INFO_PRINTF1(_L("Plain text + phrase markup, with empty target"));
   725 	TRAP(ret,
   742 	TRAP(ret,
   726 	AppendTest2L(STATIC_CAST(CRichText*,NULL)));
   743 	AppendTest2L(STATIC_CAST(CRichText*,NULL)));
   727 	test(ret==KErrNone);
   744 	test(ret==KErrNone);
   728 	//
   745 	//
   729 	test.Next(_L("Plain text + phrase markup, with non-empty target"));
   746 	INFO_PRINTF1(_L("Plain text + phrase markup, with non-empty target"));
   730 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   747 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   731 	CRichText* target=LoadIntoTextL(filename);
   748 	CRichText* target=LoadIntoTextL(filename);
   732 	TRAP(ret,
   749 	TRAP(ret,
   733 	AppendTest2L(target));
   750 	AppendTest2L(target));
   734 	test(ret==KErrNone);
   751 	test(ret==KErrNone);
   735 	//
   752 	//
   736 //	test.Next(_L("Plain text + shared markup, with empty target"));
   753 //	INFO_PRINTF1(_L("Plain text + shared markup, with empty target"));
   737 //	TRAP(ret,
   754 //	TRAP(ret,
   738 //	AppendTest3L(STATIC_CAST(CRichText*,NULL)));
   755 //	AppendTest3L(STATIC_CAST(CRichText*,NULL)));
   739 //	test(ret==KErrNone);
   756 //	test(ret==KErrNone);
   740 	//
   757 	//
   741 	test.Next(_L("Plain text + shared markup, non-empty target"));
   758 	INFO_PRINTF1(_L("Plain text + shared markup, non-empty target"));
   742 	TRAP(ret,
   759 	TRAP(ret,
   743 	AppendTestNewL(STATIC_CAST(CRichText*,NULL)));
   760 	AppendTestNewL(STATIC_CAST(CRichText*,NULL)));
   744 	test(ret==KErrNone);
   761 	test(ret==KErrNone);
   745 	//
   762 	//
   746 	test.Next(_L("Plain text + shared markup, with non-empty target"));
   763 	INFO_PRINTF1(_L("Plain text + shared markup, with non-empty target"));
   747 	filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   764 	filename=_L("z:\\test\\app-framework\\etext\\richoom2.pml");
   748 	target=LoadIntoTextL(filename);
   765 	target=LoadIntoTextL(filename);
   749 	TRAP(ret,
   766 	TRAP(ret,
   750 	AppendTest3L(target));
   767 	AppendTest3L(target));
   751 	test(ret==KErrNone);
   768 	test(ret==KErrNone);
   752 	//
   769 	}
   753 	test.End();
   770 
   754 	}
   771 
   755 
   772 void CT_RICHOOM::DoAppendParagraphOOM(CRichText* aRichText,TBool aUnderOOM,TInt aReplicas)
   756 
       
   757 LOCAL_C void DoAppendParagraphOOM(CRichText* aRichText,TBool aUnderOOM,TInt aReplicas)
       
   758 	{
   773 	{
   759 	if (!aUnderOOM)
   774 	if (!aUnderOOM)
   760 		{
   775 		{
   761 		aRichText->AppendParagraphL(aReplicas);
   776 		aRichText->AppendParagraphL(aReplicas);
   762 		return;
   777 		return;
   782 			{
   797 			{
   783 			test(newCharCount==charCount+aReplicas);
   798 			test(newCharCount==charCount+aReplicas);
   784 			test(newParaCount==paraCount+aReplicas);
   799 			test(newParaCount==paraCount+aReplicas);
   785 			TBuf<30> buf;
   800 			TBuf<30> buf;
   786 			buf.Format(_L("   allocs=%d\n"),jj);
   801 			buf.Format(_L("   allocs=%d\n"),jj);
   787 			test.Printf(buf);
   802 			INFO_PRINTF1(buf);
   788 			break;
   803 			break;
   789 			}
   804 			}
   790 		}
   805 		}
   791 	}
   806 	}
   792 
   807 
   793 
   808 
   794 LOCAL_C void AppendParagraphOOM()
   809 void CT_RICHOOM::AppendParagraphOOM()
   795 //	
   810 //	
   796 	{
   811 	{
   797 	TInt manyParas=5;
   812 	TInt manyParas=5;
   798 	TInt singlePara=1;
   813 	TInt singlePara=1;
   799 	test.Next(_L("AppendParagraphL() under OOM"));
   814 	INFO_PRINTF1(_L("AppendParagraphL() under OOM"));
   800 //
   815 //
   801 	test.Start(_L("appending normally - text has markup - single para"));
   816 	INFO_PRINTF1(_L("appending normally - text has markup - single para"));
   802 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   817 	TFileName filename=_L("z:\\test\\app-framework\\etext\\richoom1.pml");
   803 	CRichText* text=LoadIntoTextL(filename);
   818 	CRichText* text=LoadIntoTextL(filename);
   804 	DoAppendParagraphOOM(text,EFalse,singlePara);
   819 	DoAppendParagraphOOM(text,EFalse,singlePara);
   805 	delete text;
   820 	delete text;
   806 	text=NULL;
   821 	text=NULL;
   807 
   822 
   808 	test.Next(_L("appending with OOM - text has markup - single para"));
   823 	INFO_PRINTF1(_L("appending with OOM - text has markup - single para"));
   809 	text=LoadIntoTextL(filename);
   824 	text=LoadIntoTextL(filename);
   810 	DoAppendParagraphOOM(text,ETrue,singlePara);
   825 	DoAppendParagraphOOM(text,ETrue,singlePara);
   811 	delete text;
   826 	delete text;
   812 	text=NULL;
   827 	text=NULL;
   813 
   828 
   814 	test.Next(_L("appending normally - text has markup - many paras"));
   829 	INFO_PRINTF1(_L("appending normally - text has markup - many paras"));
   815 	text=LoadIntoTextL(filename);
   830 	text=LoadIntoTextL(filename);
   816 	DoAppendParagraphOOM(text,EFalse,manyParas);
   831 	DoAppendParagraphOOM(text,EFalse,manyParas);
   817 	delete text;
   832 	delete text;
   818 	text=NULL;
   833 	text=NULL;
   819 
   834 
   820 	test.Next(_L("appending with OOM - text has markup - many paras"));
   835 	INFO_PRINTF1(_L("appending with OOM - text has markup - many paras"));
   821 	text=LoadIntoTextL(filename);
   836 	text=LoadIntoTextL(filename);
   822 	DoAppendParagraphOOM(text,ETrue,manyParas);
   837 	DoAppendParagraphOOM(text,ETrue,manyParas);
   823 	delete text;
   838 	delete text;
   824 	text=NULL;
   839 	text=NULL;
   825 
   840 	}
   826 	test.End();
   841 
   827 	}
   842 
   828 
   843 void CT_RICHOOM::ApplyCharFormatOOM1()
   829 
       
   830 LOCAL_C void ApplyCharFormatOOM1()
       
   831 	{
   844 	{
   832 // Set up the framework
   845 // Set up the framework
   833 	test.Next(_L("ApplyCharFormatL() OOM - no markup"));
   846 	INFO_PRINTF1(_L("ApplyCharFormatL() OOM - no markup"));
   834 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   847 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   835 	richText1->InsertL(0,_L("SOME VERY FINE TEXT"));
   848 	richText1->InsertL(0,_L("SOME VERY FINE TEXT"));
   836 
   849 
   837 // Apply some random formatting
   850 // Apply some random formatting
   838 	TCharFormat charFormat; TCharFormatMask charMask;
   851 	TCharFormat charFormat; TCharFormatMask charMask;
   863 	delete richText1;
   876 	delete richText1;
   864 	richText1=NULL;
   877 	richText1=NULL;
   865 	}
   878 	}
   866 
   879 
   867 
   880 
   868 LOCAL_C void ApplyCharFormatOOM2()
   881 void CT_RICHOOM::ApplyCharFormatOOM2()
   869 	{
   882 	{
   870 // Set up the framework
   883 // Set up the framework
   871 	test.Next(_L("ApplyCharFormatL() OOM - with markup"));
   884 	INFO_PRINTF1(_L("ApplyCharFormatL() OOM - with markup"));
   872 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   885 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   873 	richText1->InsertL(0,_L("SOME TEXT"));
   886 	richText1->InsertL(0,_L("SOME TEXT"));
   874 
   887 
   875 // Generate some markup
   888 // Generate some markup
   876 	TCharFormat cF;
   889 	TCharFormat cF;
   909 	delete richText1;
   922 	delete richText1;
   910 	richText1=NULL;
   923 	richText1=NULL;
   911 	}
   924 	}
   912 
   925 
   913 
   926 
   914 LOCAL_C void doMainL()
   927 void CT_RICHOOM::doMainL()
   915 	{
   928 	{
   916  
   929  
   917 	GlobalPictureFactory=new(ELeave) MDemPictureFactory;
   930 	GlobalPictureFactory=new(ELeave) MDemPictureFactory;
   918 	GlobalParaFormatLayer=CParaFormatLayer::NewL();
   931 	GlobalParaFormatLayer=CParaFormatLayer::NewL();
   919 	GlobalCharFormatLayer=CCharFormatLayer::NewL();
   932 	GlobalCharFormatLayer=CCharFormatLayer::NewL();
   935 		test(ret==KErrNone);
   948 		test(ret==KErrNone);
   936 	TRAP(ret,ApplyCharFormatOOM1());
   949 	TRAP(ret,ApplyCharFormatOOM1());
   937 		test(ret==KErrNone);
   950 		test(ret==KErrNone);
   938 	TRAP(ret,ApplyCharFormatOOM2());
   951 	TRAP(ret,ApplyCharFormatOOM2());
   939 		test(ret==KErrNone);
   952 		test(ret==KErrNone);
   940 	test.End();
       
   941 	//
   953 	//
   942 	delete GlobalPictureFactory;
   954 	delete GlobalPictureFactory;
   943 	delete GlobalParaFormatLayer;
   955 	delete GlobalParaFormatLayer;
   944 	delete GlobalCharFormatLayer;
   956 	delete GlobalCharFormatLayer;
   945 	theFs.Close();
   957 	theFs.Close();
   946 	}
   958 	}
   947 
   959 
   948 
   960 
   949 LOCAL_C void setupCleanup()
   961 void CT_RICHOOM::setupCleanup()
   950 //
   962 //
   951 // Initialise the cleanup stack.
   963 // Initialise the cleanup stack.
   952 //
   964 //
   953     {
   965     {
   954 	TheTrapCleanup=CTrapCleanup::New();
   966 	TheTrapCleanup=CTrapCleanup::New();
   961 		});
   973 		});
   962 	test(r==KErrNone);
   974 	test(r==KErrNone);
   963 	}
   975 	}
   964 
   976 
   965 
   977 
   966 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   978 void CT_RICHOOM::DeleteDataFile(const TDesC& aFullName)
   967 	{
   979 	{
   968 	RFs fsSession;
   980 	RFs fsSession;
   969 	TInt err = fsSession.Connect();
   981 	TInt err = fsSession.Connect();
   970 	if(err == KErrNone)
   982 	if(err == KErrNone)
   971 		{
   983 		{
   990 		{
  1002 		{
   991 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
  1003 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   992 		}
  1004 		}
   993 	}
  1005 	}
   994 
  1006 
   995 GLDEF_C TInt E32Main()
  1007 CT_RICHOOM::CT_RICHOOM()
   996 //
       
   997 // Test permanent file store.
       
   998 //
       
   999     {
  1008     {
  1000 	test.Title();
  1009     SetTestStepName(KTestStep_T_RICHOOM);
       
  1010     }
       
  1011 
       
  1012 TVerdict CT_RICHOOM::doTestStepL()
       
  1013     {
       
  1014     SetTestStepResult(EFail);
       
  1015 
       
  1016     __UHEAP_MARK;
       
  1017 
  1001 	setupCleanup();
  1018 	setupCleanup();
  1002 	
  1019     
  1003 	__UHEAP_MARK;
  1020 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRICHOOM-0001 RichText OOM Testing "));
  1004 //
  1021     TRAPD(error1, doMainL());
  1005 	test.Start(_L(" @SYMTestCaseID:SYSLIB-TTEXT-LEGACY-T_TRICHOOM-0001 RichText OOM Testing "));
  1022 
  1006 	TRAPD(ret,doMainL());	
       
  1007 	test(ret==KErrNone);
       
  1008 	
       
  1009 	::DeleteDataFile(KTRichOutputFile);	//deletion of data files must be before call to End() - DEF047652
       
  1010 	test.End();
       
  1011 //
       
  1012 	__UHEAP_MARKEND;
       
  1013 	delete TheTrapCleanup;
  1023 	delete TheTrapCleanup;
  1014 	test.Close();
  1024 
  1015 
  1025     __UHEAP_MARKEND;
  1016 	return KErrNone;
  1026 
       
  1027     if(error1 == KErrNone)
       
  1028         {
       
  1029         SetTestStepResult(EPass);
       
  1030         }
       
  1031 
       
  1032     return TestStepResult();
  1017     }
  1033     }
  1018