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