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