telephonyserverplugins/multimodetsy/test/Te_LoopBack/Te_LoopBackcphoneBook.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Phase 1 - variable name change only - still compiles
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include <e32test.h>
       
    23 #include <etelmm.h>
       
    24 #include <mpbutil.h>	
       
    25 #include "Te_LoopBackcphoneBook.h"
       
    26 #include "../../hayes/TSYCONFG.H" // for KInternetAccessPoint
       
    27 
       
    28 // Entries to write to the iPhone book
       
    29 _LIT(KMuddyWatersText,"MuddyW");
       
    30 _LIT(KArethaFText,"ArethaF");
       
    31 _LIT(KMuddyWatersPhoneNum,"02220111");
       
    32 _LIT(KArethaFPhoneNum,"03334567");
       
    33 
       
    34 
       
    35 //
       
    36 // Test-side class
       
    37 // With the assistance of the base class, this class must start the emulator
       
    38 // and drive the ETel API.
       
    39 //
       
    40 CTestDrivePhoneBook* CTestDrivePhoneBook::NewL(const TScriptList aScriptListEntry)
       
    41 	{
       
    42 	CTestDrivePhoneBook* phBk=new(ELeave) CTestDrivePhoneBook(aScriptListEntry);
       
    43 	CleanupStack::PushL(phBk);
       
    44 	phBk->ConstructL();
       
    45 	CleanupStack::Pop();
       
    46 	return phBk;
       
    47 	}
       
    48 
       
    49 CTestDrivePhoneBook::CTestDrivePhoneBook(const TScriptList aScriptListEntry) : 
       
    50 	iMESupported(EFalse), iScriptListEntry(aScriptListEntry)
       
    51 	{}
       
    52 
       
    53 TInt CTestDrivePhoneBook::RunTestL()
       
    54 	{
       
    55 	iCurrentScript=iScriptListEntry;
       
    56 	return StartEmulatorL();
       
    57 	}
       
    58 
       
    59 TInt CTestDrivePhoneBook::DriveETelApiL()
       
    60 //
       
    61 // This function contains the real meat of the Client-side test code
       
    62 //
       
    63 	{
       
    64  	_LIT(KMmPhoneName,"GsmPhone1");
       
    65 	
       
    66 	// Open and Initialise the iPhone
       
    67  	TESTL(iMmPhone.Open(iServer,KMmPhoneName)==KErrNone);
       
    68 
       
    69 	TRequestStatus reqStatus;
       
    70 	RMobilePhone::TMMTableSettings tableSettings;
       
    71 	tableSettings.iLocId=KInternetAccessPoint;
       
    72 	RMobilePhone::TMMTableSettingsPckg tableSettingsPckg(tableSettings);
       
    73 	iMmPhone.InitialiseMM(reqStatus , tableSettingsPckg); 	
       
    74 	User::WaitForRequest(reqStatus);
       
    75 	TESTL(reqStatus == KErrNone);
       
    76 
       
    77  	ERR_PRINTF1(_L("Phone Id, Available Phone books and Get Info"));
       
    78  	GetPhoneInfoL();
       
    79 
       
    80  	ERR_PRINTF1(_L("Get PhoneBook Capabilities and Information"));
       
    81   	testGetPhBkCapsAndInfoL(); 
       
    82 
       
    83  	ERR_PRINTF1(_L("Deleting the 1st 5 entries in the SM and ME (if supported) phonebooks"));
       
    84  	TInt ret;
       
    85  	ret=testClearPhBkL(KETelIccAdnPhoneBook);
       
    86  	TESTL(ret==KErrNone);
       
    87  	if (iMESupported)
       
    88 		{
       
    89  		ret=testClearPhBkL(KETelMeAdnPhoneBook);
       
    90  		TESTL(ret==KErrNone);
       
    91 		}
       
    92 
       
    93  	ERR_PRINTF1(_L("Phone book Read and Write"));
       
    94  	testPhoneBookReadAndWrite(); // New method using CPhoneBookBuffer
       
    95 
       
    96  	ERR_PRINTF1(_L("Advanced Phone book tests"));
       
    97 	testAdvancedPhoneBook();  // New method using CPhoneBookBuffer
       
    98 
       
    99 	ERR_PRINTF1(_L("Phone book Notifications"));
       
   100  	testPhoneBookNotifications(); // New method using CPhoneBookBuffer
       
   101 
       
   102 	ERR_PRINTF1(_L("Phone book Read Cancel Requests"));
       
   103 	testPhoneBookReadCancel(); // New method using CPhoneBookBuffer
       
   104 
       
   105 	ERR_PRINTF1(_L("Phone book Read & Write International Numbers"));
       
   106 	testPhoneBookReadAndWriteInternationalL();
       
   107 
       
   108 	ERR_PRINTF1(_L("Phone book Multithread Write"));
       
   109 	testPhoneBookMultiWriteL();
       
   110 
       
   111 	iMmPhone.Close();
       
   112 	return KErrNone;
       
   113 	}
       
   114 
       
   115 
       
   116 void CTestDrivePhoneBook::GetPhoneInfoL()
       
   117 /**
       
   118  * Retrieve iPhone Information
       
   119  */
       
   120 	{
       
   121 
       
   122 	TRequestStatus stat;
       
   123 	RMobilePhone::TMobilePhoneIdentityV1 phoneId;
       
   124 	iMmPhone.GetPhoneId(stat,phoneId);
       
   125 	User::WaitForRequest(stat);
       
   126 	TESTL(stat == KErrNone);
       
   127 
       
   128 	// check version id ?
       
   129 	INFO_PRINTF2(_L("Extension ID : %d"), phoneId.ExtensionId());
       
   130 	INFO_PRINTF2(_L("\nManufacturer ID : %S"), &phoneId.iManufacturer);
       
   131 	INFO_PRINTF2(_L("Model ID : %S"), &phoneId.iModel);
       
   132 	INFO_PRINTF2(_L("Revision ID : %S"), &phoneId.iRevision);
       
   133 	INFO_PRINTF2(_L("Serial number : %S\n"), &phoneId.iSerialNumber);
       
   134 
       
   135 	// common mode
       
   136 	TInt numAvail=0;  // counts number of phonebooks
       
   137 	IsPhoneBookAvailable (KETelMeAdnPhoneBook, numAvail);
       
   138 	IsPhoneBookAvailable (KETelMeDialledPhoneBook, numAvail);
       
   139 	IsPhoneBookAvailable (KETelMeMissedPhoneBook, numAvail);
       
   140 	IsPhoneBookAvailable (KETelMeReceivedPhoneBook, numAvail);
       
   141 	IsPhoneBookAvailable (KETelCombinedAdnPhoneBook, numAvail);
       
   142 	IsPhoneBookAvailable (KETelIccAdnPhoneBook, numAvail);
       
   143 	IsPhoneBookAvailable (KETelIccFdnPhoneBook, numAvail);
       
   144 	IsPhoneBookAvailable (KETelIccSdnPhoneBook, numAvail);
       
   145 	// gsm mode
       
   146 	IsPhoneBookAvailable (KETelTaAdnPhoneBook, numAvail);
       
   147 	IsPhoneBookAvailable (KETelIccBdnPhoneBook, numAvail);
       
   148 	IsPhoneBookAvailable (KETelIccVoiceMailBox, numAvail);
       
   149 	INFO_PRINTF2(_L("%d Phonebooks available.\n"), numAvail);
       
   150 
       
   151 }
       
   152 
       
   153 TRequestStatus CTestDrivePhoneBook::IsPhoneBookAvailable(const TDesC& aPhoneBook,
       
   154                                                          TInt &aCount)
       
   155 	{
       
   156 	TRequestStatus stat;
       
   157 	RMobilePhoneStore::TMobilePhoneStoreInfoV1 info;
       
   158 	RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg infoPkg(info);
       
   159 
       
   160 	iMmPhone.GetPhoneStoreInfo(stat,infoPkg,aPhoneBook);
       
   161 	User::WaitForRequest(stat);
       
   162 	if (stat == KErrNone)	// available
       
   163 		{
       
   164 		INFO_PRINTF2(_L("%S Phone Book is available.\n"), &aPhoneBook);
       
   165 		aCount++;
       
   166 		}
       
   167 	else
       
   168 		{
       
   169 		INFO_PRINTF3(_L("%S Phone Book is NOT available. Status %d.\n"), &aPhoneBook, stat.Int());
       
   170 		}
       
   171 
       
   172 	return stat;
       
   173 	}
       
   174 
       
   175 void CTestDrivePhoneBook::testGetPhBkCapsAndInfoL()
       
   176 /**
       
   177  * This function:
       
   178  *		Gets the SIM and ME iPhone books static capabilities,
       
   179  *		Information associated with the iPhone books,
       
   180  *		and also Validates the obtained information.
       
   181  */
       
   182 	{
       
   183 	// SIM iPhone book - mandatory
       
   184 	TInt ret=KErrNone;
       
   185 	RMobilePhoneBookStore simPhBk;
       
   186 
       
   187 	ret=simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook);
       
   188 	TESTL(ret==KErrNone);
       
   189 
       
   190 	// Get SM Phone book Capabilities
       
   191 
       
   192 	TRequestStatus stat=0;
       
   193 	RMobilePhoneStore::TMobilePhoneStoreInfoV1 info;
       
   194 	RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg infoPkg(info);
       
   195 
       
   196 	simPhBk.GetInfo(stat,infoPkg);
       
   197 	User::WaitForRequest(stat);
       
   198 	TESTL(stat == KErrNone);
       
   199 	info = infoPkg();
       
   200 	
       
   201 	// Need to Read entries 
       
   202 
       
   203 	TESTL((info.iCaps & RMobilePhoneStore::KCapsWriteAccess)!=0);
       
   204 	TESTL(info.iName == KETelIccAdnPhoneBook);
       
   205 	TESTL(info.iType == RMobilePhoneStore::EPhoneBookStore); 
       
   206 	TESTL(info.iTotalEntries > 0);
       
   207 
       
   208 	simPhBk.Close();
       
   209 
       
   210 	
       
   211 	RMobilePhoneBookStore mePhBk;
       
   212 	ret=mePhBk.Open(iMmPhone,KETelMeAdnPhoneBook);
       
   213 	
       
   214 	if (ret==KErrNone)
       
   215 		{
       
   216 		INFO_PRINTF1(_L("ME phonebook supported\n"));
       
   217 		iMESupported=ETrue;
       
   218 
       
   219 		mePhBk.GetInfo(stat,infoPkg);
       
   220 		User::WaitForRequest(stat);
       
   221 		TESTL(stat == KErrNone);
       
   222 		info = infoPkg();
       
   223 		TESTL((info.iCaps & RMobilePhoneStore::KCapsWriteAccess)!=0);
       
   224 		
       
   225 		// Need to read entries
       
   226 		TESTL(info.iName == KETelMeAdnPhoneBook);
       
   227 		TESTL(info.iType == RMobilePhoneStore::EPhoneBookStore);
       
   228 		TESTL(info.iTotalEntries > 0);
       
   229 
       
   230 		// GetInfo Cancel Request
       
   231 		INFO_PRINTF1(_L("GetInfo Cancel Request..."));
       
   232 		mePhBk.GetInfo(stat,infoPkg);
       
   233 		mePhBk.CancelAsyncRequest(EMobilePhoneStoreGetInfo);
       
   234 		User::WaitForRequest(stat);
       
   235 		INFO_PRINTF2(_L("GetInfo Cancel Status = %d"), stat.Int());
       
   236 		TESTL(stat==KErrNone || stat==KErrCancel);
       
   237 	
       
   238 		mePhBk.Close();
       
   239 		}
       
   240 	else 
       
   241 		INFO_PRINTF1(_L("ME phonebook is NOT supported"));
       
   242 	}
       
   243 
       
   244 TInt CTestDrivePhoneBook::testClearPhBkL(const TDesC& aPhoneBookName)
       
   245 /**
       
   246  * This function deletes the first 5 entries in the SM and ME (if supported) phonebooks.
       
   247  */
       
   248 	{	
       
   249 	TInt ret=KErrNone;
       
   250 
       
   251 	RMobilePhoneBookStore thePhBk;
       
   252 	TRequestStatus stat;
       
   253 
       
   254 	// Open the SM iPhone book
       
   255 	ret=thePhBk.Open(iMmPhone,aPhoneBookName);
       
   256 	TESTL(ret==KErrNone);
       
   257 
       
   258 	INFO_PRINTF2(_L("Deleting %S phonebook entries..."), &aPhoneBookName);
       
   259 	TInt i;
       
   260 	for (i=1; i<=5; i++)
       
   261 		{
       
   262 	
       
   263 		thePhBk.Delete(stat,i);
       
   264 		User::WaitForRequest(stat);
       
   265 
       
   266 		if (stat!=KErrNone && stat!=KErrNotFound)
       
   267 			break;
       
   268 		}
       
   269 
       
   270 // Check that KErrNotFound is returned when reading an empty phonebook.
       
   271 	TBuf8<50> buf;
       
   272 	thePhBk.Read(stat,1,99,buf);
       
   273 	User::WaitForRequest(stat);
       
   274 	TESTL(stat==KErrNotFound);
       
   275 
       
   276 	thePhBk.Close();
       
   277 	return ret;
       
   278 	}
       
   279 
       
   280 void CTestDrivePhoneBook::ReadAndWriteL()
       
   281 /**
       
   282  * This function writes a few entries to the SM phonebook and then reads them back.
       
   283  */
       
   284 	{
       
   285 	TInt ret=KErrNone;
       
   286 	RMobilePhoneBookStore simPhBk;
       
   287 
       
   288 	// Open the SM iPhone book
       
   289 	ret=simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook);
       
   290 	TESTL(ret==KErrNone);
       
   291 	simPhBk.Close();
       
   292 	}
       
   293 
       
   294 void CTestDrivePhoneBook::testAdvancedPhBkL() 
       
   295 /**
       
   296  * This function opens an Advanced GSM ME PhoneBook, writes a few entries to it, and then
       
   297  * deletes these entries.
       
   298  */
       
   299 	{
       
   300 	TInt ret=KErrNone;
       
   301 	RMobilePhoneBookStore mePhBk;
       
   302 	ret=mePhBk.Open(iMmPhone,KETelMeAdnPhoneBook);
       
   303 	TESTL(ret==KErrNone);
       
   304 
       
   305 	mePhBk.Close();
       
   306 	}
       
   307 
       
   308  void CTestDrivePhoneBook::testPhBkNotificationsL()
       
   309 /**
       
   310  * This function opens the ME phonebook and posts a request for notification when an 
       
   311  * entry is modified.
       
   312  */
       
   313 	{
       
   314 	RMobilePhoneBookStore mePhBk;
       
   315 	const TInt Pause=2000000;		// 2 second pause
       
   316 	TRequestStatus writeStatus = KErrNone;
       
   317 
       
   318 	TESTL(mePhBk.Open(iMmPhone,KETelMeAdnPhoneBook)==KErrNone);
       
   319 
       
   320 	TRequestStatus status;
       
   321 	TInt index=KErrNone;
       
   322 	TUint32 eventChange;
       
   323 
       
   324 	// Post a notification request
       
   325 	//mePhBk.EntryChangedNotification(status,index);
       
   326 	mePhBk.NotifyStoreEvent(status,eventChange,index);
       
   327 
       
   328 	if (writeStatus==KErrCancel)
       
   329 		{
       
   330 		INFO_PRINTF1(_L("This is unexpected!!!. If the test carries on, this means that\n"));
       
   331 		INFO_PRINTF1(_L("the Write request has been transmitted to the iPhone regardless of\n"));		
       
   332 		INFO_PRINTF1(_L("of the apparent success of the Write cancel request.\n\n"));
       
   333 		}
       
   334 	else
       
   335 		TESTL(writeStatus==KErrNone);	// The Cancel request was not successful
       
   336 
       
   337 	// Completion of the notification request posted earlier
       
   338 	User::WaitForRequest(status);
       
   339 	TESTL(status==KErrNone);
       
   340 	TESTL(index==1);
       
   341 
       
   342 	// Post another notification request
       
   343 	mePhBk.NotifyStoreEvent(status,eventChange,index);
       
   344 	
       
   345 	// Delete and DeleteCancel Request. Wait 2 seconds before posting the Cancel request.
       
   346 	// Enables the request to get through to the TSY (simplifies the script).
       
   347 	INFO_PRINTF1(_L("Delete Cancel Request..."));
       
   348 	TRequestStatus deleteStatus;
       
   349 	mePhBk.Delete(deleteStatus,index);
       
   350 	User::After(Pause);		// Wait 2s, give the request time to get through to the TSY.
       
   351 	mePhBk.CancelAsyncRequest(EMobilePhoneStoreDelete);
       
   352 	User::WaitForRequest(deleteStatus);
       
   353 	INFO_PRINTF2(_L("Delete Cancel Status = %d"), deleteStatus.Int());
       
   354 
       
   355 	if (deleteStatus==KErrCancel)
       
   356 		{
       
   357 		INFO_PRINTF1(_L("This is unexpected!!!. If the test carries on, this means that"));
       
   358 		INFO_PRINTF1(_L("the Delete request has been transmitted to the iPhone regardless"));
       
   359 		INFO_PRINTF1(_L("of the apparent success of the Delete cancel request."));
       
   360 		}
       
   361 	else
       
   362 		{
       
   363 		TESTL(deleteStatus==KErrNone);	// The Cancel request was not successful
       
   364 		}
       
   365 
       
   366 	// Completion of the 2nd notification request posted, (dependent on the Delete request above)
       
   367 	User::WaitForRequest(status);
       
   368 	TESTL(status==KErrNone);
       
   369 	TESTL(index==1);
       
   370 
       
   371 	// EntryChangedNotificationCancel Request
       
   372 	mePhBk.NotifyStoreEvent(status,eventChange,index);
       
   373 	mePhBk.CancelAsyncRequest(EMobilePhoneStoreNotifyStoreEvent);
       
   374 	User::WaitForRequest(status);
       
   375 
       
   376 	TESTL(status==KErrCancel || status==KErrNone);
       
   377 	INFO_PRINTF2(_L("EntryChangedNotificationCancel Status = %d"), status.Int());
       
   378 
       
   379 	mePhBk.Close();
       
   380 	}		
       
   381 
       
   382 
       
   383 void CTestDrivePhoneBook::testPhBkReadCancelL()
       
   384 /**
       
   385  * This function writes a few entries to the SM phonebook, and then does some Read Requests
       
   386  * which are cancelled.
       
   387  */
       
   388 	{
       
   389 	TInt ret=KErrNone;
       
   390 	RMobilePhoneBookStore simPhBk;
       
   391 
       
   392 	// Open the SM iPhone book
       
   393 	ret=simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook);
       
   394 	TESTL(ret==KErrNone);
       
   395 
       
   396 	// Close the iPhone book
       
   397 	simPhBk.Close();
       
   398 	}
       
   399 
       
   400 
       
   401 
       
   402 //****************************************************************************
       
   403 //						NEW Methods based on CPhoneBookBuffer class
       
   404 //****************************************************************************
       
   405 
       
   406 // testing the PhoneBook ReadAndWrite
       
   407 
       
   408 void CTestDrivePhoneBook::testPhoneBookReadAndWrite()
       
   409 	{
       
   410 	TRAP_IGNORE(DotestPhoneBookReadAndWriteL());		// trap but ignore error
       
   411 	}
       
   412 
       
   413 void CTestDrivePhoneBook::DotestPhoneBookReadAndWriteL()
       
   414 	{
       
   415 	TInt ret=KErrNone;
       
   416 	TRequestStatus aStatus;
       
   417 	RMobilePhoneBookStore simPhBk;
       
   418 
       
   419 	TBuf8<(RMobileSmsMessaging::KGsmTpduSize*3)> pbData, pbReadData1;
       
   420 	TInt requestedIndex(0), numOfEntries(1);
       
   421 
       
   422 	TESTL(simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook()) == KErrNone);
       
   423 
       
   424 	const TText16* names[]={(TText16*)KMuddyWatersText.iBuf, (TText16*)KArethaFText.iBuf};
       
   425 	const TText16* numbers[]={(TText16*)KMuddyWatersPhoneNum.iBuf, (TText16*)KArethaFPhoneNum.iBuf};
       
   426 
       
   427 	const TInt KBufSize=20;
       
   428 
       
   429 	TBuf16<KBufSize> entryNumber(numbers[0]);
       
   430 	TBuf16<KBufSize> entryName(names[0]);
       
   431 
       
   432 	CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer();
       
   433 	pbBuffer->Set(&pbData); // Set it to point to the Client buffer
       
   434 
       
   435 	// Write the entries to the SIM Phone Book
       
   436 	TInt writeIndex(0);
       
   437 	TUint i(0), size(2); // Only entries are written
       
   438 
       
   439 	for (i=1; i<=size; ++i)
       
   440 		{
       
   441 		//first reset the following three local buffers to delete any existing data
       
   442 		entryNumber.FillZ();
       
   443 		entryNumber.Zero();
       
   444 		entryName.FillZ();
       
   445 		entryName.Zero();
       
   446 		pbData.FillZ();
       
   447 		pbData.Zero();
       
   448 
       
   449 		entryNumber=numbers[i-1];
       
   450 		entryName=names[i-1];
       
   451 
       
   452 		// First specify starting index and set iNumofEntries to 1, since it is only
       
   453 		// possible to write one entry at a time
       
   454 
       
   455 		writeIndex = i; // Note that TSY will overwrite any existing data. It is up to
       
   456 						// the Sync to check whether it is the first available entry
       
   457 
       
   458 		// convert number into TLV format and append it to allocated buffer
       
   459 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber, entryNumber);
       
   460 		TESTL(ret == KErrNone) ;
       
   461 
       
   462 		// convert type into TLV format and append it to allocated buffer
       
   463  		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi, (TUint8)129/****RMobilePhone::EUnknownNumber***/);
       
   464  		TESTL(ret == KErrNone) ;
       
   465 
       
   466 		// convert text into TLV format and append it to allocated buffer
       
   467 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText, entryName);
       
   468 		TESTL(ret == KErrNone) ;
       
   469 
       
   470 		simPhBk.Write(aStatus,pbData,writeIndex);
       
   471 		User::WaitForRequest(aStatus);
       
   472 		TESTL(aStatus==KErrNone);
       
   473 		}
       
   474 
       
   475 		/* Read the entries back */
       
   476 		TPtrC16 number(NULL,0);
       
   477 		TPtrC16 text(NULL,0);
       
   478 
       
   479 		TUint8 aTagValue(0);
       
   480 		CPhoneBookBuffer::TPhBkTagType aDataType;
       
   481 		TPtrC16 field(NULL,0);
       
   482 		TInt counter(0);
       
   483 
       
   484 		/* Reads Forwards and to read all entries individually */
       
   485 		for(i=1; i<=size; ++i)
       
   486 			{
       
   487 			//first reset the following three local buffers to delete any existing data
       
   488 			entryNumber.FillZ();
       
   489 			entryNumber.Zero();
       
   490 			entryName.FillZ();
       
   491 			entryName.Zero();
       
   492 			pbData.FillZ();
       
   493 			pbData.Zero();
       
   494 
       
   495 			// reset all loop variables
       
   496 			counter = 0;
       
   497 			aTagValue = 0;
       
   498 
       
   499 			requestedIndex = i;
       
   500 			simPhBk.Read(aStatus, requestedIndex, numOfEntries, pbReadData1);
       
   501 			User::WaitForRequest(aStatus);
       
   502 			TESTL(aStatus.Int()== KErrNone) ;
       
   503 
       
   504 			entryNumber=numbers[i-1];
       
   505 			entryName=names[i-1];
       
   506 
       
   507 			// now decode PB data received in TLV format
       
   508 			pbBuffer->Set(&pbReadData1); // Set pbBuffer to point to received phonebook data
       
   509 			pbBuffer->StartRead();       // Start reading received phonebook data
       
   510 			while(counter < pbReadData1.Length())
       
   511 				{
       
   512 				TInt ret = pbBuffer->GetTagAndType(aTagValue, aDataType);
       
   513 				if(ret==KErrNotFound) // Reached the end of phonebook data
       
   514 					break;
       
   515 				TESTL(ret == KErrNone) ;
       
   516 				switch(aDataType)
       
   517 					{
       
   518 				case CPhoneBookBuffer::EPhBkTypeInt8:
       
   519 					{
       
   520 					TUint8 int8(0);
       
   521 					counter = counter + 1; // add tag-field only in case that is beginning of new field
       
   522 					if(aTagValue == RMobilePhoneBookStore::ETagPBAdnIndex)
       
   523 						{
       
   524 						pbBuffer->GetValue(int8); //
       
   525 						counter = counter + 1; // 1-byte integer
       
   526 						}
       
   527 					}
       
   528 					break;
       
   529 
       
   530 				case CPhoneBookBuffer::EPhBkTypeInt16:
       
   531 					{
       
   532 					TUint16 int16(0);
       
   533 					pbBuffer->GetValue(int16);
       
   534 					counter = counter + 3; // 2-byte integer + tag-field
       
   535 					if(aTagValue == RMobilePhoneBookStore::ETagPBTonNpi)
       
   536 						{
       
   537 						}
       
   538 					}
       
   539 					break;
       
   540 
       
   541 				case CPhoneBookBuffer::EPhBkTypeInt32:
       
   542 					{
       
   543 					TUint32 int32(0);
       
   544 					pbBuffer->GetValue(int32);
       
   545 					counter = counter + 5; // 4-byte integer + tag-field
       
   546 					}
       
   547 					break;
       
   548 
       
   549 		 
       
   550 				case CPhoneBookBuffer::EPhBkTypeDes8:
       
   551 					{
       
   552 					pbBuffer->GetValue(field);
       
   553 					counter = counter + field.Length() + 1; // add desc length + length-field + tag-field
       
   554 					if(aTagValue == RMobilePhoneBookStore::ETagPBText)
       
   555 						{
       
   556 						text.Set(field);
       
   557 						}
       
   558 					else if(aTagValue == RMobilePhoneBookStore::ETagPBNumber)
       
   559 						{
       
   560 						number.Set(field);
       
   561 						}
       
   562 					}
       
   563 					break;
       
   564 
       
   565 				case CPhoneBookBuffer::EPhBkTypeDes16:
       
   566 					{
       
   567 					pbBuffer->GetValue(field);
       
   568 					counter = counter + field.Length() + 3; // add desc length + length-field + tag-field
       
   569 					if(aTagValue == RMobilePhoneBookStore::ETagPBText)
       
   570 						{
       
   571 						text.Set(field);
       
   572 						}
       
   573 					else if(aTagValue == RMobilePhoneBookStore::ETagPBNumber)
       
   574 						{
       
   575 						number.Set(field);
       
   576 						}
       
   577 					}
       
   578 					break;
       
   579  
       
   580 				default:
       
   581 					break;
       
   582 					} // end switch aDataType
       
   583 
       
   584 				} // end while
       
   585 
       
   586 			TBuf<128> pName;
       
   587 			TBuf<128> pNumber;
       
   588 
       
   589 			pName = text;
       
   590 			pNumber = number;
       
   591 
       
   592 			INFO_PRINTF2(_L("Reading \'%S\'"),&pName);
       
   593 			INFO_PRINTF2(_L("Reading \'%S\'\n"),&pNumber);
       
   594 
       
   595 			   
       
   596 		} // end for
       
   597 
       
   598 		simPhBk.Close();
       
   599 		delete pbBuffer;
       
   600 }
       
   601 
       
   602 
       
   603 // testing Advanced Phone book Read Write
       
   604 
       
   605 void CTestDrivePhoneBook::testAdvancedPhoneBook() 
       
   606 	{
       
   607 	TRAP_IGNORE(DotestAdvancedPhoneBookL());		// trap but ignore error
       
   608 	}
       
   609 
       
   610 void CTestDrivePhoneBook::DotestAdvancedPhoneBookL() 
       
   611 	{
       
   612 	/**
       
   613 	 * This function opens an Advanced GSM ME PhoneBook, writes a few entries to it, and then
       
   614 	 * deletes these entries.
       
   615 	 */
       
   616 	const TInt KFillTo=2;
       
   617 
       
   618 	TInt ret=KErrNone;
       
   619 	TRequestStatus aStatus;
       
   620 	RMobilePhoneBookStore::TMobilePhoneBookInfoV1 aPhoneStoreInfob;
       
   621 	RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg aPhoneStoreInfoPckgb(aPhoneStoreInfob);
       
   622 	RMobilePhoneBookStore simPhBk;
       
   623 
       
   624 	TBuf8<(RMobileSmsMessaging::KGsmTpduSize*3)> pbData; // Client reserved space for phonebook data
       
   625 
       
   626 	_LIT(KTel,"0123456789%02d");
       
   627 	_LIT(KText,"Tel %02d");
       
   628 	TBuf<15> text(KTel), number(KText);
       
   629 	TInt index(1);
       
   630 
       
   631 	TESTL(simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook()) == KErrNone);
       
   632 	
       
   633 
       
   634 	// Write the entries
       
   635 	INFO_PRINTF1(_L("\nFill the 1st 30 locations in the SIM phonebook..."));
       
   636 	simPhBk.GetInfo(aStatus, aPhoneStoreInfoPckgb);
       
   637 	User::WaitForRequest(aStatus);
       
   638 	TESTL(aStatus.Int()== KErrNone) ;
       
   639 	aPhoneStoreInfob = aPhoneStoreInfoPckgb();
       
   640 	TESTL(aPhoneStoreInfob.iTotalEntries>0);
       
   641 	TInt used=aPhoneStoreInfob.iUsedEntries ;
       
   642 
       
   643 	CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer(); // used to write phonebook data
       
   644 	pbBuffer->Set(&pbData); // Set it to point to the Client buffer
       
   645 
       
   646 	// Fields supported by this phonebook are returned to client as capabilities
       
   647 	// in aPhoneStoreInfoPckgb. It is assumed that all GSM phonebook fields (index, tel num,
       
   648 	// type and name) are supported even though that part of the code has to be tested as well.
       
   649 
       
   650 	while (used<KFillTo)
       
   651 		{
       
   652 		// First specify starting index and set iNumofEntries to 1, since it is only
       
   653 		// possible to write one entry at a time
       
   654 
       
   655 		number.FillZ(); // Reset previous values
       
   656 		number.Zero();
       
   657 		text.FillZ();
       
   658 		text.Zero();
       
   659 		pbData.FillZ();
       
   660 		pbData.Zero();
       
   661 
       
   662 		// convert number into TLV format and append it to allocated buffer
       
   663 		number.Format(KTel(), index);
       
   664 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber, number);
       
   665 		TESTL(ret == KErrNone) ;
       
   666 
       
   667 		// convert number type into TLV format and append it to allocated buffer
       
   668 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi, (TUint8)129);
       
   669 		TESTL(ret == KErrNone) ;
       
   670 
       
   671 		text.Format(KText(), index);
       
   672 		INFO_PRINTF2(_L("Writing \'%S\'\n"),&text);
       
   673 		// convert text into TLV format and append it to allocated buffer
       
   674 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText, text);
       
   675 		TESTL(ret == KErrNone) ;
       
   676 
       
   677 		simPhBk.Write(aStatus, pbData,index);
       
   678 		User::WaitForRequest(aStatus);
       
   679 		TESTL(aStatus.Int()== KErrNone);
       
   680 		used++;
       
   681 		index++;
       
   682 		} // end while
       
   683 
       
   684 	simPhBk.Close();
       
   685 	delete pbBuffer;
       
   686 
       
   687 	// Delete the entries //
       
   688 	INFO_PRINTF1(_L("Re-opening phonebook...")) ;
       
   689 	
       
   690 	TESTL(simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook()) == KErrNone);
       
   691 	
       
   692 	simPhBk.GetInfo(aStatus, aPhoneStoreInfoPckgb);
       
   693 	User::WaitForRequest(aStatus);
       
   694 	TESTL(aStatus.Int()== KErrNone);
       
   695 	aPhoneStoreInfob = aPhoneStoreInfoPckgb();
       
   696 	INFO_PRINTF1(_L("Deleting the entries...")); 
       
   697 	for (int iy=1;iy<=KFillTo;++iy)
       
   698 		{
       
   699 		INFO_PRINTF2(_L("Deleting %03d\n"),iy);
       
   700 		simPhBk.Delete(aStatus, iy);
       
   701 		User::WaitForRequest(aStatus);
       
   702 		TESTL(aStatus.Int()== KErrNone );
       
   703 		}
       
   704 
       
   705 	simPhBk.Close();
       
   706 
       
   707 	}
       
   708 
       
   709 
       
   710 
       
   711 // testing PhoneBook Notifications 
       
   712 
       
   713 void CTestDrivePhoneBook::testPhoneBookNotifications()
       
   714 	{
       
   715 	TRAP_IGNORE(DotestPhoneBookNotificationsL());		// trap but ignore erorr
       
   716 	}
       
   717 
       
   718 void CTestDrivePhoneBook::DotestPhoneBookNotificationsL()
       
   719 	{
       
   720 
       
   721 	/**
       
   722 	 * This function opens the ME phonebook and posts a request for notification when an 
       
   723 	 * entry is modified.
       
   724 	 */
       
   725 	RMobilePhoneBookStore simPhBk;//, combPhBk;
       
   726 	TBuf8<(RMobileSmsMessaging::KGsmTpduSize*3)> pbData; // Client reserved space for phonebook data
       
   727 	TInt index(0), ret(0);
       
   728 
       
   729 	CPhoneBookBuffer* pbBuffer=new(ELeave) CPhoneBookBuffer(); // used to read/write phonebook entries
       
   730 	pbBuffer->Set(&pbData); // Set it to point to the Client buffer
       
   731 
       
   732 	TESTL(simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook)==KErrNone);
       
   733 
       
   734 	TRequestStatus aStatus, status1;//, status2;
       
   735 	TInt index1 = 0;
       
   736 	TUint32 eventToReturn;
       
   737 	simPhBk.NotifyStoreEvent(status1, eventToReturn,index1);	// Will Notify if an entry is added
       
   738 
       
   739 	index = 1; // write to the first slot
       
   740 	// convert number into TLV format and append it to allocated buffer
       
   741 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber, KMuddyWatersPhoneNum);
       
   742 	TESTL(ret == KErrNone) ;
       
   743 
       
   744 	// convert number type into TLV format and append it to allocated buffer
       
   745 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi,(TUint8)129);
       
   746 	TESTL(ret == KErrNone) ;
       
   747 
       
   748 	// convert text into TLV format and append it to allocated buffer
       
   749 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText, KMuddyWatersText);
       
   750 	TESTL(ret == KErrNone) ;
       
   751 
       
   752 	simPhBk.Write(aStatus,pbData,index);
       
   753 	User::WaitForRequest(aStatus); // Write request
       
   754 	TESTL(aStatus.Int()== KErrNone) ;
       
   755 
       
   756 	User::WaitForRequest(status1); // Notification
       
   757 	TEST(status1==KErrNotSupported);
       
   758 	if (status1==KErrNotSupported)
       
   759 		{
       
   760 		// Notification is not supported by phonebook store - as expected
       
   761 		INFO_PRINTF1(_L("Phonebook Store Write Notification is NOT Supported - as expected\n"));
       
   762 		}
       
   763 	else
       
   764 		{
       
   765 		// This should not happen since this notification is not supported by phonebook store
       
   766 		INFO_PRINTF1(_L("Phonebook Store Write Notification IS Supported - not expected\n"));
       
   767 		}
       
   768 
       
   769 
       
   770 	status1= KErrNone; // reset status variable
       
   771 	simPhBk.NotifyStoreEvent(status1, eventToReturn, index1);
       
   772 
       
   773 	// Now delete that entry
       
   774 	simPhBk.Delete(aStatus, 1);
       
   775 	User::WaitForRequest(aStatus);
       
   776 	TESTL(aStatus.Int()== KErrNone);
       
   777 
       
   778 	User::WaitForRequest(status1);
       
   779 	TEST(status1==KErrNotSupported);
       
   780 	if (status1==KErrNotSupported)
       
   781 		{
       
   782 		// Notification is not supported by phonebook store - as expected
       
   783 		INFO_PRINTF1(_L("Phonebook Store Delete Notification is NOT Supported - as expected\n"));
       
   784 		}
       
   785 	else
       
   786 		{
       
   787 		// This should not happen since this notification is not supported by phonebook store
       
   788 		INFO_PRINTF1(_L("Phonebook Store Delete Notification IS Supported - not expected\n"));
       
   789 		}
       
   790 
       
   791 	
       
   792 	// EntryChangedNotificationCancel Request
       
   793 	status1= KErrNone; // reset status variable
       
   794 	simPhBk.NotifyStoreEvent(status1, eventToReturn, index1);
       
   795 	simPhBk.CancelAsyncRequest(EMobilePhoneStoreNotifyStoreEvent);
       
   796 	User::WaitForRequest(status1);
       
   797 
       
   798 	TEST(status1==KErrNotSupported);
       
   799 	if (status1==KErrNotSupported)
       
   800 		{
       
   801 		// Notification is not supported by phonebook store - as expected
       
   802 		INFO_PRINTF1(_L("Phonebook Store Notification is NOT Supported - as expected\n"));
       
   803 		}
       
   804 	else
       
   805 		{
       
   806 		// This should not happen since this notification is not supported by phonebook store
       
   807 		INFO_PRINTF1(_L("Phonebook Store Notification cancelled - not expected\n"));
       
   808 		}
       
   809 
       
   810 	// Cancel Notification Request after 2 seconds
       
   811 	status1= KErrNone; // reset status variable
       
   812 	simPhBk.NotifyStoreEvent(status1, eventToReturn, index1);
       
   813 
       
   814 	// Now write the same entry again
       
   815 	simPhBk.Write(aStatus,pbData, index);
       
   816 	User::WaitForRequest(aStatus);
       
   817 	TESTL(aStatus.Int()==KErrNone) ;
       
   818 
       
   819 	User::After(2000000L);
       
   820 	simPhBk.CancelAsyncRequest(EMobilePhoneStoreNotifyStoreEvent);
       
   821 	User::WaitForRequest(status1);
       
   822 
       
   823 	INFO_PRINTF2(_L("Cancel Status = %d\n"), status1.Int());
       
   824 
       
   825 	TESTL(status1==KErrCancel || status1==KErrNotSupported || status1==KErrNone);
       
   826 
       
   827 	simPhBk.Delete(aStatus, 1); // Deleting the last added entry so that the test ends "clean".
       
   828 	User::WaitForRequest(aStatus);
       
   829 
       
   830 	simPhBk.Close();
       
   831 
       
   832 	delete pbBuffer;
       
   833 
       
   834 	}
       
   835 
       
   836 
       
   837 
       
   838 // Testing Phonebook Read cancel
       
   839 
       
   840 void CTestDrivePhoneBook::testPhoneBookReadCancel()
       
   841 	{
       
   842 	TRAP_IGNORE(DotestPhoneBookReadCancelL());		// trap but ignore error
       
   843 	}
       
   844 
       
   845 void CTestDrivePhoneBook::DotestPhoneBookReadCancelL()
       
   846 	{
       
   847 
       
   848 	/**
       
   849 	 * This function writes a few entries to the SM phonebook, and then does some Read Requests
       
   850 	 * which are cancelled.
       
   851 	 */
       
   852 
       
   853 	TInt ret=KErrNone;
       
   854 	TRequestStatus aStatus;
       
   855 	RMobilePhoneBookStore simPhBk;
       
   856 
       
   857 	TBuf8<(RMobileSmsMessaging::KGsmTpduSize*3)> pbData, pbReadData1;//, pbReadData2, pbReadEmpty; // Client reserved space for phonebook data
       
   858 	TInt requestedIndex(0), numOfEntries(1);
       
   859 
       
   860 	TESTL(simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook()) == KErrNone);
       
   861 
       
   862 	const TText16* names[]={(TText16*)KMuddyWatersText.iBuf, (TText16*)KArethaFText.iBuf};
       
   863 	const TText16* numbers[]={(TText16*)KMuddyWatersPhoneNum.iBuf, (TText16*)KArethaFPhoneNum.iBuf};
       
   864 
       
   865 
       
   866 	const TInt KBufSize=20;
       
   867 
       
   868 	TBuf16<KBufSize> entryNumber(numbers[0]);
       
   869 	TBuf16<KBufSize> entryName(names[0]);
       
   870 
       
   871 	CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer();
       
   872 	pbBuffer->Set(&pbData); // Set it to point to the Client buffer
       
   873 
       
   874 	// Write the entries to the SIM Phone Book
       
   875 	TInt writeIndex(0);
       
   876 	TUint i(0), size(2);
       
   877 
       
   878 	for (i=1; i<=size; ++i)
       
   879 		{
       
   880 		//first reset the following three local buffers to delete any existing data
       
   881 		entryNumber.FillZ();
       
   882 		entryNumber.Zero();
       
   883 		entryName.FillZ();
       
   884 		entryName.Zero();
       
   885 		pbData.FillZ();
       
   886 		pbData.Zero();
       
   887 
       
   888 		entryNumber=numbers[i-1];
       
   889 		entryName=names[i-1];
       
   890 
       
   891 		// First specify starting index and set iNumofEntries to 1, since it is only
       
   892 		// possible to write one entry at a time
       
   893 
       
   894 		writeIndex = i; // Note that TSY will overwrite any existing data. It is up to
       
   895 						// the Sync to check whether it is the first available entry
       
   896 
       
   897 		// convert number into TLV format and append it to allocated buffer
       
   898 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber, entryNumber);
       
   899 		TESTL(ret == KErrNone) ;
       
   900 
       
   901 		// convert type into TLV format and append it to allocated buffer
       
   902 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi, (TUint8)129);
       
   903 		TESTL(ret == KErrNone) ;
       
   904 
       
   905 		// convert text into TLV format and append it to allocated buffer
       
   906 		ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText, entryName);
       
   907 		TESTL(ret == KErrNone) ;
       
   908 
       
   909 		simPhBk.Write(aStatus,pbData,writeIndex);
       
   910 		User::WaitForRequest(aStatus);
       
   911 		TESTL(aStatus==KErrNone);
       
   912 		}
       
   913 
       
   914 		/* Read the entries back */
       
   915 		TPtrC16 number(NULL,0);
       
   916 		TPtrC16 text(NULL,0);
       
   917 
       
   918 		TUint8 aTagValue(0);
       
   919 		CPhoneBookBuffer::TPhBkTagType aDataType;
       
   920 		TPtrC16 field(NULL,0);
       
   921 		TInt counter(0);
       
   922 
       
   923 		/* Reads 1 entry */
       
   924 		
       
   925 		//first reset the following three local buffers to delete any existing data
       
   926 		entryNumber.FillZ();
       
   927 		entryNumber.Zero();
       
   928 		entryName.FillZ();
       
   929 		entryName.Zero();
       
   930 		pbData.FillZ();
       
   931 		pbData.Zero();
       
   932 
       
   933 		// reset all loop variables
       
   934 		counter = 0;
       
   935 		aTagValue = 0;
       
   936 
       
   937 
       
   938 		requestedIndex = 1;
       
   939 		simPhBk.Read(aStatus, requestedIndex, numOfEntries, pbReadData1);
       
   940  
       
   941 		// Cancel the Read
       
   942 		simPhBk.CancelAsyncRequest(EMobilePhoneBookStoreRead);
       
   943 		User::WaitForRequest(aStatus);
       
   944 		INFO_PRINTF2(_L("Read First Entry Cancel Status = %d\n\n"), aStatus.Int());
       
   945 
       
   946 		// If the request was successfully cancelled, then do read the first entry, 'want 
       
   947 		// the phonebook pointer to point to a valid entry for the ReadNext() operation.
       
   948 		TESTL(aStatus == KErrCancel || aStatus == KErrNone);
       
   949 		if (aStatus==KErrCancel)
       
   950 			{
       
   951 			INFO_PRINTF1(_L("Read First Entry Cancel Successful. Read First Entry Again.\n"));
       
   952 			simPhBk.Read(aStatus, requestedIndex, 1, pbReadData1);
       
   953 			User::WaitForRequest(aStatus);
       
   954 			TESTL(aStatus==KErrNone);
       
   955 			}
       
   956 
       
   957 			// reset all loop variables
       
   958 			counter = 0;
       
   959 			aTagValue = 0;
       
   960 
       
   961 			// now decode PB data received in TLV format
       
   962 			pbBuffer->Set(&pbReadData1); // Set pbBuffer to point to received phonebook data
       
   963 			pbBuffer->StartRead();       // Start reading received phonebook data
       
   964 			while(counter < pbReadData1.Length())
       
   965 				{
       
   966 				TInt ret = pbBuffer->GetTagAndType(aTagValue, aDataType);
       
   967 				if(ret==KErrNotFound) // Reached the end of phonebook data
       
   968 					break;
       
   969 				TESTL(ret == KErrNone) ;
       
   970 				switch(aDataType)
       
   971 					{
       
   972 				case CPhoneBookBuffer::EPhBkTypeInt8:
       
   973 					{
       
   974 					TUint8 int8(0);
       
   975 					counter = counter + 1; // add tag-field only in case that is beginning of new field
       
   976 					if(aTagValue == RMobilePhoneBookStore::ETagPBAdnIndex)
       
   977 						{
       
   978 						pbBuffer->GetValue(int8); //
       
   979 						counter = counter + 1; // 1-byte integer
       
   980 						}
       
   981 					}
       
   982 					break;
       
   983 
       
   984 				case CPhoneBookBuffer::EPhBkTypeInt16:
       
   985 					{
       
   986 					TUint16 int16(0);
       
   987 					pbBuffer->GetValue(int16);
       
   988 					counter = counter + 3; // 2-byte integer + tag-field
       
   989 					if(aTagValue == RMobilePhoneBookStore::ETagPBTonNpi)
       
   990 						{
       
   991 						}
       
   992 					}
       
   993 					break;
       
   994 
       
   995 				case CPhoneBookBuffer::EPhBkTypeInt32:
       
   996 					{
       
   997 					TUint32 int32(0);
       
   998 					pbBuffer->GetValue(int32);
       
   999 					counter = counter + 5; // 4-byte integer + tag-field
       
  1000 					}
       
  1001 					break;
       
  1002  
       
  1003 			 	case CPhoneBookBuffer::EPhBkTypeDes8:
       
  1004 					{
       
  1005 					pbBuffer->GetValue(field);
       
  1006 					counter = counter + field.Length() + 1; // add desc length + length-field + tag-field
       
  1007 					if(aTagValue == RMobilePhoneBookStore::ETagPBText)
       
  1008 						{
       
  1009 						text.Set(field);
       
  1010 						}
       
  1011 					else if(aTagValue == RMobilePhoneBookStore::ETagPBNumber)
       
  1012 						{
       
  1013 						number.Set(field);
       
  1014 						}
       
  1015 					}
       
  1016 					break;
       
  1017 
       
  1018 				case CPhoneBookBuffer::EPhBkTypeDes16:
       
  1019 					{
       
  1020 					pbBuffer->GetValue(field);
       
  1021 					counter = counter + field.Length() + 3; // add desc length + length-field + tag-field
       
  1022 					if(aTagValue == RMobilePhoneBookStore::ETagPBText)
       
  1023 						{
       
  1024 						text.Set(field);
       
  1025 						}
       
  1026 					else if(aTagValue == RMobilePhoneBookStore::ETagPBNumber)
       
  1027 						{
       
  1028 						number.Set(field);
       
  1029 						}
       
  1030 					}
       
  1031 					break;
       
  1032  
       
  1033 				default:
       
  1034 					break;
       
  1035 					} // end switch aDataType
       
  1036 
       
  1037 				} // end while
       
  1038 
       
  1039 
       
  1040 		TBuf<128> pName;
       
  1041 		TBuf<128> pNumber;
       
  1042 
       
  1043 		pName = text;
       
  1044 		pNumber = number;
       
  1045 
       
  1046 
       
  1047 		INFO_PRINTF2(_L("Reading  \'%S\'"),&pName);
       
  1048 		INFO_PRINTF2(_L("Reading \'%S\'\n"),&pNumber);
       
  1049 		
       
  1050 	simPhBk.Close();
       
  1051 	delete pbBuffer;
       
  1052 	}
       
  1053 
       
  1054 void CTestDrivePhoneBook::testPhoneBookReadAndWriteInternationalL()
       
  1055 	{
       
  1056 	TInt ret=KErrNone;
       
  1057 	TRequestStatus status;
       
  1058 	RMobilePhoneBookStore simPhBk;
       
  1059 
       
  1060 	TBuf8<200> writeBuf,readBuf;
       
  1061 	_LIT(KInterNum1,"441234");
       
  1062 	_LIT(KInterName1,"ABCD");
       
  1063 	_LIT(KInterNum2,"445678");
       
  1064 	_LIT(KInterName2,"EFGH");
       
  1065 
       
  1066 	TESTL(simPhBk.Open(iMmPhone,KETelIccAdnPhoneBook()) == KErrNone);
       
  1067 
       
  1068 	/* Write entries */
       
  1069 	CPhoneBookBuffer* pbBuffer=NULL;
       
  1070 	TRAP_IGNORE(pbBuffer = new(ELeave) CPhoneBookBuffer());		// TRAP but ignore error
       
  1071 	TESTL(pbBuffer!=NULL);
       
  1072 
       
  1073 	pbBuffer->Set(&writeBuf); // Set it to point to the Client buffer
       
  1074 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber, KInterNum1);
       
  1075 	TESTL(ret == KErrNone) ;
       
  1076  	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi, (TUint8)145);
       
  1077  	TESTL(ret == KErrNone) ;
       
  1078 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText, KInterName1);
       
  1079 	TESTL(ret == KErrNone) ;
       
  1080 
       
  1081 	TInt writeIndex=1;
       
  1082 	simPhBk.Write(status,writeBuf,writeIndex);
       
  1083 	User::WaitForRequest(status);
       
  1084 	TESTL(status==KErrNone);
       
  1085 
       
  1086 	pbBuffer->Set(&writeBuf); // Set it to point to the Client buffer
       
  1087 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber, KInterNum2);
       
  1088 	TESTL(ret == KErrNone) ;
       
  1089  	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi, (TUint8)145);
       
  1090  	TESTL(ret == KErrNone) ;
       
  1091 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText, KInterName2);
       
  1092 	TESTL(ret == KErrNone) ;
       
  1093 
       
  1094 	writeIndex=2;
       
  1095 	simPhBk.Write(status,writeBuf,writeIndex);
       
  1096 	User::WaitForRequest(status);
       
  1097 	TESTL(status==KErrNone);
       
  1098 
       
  1099 	/* Read the entries back */
       
  1100 	simPhBk.Read(status, 1, 2, readBuf);
       
  1101 	User::WaitForRequest(status);
       
  1102 	TESTL(status.Int()==KErrNone);
       
  1103 
       
  1104 	TInt index=0;
       
  1105 	pbBuffer->Set(&readBuf); // Set pbBuffer to point to received phonebook data
       
  1106 	pbBuffer->StartRead();       // Start reading received phonebook data
       
  1107 	for(;;)
       
  1108 		{
       
  1109 		TUint8 tagValue;
       
  1110 		CPhoneBookBuffer::TPhBkTagType dataType;
       
  1111 		ret=pbBuffer->GetTagAndType(tagValue,dataType);
       
  1112 		if(ret!=KErrNone)
       
  1113 			break;
       
  1114 		switch(tagValue)
       
  1115 			{
       
  1116 		case RMobilePhoneBookStore::ETagPBNewEntry:
       
  1117 			index++;
       
  1118 			break;
       
  1119 
       
  1120 		case RMobilePhoneBookStore::ETagPBAdnIndex:
       
  1121 				{
       
  1122 				TUint16 val;
       
  1123 				pbBuffer->GetValue(val);
       
  1124 				TESTL(val==index);
       
  1125 				}
       
  1126 			break;
       
  1127 
       
  1128 		case RMobilePhoneBookStore::ETagPBText:
       
  1129 				{
       
  1130 				TPtrC text;
       
  1131 				pbBuffer->GetValue(text);
       
  1132 				if(index==1)
       
  1133 				{
       
  1134 					TESTL(text==KInterName1);
       
  1135 				}
       
  1136 				else
       
  1137 				{
       
  1138 					TESTL(text==KInterName2);
       
  1139 				}
       
  1140 				}
       
  1141 			break;
       
  1142 
       
  1143 		case RMobilePhoneBookStore::ETagPBNumber:
       
  1144 				{
       
  1145 				TPtrC number;
       
  1146 				pbBuffer->GetValue(number);
       
  1147 				if(index==1)
       
  1148 				{
       
  1149 					TESTL(number==KInterNum1);
       
  1150 				}
       
  1151 				else
       
  1152 				{
       
  1153 					TESTL(number==KInterNum2);
       
  1154 				}
       
  1155 				}
       
  1156 			break;
       
  1157 
       
  1158 		case RMobilePhoneBookStore::ETagPBTonNpi:
       
  1159 				{
       
  1160 				TUint8 ton;
       
  1161 				pbBuffer->GetValue(ton);
       
  1162 				TESTL(ton==145);
       
  1163 				}
       
  1164 			break;
       
  1165 
       
  1166 		default:
       
  1167 			TESTL(KErrGeneral);
       
  1168 			break;
       
  1169 			}
       
  1170 		}
       
  1171 
       
  1172 	simPhBk.Close();
       
  1173 	delete pbBuffer;
       
  1174 	}
       
  1175 
       
  1176 void CTestDrivePhoneBook::testPhoneBookMultiWriteL()
       
  1177 	{
       
  1178 	_LIT(KThreadName,"MultiPhBkWriteTest%d");
       
  1179 	const TInt KStackSize=0x4000;
       
  1180 	const TInt KHeapSize=0x4000;
       
  1181 	const TInt KMaxHeapSize=0x8000;
       
  1182 	const TInt KNumThreads=2;
       
  1183 
       
  1184 	RThread thread[KNumThreads];
       
  1185 	TRequestStatus status[KNumThreads];
       
  1186 	TInt ret=KErrNone;
       
  1187 
       
  1188 	TInt i=0;
       
  1189 	for(i=0;i<KNumThreads;i++)
       
  1190 		{
       
  1191 		TName name;
       
  1192 		name.Format(KThreadName,i);
       
  1193 		ret=thread[i].Create(name,CTestDrivePhoneBook::ThreadFnWritePhoneBookEntry,KStackSize,KHeapSize,KMaxHeapSize,NULL);
       
  1194 		if(ret!=KErrNone)
       
  1195 			break;
       
  1196 		}
       
  1197 
       
  1198 	if(ret!=KErrNone)
       
  1199 		{
       
  1200 		for(i=0;i<KNumThreads;i++)
       
  1201 			thread[i].Close();
       
  1202 		TESTL(ret==KErrNone);
       
  1203 		return;
       
  1204 		}
       
  1205 
       
  1206 	for(i=0;i<KNumThreads;i++)
       
  1207 		thread[i].Logon(status[i]);
       
  1208 
       
  1209 	for(i=0;i<KNumThreads;i++)
       
  1210 		thread[i].Resume();
       
  1211 
       
  1212 	for(i=0;i<KNumThreads;i++)
       
  1213 		{
       
  1214 		User::WaitForRequest(status[i]);
       
  1215 		TESTL(status[i]==KErrNone);
       
  1216 		}
       
  1217 	}
       
  1218 
       
  1219 TInt CTestDrivePhoneBook::ThreadFnWritePhoneBookEntry(TAny*)
       
  1220 	{
       
  1221 	_LIT(KNum1,"12345678");
       
  1222 	_LIT(KName1,"ABCDEFGH");
       
  1223 	_LIT(KPhoneName,"GsmPhone1");
       
  1224 
       
  1225 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
  1226 	if(cleanup==NULL)
       
  1227 		return KErrNoMemory;
       
  1228 
       
  1229 	RTelServer telServer;
       
  1230 	TInt ret=telServer.Connect();
       
  1231 	if(ret!=KErrNone)
       
  1232 		return ret;
       
  1233 
       
  1234 	RMobilePhone mmPhone;
       
  1235 	ret=mmPhone.Open(telServer,KPhoneName);
       
  1236 	if(ret!=KErrNone)
       
  1237 		return ret;
       
  1238 
       
  1239 	RMobilePhoneBookStore simPhBk;
       
  1240 	ret=simPhBk.Open(mmPhone,KETelIccAdnPhoneBook());
       
  1241 	if(ret!=KErrNone)
       
  1242 		return ret;
       
  1243 
       
  1244 	CPhoneBookBuffer* pbBuffer = new CPhoneBookBuffer();
       
  1245 	if(pbBuffer==NULL)
       
  1246 		return KErrNoMemory;
       
  1247 	TBuf8<200> writeBuf;
       
  1248 
       
  1249 	pbBuffer->Set(&writeBuf); // Set it to point to the Client buffer
       
  1250 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBNumber,KNum1);
       
  1251 	if(ret!=KErrNone)
       
  1252 		return ret;
       
  1253  	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBTonNpi,(TUint8)129);
       
  1254 	if(ret!=KErrNone)
       
  1255 		return ret;
       
  1256 	ret=pbBuffer->PutTagAndValue((TUint8)RMobilePhoneBookStore::ETagPBText,KName1);
       
  1257 	if(ret!=KErrNone)
       
  1258 		return ret;
       
  1259 
       
  1260 	TInt writeIndex=1;
       
  1261 	TRequestStatus status;
       
  1262 	simPhBk.Write(status,writeBuf,writeIndex);
       
  1263 	User::WaitForRequest(status);
       
  1264 	if(status!=KErrNone)
       
  1265 		return status.Int();
       
  1266 
       
  1267 	delete pbBuffer;
       
  1268 	delete cleanup;
       
  1269 	simPhBk.Close();
       
  1270 	mmPhone.Close();
       
  1271 	telServer.Close();
       
  1272 	return KErrNone;
       
  1273 	}
       
  1274 
       
  1275 //
       
  1276 // Emulator-side class
       
  1277 // With the assistance of the base class, this class must run the designated script
       
  1278 //
       
  1279 CTestPhoneBook* CTestPhoneBook::NewL(const TScript* aScript)
       
  1280 	{
       
  1281 	CTestPhoneBook* phBk=new(ELeave) CTestPhoneBook(aScript);
       
  1282 	CleanupStack::PushL(phBk);
       
  1283 	phBk->ConstructL();
       
  1284 	CleanupStack::Pop();
       
  1285 	return phBk;
       
  1286 	}
       
  1287 
       
  1288 CTestPhoneBook::CTestPhoneBook(const TScript* aScript) : iScript(aScript)
       
  1289 	{}
       
  1290 
       
  1291 void CTestPhoneBook::ConstructL()
       
  1292 	{
       
  1293 	CATScriptEng::ConstructL();
       
  1294 	}
       
  1295 
       
  1296 TInt CTestPhoneBook::Start()
       
  1297 	{
       
  1298 	StartScript(iScript);
       
  1299 	return KErrNone;
       
  1300 	}
       
  1301 
       
  1302 void CTestPhoneBook::SpecificAlgorithmL(TInt /* aParam */)
       
  1303 	{
       
  1304 	}
       
  1305 
       
  1306 void CTestPhoneBook::Complete(TInt aError)
       
  1307 	{
       
  1308 	iReturnValue=aError;
       
  1309 	CActiveScheduler::Stop();
       
  1310 	}