sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "TESTFAC.H" sl@0: #include "T_STREAM.h" sl@0: sl@0: #define test(cond) \ sl@0: { \ sl@0: TBool __bb = (cond); \ sl@0: TEST(__bb); \ sl@0: if (!__bb) \ sl@0: { \ sl@0: ERR_PRINTF1(_L("ERROR: Test Failed")); \ sl@0: User::Leave(1); \ sl@0: } \ sl@0: } sl@0: sl@0: const TInt KTestCleanupStack=0x20; sl@0: sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: LOCAL_D CTextFieldSet* TheFieldSetOriginal; sl@0: LOCAL_D CTextFieldSet* TheFieldSetCopy; sl@0: LOCAL_D TTestFieldFactory* TheFactory; sl@0: sl@0: _LIT(KTFieldOutputFile, "c:\\etext\\tfield.tst"); sl@0: // Test Picture persistance. sl@0: void CT_STREAM::testStoreRestore(CTextFieldSet* aCopy,const CTextFieldSet* aOriginal) sl@0: { sl@0: // set up the store sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: theFs.Delete(KTFieldOutputFile); sl@0: theFs.MkDirAll(KTFieldOutputFile); sl@0: CFileStore* theStore=CDirectFileStore::CreateL(theFs, KTFieldOutputFile, EFileRead | EFileWrite); sl@0: CleanupStack::PushL(theStore); sl@0: theStore->SetTypeL(KDirectFileStoreLayoutUid); sl@0: // sl@0: // store the original sl@0: TStreamId id(0); sl@0: TRAPD(ret,id=aOriginal->StoreL(*theStore)); sl@0: test(ret==KErrNone); sl@0: // sl@0: // restore into the copy sl@0: TRAP(ret,aCopy->RestoreL(*theStore,id)); sl@0: test(ret==KErrNone); sl@0: // sl@0: // tidy up sl@0: CleanupStack::PopAndDestroy(); // theStore sl@0: theFs.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: template sl@0: void CT_STREAM::testCopyPaste(T* aCopy, T* aOriginal,TInt aCopyPos,TInt aLen,TInt aPastePos,TInt aPasteLen) sl@0: // Copy part of anOriginal to aCopy using memory-based streams. sl@0: // sl@0: { sl@0: // set up the store sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: CFileStore* theStore=CDirectFileStore::ReplaceL(theFs,KTFieldOutputFile,EFileRead|EFileWrite); sl@0: CleanupStack::PushL(theStore); sl@0: theStore->SetTypeL(KDirectFileStoreLayoutUid); sl@0: // sl@0: // Copy anOriginal out to the buffer sl@0: TStreamId id(0); sl@0: TRAPD(ret,id=aOriginal->CopyToStoreL(*theStore,aCopyPos,aLen)); sl@0: test(ret==KErrNone); sl@0: // sl@0: // paste into the copy sl@0: TRAP(ret,aCopy->PasteFromStoreL(*theStore,id,aPastePos,aPasteLen)); sl@0: test(ret==KErrNone); sl@0: // sl@0: // tidy up sl@0: CleanupStack::PopAndDestroy(); // theStore sl@0: theFs.Close(); sl@0: sl@0: } sl@0: sl@0: sl@0: TBool CT_STREAM::IsEqual(const CTextFieldSet* aCopy,const CTextFieldSet* anOriginal) sl@0: // sl@0: // Returns true if aCopy contents matches anOriginal contents. sl@0: // sl@0: { sl@0: // test the num chars and num fields sl@0: TInt charCount = anOriginal->CharCount(); sl@0: TInt fieldCount = anOriginal->FieldCount(); sl@0: test(charCount==aCopy->CharCount()); sl@0: test(fieldCount==aCopy->FieldCount()); sl@0: sl@0: // test each entry in the array sl@0: for (TInt pos=0 ; posFindFields(infoOrig,pos,charCount-pos); sl@0: aCopy->FindFields(infoCopy,pos,charCount-pos); sl@0: test(infoOrig==infoCopy); sl@0: pos += infoOrig.iFirstFieldPos+infoOrig.iFirstFieldLen; sl@0: if (infoOrig.iFieldCountInRange==0) sl@0: break; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: TBool CT_STREAM::UpdateField(TInt aPos,CTextFieldSet* aSet) sl@0: { sl@0: // find out which field aPos is in sl@0: TFindFieldInfo info; sl@0: TBool ret; sl@0: ret=aSet->FindFields(info,aPos); sl@0: test(ret); sl@0: // get the new value sl@0: HBufC* buf = HBufC::NewL(5); sl@0: CleanupStack::PushL(buf); sl@0: TInt err=aSet->NewFieldValueL(buf,aPos); sl@0: test(err==KErrNone); sl@0: // Notify FieldSet of update sl@0: aSet->NotifyFieldUpdate(aPos,buf->Length()); sl@0: // tidy up sl@0: CleanupStack::PopAndDestroy(); sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test2() sl@0: // Streams an empty field set sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- streaming of a default FieldSet (no fields)")); sl@0: testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); sl@0: test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test3() sl@0: // Streams a field set containing 100 chars & 1 field sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- streaming with a field")); sl@0: sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert a field into the original sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(10,TheFieldSetOriginal); sl@0: test(ret); sl@0: sl@0: // test streaming sl@0: testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); sl@0: test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test4() sl@0: // Streams a field set into a non-empty target sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- streaming into a non-empty target")); sl@0: sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert a field into the original sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(10,TheFieldSetOriginal); sl@0: test(ret); sl@0: sl@0: // insert a block of text into the copy sl@0: TheFieldSetCopy->NotifyInsertion(0,40); // pos=0, len=40 sl@0: // insert two fields into the copy sl@0: CTextField* field2 = TheFieldSetCopy->NewFieldL(KDummyFieldUid); sl@0: CTextField* field3 = TheFieldSetCopy->NewFieldL(KDummyFieldUid); sl@0: ret=TheFieldSetCopy->InsertFieldL(20,field2,KDummyFieldUid); sl@0: test(ret==KErrNone); sl@0: ret=TheFieldSetCopy->InsertFieldL(30,field3,KDummyFieldUid); sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(20,TheFieldSetCopy); sl@0: test(ret); sl@0: ret=UpdateField(33,TheFieldSetCopy); sl@0: test(ret); sl@0: sl@0: // test streaming sl@0: testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); sl@0: test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test5() sl@0: // Streams a field set containing an out of date field sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- streaming an out of date field")); sl@0: sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert a field into the original sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(10,TheFieldSetOriginal); sl@0: test(ret); sl@0: // invalidate the field sl@0: TheFieldSetOriginal->NotifyInsertion(11,7); // pos=11, len=7 sl@0: sl@0: // test streaming sl@0: testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); sl@0: test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test6() sl@0: // Tests that copy/paste methods exist sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- testing copy/paste methods with empty array")); sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,0,0,0); // copyPos,Len,PastePos sl@0: test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test7() sl@0: // Tests copy/paste methods in detail sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- testing copy/paste methods in detail")); sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert a field into the original sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: TBool ok=UpdateField(10,TheFieldSetOriginal); sl@0: test(ok); sl@0: test(TheFieldSetOriginal->CharCount()==103); sl@0: // copy out of that into an empty array sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,0); // copyPos,Len,PastePos sl@0: // check that the contents of the array are as expected sl@0: TFindFieldInfo info; sl@0: TheFieldSetCopy->FindFields(info,0,15); sl@0: test(TheFieldSetCopy->CharCount()==15); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==5); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->Reset(); sl@0: // test copying part of a field sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,6,0); // copyPos,Len,PastePos sl@0: TheFieldSetCopy->FindFields(info,0,6); sl@0: test(TheFieldSetCopy->CharCount()==6); sl@0: test(TheFieldSetCopy->FieldCount()==0); sl@0: test(info.iFieldCountInRange==0); sl@0: TheFieldSetCopy->Reset(); sl@0: // test copying exactly one field sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,0); // copyPos,Len,PastePos sl@0: TheFieldSetCopy->FindFields(info,0,3); sl@0: test(TheFieldSetCopy->CharCount()==3); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==0); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->Reset(); sl@0: // test pasting into text in a non-empty array sl@0: TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50 sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,10); // copyPos,Len,PastePos sl@0: TheFieldSetCopy->FindFields(info,0,65); sl@0: test(TheFieldSetCopy->CharCount()==65); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==15); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->Reset(); sl@0: // test pasting into a field sl@0: TheFieldSetCopy->NotifyInsertion(0,50); // pos=0, len=50 sl@0: field=TheFieldSetCopy->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: ret=TheFieldSetCopy->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: ok=UpdateField(10,TheFieldSetCopy); sl@0: test(ok); sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,15,11); // copyPos,Len,PastePos sl@0: TheFieldSetCopy->FindFields(info,0,68); sl@0: test(TheFieldSetCopy->CharCount()==68); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==10); sl@0: test(info.iFirstFieldLen==18); sl@0: TheFieldSetCopy->Reset(); sl@0: // test pasting at the start & end of a field sl@0: TheFieldSetCopy->NotifyInsertion(0,10); // pos=0, len=10 sl@0: field=TheFieldSetCopy->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: ret=TheFieldSetCopy->InsertFieldL(5,field,KDummyFieldUid); // pos=5 sl@0: test(ret==KErrNone); sl@0: ok=UpdateField(5,TheFieldSetCopy); sl@0: test(ok); sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,8); // copyPos,Len,PastePos sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,3,5); // copyPos,Len,PastePos sl@0: TheFieldSetCopy->FindFields(info,0,19); sl@0: test(TheFieldSetCopy->CharCount()==19); sl@0: test(TheFieldSetCopy->FieldCount()==3); sl@0: test(info.iFieldCountInRange==3); sl@0: test(info.iFirstFieldPos==5); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->FindFields(info,8,11); sl@0: test(info.iFieldCountInRange==2); sl@0: test(info.iFirstFieldPos==8); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->FindFields(info,11,8); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==11); sl@0: test(info.iFirstFieldLen==3); sl@0: // tidy up sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test8() sl@0: // Tests paste method with restricted target length sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- testing paste method with restricted length")); sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert 2 fields into the original sl@0: // 1... sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: TBool ok=UpdateField(10,TheFieldSetOriginal); sl@0: test(ok); sl@0: // 2.. sl@0: field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: ret=TheFieldSetOriginal->InsertFieldL(20,field,KDummyFieldUid); // pos=20 sl@0: test(ret==KErrNone); sl@0: ok=UpdateField(20,TheFieldSetOriginal); sl@0: test(ok); sl@0: // paste part of original into copy with length greater than required sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,7); // copyPos,Len,PastePos,PasteLen sl@0: TFindFieldInfo info; sl@0: TheFieldSetCopy->FindFields(info,0,5); sl@0: test(TheFieldSetCopy->CharCount()==5); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==0); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->Reset(); sl@0: // paste part of original into copy with length equal to that required sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,5); // copyPos,Len,PastePos,PasteLen sl@0: TheFieldSetCopy->FindFields(info,0,5); sl@0: test(TheFieldSetCopy->CharCount()==5); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==0); sl@0: test(info.iFirstFieldLen==3); sl@0: TheFieldSetCopy->Reset(); sl@0: // paste part of original into copy with length zero sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,10,5,0,0); // copyPos,Len,PastePos,PasteLen sl@0: test(TheFieldSetCopy->CharCount()==0); sl@0: test(TheFieldSetCopy->FieldCount()==0); sl@0: TheFieldSetCopy->Reset(); sl@0: // paste part of original into copy with length st field is chopped sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,10,0,6); // copyPos,Len,PastePos,PasteLen sl@0: TheFieldSetCopy->FindFields(info,0,6); sl@0: test(TheFieldSetCopy->CharCount()==6); sl@0: test(TheFieldSetCopy->FieldCount()==0); sl@0: test(info.iFieldCountInRange==0); sl@0: TheFieldSetCopy->Reset(); sl@0: // paste part of original into copy with length st one field is left off, the other pasted in sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,20,0,10); // copyPos,Len,PastePos,PasteLen sl@0: TheFieldSetCopy->FindFields(info,0,10); sl@0: test(TheFieldSetCopy->CharCount()==10); sl@0: test(TheFieldSetCopy->FieldCount()==1); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldPos==5); sl@0: test(info.iFirstFieldLen==3); sl@0: // tidy up sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test9() sl@0: // Tests paste into set with no field factory sl@0: // Should convert all pasted fields to text... sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- testing paste into set with no field factory")); sl@0: TheFieldSetCopy->SetFieldFactory(NULL); sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert a field into the original sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDummyFieldUid); sl@0: test(field!=NULL); sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDummyFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: TBool ok=UpdateField(10,TheFieldSetOriginal); sl@0: test(ok); sl@0: // paste part of original into copy sl@0: testCopyPaste(TheFieldSetCopy,TheFieldSetOriginal,5,25,0); // copyPos,Len,PastePos sl@0: TFindFieldInfo info; sl@0: TheFieldSetCopy->FindFields(info,0,25); sl@0: test(TheFieldSetCopy->CharCount()==25); sl@0: test(TheFieldSetCopy->FieldCount()==0); sl@0: // tidy up sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: TheFieldSetCopy->SetFieldFactory(TheFactory); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::test10() sl@0: // Streams a field set containing 100 chars & 1 field sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- streaming CDateTimeField")); sl@0: sl@0: // insert a block of text into the original sl@0: TheFieldSetOriginal->NotifyInsertion(0,100); // pos=0, len=100 sl@0: // insert a field into the original sl@0: CTextField* field=TheFieldSetOriginal->NewFieldL(KDateTimeFieldUid); sl@0: test(field!=NULL); sl@0: TBuf<14> buff = _L("%-A%*I%:1%T%+A"); sl@0: ((CDateTimeField*)field)->SetFormat(buff); // 01:53pm sl@0: TInt ret=TheFieldSetOriginal->InsertFieldL(10,field,KDateTimeFieldUid); // pos=10 sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(10,TheFieldSetOriginal); sl@0: test(ret); sl@0: // value before sl@0: HBufC* miniBuf = HBufC::NewL(5); sl@0: CleanupStack::PushL(miniBuf); sl@0: ret=TheFieldSetOriginal->NewFieldValueL(miniBuf,10); // pos=10 sl@0: test(ret==KErrNone); sl@0: TPtr buf = miniBuf->Des(); sl@0: INFO_PRINTF1(_L(" Value before streaming: ")); sl@0: INFO_PRINTF1(buf); sl@0: INFO_PRINTF1(_L("\n")); sl@0: // test streaming sl@0: testStoreRestore(TheFieldSetCopy,TheFieldSetOriginal); sl@0: test(IsEqual(TheFieldSetCopy,TheFieldSetOriginal)); sl@0: // value after sl@0: ret=TheFieldSetCopy->NewFieldValueL(miniBuf,10); // pos=10 sl@0: test(ret==KErrNone); sl@0: buf = miniBuf->Des(); sl@0: INFO_PRINTF1(_L(" Value after streaming: ")); sl@0: INFO_PRINTF1(buf); sl@0: INFO_PRINTF1(_L("\n")); sl@0: CleanupStack::PopAndDestroy(); // miniBuf sl@0: TheFieldSetOriginal->Reset(); sl@0: TheFieldSetCopy->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::TestStreamingL() sl@0: // sl@0: // Test streaming of PrintSetup info. sl@0: // Stream from one copy to another, then compare sl@0: // sl@0: { sl@0: // create the PrintSetups sl@0: INFO_PRINTF1(_L("Streaming CTextFieldSet")); sl@0: sl@0: // instantiate the factory and FieldSet sl@0: TheFactory = new(ELeave) TTestFieldFactory(); sl@0: TheFieldSetOriginal = CTextFieldSet::NewL(); sl@0: TheFieldSetOriginal->SetFieldFactory(TheFactory); sl@0: TheFieldSetCopy = CTextFieldSet::NewL(); sl@0: TheFieldSetCopy->SetFieldFactory(TheFactory); sl@0: sl@0: // Use "original" with default settings & test stream sl@0: test2(); sl@0: sl@0: // change data in original and test stream again sl@0: test3(); sl@0: sl@0: // Stream a field set into a non-empty target sl@0: test4(); sl@0: sl@0: // Stream a field set containing an out of date field sl@0: test5(); sl@0: sl@0: // Test that copy/paste methods exist sl@0: test6(); sl@0: sl@0: // Test copy/paste methods in detail sl@0: test7(); sl@0: sl@0: // Test paste with limited target area sl@0: test8(); sl@0: sl@0: // Test paste into set with no field factory sl@0: test9(); sl@0: sl@0: // Test streaming of built-in types sl@0: test10(); sl@0: sl@0: // end sl@0: delete TheFieldSetOriginal; sl@0: delete TheFieldSetCopy; sl@0: delete TheFactory; sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::setupCleanup() sl@0: // sl@0: // Initialise the cleanup stack. sl@0: // sl@0: { sl@0: sl@0: TheTrapCleanup=CTrapCleanup::New(); sl@0: TRAPD(r,\ sl@0: {\ sl@0: for (TInt i=KTestCleanupStack;i>0;i--)\ sl@0: CleanupStack::PushL((TAny*)1);\ sl@0: test(r==KErrNone);\ sl@0: CleanupStack::Pop(KTestCleanupStack);\ sl@0: }); sl@0: } sl@0: sl@0: sl@0: void CT_STREAM::DeleteDataFile(const TDesC& aFullName) sl@0: { sl@0: RFs fsSession; sl@0: TInt err = fsSession.Connect(); sl@0: if(err == KErrNone) sl@0: { sl@0: TEntry entry; sl@0: if(fsSession.Entry(aFullName, entry) == KErrNone) sl@0: { sl@0: RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); sl@0: err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); sl@0: } sl@0: err = fsSession.Delete(aFullName); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: fsSession.Close(); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: sl@0: sl@0: CT_STREAM::CT_STREAM() sl@0: { sl@0: SetTestStepName(KTestStep_T_STREAM); sl@0: } sl@0: sl@0: TVerdict CT_STREAM::doTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("T_STREAM - Fields Persistence")); sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: setupCleanup(); sl@0: sl@0: TRAPD(error1, TestStreamingL()); sl@0: sl@0: delete TheTrapCleanup; sl@0: sl@0: __UHEAP_MARKEND; sl@0: DeleteDataFile(KTFieldOutputFile); //deletion of data files must be before call to End() - DEF047652 sl@0: sl@0: if(error1 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }