sl@0: /* sl@0: * Copyright (c) 1997-2010 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 "T_FIELD1.h" sl@0: #include "TESTFAC.H" sl@0: #include sl@0: #include 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: #define UNUSED_VAR(a) a = a sl@0: sl@0: const TInt KTestCleanupStack=0x40; sl@0: sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: LOCAL_D CTextFieldSet* TheFieldSet; sl@0: LOCAL_D TTestFieldFactory* TheFactory; sl@0: sl@0: sl@0: TBool CT_FIELD1::UpdateField(TInt aPos) sl@0: { sl@0: // find out which field aPos is in sl@0: TFindFieldInfo info; sl@0: TBool inField=TheFieldSet->FindFields(info,aPos); sl@0: test(inField); sl@0: // get the new value sl@0: HBufC* buf = HBufC::NewLC(5); sl@0: TInt ret=TheFieldSet->NewFieldValueL(buf,aPos); sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(buf); sl@0: test(ret==KErrNone); sl@0: // Notify FieldSet of update sl@0: TheFieldSet->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_FIELD1::test1() sl@0: // Tests that all CTextFieldSet methods exist as specced sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- Testing that all CTextFieldSet methods exist")); sl@0: // inform TheFieldSet about an imaginary insertion, then an imaginary deletion sl@0: TheFieldSet->NotifyInsertion(0,10); // pos=0, len=10 sl@0: TheFieldSet->NotifyDeletion(2,5); // pos=2, len=5 sl@0: // insert a field & get its initial value sl@0: CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: TInt ret = TheFieldSet->InsertFieldL(1,field,KDummyFieldUid); // pos=1 sl@0: test(ret==KErrNone); sl@0: HBufC* buf = HBufC::NewLC(20); // max length 20 sl@0: TheFieldSet->NewFieldValueL(buf,1); // pos=1 sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(buf); sl@0: TheFieldSet->NotifyFieldUpdate(1,buf->Length()); sl@0: CleanupStack::PopAndDestroy(); // buf sl@0: // count number of fields & characters sl@0: TheFieldSet->FieldCount(); sl@0: TheFieldSet->CharCount(); sl@0: // find the inserted field sl@0: TheFieldSet->FindFields(0); // pos=0 sl@0: TFindFieldInfo info; sl@0: TheFieldSet->FindFields(info,0,3); // pos=0, range=3 sl@0: // remove the field sl@0: TheFieldSet->RemoveField(2); sl@0: // reset the field array sl@0: TheFieldSet->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test2() sl@0: // Tests inserting, updating and removing a field sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- Testing field insertion, update and removal")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // insert a field sl@0: CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its initial value sl@0: ret=UpdateField(0); sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==3); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its value in a buffer of insufficient size sl@0: HBufC* miniBuf = HBufC::NewLC(0); sl@0: ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0 sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(miniBuf); sl@0: test(ret==KErrNone); sl@0: // delete part of the field & update sl@0: TheFieldSet->NotifyDeletion(1,1); // pos=1, len=1 sl@0: test(TheFieldSet->CharCount()==2); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: ret=UpdateField(0); sl@0: test(TheFieldSet->CharCount()==3); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // delete over a zero length sl@0: TheFieldSet->NotifyDeletion(1,0); // pos=1, len=0 sl@0: test(TheFieldSet->CharCount()==3); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: TFindFieldInfo info; sl@0: TBool inField=TheFieldSet->FindFields(info,0); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==0); sl@0: // delete all the contents of the field & update sl@0: TheFieldSet->NotifyDeletion(0,3); // pos=0, len=3 sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: /* ret=UpdateField(0); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: ret=TheFieldSet->RemoveField(0); // pos=0 sl@0: test(ret); sl@0: test(TheFieldSet->CharCount()==3); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: */ // reset the field array sl@0: TheFieldSet->Reset(); sl@0: CleanupStack::PopAndDestroy(); // miniBuf sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test3() sl@0: // Tests InField() in "all" the oddball situations sl@0: // sl@0: { sl@0: TFindFieldInfo info; sl@0: INFO_PRINTF1(_L("- Testing InField() calls")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // Zero length doc sl@0: TBool inField=TheFieldSet->FindFields(info,0); sl@0: test(!inField); sl@0: test(info.iFieldCountInRange==0); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==0); sl@0: // Insert field (zero length) & test before sl@0: CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: inField=TheFieldSet->FindFields(info,0); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==0); sl@0: // Insert another field (zero length) & test before sl@0: CTextField* field2 = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: ret=TheFieldSet->InsertFieldL(0,field2,KDummyFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: inField=TheFieldSet->FindFields(info,0); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==2); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==0); sl@0: // Get the value of the first field, test before & test between them sl@0: ret=UpdateField(0); sl@0: test(ret==KErrNone); sl@0: inField=TheFieldSet->FindFields(info,0); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==0); sl@0: inField=TheFieldSet->FindFields(info,3); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==3); sl@0: // Get the value of the second field, test between them sl@0: ret=UpdateField(3); sl@0: test(ret==KErrNone); sl@0: inField=TheFieldSet->FindFields(info,3); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==3); sl@0: // end of doc - after field sl@0: inField=TheFieldSet->FindFields(info,6); sl@0: test(!inField); sl@0: test(info.iFieldCountInRange==0); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==0); sl@0: // In field sl@0: inField=TheFieldSet->FindFields(info,2); sl@0: test(inField); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==0); sl@0: // Other method at same pos sl@0: inField=TheFieldSet->FindFields(2); sl@0: test(inField); sl@0: // Pretend to insert some text between the fields sl@0: TheFieldSet->NotifyInsertion(3,5); // pos=3, len=5 sl@0: test(TheFieldSet->CharCount()==11); sl@0: test(TheFieldSet->FieldCount()==2); sl@0: // Test in text sl@0: inField=TheFieldSet->FindFields(info,6); sl@0: test(info.iFieldCountInRange==0); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==0); sl@0: // Test from field to field over the intervening text sl@0: inField=TheFieldSet->FindFields(info,1,9); sl@0: test(info.iFieldCountInRange==2); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==0); sl@0: // Test from field 1 up to field 2 sl@0: inField=TheFieldSet->FindFields(info,0,8); sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==0); sl@0: TheFieldSet->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test4() sl@0: // Tests Insertion and deletion of text around and into fields sl@0: // sl@0: { sl@0: TFindFieldInfo info; sl@0: INFO_PRINTF1(_L("- Testing insertion and deletion of text around and into fields")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // Insert some text sl@0: TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4 sl@0: test(TheFieldSet->CharCount()==4); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // Insert some text into the text sl@0: TheFieldSet->NotifyInsertion(2,6); // pos=2, len=6 sl@0: test(TheFieldSet->CharCount()==10); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // Insert a field into the text sl@0: CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: TInt ret=TheFieldSet->InsertFieldL(4,field,KDummyFieldUid); // pos=4 sl@0: if(ret != KErrNone && field !=NULL) sl@0: { sl@0: delete field; sl@0: field = NULL; sl@0: } sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(4); sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==13); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // Insert some text directly before the field (check it hasn't inserted into the field) sl@0: TheFieldSet->NotifyInsertion(4,2); // pos=4, len=2 sl@0: test(TheFieldSet->CharCount()==15); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: TBool inField=TheFieldSet->FindFields(info,7); // pos=7 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==6); sl@0: // Insert some text directly after the field sl@0: TheFieldSet->NotifyInsertion(9,1); // pos=9, len=1 sl@0: test(TheFieldSet->CharCount()==16); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,7); // pos=7 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==6); sl@0: // Insert some text into the field sl@0: TheFieldSet->NotifyInsertion(7,4); // pos=9, len=4 sl@0: test(TheFieldSet->CharCount()==20); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,7); // pos=7 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==7); sl@0: test(info.iFirstFieldPos==6); sl@0: // Delete some text directly after the field sl@0: TheFieldSet->NotifyDeletion(13,1); // pos=13, len=1 sl@0: test(TheFieldSet->CharCount()==19); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,9); // pos=9 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==7); sl@0: test(info.iFirstFieldPos==6); sl@0: // Delete some text before the field sl@0: TheFieldSet->NotifyDeletion(4,2); // pos=4, len=2 sl@0: test(TheFieldSet->CharCount()==17); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,7); // pos=7 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==7); sl@0: test(info.iFirstFieldPos==4); sl@0: // Delete some text overlapping into the field sl@0: TheFieldSet->NotifyDeletion(1,5); // pos=1, len=5 sl@0: test(TheFieldSet->CharCount()==12); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,3); // pos=3 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==5); sl@0: test(info.iFirstFieldPos==1); sl@0: // Delete some text overlapping out of the field sl@0: TheFieldSet->NotifyDeletion(3,4); // pos=3, len=4 sl@0: test(TheFieldSet->CharCount()==8); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,2); // pos=2 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==2); sl@0: test(info.iFirstFieldPos==1); sl@0: // Delete all text, inc field sl@0: TheFieldSet->NotifyDeletion(0,8); // pos=0, len=8 sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: sl@0: //Adding some character & field at the end & then deleting all sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // Insert some text sl@0: TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4 sl@0: test(TheFieldSet->CharCount()==4); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // Insert some text into the text sl@0: TheFieldSet->NotifyInsertion(2,7); // pos=2, len=7 sl@0: test(TheFieldSet->CharCount()==11); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: //Insert field at the last position sl@0: CTextField* field1 = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: ret=TheFieldSet->InsertFieldL(5,field1,KDummyFieldUid); // pos=5 sl@0: if(ret != KErrNone && field1 !=NULL) sl@0: { sl@0: delete field1; sl@0: field1 = NULL; sl@0: } sl@0: test(ret==KErrNone); sl@0: ret=UpdateField(5); sl@0: //Delete last character sl@0: TheFieldSet->NotifyDeletion(10,1); // pos=10, len=1 sl@0: test(TheFieldSet->CharCount()==13); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: //Insert characters at the field position so field moves to 8th pos sl@0: TheFieldSet->NotifyInsertion(5,3); // pos=5, len=3 sl@0: test(TheFieldSet->CharCount()==16); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,8); // pos=8 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==3); sl@0: test(info.iFirstFieldPos==8); sl@0: //Delete last character sl@0: TheFieldSet->NotifyDeletion(15,1); // pos=15, len=1 sl@0: test(TheFieldSet->CharCount()==15); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: //Delete out of range character that doesnt exist.. sl@0: TheFieldSet->NotifyDeletion(15,1); // pos=15, len=1 sl@0: test(TheFieldSet->CharCount()==15); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: //Delete all the characters after the field sl@0: TheFieldSet->NotifyDeletion(11, 4); // pos=11, len=4 sl@0: test(TheFieldSet->CharCount()==11); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: //Shorten the field by deleting the last character of the field sl@0: TheFieldSet->NotifyDeletion(10, 1); // pos=10, len=1 sl@0: test(TheFieldSet->CharCount()==10); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: inField=TheFieldSet->FindFields(info,8); // pos=0 sl@0: test(info.iFieldCountInRange==1); sl@0: test(info.iFirstFieldLen==2); sl@0: test(info.iFirstFieldPos==8); sl@0: //length to be removed is one more than the existing data..DEF095911 sl@0: TheFieldSet->NotifyDeletion(0,11); // pos=0, len=11 sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: inField=TheFieldSet->FindFields(info,0); // pos=0 sl@0: test(info.iFieldCountInRange==0); sl@0: test(info.iFirstFieldLen==0); sl@0: test(info.iFirstFieldPos==0); sl@0: sl@0: // Finish up sl@0: TheFieldSet->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test5() sl@0: // Tests inserting, updating and removing a CDateTimeField sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- Testing CDateTimeField")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // insert a field with default format sl@0: CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid); sl@0: TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its initial value sl@0: ret=UpdateField(0); sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its value and display it sl@0: HBufC* miniBuf = HBufC::NewLC(5); sl@0: ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0 sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(miniBuf); sl@0: test(ret==KErrNone); sl@0: TPtr buf = miniBuf->Des(); sl@0: INFO_PRINTF1(_L(" The field value is: ")); sl@0: INFO_PRINTF1(buf); sl@0: INFO_PRINTF1(_L("\n")); sl@0: // reset the field array sl@0: TheFieldSet->Reset(); sl@0: CleanupStack::PopAndDestroy(); // miniBuf sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test6() sl@0: // Tests CDateTimeFields with non-default formatting sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- Testing CDateTimeField with non-default formatting")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // create a field and set format sl@0: CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid); sl@0: ((CDateTimeField*)field)->SetFormat(_L("%-A%*I%:1%T%+A")); // sl@0: // insert field sl@0: TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its initial value sl@0: ret=UpdateField(0); sl@0: test(ret==KErrNone); sl@0: // test(TheFieldSet->CharCount()==5); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its value and display it sl@0: HBufC* miniBuf = HBufC::NewLC(5); sl@0: ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0 sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(miniBuf); sl@0: test(ret==KErrNone); sl@0: TPtr buf = miniBuf->Des(); sl@0: INFO_PRINTF1(_L(" The field value is: ")); sl@0: INFO_PRINTF1(buf); sl@0: INFO_PRINTF1(_L("\n")); sl@0: // reset the field array sl@0: TheFieldSet->Reset(); sl@0: CleanupStack::PopAndDestroy(); // miniBuf sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test7() sl@0: // Tests inserting, updating and removing a CPageNumberField sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- Testing CPageNumberField")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // insert a field with default format sl@0: CTextField* field = TheFieldSet->NewFieldL(KPageNumberFieldUid); sl@0: TInt ret=TheFieldSet->InsertFieldL(0,field,KPageNumberFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its initial value sl@0: ret=UpdateField(0); sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its value and display it sl@0: HBufC* miniBuf = HBufC::NewLC(5); sl@0: ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0 sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(miniBuf); sl@0: test(ret==KErrNone); sl@0: TPtr buf = miniBuf->Des(); sl@0: INFO_PRINTF1(_L(" The field value is: ")); sl@0: INFO_PRINTF1(buf); sl@0: INFO_PRINTF1(_L("\n")); sl@0: // reset the field array sl@0: TheFieldSet->Reset(); sl@0: CleanupStack::PopAndDestroy(); // miniBuf sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::test8() sl@0: // Tests inserting, updating and removing a CPageNumberField sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("- Testing CFileNameField")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: // insert a field with default format sl@0: CTextField* field = TheFieldSet->NewFieldL(KFileNameFieldUid); sl@0: TInt ret=TheFieldSet->InsertFieldL(0,field,KFileNameFieldUid); // pos=0 sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its initial value sl@0: ret=UpdateField(0); sl@0: test(ret==KErrNone); sl@0: test(TheFieldSet->FieldCount()==1); sl@0: // get its value and display it sl@0: HBufC* miniBuf = HBufC::NewLC(5); sl@0: ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0 sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(miniBuf); sl@0: test(ret==KErrNone); sl@0: TPtr buf = miniBuf->Des(); sl@0: INFO_PRINTF1(_L(" The field value is: ")); sl@0: INFO_PRINTF1(buf); sl@0: INFO_PRINTF1(_L("\n")); sl@0: // reset the field array sl@0: TheFieldSet->Reset(); sl@0: CleanupStack::PopAndDestroy(); // miniBuf sl@0: } sl@0: sl@0: sl@0: /* sl@0: Added to test the fix to 'EDNHARN-4NVDHC: Text fields are not removed correctly in edwin'. Deletion sl@0: of two fields failed to delete the second one. sl@0: */ sl@0: void CT_FIELD1::test_multiple_fields() sl@0: { sl@0: INFO_PRINTF1(_L(" - testing multiple fields")); sl@0: test(TheFieldSet->CharCount()==0); sl@0: test(TheFieldSet->FieldCount()==0); sl@0: sl@0: /* sl@0: Insert two dummy fields and some imaginary text. Dummy fields have the value 'XXX'. sl@0: If the text is represented by 'x's the text will be: "xxXXXxXXXxxxx". sl@0: */ sl@0: CTextField* field1 = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: TInt ret = TheFieldSet->InsertFieldL(0,field1,KDummyFieldUid); sl@0: test(ret == KErrNone); sl@0: test(TheFieldSet->FieldCount() == 1); sl@0: ret = UpdateField(0); sl@0: test(ret == KErrNone); sl@0: CTextField* field2 = TheFieldSet->NewFieldL(KDummyFieldUid); sl@0: ret = TheFieldSet->InsertFieldL(3,field2,KDummyFieldUid); sl@0: test(ret == KErrNone); sl@0: test(TheFieldSet->FieldCount() == 2); sl@0: ret = UpdateField(3); sl@0: test(ret == KErrNone); sl@0: TheFieldSet->NotifyInsertion(0,2); sl@0: TheFieldSet->NotifyInsertion(5,1); sl@0: TheFieldSet->NotifyInsertion(9,4); sl@0: test(TheFieldSet->CharCount() == 13); sl@0: sl@0: // Delete the two fields and the character between them. sl@0: TheFieldSet->NotifyDeletion(2,7); sl@0: test(TheFieldSet->FieldCount() == 0); sl@0: test(TheFieldSet->CharCount() == 6); sl@0: sl@0: TheFieldSet->Reset(); sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::testFields() sl@0: // Test the fields dll. sl@0: // sl@0: { sl@0: INFO_PRINTF1(_L("Testing Fields")); sl@0: sl@0: // instantiate the FieldSet and use the default factory sl@0: TheFactory = new(ELeave) TTestFieldFactory(); sl@0: TheFieldSet = CTextFieldSet::NewL(); sl@0: TheFieldSet->SetFieldFactory(TheFactory); sl@0: sl@0: // the first test just checks that all methods exist (a la Duncan) sl@0: test1(); sl@0: // Tests inserting, updating and removing a field sl@0: test2(); sl@0: // Tests FindFields() & InField() in "all" the oddball situations sl@0: test3(); sl@0: // Tests Insertion and deletion of text around and into fields sl@0: test4(); sl@0: // Tests the CDateTimeField class sl@0: test5(); sl@0: // Tests the CDateTimeField class with non-default formatting sl@0: test6(); sl@0: // Test CPageNumberField sl@0: test7(); sl@0: // Test CFileNameField sl@0: test8(); sl@0: // Test multiple field insertion and deletion. sl@0: test_multiple_fields(); sl@0: sl@0: // clean up sl@0: delete TheFieldSet; sl@0: delete TheFactory; sl@0: //CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: sl@0: void CT_FIELD1::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: CT_FIELD1::CT_FIELD1() sl@0: { sl@0: SetTestStepName(KTestStep_T_FIELD1); sl@0: } sl@0: sl@0: TVerdict CT_FIELD1::doTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Testing Fields")); sl@0: SetTestStepResult(EFail); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: setupCleanup(); sl@0: sl@0: TRAPD(error1, testFields()); sl@0: sl@0: delete TheTrapCleanup; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if(error1 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: }