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