Update contrib.
2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
26 TBool __bb = (cond); \
30 ERR_PRINTF1(_L("ERROR: Test Failed")); \
35 #define UNUSED_VAR(a) a = a
37 const TInt KTestCleanupStack=0x40;
39 LOCAL_D CTrapCleanup* TheTrapCleanup;
40 LOCAL_D CTextFieldSet* TheFieldSet;
41 LOCAL_D TTestFieldFactory* TheFactory;
44 TBool CT_FIELD1::UpdateField(TInt aPos)
46 // find out which field aPos is in
48 TBool inField=TheFieldSet->FindFields(info,aPos);
51 HBufC* buf = HBufC::NewLC(5);
52 TInt ret=TheFieldSet->NewFieldValueL(buf,aPos);
54 CleanupStack::PushL(buf);
56 // Notify FieldSet of update
57 TheFieldSet->NotifyFieldUpdate(aPos,buf->Length());
59 CleanupStack::PopAndDestroy();
64 void CT_FIELD1::test1()
65 // Tests that all CTextFieldSet methods exist as specced
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
76 HBufC* buf = HBufC::NewLC(20); // max length 20
77 TheFieldSet->NewFieldValueL(buf,1); // pos=1
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
88 TheFieldSet->FindFields(info,0,3); // pos=0, range=3
90 TheFieldSet->RemoveField(2);
91 // reset the field array
96 void CT_FIELD1::test2()
97 // Tests inserting, updating and removing a field
100 INFO_PRINTF1(_L("- Testing field insertion, update and removal"));
101 test(TheFieldSet->CharCount()==0);
102 test(TheFieldSet->FieldCount()==0);
104 CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
105 TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
107 test(TheFieldSet->CharCount()==0);
108 test(TheFieldSet->FieldCount()==1);
109 // get its initial value
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
118 CleanupStack::PushL(miniBuf);
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);
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);
132 TBool inField=TheFieldSet->FindFields(info,0);
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
146 test(TheFieldSet->CharCount()==3);
147 test(TheFieldSet->FieldCount()==0);
148 */ // reset the field array
149 TheFieldSet->Reset();
150 CleanupStack::PopAndDestroy(); // miniBuf
154 void CT_FIELD1::test3()
155 // Tests InField() in "all" the oddball situations
159 INFO_PRINTF1(_L("- Testing InField() calls"));
160 test(TheFieldSet->CharCount()==0);
161 test(TheFieldSet->FieldCount()==0);
163 TBool inField=TheFieldSet->FindFields(info,0);
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
172 inField=TheFieldSet->FindFields(info,0);
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
181 inField=TheFieldSet->FindFields(info,0);
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
189 inField=TheFieldSet->FindFields(info,0);
191 test(info.iFieldCountInRange==1);
192 test(info.iFirstFieldLen==3);
193 test(info.iFirstFieldPos==0);
194 inField=TheFieldSet->FindFields(info,3);
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
202 inField=TheFieldSet->FindFields(info,3);
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);
210 test(info.iFieldCountInRange==0);
211 test(info.iFirstFieldLen==0);
212 test(info.iFirstFieldPos==0);
214 inField=TheFieldSet->FindFields(info,2);
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);
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);
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();
245 void CT_FIELD1::test4()
246 // Tests Insertion and deletion of text around and into fields
250 INFO_PRINTF1(_L("- Testing insertion and deletion of text around and into fields"));
251 test(TheFieldSet->CharCount()==0);
252 test(TheFieldSet->FieldCount()==0);
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)
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);
335 //Adding some character & field at the end & then deleting all
336 test(TheFieldSet->CharCount()==0);
337 test(TheFieldSet->FieldCount()==0);
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)
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);
398 TheFieldSet->Reset();
402 void CT_FIELD1::test5()
403 // Tests inserting, updating and removing a CDateTimeField
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
413 test(TheFieldSet->CharCount()==0);
414 test(TheFieldSet->FieldCount()==1);
415 // get its initial value
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
423 CleanupStack::PushL(miniBuf);
425 TPtr buf = miniBuf->Des();
426 INFO_PRINTF1(_L(" The field value is: "));
428 INFO_PRINTF1(_L("\n"));
429 // reset the field array
430 TheFieldSet->Reset();
431 CleanupStack::PopAndDestroy(); // miniBuf
435 void CT_FIELD1::test6()
436 // Tests CDateTimeFields with non-default formatting
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")); //
446 TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
448 test(TheFieldSet->CharCount()==0);
449 test(TheFieldSet->FieldCount()==1);
450 // get its initial value
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
459 CleanupStack::PushL(miniBuf);
461 TPtr buf = miniBuf->Des();
462 INFO_PRINTF1(_L(" The field value is: "));
464 INFO_PRINTF1(_L("\n"));
465 // reset the field array
466 TheFieldSet->Reset();
467 CleanupStack::PopAndDestroy(); // miniBuf
471 void CT_FIELD1::test7()
472 // Tests inserting, updating and removing a CPageNumberField
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
482 test(TheFieldSet->CharCount()==0);
483 test(TheFieldSet->FieldCount()==1);
484 // get its initial value
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
492 CleanupStack::PushL(miniBuf);
494 TPtr buf = miniBuf->Des();
495 INFO_PRINTF1(_L(" The field value is: "));
497 INFO_PRINTF1(_L("\n"));
498 // reset the field array
499 TheFieldSet->Reset();
500 CleanupStack::PopAndDestroy(); // miniBuf
504 void CT_FIELD1::test8()
505 // Tests inserting, updating and removing a CPageNumberField
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
515 test(TheFieldSet->CharCount()==0);
516 test(TheFieldSet->FieldCount()==1);
517 // get its initial value
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
525 CleanupStack::PushL(miniBuf);
527 TPtr buf = miniBuf->Des();
528 INFO_PRINTF1(_L(" The field value is: "));
530 INFO_PRINTF1(_L("\n"));
531 // reset the field array
532 TheFieldSet->Reset();
533 CleanupStack::PopAndDestroy(); // miniBuf
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.
541 void CT_FIELD1::test_multiple_fields()
543 INFO_PRINTF1(_L(" - testing multiple fields"));
544 test(TheFieldSet->CharCount()==0);
545 test(TheFieldSet->FieldCount()==0);
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".
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);
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);
573 TheFieldSet->Reset();
577 void CT_FIELD1::testFields()
578 // Test the fields dll.
581 INFO_PRINTF1(_L("Testing Fields"));
583 // instantiate the FieldSet and use the default factory
584 TheFactory = new(ELeave) TTestFieldFactory();
585 TheFieldSet = CTextFieldSet::NewL();
586 TheFieldSet->SetFieldFactory(TheFactory);
588 // the first test just checks that all methods exist (a la Duncan)
590 // Tests inserting, updating and removing a field
592 // Tests FindFields() & InField() in "all" the oddball situations
594 // Tests Insertion and deletion of text around and into fields
596 // Tests the CDateTimeField class
598 // Tests the CDateTimeField class with non-default formatting
600 // Test CPageNumberField
602 // Test CFileNameField
604 // Test multiple field insertion and deletion.
605 test_multiple_fields();
610 //CleanupStack::PopAndDestroy();
614 void CT_FIELD1::setupCleanup()
616 // Initialise the cleanup stack.
620 TheTrapCleanup=CTrapCleanup::New();
623 for (TInt i=KTestCleanupStack;i>0;i--)\
624 CleanupStack::PushL((TAny*)1);\
626 CleanupStack::Pop(KTestCleanupStack);\
630 CT_FIELD1::CT_FIELD1()
632 SetTestStepName(KTestStep_T_FIELD1);
635 TVerdict CT_FIELD1::doTestStepL()
637 INFO_PRINTF1(_L("Testing Fields"));
638 SetTestStepResult(EFail);
644 TRAPD(error1, testFields());
646 delete TheTrapCleanup;
650 if(error1 == KErrNone)
652 SetTestStepResult(EPass);
655 return TestStepResult();