os/textandloc/textrendering/texthandling/tfields/T_STREAM.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/texthandling/tfields/T_STREAM.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,620 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <s32file.h>
    1.23 +#include <flddef.h>
    1.24 +#include <fldbase.h>
    1.25 +#include <fldset.h>
    1.26 +#include "TESTFAC.H"
    1.27 +#include "T_STREAM.h"
    1.28 +
    1.29 +#define test(cond)											\
    1.30 +	{														\
    1.31 +	TBool __bb = (cond);									\
    1.32 +	TEST(__bb);												\
    1.33 +	if (!__bb)												\
    1.34 +		{													\
    1.35 +		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
    1.36 +		User::Leave(1);										\
    1.37 +		}													\
    1.38 +	}
    1.39 +
    1.40 +const TInt KTestCleanupStack=0x20;
    1.41 +
    1.42 +LOCAL_D CTrapCleanup* TheTrapCleanup;
    1.43 +LOCAL_D CTextFieldSet* TheFieldSetOriginal;
    1.44 +LOCAL_D CTextFieldSet* TheFieldSetCopy;
    1.45 +LOCAL_D TTestFieldFactory* TheFactory;
    1.46 +
    1.47 +_LIT(KTFieldOutputFile, "c:\\etext\\tfield.tst");
    1.48 +// Test Picture persistance.
    1.49 +void CT_STREAM::testStoreRestore(CTextFieldSet* aCopy,const CTextFieldSet* aOriginal)
    1.50 +    {
    1.51 +	// set up the store
    1.52 +	RFs	theFs;
    1.53 +	theFs.Connect();
    1.54 +	theFs.Delete(KTFieldOutputFile);
    1.55 +	theFs.MkDirAll(KTFieldOutputFile);
    1.56 +	CFileStore* theStore=CDirectFileStore::CreateL(theFs, KTFieldOutputFile, EFileRead | EFileWrite);
    1.57 +	CleanupStack::PushL(theStore);
    1.58 +	theStore->SetTypeL(KDirectFileStoreLayoutUid);
    1.59 +	//
    1.60 +	// store the original
    1.61 +	TStreamId id(0);
    1.62 +	TRAPD(ret,id=aOriginal->StoreL(*theStore));
    1.63 +		test(ret==KErrNone);
    1.64 +	//
    1.65 +	// restore into the copy
    1.66 +	TRAP(ret,aCopy->RestoreL(*theStore,id));
    1.67 +		test(ret==KErrNone);
    1.68 +	//
    1.69 +	// tidy up
    1.70 +	CleanupStack::PopAndDestroy();  // theStore
    1.71 +	theFs.Close();
    1.72 +    }
    1.73 +
    1.74 +
    1.75 +
    1.76 +template <class T>
    1.77 +void CT_STREAM::testCopyPaste(T* aCopy, T* aOriginal,TInt aCopyPos,TInt aLen,TInt aPastePos,TInt aPasteLen)
    1.78 +// Copy part of anOriginal to aCopy using memory-based streams.
    1.79 +//
    1.80 +	{
    1.81 +	// set up the store
    1.82 +	RFs	theFs;
    1.83 +	theFs.Connect();
    1.84 +	CFileStore* theStore=CDirectFileStore::ReplaceL(theFs,KTFieldOutputFile,EFileRead|EFileWrite);
    1.85 +	CleanupStack::PushL(theStore);
    1.86 +	theStore->SetTypeL(KDirectFileStoreLayoutUid);
    1.87 +	//
    1.88 +	// Copy anOriginal out to the buffer
    1.89 +	TStreamId id(0);
    1.90 +	TRAPD(ret,id=aOriginal->CopyToStoreL(*theStore,aCopyPos,aLen));
    1.91 +		test(ret==KErrNone);
    1.92 +	//
    1.93 +	// paste into the copy
    1.94 +	TRAP(ret,aCopy->PasteFromStoreL(*theStore,id,aPastePos,aPasteLen));
    1.95 +		test(ret==KErrNone);
    1.96 +	//
    1.97 +	// tidy up
    1.98 +	CleanupStack::PopAndDestroy();  // theStore
    1.99 +	theFs.Close();
   1.100 +
   1.101 +	}
   1.102 +
   1.103 +
   1.104 +TBool CT_STREAM::IsEqual(const CTextFieldSet* aCopy,const CTextFieldSet* anOriginal)
   1.105 +//
   1.106 +// Returns true if aCopy contents matches anOriginal contents.
   1.107 +//
   1.108 +	{
   1.109 +	// test the num chars and num fields
   1.110 +	TInt charCount = anOriginal->CharCount();
   1.111 +	TInt fieldCount = anOriginal->FieldCount();
   1.112 +	test(charCount==aCopy->CharCount());
   1.113 +	test(fieldCount==aCopy->FieldCount());
   1.114 +
   1.115 +	// test each entry in the array
   1.116 +	for (TInt pos=0 ; pos<charCount ;)
   1.117 +		{
   1.118 +		TFindFieldInfo infoOrig,infoCopy;
   1.119 +		anOriginal->FindFields(infoOrig,pos,charCount-pos);
   1.120 +		aCopy->FindFields(infoCopy,pos,charCount-pos);
   1.121 +		test(infoOrig==infoCopy);
   1.122 +		pos += infoOrig.iFirstFieldPos+infoOrig.iFirstFieldLen;
   1.123 +		if (infoOrig.iFieldCountInRange==0)
   1.124 +			break;
   1.125 +		}
   1.126 +
   1.127 +	return ETrue;
   1.128 +	}
   1.129 +
   1.130 +
   1.131 +TBool CT_STREAM::UpdateField(TInt aPos,CTextFieldSet* aSet)
   1.132 +	{
   1.133 +	// find out which field aPos is in
   1.134 +	TFindFieldInfo info;
   1.135 +	TBool ret;
   1.136 +	ret=aSet->FindFields(info,aPos);
   1.137 +		test(ret);
   1.138 +	// get the new value
   1.139 +	HBufC* buf = HBufC::NewL(5); 
   1.140 +	CleanupStack::PushL(buf);
   1.141 + 	TInt err=aSet->NewFieldValueL(buf,aPos); 
   1.142 +		test(err==KErrNone);
   1.143 +	// Notify FieldSet of update
   1.144 +	aSet->NotifyFieldUpdate(aPos,buf->Length());
   1.145 +	// tidy up
   1.146 +	CleanupStack::PopAndDestroy();
   1.147 +	return ret;
   1.148 +	}
   1.149 +
   1.150 +
   1.151 +void CT_STREAM::test2()
   1.152 +// Streams an empty field set
   1.153 +//
   1.154 +	{
   1.155 +	INFO_PRINTF1(_L("- streaming of a default FieldSet (no fields)"));
   1.156 +	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   1.157 +	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   1.158 +	TheFieldSetOriginal->Reset();
   1.159 +	TheFieldSetCopy->Reset();
   1.160 +	}
   1.161 +
   1.162 +
   1.163 +void CT_STREAM::test3()
   1.164 +// Streams a field set containing 100 chars & 1 field
   1.165 +//
   1.166 +	{
   1.167 +	INFO_PRINTF1(_L("- streaming with a field"));
   1.168 +
   1.169 +	// insert a block of text into the original
   1.170 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.171 +	// insert a field into the original
   1.172 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.173 +		test(field!=NULL);
   1.174 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.175 +		test(ret==KErrNone);
   1.176 +	ret=UpdateField(10,TheFieldSetOriginal);
   1.177 +		test(ret);
   1.178 +
   1.179 +	// test streaming
   1.180 +	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   1.181 +	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   1.182 +	TheFieldSetOriginal->Reset();
   1.183 +	TheFieldSetCopy->Reset();
   1.184 +	}
   1.185 +
   1.186 +
   1.187 +void CT_STREAM::test4()
   1.188 +// Streams a field set into a non-empty target
   1.189 +//
   1.190 +	{
   1.191 +	INFO_PRINTF1(_L("- streaming into a non-empty target"));
   1.192 +
   1.193 +	// insert a block of text into the original
   1.194 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.195 +	// insert a field into the original
   1.196 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.197 +		test(field!=NULL);
   1.198 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.199 +		test(ret==KErrNone);
   1.200 +	ret=UpdateField(10,TheFieldSetOriginal);
   1.201 +		test(ret);
   1.202 +
   1.203 +	// insert a block of text into the copy
   1.204 +	TheFieldSetCopy->NotifyInsertion(0,40); // pos=0, len=40
   1.205 +	// insert two fields into the copy
   1.206 +	CTextField* field2 = TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   1.207 +	CTextField* field3 = TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   1.208 +	ret=TheFieldSetCopy->InsertFieldL(20,field2,KDummyFieldUid); 
   1.209 +		test(ret==KErrNone);
   1.210 +	ret=TheFieldSetCopy->InsertFieldL(30,field3,KDummyFieldUid); 
   1.211 +		test(ret==KErrNone);
   1.212 +	ret=UpdateField(20,TheFieldSetCopy);
   1.213 +		test(ret);
   1.214 +	ret=UpdateField(33,TheFieldSetCopy);
   1.215 +		test(ret);
   1.216 +
   1.217 +	// test streaming
   1.218 +	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   1.219 +	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   1.220 +	TheFieldSetOriginal->Reset();
   1.221 +	TheFieldSetCopy->Reset();
   1.222 +	}
   1.223 +
   1.224 +
   1.225 +void CT_STREAM::test5()
   1.226 +// Streams a field set containing an out of date field
   1.227 +//
   1.228 +	{
   1.229 +	INFO_PRINTF1(_L("- streaming an out of date field"));
   1.230 +
   1.231 +	// insert a block of text into the original
   1.232 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.233 +	// insert a field into the original
   1.234 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.235 +		test(field!=NULL);
   1.236 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.237 +		test(ret==KErrNone);
   1.238 +	ret=UpdateField(10,TheFieldSetOriginal);
   1.239 +		test(ret);
   1.240 +	// invalidate the field
   1.241 +	TheFieldSetOriginal->NotifyInsertion(11,7); // pos=11, len=7
   1.242 +
   1.243 +	// test streaming
   1.244 +	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   1.245 +	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   1.246 +	TheFieldSetOriginal->Reset();
   1.247 +	TheFieldSetCopy->Reset();
   1.248 +	}
   1.249 +
   1.250 +
   1.251 +void CT_STREAM::test6()
   1.252 +// Tests that copy/paste methods exist
   1.253 +//
   1.254 +	{
   1.255 +	INFO_PRINTF1(_L("- testing copy/paste methods with empty array"));
   1.256 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,0,0,0); // copyPos,Len,PastePos
   1.257 +	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   1.258 +	TheFieldSetOriginal->Reset();
   1.259 +	TheFieldSetCopy->Reset();
   1.260 +	}
   1.261 +
   1.262 +
   1.263 +void CT_STREAM::test7()
   1.264 +// Tests copy/paste methods in detail
   1.265 +//
   1.266 +	{
   1.267 +	INFO_PRINTF1(_L("- testing copy/paste methods in detail"));
   1.268 +	// insert a block of text into the original
   1.269 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.270 +	// insert a field into the original
   1.271 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.272 +		test(field!=NULL);
   1.273 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.274 +		test(ret==KErrNone);
   1.275 +	TBool ok=UpdateField(10,TheFieldSetOriginal);
   1.276 +		test(ok);
   1.277 +		test(TheFieldSetOriginal->CharCount()==103);
   1.278 +	// copy out of that into an empty array
   1.279 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,0); // copyPos,Len,PastePos
   1.280 +	// check that the contents of the array are as expected
   1.281 +	TFindFieldInfo info;
   1.282 +	TheFieldSetCopy->FindFields(info,0,15);
   1.283 +		test(TheFieldSetCopy->CharCount()==15);
   1.284 +		test(TheFieldSetCopy->FieldCount()==1);
   1.285 +		test(info.iFieldCountInRange==1);
   1.286 +		test(info.iFirstFieldPos==5);
   1.287 +		test(info.iFirstFieldLen==3);
   1.288 +	TheFieldSetCopy->Reset();
   1.289 +	// test copying part of a field
   1.290 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,6,0); // copyPos,Len,PastePos
   1.291 +	TheFieldSetCopy->FindFields(info,0,6);
   1.292 +		test(TheFieldSetCopy->CharCount()==6);
   1.293 +		test(TheFieldSetCopy->FieldCount()==0);
   1.294 +		test(info.iFieldCountInRange==0);
   1.295 +	TheFieldSetCopy->Reset();
   1.296 +	// test copying exactly one field
   1.297 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,0); // copyPos,Len,PastePos
   1.298 +	TheFieldSetCopy->FindFields(info,0,3);
   1.299 +		test(TheFieldSetCopy->CharCount()==3);
   1.300 +		test(TheFieldSetCopy->FieldCount()==1);
   1.301 +		test(info.iFieldCountInRange==1);
   1.302 +		test(info.iFirstFieldPos==0);
   1.303 +		test(info.iFirstFieldLen==3);
   1.304 +	TheFieldSetCopy->Reset();
   1.305 +	// test pasting into text in a non-empty array
   1.306 +	TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50
   1.307 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,10); // copyPos,Len,PastePos
   1.308 +	TheFieldSetCopy->FindFields(info,0,65);
   1.309 +		test(TheFieldSetCopy->CharCount()==65);
   1.310 +		test(TheFieldSetCopy->FieldCount()==1);
   1.311 +		test(info.iFieldCountInRange==1);
   1.312 +		test(info.iFirstFieldPos==15);
   1.313 +		test(info.iFirstFieldLen==3);
   1.314 +	TheFieldSetCopy->Reset();
   1.315 +	// test pasting into a field
   1.316 +	TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50
   1.317 +	field=TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   1.318 +		test(field!=NULL);
   1.319 +	ret=TheFieldSetCopy->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.320 +		test(ret==KErrNone);
   1.321 +	ok=UpdateField(10,TheFieldSetCopy);
   1.322 +		test(ok);
   1.323 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,11); // copyPos,Len,PastePos
   1.324 +	TheFieldSetCopy->FindFields(info,0,68);
   1.325 +		test(TheFieldSetCopy->CharCount()==68);
   1.326 +		test(TheFieldSetCopy->FieldCount()==1);
   1.327 +		test(info.iFieldCountInRange==1);
   1.328 +		test(info.iFirstFieldPos==10);
   1.329 +		test(info.iFirstFieldLen==18);
   1.330 +	TheFieldSetCopy->Reset();
   1.331 +	// test pasting at the start & end of a field
   1.332 +	TheFieldSetCopy->NotifyInsertion(0,10); // pos=0, len=10
   1.333 +	field=TheFieldSetCopy->NewFieldL(KDummyFieldUid);
   1.334 +		test(field!=NULL);
   1.335 +	ret=TheFieldSetCopy->InsertFieldL(5,field,KDummyFieldUid); // pos=5
   1.336 +		test(ret==KErrNone);
   1.337 +	ok=UpdateField(5,TheFieldSetCopy);
   1.338 +		test(ok);
   1.339 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,8); // copyPos,Len,PastePos
   1.340 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,5); // copyPos,Len,PastePos
   1.341 +	TheFieldSetCopy->FindFields(info,0,19);
   1.342 +		test(TheFieldSetCopy->CharCount()==19);
   1.343 +		test(TheFieldSetCopy->FieldCount()==3);
   1.344 +		test(info.iFieldCountInRange==3);
   1.345 +		test(info.iFirstFieldPos==5);
   1.346 +		test(info.iFirstFieldLen==3);
   1.347 +	TheFieldSetCopy->FindFields(info,8,11);
   1.348 +		test(info.iFieldCountInRange==2);
   1.349 +		test(info.iFirstFieldPos==8);
   1.350 +		test(info.iFirstFieldLen==3);
   1.351 +	TheFieldSetCopy->FindFields(info,11,8);
   1.352 +		test(info.iFieldCountInRange==1);
   1.353 +		test(info.iFirstFieldPos==11);
   1.354 +		test(info.iFirstFieldLen==3);
   1.355 +	// tidy up
   1.356 +	TheFieldSetOriginal->Reset();
   1.357 +	TheFieldSetCopy->Reset();
   1.358 +	}
   1.359 +
   1.360 +
   1.361 +void CT_STREAM::test8()
   1.362 +// Tests paste method with restricted target length
   1.363 +//
   1.364 +	{
   1.365 +	INFO_PRINTF1(_L("- testing paste method with restricted length"));
   1.366 +	// insert a block of text into the original
   1.367 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.368 +	// insert 2 fields into the original
   1.369 +	// 1...
   1.370 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.371 +		test(field!=NULL);
   1.372 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.373 +		test(ret==KErrNone);
   1.374 +	TBool ok=UpdateField(10,TheFieldSetOriginal);
   1.375 +		test(ok);
   1.376 +	// 2..
   1.377 +	field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.378 +		test(field!=NULL);
   1.379 +	ret=TheFieldSetOriginal->InsertFieldL(20,field,KDummyFieldUid); // pos=20
   1.380 +		test(ret==KErrNone);
   1.381 +	ok=UpdateField(20,TheFieldSetOriginal);
   1.382 +		test(ok);
   1.383 +	// paste part of original into copy with length greater than required
   1.384 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,7); // copyPos,Len,PastePos,PasteLen
   1.385 +	TFindFieldInfo info;
   1.386 +	TheFieldSetCopy->FindFields(info,0,5);
   1.387 +		test(TheFieldSetCopy->CharCount()==5);
   1.388 +		test(TheFieldSetCopy->FieldCount()==1);
   1.389 +		test(info.iFieldCountInRange==1);
   1.390 +		test(info.iFirstFieldPos==0);
   1.391 +		test(info.iFirstFieldLen==3);
   1.392 +	TheFieldSetCopy->Reset();
   1.393 +	// paste part of original into copy with length equal to that required
   1.394 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,5); // copyPos,Len,PastePos,PasteLen
   1.395 +	TheFieldSetCopy->FindFields(info,0,5);
   1.396 +		test(TheFieldSetCopy->CharCount()==5);
   1.397 +		test(TheFieldSetCopy->FieldCount()==1);
   1.398 +		test(info.iFieldCountInRange==1);
   1.399 +		test(info.iFirstFieldPos==0);
   1.400 +		test(info.iFirstFieldLen==3);
   1.401 +	TheFieldSetCopy->Reset();
   1.402 +	// paste part of original into copy with length zero
   1.403 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,0); // copyPos,Len,PastePos,PasteLen
   1.404 +		test(TheFieldSetCopy->CharCount()==0);
   1.405 +		test(TheFieldSetCopy->FieldCount()==0);
   1.406 +	TheFieldSetCopy->Reset();
   1.407 +	// paste part of original into copy with length st field is chopped
   1.408 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,10,0,6); // copyPos,Len,PastePos,PasteLen
   1.409 +	TheFieldSetCopy->FindFields(info,0,6);
   1.410 +		test(TheFieldSetCopy->CharCount()==6);
   1.411 +		test(TheFieldSetCopy->FieldCount()==0);
   1.412 +		test(info.iFieldCountInRange==0);
   1.413 +	TheFieldSetCopy->Reset();
   1.414 +	// paste part of original into copy with length st one field is left off, the other pasted in
   1.415 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,20,0,10); // copyPos,Len,PastePos,PasteLen
   1.416 +	TheFieldSetCopy->FindFields(info,0,10);
   1.417 +		test(TheFieldSetCopy->CharCount()==10);
   1.418 +		test(TheFieldSetCopy->FieldCount()==1);
   1.419 +		test(info.iFieldCountInRange==1);
   1.420 +		test(info.iFirstFieldPos==5);
   1.421 +		test(info.iFirstFieldLen==3);
   1.422 +	// tidy up
   1.423 +	TheFieldSetOriginal->Reset();
   1.424 +	TheFieldSetCopy->Reset();
   1.425 +	}
   1.426 +
   1.427 +
   1.428 +void CT_STREAM::test9()
   1.429 +// Tests paste into set with no field factory
   1.430 +// Should convert all pasted fields to text...
   1.431 +//
   1.432 +	{
   1.433 +	INFO_PRINTF1(_L("- testing paste into set with no field factory"));
   1.434 +	TheFieldSetCopy->SetFieldFactory(NULL);
   1.435 +	// insert a block of text into the original
   1.436 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.437 +	// insert a field into the original
   1.438 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid);
   1.439 +		test(field!=NULL);
   1.440 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10
   1.441 +		test(ret==KErrNone);
   1.442 +	TBool ok=UpdateField(10,TheFieldSetOriginal);
   1.443 +		test(ok);
   1.444 +	// paste part of original into copy
   1.445 +	testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,25,0); // copyPos,Len,PastePos
   1.446 +	TFindFieldInfo info;
   1.447 +	TheFieldSetCopy->FindFields(info,0,25);
   1.448 +		test(TheFieldSetCopy->CharCount()==25);
   1.449 +		test(TheFieldSetCopy->FieldCount()==0);
   1.450 +	// tidy up
   1.451 +	TheFieldSetOriginal->Reset();
   1.452 +	TheFieldSetCopy->Reset();
   1.453 +	TheFieldSetCopy->SetFieldFactory(TheFactory);
   1.454 +	}
   1.455 +
   1.456 +
   1.457 +void CT_STREAM::test10()
   1.458 +// Streams a field set containing 100 chars & 1 field
   1.459 +//
   1.460 +	{
   1.461 +	INFO_PRINTF1(_L("- streaming CDateTimeField"));
   1.462 +
   1.463 +	// insert a block of text into the original
   1.464 +	TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100
   1.465 +	// insert a field into the original
   1.466 +	CTextField* field=TheFieldSetOriginal->NewFieldL(KDateTimeFieldUid);
   1.467 +		test(field!=NULL);
   1.468 +	TBuf<14> buff = _L("%-A%*I%:1%T%+A");
   1.469 +	((CDateTimeField*)field)->SetFormat(buff); // 01:53pm
   1.470 +	TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDateTimeFieldUid); // pos=10
   1.471 +		test(ret==KErrNone);
   1.472 +	ret=UpdateField(10,TheFieldSetOriginal);
   1.473 +		test(ret);
   1.474 +	// value before
   1.475 +	HBufC* miniBuf = HBufC::NewL(5); 
   1.476 +	CleanupStack::PushL(miniBuf);
   1.477 +	ret=TheFieldSetOriginal->NewFieldValueL(miniBuf,10); // pos=10
   1.478 +		test(ret==KErrNone);
   1.479 +	TPtr buf = miniBuf->Des();
   1.480 +	INFO_PRINTF1(_L("  Value before streaming: "));
   1.481 +		INFO_PRINTF1(buf);
   1.482 +		INFO_PRINTF1(_L("\n"));
   1.483 +	// test streaming
   1.484 +	testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal);
   1.485 +	test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal));
   1.486 +	// value after
   1.487 +	ret=TheFieldSetCopy->NewFieldValueL(miniBuf,10); // pos=10
   1.488 +		test(ret==KErrNone);
   1.489 +	buf = miniBuf->Des();
   1.490 +	INFO_PRINTF1(_L("  Value after streaming:  "));
   1.491 +		INFO_PRINTF1(buf);
   1.492 +		INFO_PRINTF1(_L("\n"));
   1.493 +	CleanupStack::PopAndDestroy(); // miniBuf
   1.494 +	TheFieldSetOriginal->Reset();
   1.495 +	TheFieldSetCopy->Reset();
   1.496 +	}
   1.497 +
   1.498 +
   1.499 +void CT_STREAM::TestStreamingL()
   1.500 +//
   1.501 +// Test streaming of PrintSetup info.
   1.502 +// Stream from one copy to another, then compare
   1.503 +//
   1.504 +	{
   1.505 +	// create the PrintSetups
   1.506 +	INFO_PRINTF1(_L("Streaming CTextFieldSet"));
   1.507 +
   1.508 +	// instantiate the factory and FieldSet
   1.509 +	TheFactory = new(ELeave) TTestFieldFactory();
   1.510 +	TheFieldSetOriginal = CTextFieldSet::NewL();
   1.511 +	TheFieldSetOriginal->SetFieldFactory(TheFactory);
   1.512 +	TheFieldSetCopy = CTextFieldSet::NewL();
   1.513 +	TheFieldSetCopy->SetFieldFactory(TheFactory);
   1.514 +
   1.515 +	// Use "original" with default settings & test stream
   1.516 +	test2();
   1.517 +
   1.518 +	// change data in original and test stream again
   1.519 +	test3();
   1.520 +
   1.521 +	// Stream a field set into a non-empty target
   1.522 +	test4();
   1.523 +
   1.524 +	// Stream a field set containing an out of date field
   1.525 +	test5();
   1.526 +
   1.527 +	// Test that copy/paste methods exist
   1.528 +	test6();
   1.529 +
   1.530 +	// Test copy/paste methods in detail
   1.531 +	test7();
   1.532 +
   1.533 +	// Test paste with limited target area
   1.534 +	test8();
   1.535 +
   1.536 +	// Test paste into set with no field factory
   1.537 +	test9();
   1.538 +
   1.539 +	// Test streaming of built-in types
   1.540 +	test10();
   1.541 +
   1.542 +	// end
   1.543 +	delete TheFieldSetOriginal;
   1.544 +	delete TheFieldSetCopy;
   1.545 +	delete TheFactory;
   1.546 +	}
   1.547 +
   1.548 +
   1.549 +void CT_STREAM::setupCleanup()
   1.550 +//
   1.551 +// Initialise the cleanup stack.
   1.552 +//
   1.553 +    {
   1.554 +
   1.555 +	TheTrapCleanup=CTrapCleanup::New();
   1.556 +	TRAPD(r,\
   1.557 +		{\
   1.558 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.559 +			CleanupStack::PushL((TAny*)1);\
   1.560 +		test(r==KErrNone);\
   1.561 +		CleanupStack::Pop(KTestCleanupStack);\
   1.562 +		});
   1.563 +	}
   1.564 +
   1.565 +
   1.566 +void CT_STREAM::DeleteDataFile(const TDesC& aFullName)
   1.567 +	{
   1.568 +	RFs fsSession;
   1.569 +	TInt err = fsSession.Connect();
   1.570 +	if(err == KErrNone)
   1.571 +		{
   1.572 +		TEntry entry;
   1.573 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.574 +			{
   1.575 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   1.576 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.577 +			if(err != KErrNone) 
   1.578 +				{
   1.579 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   1.580 +				}
   1.581 +			err = fsSession.Delete(aFullName);
   1.582 +			if(err != KErrNone) 
   1.583 +				{
   1.584 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   1.585 +				}
   1.586 +			}
   1.587 +		fsSession.Close();
   1.588 +		}
   1.589 +	else
   1.590 +		{
   1.591 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   1.592 +		}
   1.593 +	}
   1.594 +
   1.595 +
   1.596 +CT_STREAM::CT_STREAM()
   1.597 +    {
   1.598 +    SetTestStepName(KTestStep_T_STREAM);
   1.599 +    }
   1.600 +
   1.601 +TVerdict CT_STREAM::doTestStepL()
   1.602 +    {
   1.603 +	INFO_PRINTF1(_L("T_STREAM - Fields Persistence"));
   1.604 +    SetTestStepResult(EFail);
   1.605 +
   1.606 +    __UHEAP_MARK;
   1.607 +
   1.608 +	setupCleanup();
   1.609 +    
   1.610 +    TRAPD(error1, TestStreamingL());
   1.611 +
   1.612 +	delete TheTrapCleanup;
   1.613 +
   1.614 +    __UHEAP_MARKEND;
   1.615 +	DeleteDataFile(KTFieldOutputFile);	//deletion of data files must be before call to End() - DEF047652
   1.616 +
   1.617 +    if(error1 == KErrNone)
   1.618 +        {
   1.619 +        SetTestStepResult(EPass);
   1.620 +        }
   1.621 +
   1.622 +    return TestStepResult();
   1.623 +    }