telephonyserverplugins/multimodetsy/test/Te_PhBk/Te_PhBkTestStepBase.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2005-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 //
       
    15 
       
    16 #include "Te_PhBkTestStepBase.h"
       
    17 
       
    18 TVerdict CPhBkTestStep::doTestStepPreambleL()
       
    19 	{
       
    20 	__UHEAP_MARK;
       
    21 
       
    22 	TInt ret = iTelServer.Connect();
       
    23 	if (ret!=KErrNone)
       
    24 		{
       
    25 		INFO_PRINTF1(_L("Failed to connect to telephony server"));
       
    26 		User::Leave(ret);
       
    27 		}
       
    28    	ret=iTelServer.LoadPhoneModule(KMmtsyName);
       
    29 	if (ret!=KErrNone)
       
    30 		{
       
    31 		INFO_PRINTF1(_L("Failed to load phone module"));
       
    32 		iTelServer.Close();
       
    33 		User::Leave(ret);
       
    34 		}
       
    35 	ret=iPhone.Open(iTelServer,KPhoneName) ;
       
    36 	if (ret!=KErrNone)
       
    37 		{
       
    38 		INFO_PRINTF1(_L("Failed to open phone module"));
       
    39 		iTelServer.UnloadPhoneModule(KMmtsyName);
       
    40 		iTelServer.Close();
       
    41 		User::Leave(ret);
       
    42 		}
       
    43 //
       
    44 //	This test requires a mobile phone to be connected to the serial port
       
    45 //      specified in the .cfg file for the initialise below to work
       
    46 //
       
    47 	ret=iPhone.Initialise();
       
    48 	if (ret!=KErrNone)
       
    49 		{
       
    50 		INFO_PRINTF2(_L("Failed to initialise the phone (%d)"), ret);
       
    51 		iPhone.Close();
       
    52 		iTelServer.UnloadPhoneModule(KMmtsyName);
       
    53 		iTelServer.Close();
       
    54 		User::Leave(ret);
       
    55 		}
       
    56 	RPhone::TCaps oPhoneCaps;
       
    57 	ret = iPhone.GetCaps(oPhoneCaps) ;
       
    58 	if ((KErrNone != ret) || !(oPhoneCaps.iFlags & RPhone::KCapsVoice))
       
    59 		{
       
    60 		INFO_PRINTF2(_L("This phone does not support Voice Calls (caps=0x%x)"), oPhoneCaps.iFlags);
       
    61 		iPhone.Close();
       
    62 		iTelServer.UnloadPhoneModule(KMmtsyName);
       
    63 		iTelServer.Close();
       
    64 		User::Leave(ret);
       
    65 		}
       
    66 
       
    67 	return TestStepResult();
       
    68 	}
       
    69 
       
    70 TVerdict CPhBkTestStep::doTestStepPostambleL()
       
    71 	{
       
    72 	iPhone.Close();
       
    73 	iTelServer.UnloadPhoneModule(KMmtsyName);
       
    74 	iTelServer.Close();
       
    75 
       
    76 	__UHEAP_MARKEND;
       
    77 	return TestStepResult();
       
    78 	}
       
    79 
       
    80 void CPhBkTestStep::WaitWithTimeout(TRequestStatus& aStatus, TInt aNumberOfMicroSeconds)
       
    81 /**
       
    82  * Timeout function
       
    83  */
       
    84 	{
       
    85 	TRequestStatus timerStatus;
       
    86 	RTimer timer ;
       
    87 	timer.CreateLocal() ;
       
    88 	timer.After(timerStatus,aNumberOfMicroSeconds);
       
    89 
       
    90 	User::WaitForRequest(aStatus, timerStatus);
       
    91 	if (timerStatus == KRequestPending)
       
    92 		{
       
    93 		timer.Cancel();
       
    94 		User::WaitForRequest(timerStatus);
       
    95 		}
       
    96 	else
       
    97 		{
       
    98 		INFO_PRINTF1(_L("Time is over!!!")) ;
       
    99 		}
       
   100 	timer.Close() ;
       
   101 	}
       
   102 	
       
   103 TInt CPhBkTestStep::CheckPhoneStoreInfo(RMobilePhone& aPhone,
       
   104 										const TDesC& aPhoneStoreName,
       
   105 										const TDesC& aMode,
       
   106 										const TDesC& aPhoneStoreDescription)
       
   107 /**
       
   108  * Checks a specific phone store information features when mode is specified.
       
   109  *
       
   110  * @return		status code, as an integer of the request for GetPhoneStoreInfo
       
   111  */
       
   112 	{
       
   113 	RMobilePhoneStore::TMobilePhoneStoreInfoV1 info;
       
   114 	RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg infoPckg(info);
       
   115 	
       
   116 	INFO_PRINTF2(_L("Testing %S"), &aPhoneStoreDescription);
       
   117 	
       
   118 	TRequestStatus status;
       
   119 	aPhone.GetPhoneStoreInfo(status, infoPckg, aPhoneStoreName, aMode);
       
   120 	User::WaitForRequest(status);
       
   121 	
       
   122 	if( status.Int() == KErrNone )
       
   123 		{
       
   124 		INFO_PRINTF4(_L("%S is using %d of %d entries"), &aPhoneStoreDescription, info.iUsedEntries, info.iTotalEntries);
       
   125 		}
       
   126 	else if ( (aPhoneStoreName == KETelIccFdnPhoneBook && status.Int() == KErrGeneral) || // failure from PIN not entered 
       
   127 				(status.Int() == KErrNotSupported)) 
       
   128 		{
       
   129 			// Not a critical failure
       
   130 			status = KErrNone;	
       
   131 			INFO_PRINTF2(_L("%S Unusable"), &aPhoneStoreDescription);
       
   132 		}
       
   133 	else
       
   134 		{
       
   135 		INFO_PRINTF3(_L("%S Test failure, result:%d"), &aPhoneStoreDescription, status.Int());
       
   136 		}
       
   137 		
       
   138 	
       
   139 	return status.Int();
       
   140 	}	
       
   141 
       
   142 TInt CPhBkTestStep::clearPhoneBookL(const TDesC& aPhoneBookName)
       
   143 /**
       
   144  * This function deletes the first 15 entries in the specified Phone Book.
       
   145  * It is called by the clearPhoneBooks() function.
       
   146  * @test GT83-TPHBK-008.00 Test deleting an individual phonebook entry from a ME-based phonebook of abbreviated dialling numbers.
       
   147  * @test GT83-TPHBK-002.06	GT83-AT-070	Test closing an ICC-based phonebook of abbreviated dialling numbers
       
   148  */
       
   149 	{
       
   150 	TRequestStatus status;
       
   151 	RMobilePhoneBookStore thePhBk;
       
   152 	TInt ret(KErrNone);
       
   153 
       
   154 	if(thePhBk.Open(iPhone,aPhoneBookName)==KErrNone)
       
   155 		{
       
   156 		RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg dummyInfoPckg(iDummyInfo);
       
   157 		thePhBk.GetInfo(status, dummyInfoPckg);		// Recommended by EtelMM API documentation
       
   158 		User::WaitForRequest(status);
       
   159 
       
   160 		INFO_PRINTF2(_L("Deleting %S phonebook 15 first entries..."), &aPhoneBookName);
       
   161 		TInt i;
       
   162 		for (i=1; i<=15; i++)
       
   163 			{
       
   164 			thePhBk.Delete(status, i);
       
   165 			User::WaitForRequest(status);
       
   166 			if (status!=KErrNone && status!=KErrNotFound)
       
   167 				{
       
   168 				//it's checked by "if"
       
   169 				TEST_CHECKL(1, KErrNone, _L("GT83-TPHBK-008.00")) ;
       
   170 				break;
       
   171 				}
       
   172 			}
       
   173 		}
       
   174 	thePhBk.Close();
       
   175 	TEST_CHECKL(ret, KErrNone, _L("GT83-TPHBK-002.00")) ;
       
   176 	return ret;
       
   177 	}
       
   178 
       
   179 void CPhBkTestStep::checkPhoneBookInfoL(RMobilePhoneStore::TMobilePhoneStoreInfoV1& aInfo)
       
   180 /**
       
   181  * This function is called by the testPhoneInfo() function. It checks
       
   182  * the validity of the information in the TPhoneBookInfo struct.
       
   183  */
       
   184 	{
       
   185 //	TESTL(info.iTotalEntries>0);
       
   186 
       
   187 	// A phone book containing the recently dialled calls (RO)
       
   188 	if (!aInfo.iName.Compare(KETelMeDialledPhoneBook()))
       
   189 		{
       
   190 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));   // Shouldn't be able to write in this store
       
   191 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess); // But we should be able to read
       
   192 		INFO_PRINTF1(_L("\"DIALLED_CALLS\" tested RO successfully"));
       
   193 		}
       
   194 
       
   195 	// A phone book containing missed calls. (RO)
       
   196 	else if (!aInfo.iName.Compare(KETelMeMissedPhoneBook()))
       
   197 		{
       
   198 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));
       
   199 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   200 		INFO_PRINTF1(_L("\"MISSED_CALLS\" tested RO successfully"));
       
   201 		}
       
   202 
       
   203 	//A phone book containing received calls (RO)
       
   204 	else if (!aInfo.iName.Compare(KETelMeReceivedPhoneBook()))
       
   205 		{
       
   206 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));
       
   207 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   208 		INFO_PRINTF1(_L("\"RECEIVED_CALLS\" tested RO successfully"));
       
   209 		}
       
   210 
       
   211 	// A ME based phone book of abbreviated dialling numbers (RW)
       
   212 	else if (!aInfo.iName.Compare(KETelMeAdnPhoneBook()))
       
   213 		{
       
   214 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess);
       
   215 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   216 		INFO_PRINTF1(_L("\"ME_PHONEBOOK\" tested RW successfully"));
       
   217 		}
       
   218 
       
   219 	//A phone book containing voice mailbox numbers (RO)
       
   220 	else if (!aInfo.iName.Compare(KETelIccVoiceMailBox()))
       
   221 		{
       
   222 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess);
       
   223 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   224 		INFO_PRINTF1(_L("\"VOICE_MAILBOX\" tested RO successfully"));
       
   225 		}
       
   226 
       
   227 	//A SIM based phone book of abbreviated dialling numbers (RW)
       
   228 	else if (!aInfo.iName.Compare(KETelIccAdnPhoneBook()))
       
   229 		{
       
   230 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess);
       
   231 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   232 		INFO_PRINTF1(_L("\"SIM_PHONEBOOK\" tested RW successfully"));
       
   233 		}
       
   234 
       
   235 
       
   236 	//A combination of ME and SIM based phone books (RO)
       
   237 	else if (!aInfo.iName.Compare(KETelCombinedAdnPhoneBook()))
       
   238 		{
       
   239 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));
       
   240 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   241 		INFO_PRINTF1(_L("\"COMBINED_SIM_ME\" tested RO successfully"));
       
   242 		}
       
   243 
       
   244 	//A phone book containing the fixed dialling list(RO)
       
   245 	else if (!aInfo.iName.Compare(KETelIccFdnPhoneBook()))
       
   246 		{
       
   247 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));
       
   248 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   249 		INFO_PRINTF1(_L("\"FIXED_DIAL_NUM\" tested RO successfully"));
       
   250 		}
       
   251 
       
   252 	//A phone book containing service dialling number list (RO)
       
   253 	else if (!aInfo.iName.Compare(KETelIccSdnPhoneBook()))
       
   254 		{
       
   255 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));
       
   256 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   257 		INFO_PRINTF1(_L("\"SERV_DIAL_NUM\" tested RO successfully"));
       
   258 		}
       
   259 
       
   260 	//A phone book containing the barred dialling numbers (RO)
       
   261 	else if (!aInfo.iName.Compare(KETelIccBdnPhoneBook()))
       
   262 		{
       
   263 		TEST(!(aInfo.iCaps & RMobilePhoneStore::KCapsWriteAccess));
       
   264 		TEST(aInfo.iCaps & RMobilePhoneStore::KCapsReadAccess);
       
   265 		INFO_PRINTF1(_L("\"BARRED_DIAL_NUM\" tested RO successfully"));
       
   266 		}
       
   267 	}
       
   268 
       
   269 void CPhBkTestStep::WriteBatchOfEntriesToThePhoneL()
       
   270 /**
       
   271  * This function writes 15 entries to the phone.
       
   272  * @test GT83-TPHBK-001.06 Test opening an ICC-based phonebook of abbreviated dialling numbers
       
   273  * @test GT83-TPHBK-002.06 Test closing an ICC-based phonebook of abbreviated dialling numbers
       
   274  * @test GT83-TPHBK-007.06 "Test writing a single phonebook entry to a specified location in an ICC-based phonebook containing voice mailbox numbers, where the location is empty"
       
   275  */
       
   276 	{
       
   277 	TInt ret=KErrNone;
       
   278 	TRequestStatus status;
       
   279 	RMobilePhoneBookStore simPhBk;
       
   280 	TBuf8<KPBDataClientBuf> pbData; // Client reserved space for phonebook data
       
   281 	CPhoneBookBuffer* pbBuffer=new(ELeave) CPhoneBookBuffer();
       
   282 
       
   283 	pbBuffer->Set(&pbData); // Set it to point to the Client buffer
       
   284 	ret = simPhBk.Open(iPhone,  KETelIccAdnPhoneBook);
       
   285 	TEST_CHECKL(ret, KErrNone, _L("*** Failed to open ICC ADN Phonebook ***"));
       
   286 		
       
   287 	RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg dummyInfoPckg(iDummyInfo);
       
   288 	simPhBk.GetInfo(status, dummyInfoPckg);		// Recommended by EtelMM API documentation
       
   289 	User::WaitForRequest(status);
       
   290 
       
   291 	// Create array of names and numbers
       
   292 	const TText16* names[]={(TText16*)KAnnText.iBuf, (TText16*)KMattSText.iBuf, (TText16*)KAndyText.iBuf,
       
   293 							(TText16*)KMattMText.iBuf,(TText16*)KPaulText.iBuf, (TText16*)KMumAndDadText.iBuf,
       
   294 							(TText16*)KSymbolText.iBuf,(TText16*)KHenrikText.iBuf,(TText16*)KHenrikSVText.iBuf,
       
   295 							(TText16*)KMikaelText.iBuf,(TText16*)KIngeText.iBuf,(TText16*)KPatrickText.iBuf,
       
   296 							(TText16*)KPontusText.iBuf,(TText16*)KAndersText.iBuf,(TText16*)KHajText.iBuf};
       
   297 
       
   298 	const TText16* numbers[]={(TText16*)KAnnPhoneNum.iBuf, (TText16*)KMattSPhoneNum.iBuf, (TText16*)KAndyPhoneNum.iBuf,
       
   299 							(TText16*)KMattMPhoneNum.iBuf, (TText16*)KPaulPhoneNum.iBuf, (TText16*)KMumAndDadPhoneNum.iBuf,
       
   300 							(TText16*)KSymbolPhoneNum.iBuf,(TText16*)KHenrikPhoneNum.iBuf,(TText16*)KHenrikSVPhoneNum.iBuf,
       
   301 							(TText16*)KMikaelPhoneNum.iBuf,(TText16*)KIngePhoneNum.iBuf,(TText16*)KPatrickPhoneNum.iBuf,
       
   302 							(TText16*)KPontusPhoneNum.iBuf,(TText16*)KAndersPhoneNum.iBuf,(TText16*)KHajPhoneNum.iBuf};
       
   303 
       
   304 
       
   305 	// Write the entries to the SIM Phone Book
       
   306 	TInt size(KPPBEntriesNum);
       
   307 	TInt i(0), index(0);
       
   308 
       
   309 	TBuf16<KBufSize> entryNumber(numbers[0]);
       
   310 	TBuf16<KBufSize> entryName(names[0]);
       
   311 
       
   312 	for (i=1; i<=size; ++i)
       
   313 		{
       
   314 		//first reset the following three local buffers to delete any existing data
       
   315 		entryNumber.FillZ();
       
   316 		entryNumber.Zero();
       
   317 		entryName.FillZ();
       
   318 		entryName.Zero();
       
   319 		pbData.FillZ();
       
   320 		pbData.Zero();
       
   321 
       
   322 		entryNumber=numbers[i-1];
       
   323 		entryName=names[i-1];
       
   324 
       
   325 		// convert number into TLV format and append it to allocated buffer
       
   326 		ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, entryNumber);
       
   327 		TESTL(ret == KErrNone) ;
       
   328 
       
   329 		// convert type into TLV format and append it to allocated buffer
       
   330 		TUint8 tonNpi=KTypeOfNumber;
       
   331 		ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi, tonNpi);
       
   332 		TESTL(ret == KErrNone) ;
       
   333 
       
   334 		// convert text into TLV format and append it to allocated buffer
       
   335 		ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, entryName);
       
   336 		TESTL(ret == KErrNone) ;
       
   337 
       
   338 		index=RMobilePhoneStore::TMobilePhoneStoreEntryV1::KIndexNotUsed;
       
   339 		// Note that KIndexNotUsed cannot be used anymore to write to next available phonebook slot
       
   340 		simPhBk.Write(status, pbData, index);
       
   341 		User::WaitForRequest(status);
       
   342 
       
   343 		if (status!=KErrNone) // First write request should fail
       
   344 			{
       
   345 			// This time client needs to specify the phonebook slot
       
   346 			index=i;
       
   347 			simPhBk.Write(status, pbData, index);
       
   348 			User::WaitForRequest(status);
       
   349 			TEST_CHECKL(status.Int(), KErrNone, _L("GT83-TPHBK-007.06")) ;
       
   350 			}
       
   351 		} // end for
       
   352 	
       
   353 	simPhBk.Close();
       
   354 	delete pbBuffer;
       
   355 	}