os/textandloc/textrendering/texthandling/tfields/T_FIELD1.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/texthandling/tfields/T_FIELD1.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,656 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "T_FIELD1.h"
    1.23 +#include "TESTFAC.H"
    1.24 +#include <fldset.h>
    1.25 +#include <flddef.h>
    1.26 +
    1.27 +#define test(cond)											\
    1.28 +	{														\
    1.29 +	TBool __bb = (cond);									\
    1.30 +	TEST(__bb);												\
    1.31 +	if (!__bb)												\
    1.32 +		{													\
    1.33 +		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
    1.34 +		User::Leave(1);										\
    1.35 +		}													\
    1.36 +	}
    1.37 +
    1.38 +#define UNUSED_VAR(a) a = a
    1.39 +
    1.40 +const TInt KTestCleanupStack=0x40;
    1.41 +
    1.42 +LOCAL_D CTrapCleanup* TheTrapCleanup;
    1.43 +LOCAL_D CTextFieldSet* TheFieldSet;
    1.44 +LOCAL_D TTestFieldFactory* TheFactory;
    1.45 +
    1.46 +
    1.47 +TBool CT_FIELD1::UpdateField(TInt aPos)
    1.48 +	{
    1.49 +	// find out which field aPos is in
    1.50 +	TFindFieldInfo info;
    1.51 +	TBool inField=TheFieldSet->FindFields(info,aPos);
    1.52 +		test(inField);
    1.53 +	// get the new value
    1.54 +	HBufC* buf = HBufC::NewLC(5); 
    1.55 + 	TInt ret=TheFieldSet->NewFieldValueL(buf,aPos); 
    1.56 +	CleanupStack::Pop();
    1.57 +	CleanupStack::PushL(buf);
    1.58 +		test(ret==KErrNone);
    1.59 +	// Notify FieldSet of update
    1.60 +	TheFieldSet->NotifyFieldUpdate(aPos,buf->Length());
    1.61 +	// tidy up
    1.62 +	CleanupStack::PopAndDestroy();
    1.63 +	return ret;
    1.64 +	}
    1.65 +
    1.66 +
    1.67 +void CT_FIELD1::test1()
    1.68 +// Tests that all CTextFieldSet methods exist as specced
    1.69 +//
    1.70 +	{
    1.71 +	INFO_PRINTF1(_L("- Testing that all CTextFieldSet methods exist"));
    1.72 +	// inform TheFieldSet about an imaginary insertion, then an imaginary deletion
    1.73 +	TheFieldSet->NotifyInsertion(0,10); // pos=0, len=10
    1.74 +	TheFieldSet->NotifyDeletion(2,5); // pos=2, len=5
    1.75 +	// insert a field & get its initial value
    1.76 +	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
    1.77 +	TInt ret = TheFieldSet->InsertFieldL(1,field,KDummyFieldUid); // pos=1
    1.78 +		test(ret==KErrNone);
    1.79 +	HBufC* buf = HBufC::NewLC(20); // max length 20
    1.80 +	TheFieldSet->NewFieldValueL(buf,1); // pos=1
    1.81 +	CleanupStack::Pop();
    1.82 +	CleanupStack::PushL(buf);
    1.83 +	TheFieldSet->NotifyFieldUpdate(1,buf->Length());
    1.84 +	CleanupStack::PopAndDestroy(); // buf
    1.85 +	// count number of fields & characters
    1.86 +	TheFieldSet->FieldCount();
    1.87 +	TheFieldSet->CharCount();
    1.88 +	// find the inserted field
    1.89 +	TheFieldSet->FindFields(0); // pos=0
    1.90 +	TFindFieldInfo info;
    1.91 +	TheFieldSet->FindFields(info,0,3); // pos=0, range=3
    1.92 +	// remove the field
    1.93 +	TheFieldSet->RemoveField(2);
    1.94 +	// reset the field array
    1.95 +	TheFieldSet->Reset();
    1.96 +	}
    1.97 +
    1.98 +
    1.99 +void CT_FIELD1::test2()
   1.100 +// Tests inserting, updating and removing a field
   1.101 +//
   1.102 +	{
   1.103 +	INFO_PRINTF1(_L("- Testing field insertion, update and removal"));
   1.104 +		test(TheFieldSet->CharCount()==0);
   1.105 +		test(TheFieldSet->FieldCount()==0);
   1.106 +	// insert a field
   1.107 +	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.108 +	TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
   1.109 +		test(ret==KErrNone);
   1.110 +	test(TheFieldSet->CharCount()==0);
   1.111 +		test(TheFieldSet->FieldCount()==1);
   1.112 +	// get its initial value
   1.113 +	ret=UpdateField(0);
   1.114 +		test(ret==KErrNone);
   1.115 +		test(TheFieldSet->CharCount()==3);
   1.116 +		test(TheFieldSet->FieldCount()==1);
   1.117 +	// get its value in a buffer of insufficient size
   1.118 +	HBufC* miniBuf = HBufC::NewLC(0); 
   1.119 +	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   1.120 +	CleanupStack::Pop();
   1.121 +	CleanupStack::PushL(miniBuf);
   1.122 +		test(ret==KErrNone);
   1.123 +	// delete part of the field & update
   1.124 +	TheFieldSet->NotifyDeletion(1,1); // pos=1, len=1
   1.125 +		test(TheFieldSet->CharCount()==2);
   1.126 +		test(TheFieldSet->FieldCount()==1);
   1.127 +	ret=UpdateField(0);
   1.128 +		test(TheFieldSet->CharCount()==3);
   1.129 +		test(TheFieldSet->FieldCount()==1);
   1.130 +	// delete over a zero length
   1.131 +	TheFieldSet->NotifyDeletion(1,0); // pos=1, len=0
   1.132 +		test(TheFieldSet->CharCount()==3);
   1.133 +		test(TheFieldSet->FieldCount()==1);
   1.134 +	TFindFieldInfo info;
   1.135 +	TBool inField=TheFieldSet->FindFields(info,0);
   1.136 +		test(inField);
   1.137 +		test(info.iFieldCountInRange==1);
   1.138 +		test(info.iFirstFieldLen==3);
   1.139 +		test(info.iFirstFieldPos==0);
   1.140 +	// delete all the contents of the field & update
   1.141 +	TheFieldSet->NotifyDeletion(0,3); // pos=0, len=3
   1.142 +		test(TheFieldSet->CharCount()==0);
   1.143 +		test(TheFieldSet->FieldCount()==0);
   1.144 +/*	ret=UpdateField(0);
   1.145 +		test(TheFieldSet->CharCount()==0);
   1.146 +		test(TheFieldSet->FieldCount()==0);
   1.147 +	ret=TheFieldSet->RemoveField(0); // pos=0
   1.148 +		test(ret);
   1.149 +		test(TheFieldSet->CharCount()==3);
   1.150 +		test(TheFieldSet->FieldCount()==0);
   1.151 +*/	// reset the field array
   1.152 +	TheFieldSet->Reset();
   1.153 +	CleanupStack::PopAndDestroy(); // miniBuf
   1.154 +	}
   1.155 +
   1.156 +
   1.157 +void CT_FIELD1::test3()
   1.158 +// Tests InField() in "all" the oddball situations
   1.159 +//
   1.160 +	{
   1.161 +	TFindFieldInfo info;
   1.162 +	INFO_PRINTF1(_L("- Testing InField() calls"));
   1.163 +		test(TheFieldSet->CharCount()==0);
   1.164 +		test(TheFieldSet->FieldCount()==0);
   1.165 +	// Zero length doc
   1.166 +	TBool inField=TheFieldSet->FindFields(info,0);
   1.167 +		test(!inField);
   1.168 +		test(info.iFieldCountInRange==0);
   1.169 +		test(info.iFirstFieldLen==0);
   1.170 +		test(info.iFirstFieldPos==0);
   1.171 +	// Insert field (zero length) & test before
   1.172 +	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.173 +	TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
   1.174 +		test(ret==KErrNone);
   1.175 +	inField=TheFieldSet->FindFields(info,0);
   1.176 +		test(inField);
   1.177 +		test(info.iFieldCountInRange==1);
   1.178 +		test(info.iFirstFieldLen==0);
   1.179 +		test(info.iFirstFieldPos==0);
   1.180 +	// Insert another field (zero length) & test before
   1.181 +	CTextField* field2 = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.182 +	ret=TheFieldSet->InsertFieldL(0,field2,KDummyFieldUid); // pos=0
   1.183 +		test(ret==KErrNone);
   1.184 +	inField=TheFieldSet->FindFields(info,0);
   1.185 +		test(inField);
   1.186 +		test(info.iFieldCountInRange==2);
   1.187 +		test(info.iFirstFieldLen==0);
   1.188 +		test(info.iFirstFieldPos==0);
   1.189 +	// Get the value of the first field, test before & test between them
   1.190 +	ret=UpdateField(0);
   1.191 +		test(ret==KErrNone);
   1.192 +	inField=TheFieldSet->FindFields(info,0);
   1.193 +		test(inField);
   1.194 +		test(info.iFieldCountInRange==1);
   1.195 +		test(info.iFirstFieldLen==3);
   1.196 +		test(info.iFirstFieldPos==0);
   1.197 +	inField=TheFieldSet->FindFields(info,3);
   1.198 +		test(inField);
   1.199 +		test(info.iFieldCountInRange==1);
   1.200 +		test(info.iFirstFieldLen==0);
   1.201 +		test(info.iFirstFieldPos==3);
   1.202 +	// Get the value of the second field, test between them
   1.203 +	ret=UpdateField(3);
   1.204 +		test(ret==KErrNone);
   1.205 +	inField=TheFieldSet->FindFields(info,3);
   1.206 +		test(inField);
   1.207 +		test(info.iFieldCountInRange==1);
   1.208 +		test(info.iFirstFieldLen==3);
   1.209 +		test(info.iFirstFieldPos==3);
   1.210 +	// end of doc - after field
   1.211 +	inField=TheFieldSet->FindFields(info,6);
   1.212 +		test(!inField);
   1.213 +		test(info.iFieldCountInRange==0);
   1.214 +		test(info.iFirstFieldLen==0);
   1.215 +		test(info.iFirstFieldPos==0);
   1.216 +	// In field
   1.217 +	inField=TheFieldSet->FindFields(info,2);
   1.218 +		test(inField);
   1.219 +		test(info.iFieldCountInRange==1);
   1.220 +		test(info.iFirstFieldLen==3);
   1.221 +		test(info.iFirstFieldPos==0);
   1.222 +	// Other method at same pos
   1.223 +	inField=TheFieldSet->FindFields(2);
   1.224 +		test(inField);
   1.225 +	// Pretend to insert some text between the fields
   1.226 +	TheFieldSet->NotifyInsertion(3,5); // pos=3, len=5
   1.227 +		test(TheFieldSet->CharCount()==11);
   1.228 +		test(TheFieldSet->FieldCount()==2);
   1.229 +	// Test in text
   1.230 +	inField=TheFieldSet->FindFields(info,6);
   1.231 +		test(info.iFieldCountInRange==0);
   1.232 +		test(info.iFirstFieldLen==0);
   1.233 +		test(info.iFirstFieldPos==0);
   1.234 +	// Test from field to field over the intervening text
   1.235 +	inField=TheFieldSet->FindFields(info,1,9);
   1.236 +		test(info.iFieldCountInRange==2);
   1.237 +		test(info.iFirstFieldLen==3);
   1.238 +		test(info.iFirstFieldPos==0);
   1.239 +	// Test from field 1 up to field 2
   1.240 +	inField=TheFieldSet->FindFields(info,0,8);
   1.241 +		test(info.iFieldCountInRange==1);
   1.242 +		test(info.iFirstFieldLen==3);
   1.243 +		test(info.iFirstFieldPos==0);
   1.244 +	TheFieldSet->Reset();
   1.245 +	}
   1.246 +
   1.247 +
   1.248 +void CT_FIELD1::test4()
   1.249 +// Tests Insertion and deletion of text around and into fields
   1.250 +//
   1.251 +	{
   1.252 +	TFindFieldInfo info;
   1.253 +	INFO_PRINTF1(_L("- Testing insertion and deletion of text around and into fields"));
   1.254 +		test(TheFieldSet->CharCount()==0);
   1.255 +		test(TheFieldSet->FieldCount()==0);
   1.256 +	// Insert some text
   1.257 +	TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4
   1.258 +		test(TheFieldSet->CharCount()==4);
   1.259 +		test(TheFieldSet->FieldCount()==0);
   1.260 +	// Insert some text into the text
   1.261 +	TheFieldSet->NotifyInsertion(2,6); // pos=2, len=6
   1.262 +		test(TheFieldSet->CharCount()==10);
   1.263 +		test(TheFieldSet->FieldCount()==0);
   1.264 +	// Insert a field into the text
   1.265 +	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.266 +	TInt ret=TheFieldSet->InsertFieldL(4,field,KDummyFieldUid); // pos=4
   1.267 +	if(ret != KErrNone && field !=NULL)
   1.268 +		{
   1.269 +		delete field;
   1.270 +		field = NULL;
   1.271 +		}
   1.272 +		test(ret==KErrNone);
   1.273 +	ret=UpdateField(4);
   1.274 +		test(ret==KErrNone);
   1.275 +		test(TheFieldSet->CharCount()==13);
   1.276 +		test(TheFieldSet->FieldCount()==1);
   1.277 +	// Insert some text directly before the field (check it hasn't inserted into the field)
   1.278 +	TheFieldSet->NotifyInsertion(4,2); // pos=4, len=2
   1.279 +		test(TheFieldSet->CharCount()==15);
   1.280 +		test(TheFieldSet->FieldCount()==1);
   1.281 +	TBool inField=TheFieldSet->FindFields(info,7); // pos=7
   1.282 +		test(info.iFieldCountInRange==1);
   1.283 +		test(info.iFirstFieldLen==3);
   1.284 +		test(info.iFirstFieldPos==6);
   1.285 +	// Insert some text directly after the field
   1.286 +	TheFieldSet->NotifyInsertion(9,1); // pos=9, len=1
   1.287 +		test(TheFieldSet->CharCount()==16);
   1.288 +		test(TheFieldSet->FieldCount()==1);
   1.289 +	inField=TheFieldSet->FindFields(info,7); // pos=7
   1.290 +		test(info.iFieldCountInRange==1);
   1.291 +		test(info.iFirstFieldLen==3);
   1.292 +		test(info.iFirstFieldPos==6);
   1.293 +	// Insert some text into the field
   1.294 +	TheFieldSet->NotifyInsertion(7,4); // pos=9, len=4
   1.295 +		test(TheFieldSet->CharCount()==20);
   1.296 +		test(TheFieldSet->FieldCount()==1);
   1.297 +	inField=TheFieldSet->FindFields(info,7); // pos=7
   1.298 +		test(info.iFieldCountInRange==1);
   1.299 +		test(info.iFirstFieldLen==7);
   1.300 +		test(info.iFirstFieldPos==6);
   1.301 +	// Delete some text directly after the field
   1.302 +	TheFieldSet->NotifyDeletion(13,1); // pos=13, len=1
   1.303 +		test(TheFieldSet->CharCount()==19);
   1.304 +		test(TheFieldSet->FieldCount()==1);
   1.305 +	inField=TheFieldSet->FindFields(info,9); // pos=9
   1.306 +		test(info.iFieldCountInRange==1);
   1.307 +		test(info.iFirstFieldLen==7);
   1.308 +		test(info.iFirstFieldPos==6);
   1.309 +	// Delete some text before the field
   1.310 +	TheFieldSet->NotifyDeletion(4,2); // pos=4, len=2
   1.311 +		test(TheFieldSet->CharCount()==17);
   1.312 +		test(TheFieldSet->FieldCount()==1);
   1.313 +	inField=TheFieldSet->FindFields(info,7); // pos=7
   1.314 +		test(info.iFieldCountInRange==1);
   1.315 +		test(info.iFirstFieldLen==7);
   1.316 +		test(info.iFirstFieldPos==4);
   1.317 +	// Delete some text overlapping into the field
   1.318 +	TheFieldSet->NotifyDeletion(1,5); // pos=1, len=5
   1.319 +		test(TheFieldSet->CharCount()==12);
   1.320 +		test(TheFieldSet->FieldCount()==1);
   1.321 +	inField=TheFieldSet->FindFields(info,3); // pos=3
   1.322 +		test(info.iFieldCountInRange==1);
   1.323 +		test(info.iFirstFieldLen==5);
   1.324 +		test(info.iFirstFieldPos==1);
   1.325 +	// Delete some text overlapping out of the field
   1.326 +	TheFieldSet->NotifyDeletion(3,4); // pos=3, len=4
   1.327 +		test(TheFieldSet->CharCount()==8);
   1.328 +		test(TheFieldSet->FieldCount()==1);
   1.329 +	inField=TheFieldSet->FindFields(info,2); // pos=2
   1.330 +		test(info.iFieldCountInRange==1);
   1.331 +		test(info.iFirstFieldLen==2);
   1.332 +		test(info.iFirstFieldPos==1);
   1.333 +	// Delete all text, inc field
   1.334 +	TheFieldSet->NotifyDeletion(0,8); // pos=0, len=8
   1.335 +		test(TheFieldSet->CharCount()==0);
   1.336 +		test(TheFieldSet->FieldCount()==0);
   1.337 +		
   1.338 +	//Adding some character & field at the end & then deleting all
   1.339 +		test(TheFieldSet->CharCount()==0);
   1.340 +		test(TheFieldSet->FieldCount()==0);
   1.341 +	// Insert some text
   1.342 +	TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4
   1.343 +		test(TheFieldSet->CharCount()==4);
   1.344 +		test(TheFieldSet->FieldCount()==0);
   1.345 +	// Insert some text into the text
   1.346 +	TheFieldSet->NotifyInsertion(2,7); // pos=2, len=7
   1.347 +		test(TheFieldSet->CharCount()==11);
   1.348 +		test(TheFieldSet->FieldCount()==0);
   1.349 +	//Insert field at the last position
   1.350 +	CTextField* field1 = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.351 +	ret=TheFieldSet->InsertFieldL(5,field1,KDummyFieldUid); // pos=5
   1.352 +	if(ret != KErrNone && field1 !=NULL)
   1.353 +		{
   1.354 +		delete field1;
   1.355 +		field1 = NULL;
   1.356 +		}
   1.357 +		test(ret==KErrNone);
   1.358 +	ret=UpdateField(5);
   1.359 +	//Delete last character
   1.360 +	TheFieldSet->NotifyDeletion(10,1); // pos=10, len=1
   1.361 +		test(TheFieldSet->CharCount()==13);
   1.362 +		test(TheFieldSet->FieldCount()==1);
   1.363 +	//Insert characters at the field position so field moves to 8th pos
   1.364 +	TheFieldSet->NotifyInsertion(5,3); // pos=5, len=3
   1.365 +		test(TheFieldSet->CharCount()==16);
   1.366 +		test(TheFieldSet->FieldCount()==1);
   1.367 +	inField=TheFieldSet->FindFields(info,8); // pos=8
   1.368 +		test(info.iFieldCountInRange==1);
   1.369 +		test(info.iFirstFieldLen==3);
   1.370 +		test(info.iFirstFieldPos==8);
   1.371 +	//Delete last character
   1.372 +	TheFieldSet->NotifyDeletion(15,1); // pos=15, len=1
   1.373 +		test(TheFieldSet->CharCount()==15);
   1.374 +		test(TheFieldSet->FieldCount()==1);
   1.375 +	//Delete out of range character that doesnt exist..
   1.376 +	TheFieldSet->NotifyDeletion(15,1); // pos=15, len=1
   1.377 +		test(TheFieldSet->CharCount()==15);
   1.378 +		test(TheFieldSet->FieldCount()==1);
   1.379 +	//Delete all the characters after the field
   1.380 +	TheFieldSet->NotifyDeletion(11, 4); // pos=11, len=4
   1.381 +		test(TheFieldSet->CharCount()==11);
   1.382 +		test(TheFieldSet->FieldCount()==1);
   1.383 +	//Shorten the field by deleting the last character of the field
   1.384 +	TheFieldSet->NotifyDeletion(10, 1); // pos=10, len=1
   1.385 +		test(TheFieldSet->CharCount()==10);
   1.386 +		test(TheFieldSet->FieldCount()==1);
   1.387 +	inField=TheFieldSet->FindFields(info,8); // pos=0
   1.388 +		test(info.iFieldCountInRange==1);
   1.389 +		test(info.iFirstFieldLen==2);
   1.390 +		test(info.iFirstFieldPos==8);
   1.391 +	//length to be removed is one more than the existing data..DEF095911
   1.392 +	TheFieldSet->NotifyDeletion(0,11); // pos=0, len=11
   1.393 +		test(TheFieldSet->CharCount()==0);
   1.394 +		test(TheFieldSet->FieldCount()==0);
   1.395 +	inField=TheFieldSet->FindFields(info,0); // pos=0
   1.396 +		test(info.iFieldCountInRange==0);
   1.397 +		test(info.iFirstFieldLen==0);
   1.398 +		test(info.iFirstFieldPos==0);
   1.399 +
   1.400 +	// Finish up
   1.401 +	TheFieldSet->Reset();
   1.402 +	}
   1.403 +
   1.404 +
   1.405 +void CT_FIELD1::test5()
   1.406 +// Tests inserting, updating and removing a CDateTimeField
   1.407 +//
   1.408 +	{
   1.409 +	INFO_PRINTF1(_L("- Testing CDateTimeField"));
   1.410 +		test(TheFieldSet->CharCount()==0);
   1.411 +		test(TheFieldSet->FieldCount()==0);
   1.412 +	// insert a field with default format
   1.413 +	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   1.414 +	TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
   1.415 +		test(ret==KErrNone);
   1.416 +		test(TheFieldSet->CharCount()==0);
   1.417 +		test(TheFieldSet->FieldCount()==1);
   1.418 +	// get its initial value
   1.419 +	ret=UpdateField(0);
   1.420 +		test(ret==KErrNone);
   1.421 +		test(TheFieldSet->FieldCount()==1);
   1.422 +	// get its value and display it
   1.423 +	HBufC* miniBuf = HBufC::NewLC(5); 
   1.424 +	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   1.425 +	CleanupStack::Pop();
   1.426 +	CleanupStack::PushL(miniBuf);
   1.427 +		test(ret==KErrNone);
   1.428 +	TPtr buf = miniBuf->Des();
   1.429 +	INFO_PRINTF1(_L("  The field value is: "));
   1.430 +	INFO_PRINTF1(buf);
   1.431 +	INFO_PRINTF1(_L("\n"));
   1.432 +	// reset the field array
   1.433 +	TheFieldSet->Reset();
   1.434 +	CleanupStack::PopAndDestroy(); // miniBuf
   1.435 +	}
   1.436 +
   1.437 +
   1.438 +void CT_FIELD1::test6()
   1.439 +// Tests CDateTimeFields with non-default formatting
   1.440 +//
   1.441 +	{
   1.442 +	INFO_PRINTF1(_L("- Testing CDateTimeField with non-default formatting"));
   1.443 +		test(TheFieldSet->CharCount()==0);
   1.444 +		test(TheFieldSet->FieldCount()==0);
   1.445 +	// create a field and set format
   1.446 +	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   1.447 +	((CDateTimeField*)field)->SetFormat(_L("%-A%*I%:1%T%+A")); //
   1.448 +	// insert field
   1.449 +	TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
   1.450 +		test(ret==KErrNone);
   1.451 +		test(TheFieldSet->CharCount()==0);
   1.452 +		test(TheFieldSet->FieldCount()==1);
   1.453 +	// get its initial value
   1.454 +	ret=UpdateField(0);
   1.455 +		test(ret==KErrNone);
   1.456 +//		test(TheFieldSet->CharCount()==5);
   1.457 +		test(TheFieldSet->FieldCount()==1);
   1.458 +	// get its value and display it
   1.459 +	HBufC* miniBuf = HBufC::NewLC(5); 
   1.460 +	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   1.461 +	CleanupStack::Pop();
   1.462 +	CleanupStack::PushL(miniBuf);
   1.463 +		test(ret==KErrNone);
   1.464 +	TPtr buf = miniBuf->Des();
   1.465 +	INFO_PRINTF1(_L("  The field value is: "));
   1.466 +	INFO_PRINTF1(buf);
   1.467 +	INFO_PRINTF1(_L("\n"));
   1.468 +	// reset the field array
   1.469 +	TheFieldSet->Reset();
   1.470 +	CleanupStack::PopAndDestroy(); // miniBuf
   1.471 +	}
   1.472 +
   1.473 +
   1.474 +void CT_FIELD1::test7()
   1.475 +// Tests inserting, updating and removing a CPageNumberField
   1.476 +//
   1.477 +	{
   1.478 +	INFO_PRINTF1(_L("- Testing CPageNumberField"));
   1.479 +		test(TheFieldSet->CharCount()==0);
   1.480 +		test(TheFieldSet->FieldCount()==0);
   1.481 +	// insert a field with default format
   1.482 +	CTextField* field = TheFieldSet->NewFieldL(KPageNumberFieldUid);
   1.483 +	TInt ret=TheFieldSet->InsertFieldL(0,field,KPageNumberFieldUid); // pos=0
   1.484 +		test(ret==KErrNone);
   1.485 +		test(TheFieldSet->CharCount()==0);
   1.486 +		test(TheFieldSet->FieldCount()==1);
   1.487 +	// get its initial value
   1.488 +	ret=UpdateField(0);
   1.489 +		test(ret==KErrNone);
   1.490 +		test(TheFieldSet->FieldCount()==1);
   1.491 +	// get its value and display it
   1.492 +	HBufC* miniBuf = HBufC::NewLC(5); 
   1.493 +	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   1.494 +	CleanupStack::Pop();
   1.495 +	CleanupStack::PushL(miniBuf);
   1.496 +		test(ret==KErrNone);
   1.497 +	TPtr buf = miniBuf->Des();
   1.498 +	INFO_PRINTF1(_L("  The field value is: "));
   1.499 +	INFO_PRINTF1(buf);
   1.500 +	INFO_PRINTF1(_L("\n"));
   1.501 +	// reset the field array
   1.502 +	TheFieldSet->Reset();
   1.503 +	CleanupStack::PopAndDestroy(); // miniBuf
   1.504 +	}
   1.505 +
   1.506 +
   1.507 +void CT_FIELD1::test8()
   1.508 +// Tests inserting, updating and removing a CPageNumberField
   1.509 +//
   1.510 +	{
   1.511 +	INFO_PRINTF1(_L("- Testing CFileNameField"));
   1.512 +		test(TheFieldSet->CharCount()==0);
   1.513 +		test(TheFieldSet->FieldCount()==0);
   1.514 +	// insert a field with default format
   1.515 +	CTextField* field = TheFieldSet->NewFieldL(KFileNameFieldUid);
   1.516 +	TInt ret=TheFieldSet->InsertFieldL(0,field,KFileNameFieldUid); // pos=0
   1.517 +		test(ret==KErrNone);
   1.518 +		test(TheFieldSet->CharCount()==0);
   1.519 +		test(TheFieldSet->FieldCount()==1);
   1.520 +	// get its initial value
   1.521 +	ret=UpdateField(0);
   1.522 +		test(ret==KErrNone);
   1.523 +		test(TheFieldSet->FieldCount()==1);
   1.524 +	// get its value and display it
   1.525 +	HBufC* miniBuf = HBufC::NewLC(5); 
   1.526 +	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   1.527 +	CleanupStack::Pop();
   1.528 +	CleanupStack::PushL(miniBuf);
   1.529 +		test(ret==KErrNone);
   1.530 +	TPtr buf = miniBuf->Des();
   1.531 +	INFO_PRINTF1(_L("  The field value is: "));
   1.532 +	INFO_PRINTF1(buf);
   1.533 +	INFO_PRINTF1(_L("\n"));
   1.534 +	// reset the field array
   1.535 +	TheFieldSet->Reset();
   1.536 +	CleanupStack::PopAndDestroy(); // miniBuf
   1.537 +	}
   1.538 +
   1.539 +
   1.540 +/*
   1.541 +Added to test the fix to 'EDNHARN-4NVDHC: Text fields are not removed correctly in edwin'. Deletion
   1.542 +of two fields failed to delete the second one.
   1.543 +*/
   1.544 +void CT_FIELD1::test_multiple_fields()
   1.545 +	{
   1.546 +	INFO_PRINTF1(_L(" - testing multiple fields"));
   1.547 +	test(TheFieldSet->CharCount()==0);
   1.548 +	test(TheFieldSet->FieldCount()==0);
   1.549 +
   1.550 +	/*
   1.551 +	Insert two dummy fields and some imaginary text. Dummy fields have the value 'XXX'.
   1.552 +	If the text is represented by 'x's the text will be: "xxXXXxXXXxxxx".
   1.553 +	*/
   1.554 +	CTextField* field1 = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.555 +	TInt ret = TheFieldSet->InsertFieldL(0,field1,KDummyFieldUid);
   1.556 +	test(ret == KErrNone);
   1.557 +	test(TheFieldSet->FieldCount() == 1);
   1.558 +	ret = UpdateField(0);
   1.559 +	test(ret == KErrNone);
   1.560 +	CTextField* field2 = TheFieldSet->NewFieldL(KDummyFieldUid);
   1.561 +	ret = TheFieldSet->InsertFieldL(3,field2,KDummyFieldUid);
   1.562 +	test(ret == KErrNone);
   1.563 +	test(TheFieldSet->FieldCount() == 2);
   1.564 +	ret = UpdateField(3);
   1.565 +	test(ret == KErrNone);
   1.566 +	TheFieldSet->NotifyInsertion(0,2);
   1.567 +	TheFieldSet->NotifyInsertion(5,1);
   1.568 +	TheFieldSet->NotifyInsertion(9,4);
   1.569 +	test(TheFieldSet->CharCount() == 13);
   1.570 +
   1.571 +	// Delete the two fields and the character between them.
   1.572 +	TheFieldSet->NotifyDeletion(2,7);
   1.573 +	test(TheFieldSet->FieldCount() == 0);
   1.574 +	test(TheFieldSet->CharCount() == 6);
   1.575 +
   1.576 +	TheFieldSet->Reset();
   1.577 +	}
   1.578 +
   1.579 +
   1.580 +void CT_FIELD1::testFields()
   1.581 +// Test the fields dll.
   1.582 +//
   1.583 +    {
   1.584 +	INFO_PRINTF1(_L("Testing Fields"));
   1.585 +	
   1.586 +	// instantiate the  FieldSet and use the default factory
   1.587 +	TheFactory = new(ELeave) TTestFieldFactory();
   1.588 +	TheFieldSet = CTextFieldSet::NewL();
   1.589 +	TheFieldSet->SetFieldFactory(TheFactory);
   1.590 +	
   1.591 +	// the first test just checks that all methods exist (a la Duncan)
   1.592 +	test1();
   1.593 +	// Tests inserting, updating and removing a field
   1.594 +	test2();
   1.595 +	// Tests FindFields() & InField() in "all" the oddball situations
   1.596 +	test3();
   1.597 +	// Tests Insertion and deletion of text around and into fields
   1.598 +	test4();
   1.599 +	// Tests the CDateTimeField class
   1.600 +	test5();
   1.601 +	// Tests the CDateTimeField class with non-default formatting
   1.602 +	test6();
   1.603 +	// Test CPageNumberField
   1.604 +	test7();
   1.605 +	// Test CFileNameField
   1.606 +	test8();
   1.607 +	// Test multiple field insertion and deletion.
   1.608 +	test_multiple_fields();
   1.609 +	
   1.610 +	// clean up
   1.611 +	delete TheFieldSet;
   1.612 +	delete TheFactory;
   1.613 +	//CleanupStack::PopAndDestroy(); 
   1.614 +    }
   1.615 +
   1.616 +
   1.617 +void CT_FIELD1::setupCleanup()
   1.618 +//
   1.619 +// Initialise the cleanup stack.
   1.620 +//
   1.621 +    {
   1.622 +
   1.623 +	TheTrapCleanup=CTrapCleanup::New();
   1.624 +	TRAPD(r,\
   1.625 +		{\
   1.626 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.627 +			CleanupStack::PushL((TAny*)1);\
   1.628 +		test(r==KErrNone);\
   1.629 +		CleanupStack::Pop(KTestCleanupStack);\
   1.630 +		});
   1.631 +	}
   1.632 +
   1.633 +CT_FIELD1::CT_FIELD1()
   1.634 +    {
   1.635 +    SetTestStepName(KTestStep_T_FIELD1);
   1.636 +    }
   1.637 +
   1.638 +TVerdict CT_FIELD1::doTestStepL()
   1.639 +    {
   1.640 +	INFO_PRINTF1(_L("Testing Fields"));
   1.641 +    SetTestStepResult(EFail);
   1.642 +
   1.643 +    __UHEAP_MARK;
   1.644 +
   1.645 +	setupCleanup();
   1.646 +    
   1.647 +    TRAPD(error1, testFields());
   1.648 +
   1.649 +	delete TheTrapCleanup;
   1.650 +
   1.651 +    __UHEAP_MARKEND;
   1.652 +
   1.653 +    if(error1 == KErrNone)
   1.654 +        {
   1.655 +        SetTestStepResult(EPass);
   1.656 +        }
   1.657 +
   1.658 +    return TestStepResult();
   1.659 +    }