textrendering/texthandling/ttext/TRTCUSTM.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 <txtstyle.h>
    20 #include <txtstyle.h>
    21 #include "TXTMRTSR.H"
    21 #include "TXTMRTSR.H"
    22 #include <e32test.h>
       
    23 #include <gdi.h>
    22 #include <gdi.h>
    24 #include <conpics.h>											   						 
    23 #include <conpics.h>											   						 
    25 #include <s32mem.h>
    24 #include <s32mem.h>
    26 #include <s32file.h>
    25 #include <s32file.h>
    27 #include <flddef.h>
    26 #include <flddef.h>
    28 #include <fldbltin.h>
    27 #include <fldbltin.h>
    29 #include <fldset.h>
    28 #include <fldset.h>
    30 
    29 #include "TRTCUSTM.h"
    31 GLDEF_C RTest test(_L("TRTCUSTM"));
    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 	}
       
    41 
    32 LOCAL_D RFs theFs;
    42 LOCAL_D RFs theFs;
    33 LOCAL_D CFileStore* TheStore;
    43 LOCAL_D CFileStore* TheStore;
    34 LOCAL_D CParaFormatLayer* GlobalParaFormatLayer;
    44 LOCAL_D CParaFormatLayer* GlobalParaFormatLayer;
    35 LOCAL_D CCharFormatLayer* GlobalCharFormatLayer;
    45 LOCAL_D CCharFormatLayer* GlobalCharFormatLayer;
    36 LOCAL_D CTrapCleanup* TheTrapCleanup;
    46 LOCAL_D CTrapCleanup* TheTrapCleanup;
    45 	CStreamStore* iStore;
    55 	CStreamStore* iStore;
    46 	};
    56 	};
    47 
    57 
    48 
    58 
    49 ////////////////////////////////////////////////////////////////////////////////////////////
    59 ////////////////////////////////////////////////////////////////////////////////////////////
    50 class TTestFieldFactory : public MTextFieldFactory
    60 class TTestFieldFactoryTRTCUSTM : public MTextFieldFactory
    51 	{
    61 	{
    52 public:
    62 public:
    53 	// from MTextFieldFactory
    63 	// from MTextFieldFactory
    54 	virtual CTextField* NewFieldL(TUid aFieldType); 
    64 	virtual CTextField* NewFieldL(TUid aFieldType); 
    55 	// Creates a field of the type specified
    65 	// Creates a field of the type specified
    56 	// Returns NULL if it does not recognise/support the field type
    66 	// Returns NULL if it does not recognise/support the field type
    57 	};
    67 	};
    58 
    68 
    59 CTextField* TTestFieldFactory::NewFieldL(TUid aFieldType)
    69 CTextField* TTestFieldFactoryTRTCUSTM::NewFieldL(TUid aFieldType)
    60 // Creates a field (in aHeader) of the type specified in aHeader
    70 // Creates a field (in aHeader) of the type specified in aHeader
    61 // 
    71 // 
    62 	{
    72 	{
    63 	CTextField* field=NULL;
    73 	CTextField* field=NULL;
    64 	if (aFieldType==KDateTimeFieldUid)
    74 	if (aFieldType==KDateTimeFieldUid)
    65 		field = (CTextField*)new(ELeave) CDateTimeField();
    75 		field = (CTextField*)new(ELeave) CDateTimeField();
    66 	return field;
    76 	return field;
    67 	}
    77 	}
    68 /////////////////////////////////////////////////////////////////////////////////////////////
    78 /////////////////////////////////////////////////////////////////////////////////////////////
    69 
    79 
    70 LOCAL_D void WriteInlineL(RWriteStream& aStream,CRichText* aRichText)
    80 void CT_TRTCUSTM::WriteInlineL(RWriteStream& aStream,CRichText* aRichText)
    71 	{
    81 	{
    72 	aRichText->CancelInsertCharFormat();
    82 	aRichText->CancelInsertCharFormat();
    73 	aRichText->ExternalizeFieldDataL(aStream);
    83 	aRichText->ExternalizeFieldDataL(aStream);
    74 	aRichText->ExternalizeStyleDataL(aStream);
    84 	aRichText->ExternalizeStyleDataL(aStream);
    75 	TBool hasMarkupData=aRichText->HasMarkupData();
    85 	TBool hasMarkupData=aRichText->HasMarkupData();
    77 	if (hasMarkupData)
    87 	if (hasMarkupData)
    78 		aRichText->ExternalizeMarkupDataL(aStream);	
    88 		aRichText->ExternalizeMarkupDataL(aStream);	
    79 	aRichText->ExternalizePlainTextL(aStream);
    89 	aRichText->ExternalizePlainTextL(aStream);
    80 	}
    90 	}
    81 
    91 
    82 LOCAL_D void ReadInlineL(RReadStream& aStream,CRichText* aRichText)
    92 void CT_TRTCUSTM::ReadInlineL(RReadStream& aStream,CRichText* aRichText)
    83 	{
    93 	{
    84 	aRichText->InternalizeFieldDataL(aStream);
    94 	aRichText->InternalizeFieldDataL(aStream);
    85 	aRichText->InternalizeStyleDataL(aStream);
    95 	aRichText->InternalizeStyleDataL(aStream);
    86 	TBool hasMarkupData=(TBool)aStream.ReadUint8L();
    96 	TBool hasMarkupData=(TBool)aStream.ReadUint8L();
    87 	if (hasMarkupData)
    97 	if (hasMarkupData)
    88 		aRichText->InternalizeMarkupDataL(aStream);	
    98 		aRichText->InternalizeMarkupDataL(aStream);	
    89 	aRichText->InternalizePlainTextL(aStream);
    99 	aRichText->InternalizePlainTextL(aStream);
    90 	}
   100 	}
    91 
   101 
    92 
   102 
    93 LOCAL_D TStreamId PerformSaveL(CRichText* aRichText)
   103 TStreamId CT_TRTCUSTM::PerformSaveL(CRichText* aRichText)
    94 //
   104 //
    95 	{
   105 	{
    96 	RStoreWriteStream out;
   106 	RStoreWriteStream out;
    97 	TStreamId id1=out.CreateLC(*TheStore);
   107 	TStreamId id1=out.CreateLC(*TheStore);
    98 	WriteInlineL(out,aRichText);
   108 	WriteInlineL(out,aRichText);
   102 	TheStore->CommitL();
   112 	TheStore->CommitL();
   103 	return id1;
   113 	return id1;
   104 	}
   114 	}
   105 
   115 
   106 
   116 
   107 LOCAL_C CRichText* PerformLoadL(TStreamId aId)
   117 CRichText* CT_TRTCUSTM::PerformLoadL(TStreamId aId)
   108 //
   118 //
   109 	{
   119 	{
   110 	CRichText* text=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   120 	CRichText* text=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   111 	RStoreReadStream in;
   121 	RStoreReadStream in;
   112 	in.OpenLC(*TheStore,aId);
   122 	in.OpenLC(*TheStore,aId);
   116 	CleanupStack::PopAndDestroy();  // in
   126 	CleanupStack::PopAndDestroy();  // in
   117 	return text;
   127 	return text;
   118 	}
   128 	}
   119 
   129 
   120 
   130 
   121 LOCAL_C CStyleList* CreatePopulatedStyleList()
   131 CStyleList* CT_TRTCUSTM::CreatePopulatedStyleList()
   122 //
   132 //
   123 	{
   133 	{
   124 	//
   134 	//
   125 	// Create style aswell.
   135 	// Create style aswell.
   126 	CStyleList* list=CStyleList::NewL();
   136 	CStyleList* list=CStyleList::NewL();
   136 	return list;
   146 	return list;
   137 	}
   147 	}
   138 
   148 
   139 _LIT(KTRtCustOutputFile,"c:\\etext\\TRTCUSTM.DAT");
   149 _LIT(KTRtCustOutputFile,"c:\\etext\\TRTCUSTM.DAT");
   140 
   150 
   141 LOCAL_C void CustomLoadSave()
   151 void CT_TRTCUSTM::CustomLoadSave()
   142 	{
   152 	{
   143 // Set up the framework
   153 // Set up the framework
   144 	theFs.Delete(KTRtCustOutputFile);
   154 	theFs.Delete(KTRtCustOutputFile);
   145 	theFs.MkDirAll(KTRtCustOutputFile);
   155 	theFs.MkDirAll(KTRtCustOutputFile);
   146 	TheStore=CPermanentFileStore::CreateLC(theFs,KTRtCustOutputFile,EFileRead|EFileWrite);
   156 	TheStore=CPermanentFileStore::CreateLC(theFs,KTRtCustOutputFile,EFileRead|EFileWrite);
   147 	TheStore->SetTypeL(TheStore->Layout());
   157 	TheStore->SetTypeL(TheStore->Layout());
   148 
   158 
   149 //
   159 //
   150 // Case (1) Rich text with owned style list. - no markup data
   160 // Case (1) Rich text with owned style list. - no markup data
   151 //
   161 //
   152 	test.Start(_L("RT + no markup + style list owned"));
   162 	INFO_PRINTF1(_L("RT + no markup + style list owned"));
   153 	//
   163 	//
   154 	// Setup the rich text
   164 	// Setup the rich text
   155 	CStyleList* list=CreatePopulatedStyleList();
   165 	CStyleList* list=CreatePopulatedStyleList();
   156 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   166 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   157 	TBool hasMarkupData=richText1->HasMarkupData();
   167 	TBool hasMarkupData=richText1->HasMarkupData();
   173 	delete empty;
   183 	delete empty;
   174 	empty=NULL;
   184 	empty=NULL;
   175 //
   185 //
   176 // Case (2) Rich text with referenced style list. - no markup data
   186 // Case (2) Rich text with referenced style list. - no markup data
   177 //
   187 //
   178 	test.Next(_L("RT + no markup + style list externally owned"));
   188 	INFO_PRINTF1(_L("RT + no markup + style list externally owned"));
   179 	//
   189 	//
   180 	// Setup the rich text
   190 	// Setup the rich text
   181 	list=CreatePopulatedStyleList();
   191 	list=CreatePopulatedStyleList();
   182 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list,CEditableText::ESegmentedStorage,2);
   192 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list,CEditableText::ESegmentedStorage,2);
   183 	richText1->SetStyleListExternallyOwned(ETrue);
   193 	richText1->SetStyleListExternallyOwned(ETrue);
   205 	delete list;
   215 	delete list;
   206 	empty=NULL;
   216 	empty=NULL;
   207 //
   217 //
   208 // Case (3) Rich text with referenced style list. - with markup
   218 // Case (3) Rich text with referenced style list. - with markup
   209 //
   219 //
   210 	test.Next(_L("RT + markup + style list externally owned"));
   220 	INFO_PRINTF1(_L("RT + markup + style list externally owned"));
   211 	// Setup the rich text
   221 	// Setup the rich text
   212 	list=CreatePopulatedStyleList();
   222 	list=CreatePopulatedStyleList();
   213 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   223 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   214 	richText1->SetStyleListExternallyOwned(ETrue);
   224 	richText1->SetStyleListExternallyOwned(ETrue);
   215 	hasMarkupData=richText1->HasMarkupData();
   225 	hasMarkupData=richText1->HasMarkupData();
   242 	delete list;
   252 	delete list;
   243 	empty=NULL;
   253 	empty=NULL;
   244 //
   254 //
   245 // Case (4) Rich text with no style list. - no effective markup
   255 // Case (4) Rich text with no style list. - no effective markup
   246 //
   256 //
   247 	test.Next(_L("RT + delete picture + no style list"));
   257 	INFO_PRINTF1(_L("RT + delete picture + no style list"));
   248 	// Setup the rich text
   258 	// Setup the rich text
   249 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   259 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   250 	hasMarkupData=richText1->HasMarkupData();
   260 	hasMarkupData=richText1->HasMarkupData();
   251 	test(!hasMarkupData);
   261 	test(!hasMarkupData);
   252 	richText1->InsertL(0,_L("hello"));
   262 	richText1->InsertL(0,_L("hello"));
   281 	delete empty;
   291 	delete empty;
   282 	empty=NULL;
   292 	empty=NULL;
   283 //
   293 //
   284 // Case (5) Rich text with SetInsertCharFormat()
   294 // Case (5) Rich text with SetInsertCharFormat()
   285 //
   295 //
   286 	test.Next(_L("RT + SetInsertCharFormatL()"));
   296 	INFO_PRINTF1(_L("RT + SetInsertCharFormatL()"));
   287 	// Setup the rich text
   297 	// Setup the rich text
   288 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   298 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   289 	hasMarkupData=richText1->HasMarkupData();
   299 	hasMarkupData=richText1->HasMarkupData();
   290 	test(!hasMarkupData);
   300 	test(!hasMarkupData);
   291 	richText1->InsertL(0,_L("hello"));
   301 	richText1->InsertL(0,_L("hello"));
   313 	empty=NULL;
   323 	empty=NULL;
   314 //
   324 //
   315 // Case (6) Rich text with components - default re/store used.
   325 // Case (6) Rich text with components - default re/store used.
   316 //
   326 //
   317 
   327 
   318 	test.Next(_L("RT + components"));
   328 	INFO_PRINTF1(_L("RT + components"));
   319 	// Setup the rich text
   329 	// Setup the rich text
   320 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   330 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   321 	hasMarkupData=richText1->HasMarkupData();
   331 	hasMarkupData=richText1->HasMarkupData();
   322 	test(!hasMarkupData);
   332 	test(!hasMarkupData);
   323 	richText1->InsertL(0,_L("hello"));
   333 	richText1->InsertL(0,_L("hello"));
   324 	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   334 	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   325 	richText1->InsertL(richText1->DocumentLength(),_L("there"));
   335 	richText1->InsertL(richText1->DocumentLength(),_L("there"));
   326 	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   336 	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   327 	//
   337 	//
   328 	// Create & insert some fields
   338 	// Create & insert some fields
   329 	TTestFieldFactory factory;
   339 	TTestFieldFactoryTRTCUSTM factory;
   330 	richText1->SetFieldFactory(&factory);
   340 	richText1->SetFieldFactory(&factory);
   331 	CTextField* field=NULL;
   341 	CTextField* field=NULL;
   332 	CTextField* field2=NULL;
   342 	CTextField* field2=NULL;
   333 	TRAP(ret,
   343 	TRAP(ret,
   334 	field=factory.NewFieldL(KDateTimeFieldUid));	test(ret==KErrNone);
   344 	field=factory.NewFieldL(KDateTimeFieldUid));	test(ret==KErrNone);
   382 	empty=NULL;
   392 	empty=NULL;
   383 	delete pictureFactory;
   393 	delete pictureFactory;
   384 //
   394 //
   385 // Case (7) Rich text with fields with referenced style list with markup
   395 // Case (7) Rich text with fields with referenced style list with markup
   386 //
   396 //
   387 	test.Next(_L("RT + fields + markup + style list"));
   397 	INFO_PRINTF1(_L("RT + fields + markup + style list"));
   388 	// Setup the rich text
   398 	// Setup the rich text
   389 	list=CreatePopulatedStyleList();
   399 	list=CreatePopulatedStyleList();
   390 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   400 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   391 	hasMarkupData=richText1->HasMarkupData();
   401 	hasMarkupData=richText1->HasMarkupData();
   392 	test(hasMarkupData);
   402 	test(hasMarkupData);
   463 	delete empty;
   473 	delete empty;
   464 	empty=NULL;
   474 	empty=NULL;
   465 //
   475 //
   466 // Case (8) Rich text with fields with referenced style list with markup - default store
   476 // Case (8) Rich text with fields with referenced style list with markup - default store
   467 //
   477 //
   468 	test.Next(_L("RT + fields + markup + style list - default store"));
   478 	INFO_PRINTF1(_L("RT + fields + markup + style list - default store"));
   469 	// Setup the rich text
   479 	// Setup the rich text
   470 	list=CreatePopulatedStyleList();
   480 	list=CreatePopulatedStyleList();
   471 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   481 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer,*list);
   472 	hasMarkupData=richText1->HasMarkupData();
   482 	hasMarkupData=richText1->HasMarkupData();
   473 	test(hasMarkupData);
   483 	test(hasMarkupData);
   516 	delete empty;
   526 	delete empty;
   517 	empty=NULL;	//
   527 	empty=NULL;	//
   518 //
   528 //
   519 // Case (9) Rich text with no components whatsoever - default store
   529 // Case (9) Rich text with no components whatsoever - default store
   520 //
   530 //
   521 	test.Next(_L("RT + no markup whatsoever - default store"));
   531 	INFO_PRINTF1(_L("RT + no markup whatsoever - default store"));
   522 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   532 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   523 	hasMarkupData=richText1->HasMarkupData();
   533 	hasMarkupData=richText1->HasMarkupData();
   524 	test(!hasMarkupData);
   534 	test(!hasMarkupData);
   525 	richText1->InsertL(0,_L("hello"));
   535 	richText1->InsertL(0,_L("hello"));
   526 	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   536 	richText1->InsertL(richText1->DocumentLength(),CEditableText::EParagraphDelimiter);
   546 	delete empty;
   556 	delete empty;
   547 	empty=NULL;
   557 	empty=NULL;
   548 	//
   558 	//
   549 	//
   559 	//
   550 	CleanupStack::PopAndDestroy();  // TheStore
   560 	CleanupStack::PopAndDestroy();  // TheStore
   551 	test.End();
       
   552 	}
   561 	}
   553 	
   562 	
   554 /**
   563 /**
   555 @SYMTestCaseID 			SYSLIB-ETEXT-CT-3380
   564 @SYMTestCaseID 			SYSLIB-ETEXT-CT-3380
   556 @SYMTestCaseDesc  		Inserting and deleting rich text and verify behaviours of DeleteParagraph(), Delete() and NotifyDelete(); 
   565 @SYMTestCaseDesc  		Inserting and deleting rich text and verify behaviours of DeleteParagraph(), Delete() and NotifyDelete(); 
   565 						7. Insert plain text in between two fields to rich text object then delete plain text to merge two fields
   574 						7. Insert plain text in between two fields to rich text object then delete plain text to merge two fields
   566 @SYMTestExpectedResults	CTextFieldSet, CPlainText, CRichText's APIs for performing various types of deletion function properly when 
   575 @SYMTestExpectedResults	CTextFieldSet, CPlainText, CRichText's APIs for performing various types of deletion function properly when 
   567   dealing with paragraph delimiter and hidden characters in a paragraph
   576   dealing with paragraph delimiter and hidden characters in a paragraph
   568 @SYMDEF					PDEF101757
   577 @SYMDEF					PDEF101757
   569 */
   578 */
   570 LOCAL_C void TestDEF101757()
   579 void CT_TRTCUSTM::TestDEF101757()
   571 	{	
   580 	{	
   572 	TFindFieldInfo info;
   581 	TFindFieldInfo info;
   573 	TTestFieldFactory factory;
   582 	TTestFieldFactoryTRTCUSTM factory;
   574 	CTextField* field=NULL;
   583 	CTextField* field=NULL;
   575 	CTextField* field1=NULL;
   584 	CTextField* field1=NULL;
   576 	CTextField* field2=NULL;
   585 	CTextField* field2=NULL;
   577 	CTextField* field3=NULL;
   586 	CTextField* field3=NULL;
   578 	CTextField* field4=NULL;
   587 	CTextField* field4=NULL;
   579 	
   588 	
   580 	_LIT(KSample1, "Hello"); // length:5
   589 	_LIT(KSample1, "Hello"); // length:5
   581 	_LIT(KSample2, "How are you"); // length:11
   590 	_LIT(KSample2, "How are you"); // length:11
   582 	
   591 	
   583 	test.Start(_L(" @SYMTestCaseID:SYSLIB-ETEXT-CT-3380 Insertion and deletion to rich text object "));
   592 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-CT-3380 Insertion and deletion to rich text object "));
   584 	
   593 	
   585 	CRichText* richText=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   594 	CRichText* richText=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   586 	CleanupStack::PushL(richText);
   595 	CleanupStack::PushL(richText);
   587 	
   596 	
   588 	// Case1
   597 	// Case1
   695 	test(info.iFirstFieldLen==10);
   704 	test(info.iFirstFieldLen==10);
   696 	test(info.iFirstFieldPos==10);
   705 	test(info.iFirstFieldPos==10);
   697 	test(richText->FieldCount()==2);
   706 	test(richText->FieldCount()==2);
   698 	
   707 	
   699 	CleanupStack::PopAndDestroy(richText);
   708 	CleanupStack::PopAndDestroy(richText);
   700 	test.End();
       
   701 	}
   709 	}
   702 	
   710 	
   703 
   711 
   704 //Testcode for INC054540
   712 //Testcode for INC054540
   705 LOCAL_C void TestINC054540()
   713 void CT_TRTCUSTM::TestINC054540()
   706 	{
   714 	{
   707 	theFs.Delete(KTRtCustOutputFile);
   715 	theFs.Delete(KTRtCustOutputFile);
   708 	theFs.MkDirAll(KTRtCustOutputFile);
   716 	theFs.MkDirAll(KTRtCustOutputFile);
   709 	TheStore=CPermanentFileStore::CreateLC(theFs,KTRtCustOutputFile,EFileRead|EFileWrite);
   717 	TheStore=CPermanentFileStore::CreateLC(theFs,KTRtCustOutputFile,EFileRead|EFileWrite);
   710 	TheStore->SetTypeL(TheStore->Layout());
   718 	TheStore->SetTypeL(TheStore->Layout());
   711 //
   719 //
   712 //test 1: Test INC054540 fix for 255 fields
   720 //test 1: Test INC054540 fix for 255 fields
   713 //	
   721 //	
   714 	test.Start(_L("test"));
   722 	INFO_PRINTF1(_L("test"));
   715 	
   723 	
   716 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   724 	CRichText* richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   717 	//
   725 	//
   718 	// Now add a text field to this.
   726 	// Now add a text field to this.
   719 	TTestFieldFactory factory;
   727 	TTestFieldFactoryTRTCUSTM factory;
   720 	richText1->SetFieldFactory(&factory);
   728 	richText1->SetFieldFactory(&factory);
   721 	CTextField* field=NULL;
   729 	CTextField* field=NULL;
   722 	TInt x=0;
   730 	TInt x=0;
   723 	//add 255 fields
   731 	//add 255 fields
   724 	while(x<255)
   732 	while(x<255)
   762 	empty=NULL;
   770 	empty=NULL;
   763 	
   771 	
   764 //
   772 //
   765 //test 2: Test INC054540 fix for more than 255 fields
   773 //test 2: Test INC054540 fix for more than 255 fields
   766 //	
   774 //	
   767 	test.Next(_L("test for more than 255 fields"));
   775 	INFO_PRINTF1(_L("test for more than 255 fields"));
   768 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   776 	richText1=CRichText::NewL(GlobalParaFormatLayer,GlobalCharFormatLayer);
   769 	// Add the text fields
   777 	// Add the text fields
   770 	richText1->SetFieldFactory(&factory);
   778 	richText1->SetFieldFactory(&factory);
   771 	field=NULL;
   779 	field=NULL;
   772 	x=0;
   780 	x=0;
   810 	delete empty;
   818 	delete empty;
   811 	empty=NULL;
   819 	empty=NULL;
   812 	//
   820 	//
   813 	//
   821 	//
   814 	CleanupStack::PopAndDestroy();  // TheStore
   822 	CleanupStack::PopAndDestroy();  // TheStore
   815 	test.End();
   823 	}
   816 	}
   824 
   817 
   825 
   818 
   826 void CT_TRTCUSTM::doMainL()
   819 LOCAL_C void doMainL()
       
   820 	{
   827 	{
   821 	GlobalParaFormatLayer=CParaFormatLayer::NewL();
   828 	GlobalParaFormatLayer=CParaFormatLayer::NewL();
   822 	GlobalCharFormatLayer=CCharFormatLayer::NewL();
   829 	GlobalCharFormatLayer=CCharFormatLayer::NewL();
   823 	theFs.Connect();
   830 	theFs.Connect();
   824 	//
   831 	//
   830 	delete GlobalCharFormatLayer;
   837 	delete GlobalCharFormatLayer;
   831 	theFs.Close();
   838 	theFs.Close();
   832 	}
   839 	}
   833 
   840 
   834 
   841 
   835 LOCAL_C void setupCleanup()
   842 void CT_TRTCUSTM::setupCleanup()
   836 //
   843 //
   837 // Initialise the cleanup stack.
   844 // Initialise the cleanup stack.
   838 //
   845 //
   839     {
   846     {
   840 	TheTrapCleanup=CTrapCleanup::New();
   847 	TheTrapCleanup=CTrapCleanup::New();
   847 		});
   854 		});
   848 	test(r==KErrNone);
   855 	test(r==KErrNone);
   849 	}
   856 	}
   850 
   857 
   851 
   858 
   852 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   859 void CT_TRTCUSTM::DeleteDataFile(const TDesC& aFullName)
   853 	{
   860 	{
   854 	RFs fsSession;
   861 	RFs fsSession;
   855 	TInt err = fsSession.Connect();
   862 	TInt err = fsSession.Connect();
   856 	if(err == KErrNone)
   863 	if(err == KErrNone)
   857 		{
   864 		{
   876 		{
   883 		{
   877 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   884 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   878 		}
   885 		}
   879 	}
   886 	}
   880 
   887 
   881 GLDEF_C TInt E32Main()
   888 
   882 //
   889 CT_TRTCUSTM::CT_TRTCUSTM()
   883 // Test permanent file TheStore.
       
   884 //
       
   885     {
   890     {
   886 	test.Title();
   891     SetTestStepName(KTestStep_T_TRTCUSTM);
   887 	setupCleanup();
       
   888 	__UHEAP_MARK;
       
   889 //
       
   890 	test.Start(_L("Testing custom save/load optimization"));
       
   891 	TRAPD(ret,doMainL());	
       
   892 	test(ret==KErrNone);
       
   893 	
       
   894 	::DeleteDataFile(KTRtCustOutputFile); 	//deletion of data files must be before call to End() - DEF047652
       
   895 	test.End();
       
   896 //
       
   897 	__UHEAP_MARKEND;
       
   898 	delete TheTrapCleanup;
       
   899 	test.Close();
       
   900 
       
   901 	return KErrNone;
       
   902     }
   892     }
   903 
   893 
       
   894 TVerdict CT_TRTCUSTM::doTestStepL()
       
   895     {
       
   896     SetTestStepResult(EFail);
       
   897 
       
   898     setupCleanup();
       
   899     __UHEAP_MARK;
       
   900     
       
   901     INFO_PRINTF1(_L("TRTCUSTM"));
       
   902     INFO_PRINTF1(_L("Testing custom save/load optimization"));
       
   903     TRAPD(error1, doMainL());
       
   904     DeleteDataFile(KTRtCustOutputFile);   //deletion of data files must be before call to End() - DEF047652
       
   905 
       
   906     __UHEAP_MARKEND;
       
   907     delete TheTrapCleanup;
       
   908 
       
   909     if(error1 == KErrNone)
       
   910         {
       
   911         SetTestStepResult(EPass);
       
   912         }
       
   913 
       
   914     return TestStepResult();
       
   915     }