os/textandloc/textrendering/texthandling/tfields/T_FIELD1.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "T_FIELD1.h"
    20 #include "TESTFAC.H"
    21 #include <fldset.h>
    22 #include <flddef.h>
    23 
    24 #define test(cond)											\
    25 	{														\
    26 	TBool __bb = (cond);									\
    27 	TEST(__bb);												\
    28 	if (!__bb)												\
    29 		{													\
    30 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
    31 		User::Leave(1);										\
    32 		}													\
    33 	}
    34 
    35 #define UNUSED_VAR(a) a = a
    36 
    37 const TInt KTestCleanupStack=0x40;
    38 
    39 LOCAL_D CTrapCleanup* TheTrapCleanup;
    40 LOCAL_D CTextFieldSet* TheFieldSet;
    41 LOCAL_D TTestFieldFactory* TheFactory;
    42 
    43 
    44 TBool CT_FIELD1::UpdateField(TInt aPos)
    45 	{
    46 	// find out which field aPos is in
    47 	TFindFieldInfo info;
    48 	TBool inField=TheFieldSet->FindFields(info,aPos);
    49 		test(inField);
    50 	// get the new value
    51 	HBufC* buf = HBufC::NewLC(5); 
    52  	TInt ret=TheFieldSet->NewFieldValueL(buf,aPos); 
    53 	CleanupStack::Pop();
    54 	CleanupStack::PushL(buf);
    55 		test(ret==KErrNone);
    56 	// Notify FieldSet of update
    57 	TheFieldSet->NotifyFieldUpdate(aPos,buf->Length());
    58 	// tidy up
    59 	CleanupStack::PopAndDestroy();
    60 	return ret;
    61 	}
    62 
    63 
    64 void CT_FIELD1::test1()
    65 // Tests that all CTextFieldSet methods exist as specced
    66 //
    67 	{
    68 	INFO_PRINTF1(_L("- Testing that all CTextFieldSet methods exist"));
    69 	// inform TheFieldSet about an imaginary insertion, then an imaginary deletion
    70 	TheFieldSet->NotifyInsertion(0,10); // pos=0, len=10
    71 	TheFieldSet->NotifyDeletion(2,5); // pos=2, len=5
    72 	// insert a field & get its initial value
    73 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
    74 	TInt ret = TheFieldSet->InsertFieldL(1,field,KDummyFieldUid); // pos=1
    75 		test(ret==KErrNone);
    76 	HBufC* buf = HBufC::NewLC(20); // max length 20
    77 	TheFieldSet->NewFieldValueL(buf,1); // pos=1
    78 	CleanupStack::Pop();
    79 	CleanupStack::PushL(buf);
    80 	TheFieldSet->NotifyFieldUpdate(1,buf->Length());
    81 	CleanupStack::PopAndDestroy(); // buf
    82 	// count number of fields & characters
    83 	TheFieldSet->FieldCount();
    84 	TheFieldSet->CharCount();
    85 	// find the inserted field
    86 	TheFieldSet->FindFields(0); // pos=0
    87 	TFindFieldInfo info;
    88 	TheFieldSet->FindFields(info,0,3); // pos=0, range=3
    89 	// remove the field
    90 	TheFieldSet->RemoveField(2);
    91 	// reset the field array
    92 	TheFieldSet->Reset();
    93 	}
    94 
    95 
    96 void CT_FIELD1::test2()
    97 // Tests inserting, updating and removing a field
    98 //
    99 	{
   100 	INFO_PRINTF1(_L("- Testing field insertion, update and removal"));
   101 		test(TheFieldSet->CharCount()==0);
   102 		test(TheFieldSet->FieldCount()==0);
   103 	// insert a field
   104 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   105 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
   106 		test(ret==KErrNone);
   107 	test(TheFieldSet->CharCount()==0);
   108 		test(TheFieldSet->FieldCount()==1);
   109 	// get its initial value
   110 	ret=UpdateField(0);
   111 		test(ret==KErrNone);
   112 		test(TheFieldSet->CharCount()==3);
   113 		test(TheFieldSet->FieldCount()==1);
   114 	// get its value in a buffer of insufficient size
   115 	HBufC* miniBuf = HBufC::NewLC(0); 
   116 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   117 	CleanupStack::Pop();
   118 	CleanupStack::PushL(miniBuf);
   119 		test(ret==KErrNone);
   120 	// delete part of the field & update
   121 	TheFieldSet->NotifyDeletion(1,1); // pos=1, len=1
   122 		test(TheFieldSet->CharCount()==2);
   123 		test(TheFieldSet->FieldCount()==1);
   124 	ret=UpdateField(0);
   125 		test(TheFieldSet->CharCount()==3);
   126 		test(TheFieldSet->FieldCount()==1);
   127 	// delete over a zero length
   128 	TheFieldSet->NotifyDeletion(1,0); // pos=1, len=0
   129 		test(TheFieldSet->CharCount()==3);
   130 		test(TheFieldSet->FieldCount()==1);
   131 	TFindFieldInfo info;
   132 	TBool inField=TheFieldSet->FindFields(info,0);
   133 		test(inField);
   134 		test(info.iFieldCountInRange==1);
   135 		test(info.iFirstFieldLen==3);
   136 		test(info.iFirstFieldPos==0);
   137 	// delete all the contents of the field & update
   138 	TheFieldSet->NotifyDeletion(0,3); // pos=0, len=3
   139 		test(TheFieldSet->CharCount()==0);
   140 		test(TheFieldSet->FieldCount()==0);
   141 /*	ret=UpdateField(0);
   142 		test(TheFieldSet->CharCount()==0);
   143 		test(TheFieldSet->FieldCount()==0);
   144 	ret=TheFieldSet->RemoveField(0); // pos=0
   145 		test(ret);
   146 		test(TheFieldSet->CharCount()==3);
   147 		test(TheFieldSet->FieldCount()==0);
   148 */	// reset the field array
   149 	TheFieldSet->Reset();
   150 	CleanupStack::PopAndDestroy(); // miniBuf
   151 	}
   152 
   153 
   154 void CT_FIELD1::test3()
   155 // Tests InField() in "all" the oddball situations
   156 //
   157 	{
   158 	TFindFieldInfo info;
   159 	INFO_PRINTF1(_L("- Testing InField() calls"));
   160 		test(TheFieldSet->CharCount()==0);
   161 		test(TheFieldSet->FieldCount()==0);
   162 	// Zero length doc
   163 	TBool inField=TheFieldSet->FindFields(info,0);
   164 		test(!inField);
   165 		test(info.iFieldCountInRange==0);
   166 		test(info.iFirstFieldLen==0);
   167 		test(info.iFirstFieldPos==0);
   168 	// Insert field (zero length) & test before
   169 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   170 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
   171 		test(ret==KErrNone);
   172 	inField=TheFieldSet->FindFields(info,0);
   173 		test(inField);
   174 		test(info.iFieldCountInRange==1);
   175 		test(info.iFirstFieldLen==0);
   176 		test(info.iFirstFieldPos==0);
   177 	// Insert another field (zero length) & test before
   178 	CTextField* field2 = TheFieldSet->NewFieldL(KDummyFieldUid);
   179 	ret=TheFieldSet->InsertFieldL(0,field2,KDummyFieldUid); // pos=0
   180 		test(ret==KErrNone);
   181 	inField=TheFieldSet->FindFields(info,0);
   182 		test(inField);
   183 		test(info.iFieldCountInRange==2);
   184 		test(info.iFirstFieldLen==0);
   185 		test(info.iFirstFieldPos==0);
   186 	// Get the value of the first field, test before & test between them
   187 	ret=UpdateField(0);
   188 		test(ret==KErrNone);
   189 	inField=TheFieldSet->FindFields(info,0);
   190 		test(inField);
   191 		test(info.iFieldCountInRange==1);
   192 		test(info.iFirstFieldLen==3);
   193 		test(info.iFirstFieldPos==0);
   194 	inField=TheFieldSet->FindFields(info,3);
   195 		test(inField);
   196 		test(info.iFieldCountInRange==1);
   197 		test(info.iFirstFieldLen==0);
   198 		test(info.iFirstFieldPos==3);
   199 	// Get the value of the second field, test between them
   200 	ret=UpdateField(3);
   201 		test(ret==KErrNone);
   202 	inField=TheFieldSet->FindFields(info,3);
   203 		test(inField);
   204 		test(info.iFieldCountInRange==1);
   205 		test(info.iFirstFieldLen==3);
   206 		test(info.iFirstFieldPos==3);
   207 	// end of doc - after field
   208 	inField=TheFieldSet->FindFields(info,6);
   209 		test(!inField);
   210 		test(info.iFieldCountInRange==0);
   211 		test(info.iFirstFieldLen==0);
   212 		test(info.iFirstFieldPos==0);
   213 	// In field
   214 	inField=TheFieldSet->FindFields(info,2);
   215 		test(inField);
   216 		test(info.iFieldCountInRange==1);
   217 		test(info.iFirstFieldLen==3);
   218 		test(info.iFirstFieldPos==0);
   219 	// Other method at same pos
   220 	inField=TheFieldSet->FindFields(2);
   221 		test(inField);
   222 	// Pretend to insert some text between the fields
   223 	TheFieldSet->NotifyInsertion(3,5); // pos=3, len=5
   224 		test(TheFieldSet->CharCount()==11);
   225 		test(TheFieldSet->FieldCount()==2);
   226 	// Test in text
   227 	inField=TheFieldSet->FindFields(info,6);
   228 		test(info.iFieldCountInRange==0);
   229 		test(info.iFirstFieldLen==0);
   230 		test(info.iFirstFieldPos==0);
   231 	// Test from field to field over the intervening text
   232 	inField=TheFieldSet->FindFields(info,1,9);
   233 		test(info.iFieldCountInRange==2);
   234 		test(info.iFirstFieldLen==3);
   235 		test(info.iFirstFieldPos==0);
   236 	// Test from field 1 up to field 2
   237 	inField=TheFieldSet->FindFields(info,0,8);
   238 		test(info.iFieldCountInRange==1);
   239 		test(info.iFirstFieldLen==3);
   240 		test(info.iFirstFieldPos==0);
   241 	TheFieldSet->Reset();
   242 	}
   243 
   244 
   245 void CT_FIELD1::test4()
   246 // Tests Insertion and deletion of text around and into fields
   247 //
   248 	{
   249 	TFindFieldInfo info;
   250 	INFO_PRINTF1(_L("- Testing insertion and deletion of text around and into fields"));
   251 		test(TheFieldSet->CharCount()==0);
   252 		test(TheFieldSet->FieldCount()==0);
   253 	// Insert some text
   254 	TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4
   255 		test(TheFieldSet->CharCount()==4);
   256 		test(TheFieldSet->FieldCount()==0);
   257 	// Insert some text into the text
   258 	TheFieldSet->NotifyInsertion(2,6); // pos=2, len=6
   259 		test(TheFieldSet->CharCount()==10);
   260 		test(TheFieldSet->FieldCount()==0);
   261 	// Insert a field into the text
   262 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   263 	TInt ret=TheFieldSet->InsertFieldL(4,field,KDummyFieldUid); // pos=4
   264 	if(ret != KErrNone && field !=NULL)
   265 		{
   266 		delete field;
   267 		field = NULL;
   268 		}
   269 		test(ret==KErrNone);
   270 	ret=UpdateField(4);
   271 		test(ret==KErrNone);
   272 		test(TheFieldSet->CharCount()==13);
   273 		test(TheFieldSet->FieldCount()==1);
   274 	// Insert some text directly before the field (check it hasn't inserted into the field)
   275 	TheFieldSet->NotifyInsertion(4,2); // pos=4, len=2
   276 		test(TheFieldSet->CharCount()==15);
   277 		test(TheFieldSet->FieldCount()==1);
   278 	TBool inField=TheFieldSet->FindFields(info,7); // pos=7
   279 		test(info.iFieldCountInRange==1);
   280 		test(info.iFirstFieldLen==3);
   281 		test(info.iFirstFieldPos==6);
   282 	// Insert some text directly after the field
   283 	TheFieldSet->NotifyInsertion(9,1); // pos=9, len=1
   284 		test(TheFieldSet->CharCount()==16);
   285 		test(TheFieldSet->FieldCount()==1);
   286 	inField=TheFieldSet->FindFields(info,7); // pos=7
   287 		test(info.iFieldCountInRange==1);
   288 		test(info.iFirstFieldLen==3);
   289 		test(info.iFirstFieldPos==6);
   290 	// Insert some text into the field
   291 	TheFieldSet->NotifyInsertion(7,4); // pos=9, len=4
   292 		test(TheFieldSet->CharCount()==20);
   293 		test(TheFieldSet->FieldCount()==1);
   294 	inField=TheFieldSet->FindFields(info,7); // pos=7
   295 		test(info.iFieldCountInRange==1);
   296 		test(info.iFirstFieldLen==7);
   297 		test(info.iFirstFieldPos==6);
   298 	// Delete some text directly after the field
   299 	TheFieldSet->NotifyDeletion(13,1); // pos=13, len=1
   300 		test(TheFieldSet->CharCount()==19);
   301 		test(TheFieldSet->FieldCount()==1);
   302 	inField=TheFieldSet->FindFields(info,9); // pos=9
   303 		test(info.iFieldCountInRange==1);
   304 		test(info.iFirstFieldLen==7);
   305 		test(info.iFirstFieldPos==6);
   306 	// Delete some text before the field
   307 	TheFieldSet->NotifyDeletion(4,2); // pos=4, len=2
   308 		test(TheFieldSet->CharCount()==17);
   309 		test(TheFieldSet->FieldCount()==1);
   310 	inField=TheFieldSet->FindFields(info,7); // pos=7
   311 		test(info.iFieldCountInRange==1);
   312 		test(info.iFirstFieldLen==7);
   313 		test(info.iFirstFieldPos==4);
   314 	// Delete some text overlapping into the field
   315 	TheFieldSet->NotifyDeletion(1,5); // pos=1, len=5
   316 		test(TheFieldSet->CharCount()==12);
   317 		test(TheFieldSet->FieldCount()==1);
   318 	inField=TheFieldSet->FindFields(info,3); // pos=3
   319 		test(info.iFieldCountInRange==1);
   320 		test(info.iFirstFieldLen==5);
   321 		test(info.iFirstFieldPos==1);
   322 	// Delete some text overlapping out of the field
   323 	TheFieldSet->NotifyDeletion(3,4); // pos=3, len=4
   324 		test(TheFieldSet->CharCount()==8);
   325 		test(TheFieldSet->FieldCount()==1);
   326 	inField=TheFieldSet->FindFields(info,2); // pos=2
   327 		test(info.iFieldCountInRange==1);
   328 		test(info.iFirstFieldLen==2);
   329 		test(info.iFirstFieldPos==1);
   330 	// Delete all text, inc field
   331 	TheFieldSet->NotifyDeletion(0,8); // pos=0, len=8
   332 		test(TheFieldSet->CharCount()==0);
   333 		test(TheFieldSet->FieldCount()==0);
   334 		
   335 	//Adding some character & field at the end & then deleting all
   336 		test(TheFieldSet->CharCount()==0);
   337 		test(TheFieldSet->FieldCount()==0);
   338 	// Insert some text
   339 	TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4
   340 		test(TheFieldSet->CharCount()==4);
   341 		test(TheFieldSet->FieldCount()==0);
   342 	// Insert some text into the text
   343 	TheFieldSet->NotifyInsertion(2,7); // pos=2, len=7
   344 		test(TheFieldSet->CharCount()==11);
   345 		test(TheFieldSet->FieldCount()==0);
   346 	//Insert field at the last position
   347 	CTextField* field1 = TheFieldSet->NewFieldL(KDummyFieldUid);
   348 	ret=TheFieldSet->InsertFieldL(5,field1,KDummyFieldUid); // pos=5
   349 	if(ret != KErrNone && field1 !=NULL)
   350 		{
   351 		delete field1;
   352 		field1 = NULL;
   353 		}
   354 		test(ret==KErrNone);
   355 	ret=UpdateField(5);
   356 	//Delete last character
   357 	TheFieldSet->NotifyDeletion(10,1); // pos=10, len=1
   358 		test(TheFieldSet->CharCount()==13);
   359 		test(TheFieldSet->FieldCount()==1);
   360 	//Insert characters at the field position so field moves to 8th pos
   361 	TheFieldSet->NotifyInsertion(5,3); // pos=5, len=3
   362 		test(TheFieldSet->CharCount()==16);
   363 		test(TheFieldSet->FieldCount()==1);
   364 	inField=TheFieldSet->FindFields(info,8); // pos=8
   365 		test(info.iFieldCountInRange==1);
   366 		test(info.iFirstFieldLen==3);
   367 		test(info.iFirstFieldPos==8);
   368 	//Delete last character
   369 	TheFieldSet->NotifyDeletion(15,1); // pos=15, len=1
   370 		test(TheFieldSet->CharCount()==15);
   371 		test(TheFieldSet->FieldCount()==1);
   372 	//Delete out of range character that doesnt exist..
   373 	TheFieldSet->NotifyDeletion(15,1); // pos=15, len=1
   374 		test(TheFieldSet->CharCount()==15);
   375 		test(TheFieldSet->FieldCount()==1);
   376 	//Delete all the characters after the field
   377 	TheFieldSet->NotifyDeletion(11, 4); // pos=11, len=4
   378 		test(TheFieldSet->CharCount()==11);
   379 		test(TheFieldSet->FieldCount()==1);
   380 	//Shorten the field by deleting the last character of the field
   381 	TheFieldSet->NotifyDeletion(10, 1); // pos=10, len=1
   382 		test(TheFieldSet->CharCount()==10);
   383 		test(TheFieldSet->FieldCount()==1);
   384 	inField=TheFieldSet->FindFields(info,8); // pos=0
   385 		test(info.iFieldCountInRange==1);
   386 		test(info.iFirstFieldLen==2);
   387 		test(info.iFirstFieldPos==8);
   388 	//length to be removed is one more than the existing data..DEF095911
   389 	TheFieldSet->NotifyDeletion(0,11); // pos=0, len=11
   390 		test(TheFieldSet->CharCount()==0);
   391 		test(TheFieldSet->FieldCount()==0);
   392 	inField=TheFieldSet->FindFields(info,0); // pos=0
   393 		test(info.iFieldCountInRange==0);
   394 		test(info.iFirstFieldLen==0);
   395 		test(info.iFirstFieldPos==0);
   396 
   397 	// Finish up
   398 	TheFieldSet->Reset();
   399 	}
   400 
   401 
   402 void CT_FIELD1::test5()
   403 // Tests inserting, updating and removing a CDateTimeField
   404 //
   405 	{
   406 	INFO_PRINTF1(_L("- Testing CDateTimeField"));
   407 		test(TheFieldSet->CharCount()==0);
   408 		test(TheFieldSet->FieldCount()==0);
   409 	// insert a field with default format
   410 	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   411 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
   412 		test(ret==KErrNone);
   413 		test(TheFieldSet->CharCount()==0);
   414 		test(TheFieldSet->FieldCount()==1);
   415 	// get its initial value
   416 	ret=UpdateField(0);
   417 		test(ret==KErrNone);
   418 		test(TheFieldSet->FieldCount()==1);
   419 	// get its value and display it
   420 	HBufC* miniBuf = HBufC::NewLC(5); 
   421 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   422 	CleanupStack::Pop();
   423 	CleanupStack::PushL(miniBuf);
   424 		test(ret==KErrNone);
   425 	TPtr buf = miniBuf->Des();
   426 	INFO_PRINTF1(_L("  The field value is: "));
   427 	INFO_PRINTF1(buf);
   428 	INFO_PRINTF1(_L("\n"));
   429 	// reset the field array
   430 	TheFieldSet->Reset();
   431 	CleanupStack::PopAndDestroy(); // miniBuf
   432 	}
   433 
   434 
   435 void CT_FIELD1::test6()
   436 // Tests CDateTimeFields with non-default formatting
   437 //
   438 	{
   439 	INFO_PRINTF1(_L("- Testing CDateTimeField with non-default formatting"));
   440 		test(TheFieldSet->CharCount()==0);
   441 		test(TheFieldSet->FieldCount()==0);
   442 	// create a field and set format
   443 	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   444 	((CDateTimeField*)field)->SetFormat(_L("%-A%*I%:1%T%+A")); //
   445 	// insert field
   446 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
   447 		test(ret==KErrNone);
   448 		test(TheFieldSet->CharCount()==0);
   449 		test(TheFieldSet->FieldCount()==1);
   450 	// get its initial value
   451 	ret=UpdateField(0);
   452 		test(ret==KErrNone);
   453 //		test(TheFieldSet->CharCount()==5);
   454 		test(TheFieldSet->FieldCount()==1);
   455 	// get its value and display it
   456 	HBufC* miniBuf = HBufC::NewLC(5); 
   457 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   458 	CleanupStack::Pop();
   459 	CleanupStack::PushL(miniBuf);
   460 		test(ret==KErrNone);
   461 	TPtr buf = miniBuf->Des();
   462 	INFO_PRINTF1(_L("  The field value is: "));
   463 	INFO_PRINTF1(buf);
   464 	INFO_PRINTF1(_L("\n"));
   465 	// reset the field array
   466 	TheFieldSet->Reset();
   467 	CleanupStack::PopAndDestroy(); // miniBuf
   468 	}
   469 
   470 
   471 void CT_FIELD1::test7()
   472 // Tests inserting, updating and removing a CPageNumberField
   473 //
   474 	{
   475 	INFO_PRINTF1(_L("- Testing CPageNumberField"));
   476 		test(TheFieldSet->CharCount()==0);
   477 		test(TheFieldSet->FieldCount()==0);
   478 	// insert a field with default format
   479 	CTextField* field = TheFieldSet->NewFieldL(KPageNumberFieldUid);
   480 	TInt ret=TheFieldSet->InsertFieldL(0,field,KPageNumberFieldUid); // pos=0
   481 		test(ret==KErrNone);
   482 		test(TheFieldSet->CharCount()==0);
   483 		test(TheFieldSet->FieldCount()==1);
   484 	// get its initial value
   485 	ret=UpdateField(0);
   486 		test(ret==KErrNone);
   487 		test(TheFieldSet->FieldCount()==1);
   488 	// get its value and display it
   489 	HBufC* miniBuf = HBufC::NewLC(5); 
   490 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   491 	CleanupStack::Pop();
   492 	CleanupStack::PushL(miniBuf);
   493 		test(ret==KErrNone);
   494 	TPtr buf = miniBuf->Des();
   495 	INFO_PRINTF1(_L("  The field value is: "));
   496 	INFO_PRINTF1(buf);
   497 	INFO_PRINTF1(_L("\n"));
   498 	// reset the field array
   499 	TheFieldSet->Reset();
   500 	CleanupStack::PopAndDestroy(); // miniBuf
   501 	}
   502 
   503 
   504 void CT_FIELD1::test8()
   505 // Tests inserting, updating and removing a CPageNumberField
   506 //
   507 	{
   508 	INFO_PRINTF1(_L("- Testing CFileNameField"));
   509 		test(TheFieldSet->CharCount()==0);
   510 		test(TheFieldSet->FieldCount()==0);
   511 	// insert a field with default format
   512 	CTextField* field = TheFieldSet->NewFieldL(KFileNameFieldUid);
   513 	TInt ret=TheFieldSet->InsertFieldL(0,field,KFileNameFieldUid); // pos=0
   514 		test(ret==KErrNone);
   515 		test(TheFieldSet->CharCount()==0);
   516 		test(TheFieldSet->FieldCount()==1);
   517 	// get its initial value
   518 	ret=UpdateField(0);
   519 		test(ret==KErrNone);
   520 		test(TheFieldSet->FieldCount()==1);
   521 	// get its value and display it
   522 	HBufC* miniBuf = HBufC::NewLC(5); 
   523 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   524 	CleanupStack::Pop();
   525 	CleanupStack::PushL(miniBuf);
   526 		test(ret==KErrNone);
   527 	TPtr buf = miniBuf->Des();
   528 	INFO_PRINTF1(_L("  The field value is: "));
   529 	INFO_PRINTF1(buf);
   530 	INFO_PRINTF1(_L("\n"));
   531 	// reset the field array
   532 	TheFieldSet->Reset();
   533 	CleanupStack::PopAndDestroy(); // miniBuf
   534 	}
   535 
   536 
   537 /*
   538 Added to test the fix to 'EDNHARN-4NVDHC: Text fields are not removed correctly in edwin'. Deletion
   539 of two fields failed to delete the second one.
   540 */
   541 void CT_FIELD1::test_multiple_fields()
   542 	{
   543 	INFO_PRINTF1(_L(" - testing multiple fields"));
   544 	test(TheFieldSet->CharCount()==0);
   545 	test(TheFieldSet->FieldCount()==0);
   546 
   547 	/*
   548 	Insert two dummy fields and some imaginary text. Dummy fields have the value 'XXX'.
   549 	If the text is represented by 'x's the text will be: "xxXXXxXXXxxxx".
   550 	*/
   551 	CTextField* field1 = TheFieldSet->NewFieldL(KDummyFieldUid);
   552 	TInt ret = TheFieldSet->InsertFieldL(0,field1,KDummyFieldUid);
   553 	test(ret == KErrNone);
   554 	test(TheFieldSet->FieldCount() == 1);
   555 	ret = UpdateField(0);
   556 	test(ret == KErrNone);
   557 	CTextField* field2 = TheFieldSet->NewFieldL(KDummyFieldUid);
   558 	ret = TheFieldSet->InsertFieldL(3,field2,KDummyFieldUid);
   559 	test(ret == KErrNone);
   560 	test(TheFieldSet->FieldCount() == 2);
   561 	ret = UpdateField(3);
   562 	test(ret == KErrNone);
   563 	TheFieldSet->NotifyInsertion(0,2);
   564 	TheFieldSet->NotifyInsertion(5,1);
   565 	TheFieldSet->NotifyInsertion(9,4);
   566 	test(TheFieldSet->CharCount() == 13);
   567 
   568 	// Delete the two fields and the character between them.
   569 	TheFieldSet->NotifyDeletion(2,7);
   570 	test(TheFieldSet->FieldCount() == 0);
   571 	test(TheFieldSet->CharCount() == 6);
   572 
   573 	TheFieldSet->Reset();
   574 	}
   575 
   576 
   577 void CT_FIELD1::testFields()
   578 // Test the fields dll.
   579 //
   580     {
   581 	INFO_PRINTF1(_L("Testing Fields"));
   582 	
   583 	// instantiate the  FieldSet and use the default factory
   584 	TheFactory = new(ELeave) TTestFieldFactory();
   585 	TheFieldSet = CTextFieldSet::NewL();
   586 	TheFieldSet->SetFieldFactory(TheFactory);
   587 	
   588 	// the first test just checks that all methods exist (a la Duncan)
   589 	test1();
   590 	// Tests inserting, updating and removing a field
   591 	test2();
   592 	// Tests FindFields() & InField() in "all" the oddball situations
   593 	test3();
   594 	// Tests Insertion and deletion of text around and into fields
   595 	test4();
   596 	// Tests the CDateTimeField class
   597 	test5();
   598 	// Tests the CDateTimeField class with non-default formatting
   599 	test6();
   600 	// Test CPageNumberField
   601 	test7();
   602 	// Test CFileNameField
   603 	test8();
   604 	// Test multiple field insertion and deletion.
   605 	test_multiple_fields();
   606 	
   607 	// clean up
   608 	delete TheFieldSet;
   609 	delete TheFactory;
   610 	//CleanupStack::PopAndDestroy(); 
   611     }
   612 
   613 
   614 void CT_FIELD1::setupCleanup()
   615 //
   616 // Initialise the cleanup stack.
   617 //
   618     {
   619 
   620 	TheTrapCleanup=CTrapCleanup::New();
   621 	TRAPD(r,\
   622 		{\
   623 		for (TInt i=KTestCleanupStack;i>0;i--)\
   624 			CleanupStack::PushL((TAny*)1);\
   625 		test(r==KErrNone);\
   626 		CleanupStack::Pop(KTestCleanupStack);\
   627 		});
   628 	}
   629 
   630 CT_FIELD1::CT_FIELD1()
   631     {
   632     SetTestStepName(KTestStep_T_FIELD1);
   633     }
   634 
   635 TVerdict CT_FIELD1::doTestStepL()
   636     {
   637 	INFO_PRINTF1(_L("Testing Fields"));
   638     SetTestStepResult(EFail);
   639 
   640     __UHEAP_MARK;
   641 
   642 	setupCleanup();
   643     
   644     TRAPD(error1, testFields());
   645 
   646 	delete TheTrapCleanup;
   647 
   648     __UHEAP_MARKEND;
   649 
   650     if(error1 == KErrNone)
   651         {
   652         SetTestStepResult(EPass);
   653         }
   654 
   655     return TestStepResult();
   656     }