os/textandloc/textrendering/texthandling/tfields/T_STREAM.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <s32file.h>
    20 #include <flddef.h>
    21 #include <fldbase.h>
    22 #include <fldset.h>
    23 #include "TESTFAC.H"
    24 #include "T_STREAM.h"
    25 
    26 #define test(cond)											\
    27 	{														\
    28 	TBool __bb = (cond);									\
    29 	TEST(__bb);												\
    30 	if (!__bb)												\
    31 		{													\
    32 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
    33 		User::Leave(1);										\
    34 		}													\
    35 	}
    36 
    37 const TInt KTestCleanupStack=0x20;
    38 
    39 LOCAL_D CTrapCleanup* TheTrapCleanup;
    40 LOCAL_D CTextFieldSet* TheFieldSetOriginal;
    41 LOCAL_D CTextFieldSet* TheFieldSetCopy;
    42 LOCAL_D TTestFieldFactory* TheFactory;
    43 
    44 _LIT(KTFieldOutputFile, "c:\\etext\\tfield.tst");
    45 // Test Picture persistance.
    46 void CT_STREAM::testStoreRestore(CTextFieldSet* aCopy,const CTextFieldSet* aOriginal)
    47     {
    48 	// set up the store
    49 	RFs	theFs;
    50 	theFs.Connect();
    51 	theFs.Delete(KTFieldOutputFile);
    52 	theFs.MkDirAll(KTFieldOutputFile);
    53 	CFileStore* theStore=CDirectFileStore::CreateL(theFs, KTFieldOutputFile, EFileRead | EFileWrite);
    54 	CleanupStack::PushL(theStore);
    55 	theStore->SetTypeL(KDirectFileStoreLayoutUid);
    56 	//
    57 	// store the original
    58 	TStreamId id(0);
    59 	TRAPD(ret,id=aOriginal->StoreL(*theStore));
    60 		test(ret==KErrNone);
    61 	//
    62 	// restore into the copy
    63 	TRAP(ret,aCopy->RestoreL(*theStore,id));
    64 		test(ret==KErrNone);
    65 	//
    66 	// tidy up
    67 	CleanupStack::PopAndDestroy();  // theStore
    68 	theFs.Close();
    69     }
    70 
    71 
    72 
    73 template <class T>
    74 void CT_STREAM::testCopyPaste(T* aCopy, T* aOriginal,TInt aCopyPos,TInt aLen,TInt aPastePos,TInt aPasteLen)
    75 // Copy part of anOriginal to aCopy using memory-based streams.
    76 //
    77 	{
    78 	// set up the store
    79 	RFs	theFs;
    80 	theFs.Connect();
    81 	CFileStore* theStore=CDirectFileStore::ReplaceL(theFs,KTFieldOutputFile,EFileRead|EFileWrite);
    82 	CleanupStack::PushL(theStore);
    83 	theStore->SetTypeL(KDirectFileStoreLayoutUid);
    84 	//
    85 	// Copy anOriginal out to the buffer
    86 	TStreamId id(0);
    87 	TRAPD(ret,id=aOriginal->CopyToStoreL(*theStore,aCopyPos,aLen));
    88 		test(ret==KErrNone);
    89 	//
    90 	// paste into the copy
    91 	TRAP(ret,aCopy->PasteFromStoreL(*theStore,id,aPastePos,aPasteLen));
    92 		test(ret==KErrNone);
    93 	//
    94 	// tidy up
    95 	CleanupStack::PopAndDestroy();  // theStore
    96 	theFs.Close();
    97 
    98 	}
    99 
   100 
   101 TBool CT_STREAM::IsEqual(const CTextFieldSet* aCopy,const CTextFieldSet* anOriginal)
   102 //
   103 // Returns true if aCopy contents matches anOriginal contents.
   104 //
   105 	{
   106 	// test the num chars and num fields
   107 	TInt charCount = anOriginal->CharCount();
   108 	TInt fieldCount = anOriginal->FieldCount();
   109 	test(charCount==aCopy->CharCount());
   110 	test(fieldCount==aCopy->FieldCount());
   111 
   112 	// test each entry in the array
   113 	for (TInt pos=0 ; pos<charCount ;)
   114 		{
   115 		TFindFieldInfo infoOrig,infoCopy;
   116 		anOriginal->FindFields(infoOrig,pos,charCount-pos);
   117 		aCopy->FindFields(infoCopy,pos,charCount-pos);
   118 		test(infoOrig==infoCopy);
   119 		pos += infoOrig.iFirstFieldPos+infoOrig.iFirstFieldLen;
   120 		if (infoOrig.iFieldCountInRange==0)
   121 			break;
   122 		}
   123 
   124 	return ETrue;
   125 	}
   126 
   127 
   128 TBool CT_STREAM::UpdateField(TInt aPos,CTextFieldSet* aSet)
   129 	{
   130 	// find out which field aPos is in
   131 	TFindFieldInfo info;
   132 	TBool ret;
   133 	ret=aSet->FindFields(info,aPos);
   134 		test(ret);
   135 	// get the new value
   136 	HBufC* buf = HBufC::NewL(5); 
   137 	CleanupStack::PushL(buf);
   138  	TInt err=aSet->NewFieldValueL(buf,aPos); 
   139 		test(err==KErrNone);
   140 	// Notify FieldSet of update
   141 	aSet->NotifyFieldUpdate(aPos,buf->Length());
   142 	// tidy up
   143 	CleanupStack::PopAndDestroy();
   144 	return ret;
   145 	}
   146 
   147 
   148 void CT_STREAM::test2()
   149 // Streams an empty field set
   150 //
   151 	{
   152 	INFO_PRINTF1(_L("- streaming of a default FieldSet (no fields)"));
   153 	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   154 	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   155 	TheFieldSetOriginal->Reset();
   156 	TheFieldSetCopy->Reset();
   157 	}
   158 
   159 
   160 void CT_STREAM::test3()
   161 // Streams a field set containing 100 chars & 1 field
   162 //
   163 	{
   164 	INFO_PRINTF1(_L("- streaming with a field"));
   165 
   166 	// insert a block of text into the original
   167 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   168 	// insert a field into the original
   169 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   170 		test(field!=NULL);
   171 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   172 		test(ret==KErrNone);
   173 	ret=UpdateField(10,TheFieldSetOriginal);
   174 		test(ret);
   175 
   176 	// test streaming
   177 	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   178 	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   179 	TheFieldSetOriginal->Reset();
   180 	TheFieldSetCopy->Reset();
   181 	}
   182 
   183 
   184 void CT_STREAM::test4()
   185 // Streams a field set into a non-empty target
   186 //
   187 	{
   188 	INFO_PRINTF1(_L("- streaming into a non-empty target"));
   189 
   190 	// insert a block of text into the original
   191 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   192 	// insert a field into the original
   193 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   194 		test(field!=NULL);
   195 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   196 		test(ret==KErrNone);
   197 	ret=UpdateField(10,TheFieldSetOriginal);
   198 		test(ret);
   199 
   200 	// insert a block of text into the copy
   201 	TheFieldSetCopy->NotifyInsertion(0,40); // pos=0, len=40
   202 	// insert two fields into the copy
   203 	CTextField* field2 = TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   204 	CTextField* field3 = TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   205 	ret=TheFieldSetCopy->InsertFieldL(20,field2,KDummyFieldUid); 
   206 		test(ret==KErrNone);
   207 	ret=TheFieldSetCopy->InsertFieldL(30,field3,KDummyFieldUid); 
   208 		test(ret==KErrNone);
   209 	ret=UpdateField(20,TheFieldSetCopy);
   210 		test(ret);
   211 	ret=UpdateField(33,TheFieldSetCopy);
   212 		test(ret);
   213 
   214 	// test streaming
   215 	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   216 	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   217 	TheFieldSetOriginal->Reset();
   218 	TheFieldSetCopy->Reset();
   219 	}
   220 
   221 
   222 void CT_STREAM::test5()
   223 // Streams a field set containing an out of date field
   224 //
   225 	{
   226 	INFO_PRINTF1(_L("- streaming an out of date field"));
   227 
   228 	// insert a block of text into the original
   229 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   230 	// insert a field into the original
   231 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   232 		test(field!=NULL);
   233 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   234 		test(ret==KErrNone);
   235 	ret=UpdateField(10,TheFieldSetOriginal);
   236 		test(ret);
   237 	// invalidate the field
   238 	TheFieldSetOriginal->NotifyInsertion(11,7); // pos=11, len=7
   239 
   240 	// test streaming
   241 	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   242 	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   243 	TheFieldSetOriginal->Reset();
   244 	TheFieldSetCopy->Reset();
   245 	}
   246 
   247 
   248 void CT_STREAM::test6()
   249 // Tests that copy/paste methods exist
   250 //
   251 	{
   252 	INFO_PRINTF1(_L("- testing copy/paste methods with empty array"));
   253 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,0,0,0); // copyPos,Len,PastePos
   254 	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   255 	TheFieldSetOriginal->Reset();
   256 	TheFieldSetCopy->Reset();
   257 	}
   258 
   259 
   260 void CT_STREAM::test7()
   261 // Tests copy/paste methods in detail
   262 //
   263 	{
   264 	INFO_PRINTF1(_L("- testing copy/paste methods in detail"));
   265 	// insert a block of text into the original
   266 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   267 	// insert a field into the original
   268 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   269 		test(field!=NULL);
   270 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   271 		test(ret==KErrNone);
   272 	TBool ok=UpdateField(10,TheFieldSetOriginal);
   273 		test(ok);
   274 		test(TheFieldSetOriginal->CharCount()==103);
   275 	// copy out of that into an empty array
   276 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,0); // copyPos,Len,PastePos
   277 	// check that the contents of the array are as expected
   278 	TFindFieldInfo info;
   279 	TheFieldSetCopy->FindFields(info,0,15);
   280 		test(TheFieldSetCopy->CharCount()==15);
   281 		test(TheFieldSetCopy->FieldCount()==1);
   282 		test(info.iFieldCountInRange==1);
   283 		test(info.iFirstFieldPos==5);
   284 		test(info.iFirstFieldLen==3);
   285 	TheFieldSetCopy->Reset();
   286 	// test copying part of a field
   287 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,6,0); // copyPos,Len,PastePos
   288 	TheFieldSetCopy->FindFields(info,0,6);
   289 		test(TheFieldSetCopy->CharCount()==6);
   290 		test(TheFieldSetCopy->FieldCount()==0);
   291 		test(info.iFieldCountInRange==0);
   292 	TheFieldSetCopy->Reset();
   293 	// test copying exactly one field
   294 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,0); // copyPos,Len,PastePos
   295 	TheFieldSetCopy->FindFields(info,0,3);
   296 		test(TheFieldSetCopy->CharCount()==3);
   297 		test(TheFieldSetCopy->FieldCount()==1);
   298 		test(info.iFieldCountInRange==1);
   299 		test(info.iFirstFieldPos==0);
   300 		test(info.iFirstFieldLen==3);
   301 	TheFieldSetCopy->Reset();
   302 	// test pasting into text in a non-empty array
   303 	TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50
   304 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,10); // copyPos,Len,PastePos
   305 	TheFieldSetCopy->FindFields(info,0,65);
   306 		test(TheFieldSetCopy->CharCount()==65);
   307 		test(TheFieldSetCopy->FieldCount()==1);
   308 		test(info.iFieldCountInRange==1);
   309 		test(info.iFirstFieldPos==15);
   310 		test(info.iFirstFieldLen==3);
   311 	TheFieldSetCopy->Reset();
   312 	// test pasting into a field
   313 	TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50
   314 	field=TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   315 		test(field!=NULL);
   316 	ret=TheFieldSetCopy->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   317 		test(ret==KErrNone);
   318 	ok=UpdateField(10,TheFieldSetCopy);
   319 		test(ok);
   320 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,11); // copyPos,Len,PastePos
   321 	TheFieldSetCopy->FindFields(info,0,68);
   322 		test(TheFieldSetCopy->CharCount()==68);
   323 		test(TheFieldSetCopy->FieldCount()==1);
   324 		test(info.iFieldCountInRange==1);
   325 		test(info.iFirstFieldPos==10);
   326 		test(info.iFirstFieldLen==18);
   327 	TheFieldSetCopy->Reset();
   328 	// test pasting at the start & end of a field
   329 	TheFieldSetCopy->NotifyInsertion(0,10); // pos=0, len=10
   330 	field=TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   331 		test(field!=NULL);
   332 	ret=TheFieldSetCopy->InsertFieldL(5,field,KDummyFieldUid); // pos=5
   333 		test(ret==KErrNone);
   334 	ok=UpdateField(5,TheFieldSetCopy);
   335 		test(ok);
   336 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,8); // copyPos,Len,PastePos
   337 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,5); // copyPos,Len,PastePos
   338 	TheFieldSetCopy->FindFields(info,0,19);
   339 		test(TheFieldSetCopy->CharCount()==19);
   340 		test(TheFieldSetCopy->FieldCount()==3);
   341 		test(info.iFieldCountInRange==3);
   342 		test(info.iFirstFieldPos==5);
   343 		test(info.iFirstFieldLen==3);
   344 	TheFieldSetCopy->FindFields(info,8,11);
   345 		test(info.iFieldCountInRange==2);
   346 		test(info.iFirstFieldPos==8);
   347 		test(info.iFirstFieldLen==3);
   348 	TheFieldSetCopy->FindFields(info,11,8);
   349 		test(info.iFieldCountInRange==1);
   350 		test(info.iFirstFieldPos==11);
   351 		test(info.iFirstFieldLen==3);
   352 	// tidy up
   353 	TheFieldSetOriginal->Reset();
   354 	TheFieldSetCopy->Reset();
   355 	}
   356 
   357 
   358 void CT_STREAM::test8()
   359 // Tests paste method with restricted target length
   360 //
   361 	{
   362 	INFO_PRINTF1(_L("- testing paste method with restricted length"));
   363 	// insert a block of text into the original
   364 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   365 	// insert 2 fields into the original
   366 	// 1...
   367 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   368 		test(field!=NULL);
   369 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   370 		test(ret==KErrNone);
   371 	TBool ok=UpdateField(10,TheFieldSetOriginal);
   372 		test(ok);
   373 	// 2..
   374 	field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   375 		test(field!=NULL);
   376 	ret=TheFieldSetOriginal->InsertFieldL(20,field,KDummyFieldUid); // pos=20
   377 		test(ret==KErrNone);
   378 	ok=UpdateField(20,TheFieldSetOriginal);
   379 		test(ok);
   380 	// paste part of original into copy with length greater than required
   381 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,7); // copyPos,Len,PastePos,PasteLen
   382 	TFindFieldInfo info;
   383 	TheFieldSetCopy->FindFields(info,0,5);
   384 		test(TheFieldSetCopy->CharCount()==5);
   385 		test(TheFieldSetCopy->FieldCount()==1);
   386 		test(info.iFieldCountInRange==1);
   387 		test(info.iFirstFieldPos==0);
   388 		test(info.iFirstFieldLen==3);
   389 	TheFieldSetCopy->Reset();
   390 	// paste part of original into copy with length equal to that required
   391 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,5); // copyPos,Len,PastePos,PasteLen
   392 	TheFieldSetCopy->FindFields(info,0,5);
   393 		test(TheFieldSetCopy->CharCount()==5);
   394 		test(TheFieldSetCopy->FieldCount()==1);
   395 		test(info.iFieldCountInRange==1);
   396 		test(info.iFirstFieldPos==0);
   397 		test(info.iFirstFieldLen==3);
   398 	TheFieldSetCopy->Reset();
   399 	// paste part of original into copy with length zero
   400 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,0); // copyPos,Len,PastePos,PasteLen
   401 		test(TheFieldSetCopy->CharCount()==0);
   402 		test(TheFieldSetCopy->FieldCount()==0);
   403 	TheFieldSetCopy->Reset();
   404 	// paste part of original into copy with length st field is chopped
   405 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,10,0,6); // copyPos,Len,PastePos,PasteLen
   406 	TheFieldSetCopy->FindFields(info,0,6);
   407 		test(TheFieldSetCopy->CharCount()==6);
   408 		test(TheFieldSetCopy->FieldCount()==0);
   409 		test(info.iFieldCountInRange==0);
   410 	TheFieldSetCopy->Reset();
   411 	// paste part of original into copy with length st one field is left off, the other pasted in
   412 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,20,0,10); // copyPos,Len,PastePos,PasteLen
   413 	TheFieldSetCopy->FindFields(info,0,10);
   414 		test(TheFieldSetCopy->CharCount()==10);
   415 		test(TheFieldSetCopy->FieldCount()==1);
   416 		test(info.iFieldCountInRange==1);
   417 		test(info.iFirstFieldPos==5);
   418 		test(info.iFirstFieldLen==3);
   419 	// tidy up
   420 	TheFieldSetOriginal->Reset();
   421 	TheFieldSetCopy->Reset();
   422 	}
   423 
   424 
   425 void CT_STREAM::test9()
   426 // Tests paste into set with no field factory
   427 // Should convert all pasted fields to text...
   428 //
   429 	{
   430 	INFO_PRINTF1(_L("- testing paste into set with no field factory"));
   431 	TheFieldSetCopy->SetFieldFactory(NULL);
   432 	// insert a block of text into the original
   433 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   434 	// insert a field into the original
   435 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   436 		test(field!=NULL);
   437 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   438 		test(ret==KErrNone);
   439 	TBool ok=UpdateField(10,TheFieldSetOriginal);
   440 		test(ok);
   441 	// paste part of original into copy
   442 	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,25,0); // copyPos,Len,PastePos
   443 	TFindFieldInfo info;
   444 	TheFieldSetCopy->FindFields(info,0,25);
   445 		test(TheFieldSetCopy->CharCount()==25);
   446 		test(TheFieldSetCopy->FieldCount()==0);
   447 	// tidy up
   448 	TheFieldSetOriginal->Reset();
   449 	TheFieldSetCopy->Reset();
   450 	TheFieldSetCopy->SetFieldFactory(TheFactory);
   451 	}
   452 
   453 
   454 void CT_STREAM::test10()
   455 // Streams a field set containing 100 chars & 1 field
   456 //
   457 	{
   458 	INFO_PRINTF1(_L("- streaming CDateTimeField"));
   459 
   460 	// insert a block of text into the original
   461 	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   462 	// insert a field into the original
   463 	CTextField* field=TheFieldSetOriginal->NewFieldL(KDateTimeFieldUid);
   464 		test(field!=NULL);
   465 	TBuf<14> buff = _L("%-A%*I%:1%T%+A");
   466 	((CDateTimeField*)field)->SetFormat(buff); // 01:53pm
   467 	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDateTimeFieldUid); // pos=10
   468 		test(ret==KErrNone);
   469 	ret=UpdateField(10,TheFieldSetOriginal);
   470 		test(ret);
   471 	// value before
   472 	HBufC* miniBuf = HBufC::NewL(5); 
   473 	CleanupStack::PushL(miniBuf);
   474 	ret=TheFieldSetOriginal->NewFieldValueL(miniBuf,10); // pos=10
   475 		test(ret==KErrNone);
   476 	TPtr buf = miniBuf->Des();
   477 	INFO_PRINTF1(_L("  Value before streaming: "));
   478 		INFO_PRINTF1(buf);
   479 		INFO_PRINTF1(_L("\n"));
   480 	// test streaming
   481 	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   482 	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   483 	// value after
   484 	ret=TheFieldSetCopy->NewFieldValueL(miniBuf,10); // pos=10
   485 		test(ret==KErrNone);
   486 	buf = miniBuf->Des();
   487 	INFO_PRINTF1(_L("  Value after streaming:  "));
   488 		INFO_PRINTF1(buf);
   489 		INFO_PRINTF1(_L("\n"));
   490 	CleanupStack::PopAndDestroy(); // miniBuf
   491 	TheFieldSetOriginal->Reset();
   492 	TheFieldSetCopy->Reset();
   493 	}
   494 
   495 
   496 void CT_STREAM::TestStreamingL()
   497 //
   498 // Test streaming of PrintSetup info.
   499 // Stream from one copy to another, then compare
   500 //
   501 	{
   502 	// create the PrintSetups
   503 	INFO_PRINTF1(_L("Streaming CTextFieldSet"));
   504 
   505 	// instantiate the factory and FieldSet
   506 	TheFactory = new(ELeave) TTestFieldFactory();
   507 	TheFieldSetOriginal = CTextFieldSet::NewL();
   508 	TheFieldSetOriginal->SetFieldFactory(TheFactory);
   509 	TheFieldSetCopy = CTextFieldSet::NewL();
   510 	TheFieldSetCopy->SetFieldFactory(TheFactory);
   511 
   512 	// Use "original" with default settings & test stream
   513 	test2();
   514 
   515 	// change data in original and test stream again
   516 	test3();
   517 
   518 	// Stream a field set into a non-empty target
   519 	test4();
   520 
   521 	// Stream a field set containing an out of date field
   522 	test5();
   523 
   524 	// Test that copy/paste methods exist
   525 	test6();
   526 
   527 	// Test copy/paste methods in detail
   528 	test7();
   529 
   530 	// Test paste with limited target area
   531 	test8();
   532 
   533 	// Test paste into set with no field factory
   534 	test9();
   535 
   536 	// Test streaming of built-in types
   537 	test10();
   538 
   539 	// end
   540 	delete TheFieldSetOriginal;
   541 	delete TheFieldSetCopy;
   542 	delete TheFactory;
   543 	}
   544 
   545 
   546 void CT_STREAM::setupCleanup()
   547 //
   548 // Initialise the cleanup stack.
   549 //
   550     {
   551 
   552 	TheTrapCleanup=CTrapCleanup::New();
   553 	TRAPD(r,\
   554 		{\
   555 		for (TInt i=KTestCleanupStack;i>0;i--)\
   556 			CleanupStack::PushL((TAny*)1);\
   557 		test(r==KErrNone);\
   558 		CleanupStack::Pop(KTestCleanupStack);\
   559 		});
   560 	}
   561 
   562 
   563 void CT_STREAM::DeleteDataFile(const TDesC& aFullName)
   564 	{
   565 	RFs fsSession;
   566 	TInt err = fsSession.Connect();
   567 	if(err == KErrNone)
   568 		{
   569 		TEntry entry;
   570 		if(fsSession.Entry(aFullName, entry) == KErrNone)
   571 			{
   572 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   573 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   574 			if(err != KErrNone) 
   575 				{
   576 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   577 				}
   578 			err = fsSession.Delete(aFullName);
   579 			if(err != KErrNone) 
   580 				{
   581 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   582 				}
   583 			}
   584 		fsSession.Close();
   585 		}
   586 	else
   587 		{
   588 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   589 		}
   590 	}
   591 
   592 
   593 CT_STREAM::CT_STREAM()
   594     {
   595     SetTestStepName(KTestStep_T_STREAM);
   596     }
   597 
   598 TVerdict CT_STREAM::doTestStepL()
   599     {
   600 	INFO_PRINTF1(_L("T_STREAM - Fields Persistence"));
   601     SetTestStepResult(EFail);
   602 
   603     __UHEAP_MARK;
   604 
   605 	setupCleanup();
   606     
   607     TRAPD(error1, TestStreamingL());
   608 
   609 	delete TheTrapCleanup;
   610 
   611     __UHEAP_MARKEND;
   612 	DeleteDataFile(KTFieldOutputFile);	//deletion of data files must be before call to End() - DEF047652
   613 
   614     if(error1 == KErrNone)
   615         {
   616         SetTestStepResult(EPass);
   617         }
   618 
   619     return TestStepResult();
   620     }