messagingappbase/smsmtm/test/src/T_SmsSendRecv.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     1 // Copyright (c) 2000-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 // GT Messaging Test Harness T_SmsSendRecv
       
    15 // Test Harness: T_SmsSendRecv
       
    16 // Component: SMS
       
    17 // Owner: AA
       
    18 // Brief Description: Sends and waits to receive SMS messages specified in sendrecv.script
       
    19 // Detailed Description: As Above
       
    20 // Input Files REQUIRED:
       
    21 // <DRIVE>:\msgtest\sms\defaults.script
       
    22 // <DRIVE>:\msgtest\sms\sendrecv.script
       
    23 // Intermediate Files Produced: None
       
    24 // Output files produced: <DRIVE>:\msglogs\T_SmsSendRecv.<PLATFORM>.<VARIANT>.log
       
    25 // Building Instructions:
       
    26 // cd \msg\smcm
       
    27 // bldmake bldfiles
       
    28 // abld test build
       
    29 // Running Instructions:
       
    30 // All Platforms:
       
    31 // 1. Build T_DB test harness from COMMDB component:
       
    32 // cd \commdb\group
       
    33 // bldmake bldfiles
       
    34 // abld test build t_db
       
    35 // 2. Run T_DB and select the your modem (probably GSM Mobile Phone)
       
    36 // 3. Build the test utilities:
       
    37 // cd \msg\testutils\group\
       
    38 // bldmake bldfiles
       
    39 // abld test build
       
    40 // 4. Edit \epoc32\wins\c\msgtest\sms\defaults.script. Replace the telephone number ("Recipients") with your mobile's number. You may also need to change the service centre ("SC") number (the default is for Vodafone UK).
       
    41 // WINS Only:
       
    42 // 1. Run T_DB.exe (if it has not already been run) and select your modem (GSM mobile phone).
       
    43 // 2. \epoc32\release\wins\<VARIANT>\T_SmsSendRecv.exe can be used at the command prompt or executable can be run from Windows Explorer.
       
    44 // Platform other than WINS:
       
    45 // 1. Copy \epoc32\release\<PLATFORM>\<VARIANT>\T_SmsSendRecv.exe onto the other platform (or onto the CF card)
       
    46 // 2. Copy \epoc32\release\<PLATFORM>\<VARIANT>\T_DB.exe onto the other platform (or onto the CF card)
       
    47 // 3. Copy \epoc32\release\<PLATFORM>\<VARIANT>\MsvTestUtils.DLL into <DRIVE>:\system\libs on the other platform (or onto the CF card)
       
    48 // 4. Copy \epoc32\release\<PLATFORM>\<VARIANT>\SmsTestUtils.DLL into <DRIVE>:\system\libs on the other platform (or onto the CF card)
       
    49 // 5. Copy \epoc32\wins\c\msgtest\sms\sendrecv.script and defaults.script into <DRIVE>:\msgtest\sms on the other platform (or onto the CF card)
       
    50 // 6. Run T_DB.exe on the other platform (if it has not already been run) and select your modem (GSM mobile phone).
       
    51 // 7. Run T_SmsSendRecv.exe on the other platform.
       
    52 // 
       
    53 //
       
    54 
       
    55 #include "T_SmsSendRecv.h"
       
    56 #include <watcher.h>
       
    57 #include <smuthdr.h>
       
    58 #include <txtrich.h>
       
    59 #include <bioscmds.h>
       
    60 #include <biosmtm.h>
       
    61 #include <smss.rsg>
       
    62 #include <msgtestscripts.h>
       
    63 #include <smsclnt.h>
       
    64 #include <csmsaccount.h>
       
    65 
       
    66 
       
    67 RTest test(_L("T_SmsSendRecv Testrig"));
       
    68 CTrapCleanup* theCleanup;
       
    69 
       
    70 const TInt KTestDescriptionLength	= 15;
       
    71 
       
    72 LOCAL_C void doMainL()
       
    73 	{
       
    74 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
    75 	CleanupStack::PushL(scheduler);
       
    76 	CActiveScheduler::Install( scheduler );
       
    77 
       
    78 	CSmsTestUtils* smsTest = CSmsTestUtils::NewL(test);
       
    79 	CleanupStack::PushL(smsTest);
       
    80 	TInt nextTest = 0;
       
    81 	
       
    82 	smsTest->NotifySaPhoneOnL();
       
    83 
       
    84 	CSmsSendRecvTest* recvTest = CSmsSendRecvTest::NewLC(*smsTest, KSendRecvScript, nextTest);
       
    85 
       
    86 	smsTest->WaitForInitializeL();
       
    87 
       
    88 	recvTest->StartL();
       
    89 
       
    90 	CleanupStack::PopAndDestroy(3); //SmsTest, scheduler
       
    91 	}
       
    92 
       
    93 GLDEF_C TInt E32Main()
       
    94 	{	
       
    95 	__UHEAP_MARK;
       
    96 	test.Start(_L("Setup"));
       
    97 	theCleanup = CTrapCleanup::New();
       
    98 	TRAPD(ret,doMainL());		
       
    99 	test(ret==KErrNone);
       
   100 	delete theCleanup;	
       
   101 	test.Console()->SetPos(0, 13);
       
   102 	test.End();
       
   103 	test.Close();
       
   104 	__UHEAP_MARKEND;
       
   105 	return(KErrNone);
       
   106 	}
       
   107 
       
   108 CEntryObserver* CEntryObserver::NewL(CSmsTestUtils& aTestUtils, const TInt& aCurrentMessageNum)
       
   109 	{
       
   110 	CEntryObserver* self = new (ELeave) CEntryObserver(aTestUtils, aCurrentMessageNum);
       
   111 	CleanupStack::PushL(self);
       
   112 	self->iReceived = new (ELeave) CMsvEntrySelection();
       
   113 	CleanupStack::Pop(self);
       
   114 	return self;
       
   115 	}
       
   116 
       
   117 CEntryObserver::CEntryObserver(CSmsTestUtils& aTestUtils, const TInt& aCurrentMessageNum)
       
   118 : CBase(), iCurrentMessageNum(aCurrentMessageNum), iSmsTest(aTestUtils)
       
   119 	{
       
   120 	}
       
   121 
       
   122 
       
   123 CEntryObserver::~CEntryObserver() 
       
   124 /**
       
   125 	destructor
       
   126  */
       
   127 	{
       
   128 	delete iReceived;
       
   129 	}
       
   130 
       
   131 void CEntryObserver::CheckReceivedMessageL(TMsvId aId)
       
   132 /**
       
   133 	Checks received message
       
   134 
       
   135 	@param		aId			A message Id
       
   136  */
       
   137 	{
       
   138 	// Restore SMS settings
       
   139 	iSmsTest.SetEntryL(iSmsTest.iSmsServiceId);
       
   140 
       
   141 	CSmsAccount* account = CSmsAccount::NewLC();
       
   142 	account->LoadSettingsL(*iSmsTest.iServiceSettings);
       
   143 	CleanupStack::PopAndDestroy(account);
       
   144 
       
   145 	iSmsTest.Printf(_L("Check last received message...\n"));
       
   146 
       
   147 	iSmsTest.DisplayMessageL(aId);
       
   148 	iSmsTest.SetEntryL(aId);
       
   149 
       
   150 	CSmsHeader* header = iSmsTest.GetHeaderLC(aId);
       
   151 
       
   152 	if (header->Type() == CSmsPDU::ESmsDeliver)
       
   153 		{
       
   154  		CSmsDeliver& pdu = header->Deliver();
       
   155 
       
   156 		TBool found = EFalse;
       
   157 		TInt destination, originator, is16Bit;
       
   158 		destination = originator = is16Bit = 0;
       
   159 		if (pdu.UserDataPresent())
       
   160 			{
       
   161 			const CSmsUserData& userData = pdu.UserData();
       
   162 			TInt count = userData.NumInformationElements();
       
   163 			iSmsTest.Printf(_L("\tPdu contains %d information elements\n"), count);
       
   164 			while (!found && count--)
       
   165 				{
       
   166 				CSmsInformationElement& nextIE=userData.InformationElement(count);
       
   167 				switch(nextIE.Identifier())
       
   168 					{
       
   169 					case CSmsInformationElement::ESmsIEIApplicationPortAddressing8Bit:
       
   170 					case CSmsInformationElement::ESmsIEIApplicationPortAddressing16Bit:
       
   171 						{
       
   172 						pdu.ApplicationPortAddressing(destination, originator, &is16Bit);
       
   173 						found = ETrue;
       
   174 						break;
       
   175 						}
       
   176 					default:
       
   177 						break;
       
   178 					}
       
   179 				}
       
   180 			}
       
   181 		else
       
   182 			iSmsTest.Printf(_L("\tPdu contains NO user data header\n"));
       
   183 
       
   184 		if (found)
       
   185 			iSmsTest.Printf(_L("\tApplication Port Addressing: Dest %d, Origin %d, is16Bit %d\n"), destination, originator, is16Bit);
       
   186 		else
       
   187 			iSmsTest.Printf(_L("\tApplication Port Addressing: Not Found\n"));
       
   188 		}
       
   189 
       
   190 	//Check the description
       
   191 	const TMsvEntry& entry = iSmsTest.Entry();
       
   192 
       
   193 	if (entry.iBioType == 0)
       
   194 		{
       
   195 		//Test description
       
   196 		TInt descriptionLength = iSmsTest.iServiceSettings->DescriptionLength();
       
   197 		HBufC* buf = HBufC::NewLC(descriptionLength);
       
   198 		TPtr desc = buf->Des();
       
   199 		User::LeaveIfError(TSmsUtilities::GetDescription(header->Message(), desc, descriptionLength));
       
   200 
       
   201 		iSmsTest.Printf(_L("\tiDescription=\"%S\" desc=\"%S\"\n"), &entry.iDescription, &desc);
       
   202 		iSmsTest(desc.CompareF(entry.iDescription) == 0);
       
   203 		
       
   204 		if (header->Type() == CSmsPDU::ESmsStatusReport)
       
   205 			{
       
   206 			iSmsTest.ReadResourceStringL(KSmsResourceFile,  R_TYPE_STATUS_REPORT, desc);
       
   207 			iSmsTest.Printf(_L("\tiDescription=\"%S\" Res=\"%S\"\n"), &entry.iDescription, &desc);
       
   208 			iSmsTest(desc.CompareF(entry.iDescription) == 0);
       
   209 			}
       
   210 		CleanupStack::PopAndDestroy(buf);
       
   211 		}
       
   212 
       
   213 
       
   214 	CleanupStack::PopAndDestroy(header);
       
   215 	}
       
   216 
       
   217 
       
   218 void CEntryObserver::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* aArg1, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   219 /**
       
   220 	Handles entry event, used by MMsvEntryObserver
       
   221 
       
   222 	@param		aEvent		Msv entry event
       
   223 	@param		aArg1		Argument 1
       
   224 	@param		aArg2		Argument 2 
       
   225 	@param		aArg3		Argument 3 
       
   226  */
       
   227 	{
       
   228 	if (aEvent == EMsvNewChildren && iCurrentMessageNum > -1)
       
   229 		{
       
   230 		CMsvEntrySelection* msgs = (CMsvEntrySelection*)aArg1;
       
   231 
       
   232 		TInt count = msgs->Count();
       
   233 
       
   234 		TInt msgRecv = 0;
       
   235 
       
   236 		while (count--)
       
   237 			{
       
   238 			TMsvId id = (*msgs)[count];
       
   239 
       
   240 			CheckReceivedMessageL(id);
       
   241 			CSmsHeader* header = iSmsTest.GetHeaderLC(id);
       
   242 
       
   243 			if (header->Type() == CSmsPDU::ESmsDeliver)
       
   244 				{
       
   245 				iReceived->AppendL(id);
       
   246 				msgRecv++;
       
   247 				}
       
   248 
       
   249 			CleanupStack::PopAndDestroy(header);
       
   250 			}
       
   251 
       
   252 		if (msgRecv)	
       
   253 			iSmsTest.Printf(_L("%d Messages Received in inbox\n"), msgRecv);
       
   254 		}
       
   255 	}
       
   256 
       
   257 CSmsSendRecvTest::~CSmsSendRecvTest()
       
   258 /**
       
   259 	destructor
       
   260  */
       
   261 	{
       
   262 	delete iEntryObserver;
       
   263 	delete iEntryForObserver;
       
   264 	delete iWatchers;
       
   265 
       
   266 	iSocket.Close();
       
   267 	iSocketServ.Close();
       
   268 	}
       
   269 
       
   270 TBool CSmsSendRecvTest::WatchersAlreadyRunningL()
       
   271 /**
       
   272 	Checks if the watchers are already running
       
   273  */
       
   274 	{
       
   275 	RSocketServ server;
       
   276 	RSocket socket;
       
   277 
       
   278 	User::LeaveIfError(server.Connect());
       
   279 	CleanupClosePushL(server);
       
   280 
       
   281 		// test if it's there... 
       
   282 	TProtocolDesc protoInfo;
       
   283 	TProtocolName protocolname;
       
   284 	protocolname.Copy(KSmsDatagram);
       
   285 	User::LeaveIfError(server.FindProtocol(protocolname,protoInfo));
       
   286 
       
   287 	User::LeaveIfError(socket.Open(server,
       
   288 										protoInfo.iAddrFamily,
       
   289 										protoInfo.iSockType, 
       
   290 										protoInfo.iProtocol));
       
   291 	CleanupClosePushL(socket);
       
   292 
       
   293 	TSmsAddr addr;
       
   294 	addr.SetSmsAddrFamily(ESmsAddrRecvAny);
       
   295 	TInt err = socket.Bind(addr);
       
   296 
       
   297 	CleanupStack::Pop(2); //server, socket
       
   298 	socket.CancelAll();
       
   299 	socket.Close();
       
   300 //	server.Close();
       
   301 	return (err == KErrAlreadyExists);
       
   302 	}
       
   303 
       
   304 void CSmsSendRecvTest::StartWatcherL()
       
   305 /**
       
   306 	Starts the watcher if it is not running
       
   307  */
       
   308 	{
       
   309 	iSmsTest.Test().Next(_L("Start the Watcher"));
       
   310 
       
   311 	if (WatchersAlreadyRunningL())
       
   312 		{
       
   313 		iSmsTest.Printf(_L("Watchers are already running\n"));
       
   314 		return;
       
   315 		}
       
   316 
       
   317 	iWatchers = CTestUtilsWatcherStarter::NewL();
       
   318 
       
   319 	TTimeIntervalMicroSeconds32 wait = KWaitForWatchersToStart;
       
   320 	while (wait.Int() > 0)
       
   321 		{
       
   322 		iSmsTest.Printf(_L("Waiting %d secs for watchers to start...\n"), wait.Int() / 1000000);
       
   323 		wait = wait.Int() - KWaitForWatchersToStartDisplayInterval.Int();
       
   324 		User::After(KWaitForWatchersToStartDisplayInterval);
       
   325 		}
       
   326 	}
       
   327 
       
   328 CSmsSendRecvTest* CSmsSendRecvTest::NewLC(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
   329 	{
       
   330 	CSmsSendRecvTest* self = new (ELeave) CSmsSendRecvTest(aSmsTest, aScriptFile, aNextTest);
       
   331 	CleanupStack::PushL(self);
       
   332 	self->ConstructL();
       
   333 	return self;
       
   334 	}
       
   335 
       
   336 
       
   337 void CSmsSendRecvTest::TestSendingL()
       
   338 /**
       
   339 	Tests sending: Creates messages as defined in the script file
       
   340  */
       
   341 	{
       
   342 	iSmsTest.Test().Next(_L("Sending"));
       
   343 
       
   344 	TTime now;
       
   345 	now.HomeTime();
       
   346 	now += (TTimeIntervalSeconds) 5;
       
   347 
       
   348 	iSelection->Reset();
       
   349 
       
   350 	iSmsTest.DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId);
       
   351 
       
   352 	TBool read = EFalse;
       
   353 	iSmsTest.Printf(_L("Creating msgs in outbox from script: %S\n"), &iScriptFile);
       
   354 	TRAPD(err, read = iSmsTest.ReadScriptL(iScriptFile, KMsvGlobalOutBoxIndexEntryId, *iSelection, now));
       
   355 
       
   356 	iSmsTest.Test()(!err && read);
       
   357 
       
   358 	iSmsTest.Printf(_L("Send and Receive %d messages...\n"), iSelection->Count());
       
   359 
       
   360 	TInt count = iSelection->Count();
       
   361 	iTotal = 0;
       
   362 	iSent = 0;
       
   363 	while (count--)
       
   364 		{
       
   365 		iTotal += CountRecipientsL(iSelection->At(count));
       
   366 		}
       
   367 
       
   368 	iCurrentMessageNum = -1;
       
   369 	}
       
   370 
       
   371 TInt CSmsSendRecvTest::CountRecipientsL(TMsvId aId)
       
   372 /**
       
   373 	Counts the number receipients in aId
       
   374 
       
   375 	@param		aId		A message Id 
       
   376  */
       
   377 	{
       
   378 	CSmsHeader* header = iSmsTest.GetHeaderLC(aId);
       
   379 	const TInt count = header->Recipients().Count();
       
   380 	CleanupStack::PopAndDestroy(header);
       
   381 	return count;
       
   382 	}
       
   383 
       
   384 TBool CSmsSendRecvTest::SendNextMessageL()
       
   385 /**
       
   386 	Sends the next message 
       
   387  */
       
   388 	{
       
   389 	iCurrentMessageNum++;
       
   390 	const TInt count = iSelection->Count();
       
   391 
       
   392 	if (iCurrentMessageNum < count)
       
   393 		{
       
   394 		iSmsTest.Printf(_L("Sending message %d of %d\n"), iCurrentMessageNum + 1, count);
       
   395 
       
   396 		delete iOperation;
       
   397 		iOperation = NULL;
       
   398 
       
   399 		CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
   400 		CleanupStack::PushL(sel);
       
   401 		const TMsvId id = iSelection->At(iCurrentMessageNum);
       
   402 		
       
   403 		TInt replace_msg_one_index = GetIndexOfSectionL(_L("ReplaceTypeSMSOne"));
       
   404 		TInt replace_msg_two_index = GetIndexOfSectionL(_L("ReplaceTypeSMSTwo"));
       
   405 		TInt msg_indication_index = GetIndexOfSectionL(_L("SMSMessageIndication"));
       
   406 
       
   407 		TInt vCalendar_index = GetIndexOfSectionL(_L("WAP:vCalendar"));
       
   408  		// storing the id of vCalender message , to use it to test for replying bio messages
       
   409  		if(vCalendar_index != KErrNotFound && vCalendar_index == (iCurrentMessageNum+1))
       
   410  			iMsgVCalenderIndex = iCurrentMessageNum;
       
   411 
       
   412 		if(replace_msg_one_index != KErrNotFound && replace_msg_one_index == (iCurrentMessageNum+1))
       
   413 			SendReplaceTypeMessageL();
       
   414 					
       
   415 		if(replace_msg_two_index != KErrNotFound && replace_msg_two_index == (iCurrentMessageNum+1))
       
   416 			{
       
   417 			SendReplaceTypeMessageL();
       
   418 			iSmsTest.Printf(_L("This Message replaces previous Replace Type Message"));
       
   419 			}
       
   420 				
       
   421 		if(msg_indication_index != KErrNotFound && msg_indication_index == (iCurrentMessageNum+1))
       
   422 			SendMessageIndicationL();
       
   423 		
       
   424 		iSmsTest.DisplayMessageL(id);
       
   425 		sel->AppendL(id);
       
   426 		iSent += CountRecipientsL(id);
       
   427 		iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   428 		iOperation = MsvEntry().CopyL(*sel, iSmsTest.iSmsServiceId, iStatus);
       
   429 		CleanupStack::PopAndDestroy(); //sel
       
   430 	
       
   431 		iState = EStateSending;
       
   432 		SetActive();
       
   433 		CActiveScheduler::Start();
       
   434 		return ETrue;
       
   435 		}
       
   436 
       
   437 	return EFalse;
       
   438 	}
       
   439 
       
   440 TInt CSmsSendRecvTest::GetIndexOfSectionL(const TDesC& aSectionName)
       
   441 /**
       
   442  *  Returns back the index of the section
       
   443  */
       
   444 	{
       
   445 	CScriptFile* script = CScriptFile::NewLC(iSmsTest, KSmsComponent);
       
   446 	script->ReadScriptL(KSendRecvScript);
       
   447 		
       
   448 	TInt index = KErrNotFound;
       
   449 	TInt count = iSelection->Count();
       
   450 
       
   451 	for (TInt i = 0; i <= count; i++) //order important
       
   452 		{
       
   453 		CScriptSection& tempsection = *script->Sections()[i];
       
   454 		if (tempsection.SectionName().CompareF(aSectionName) == 0)
       
   455 			index = i;
       
   456 		}
       
   457 
       
   458 	CleanupStack::PopAndDestroy(script);
       
   459 	
       
   460 	return index;
       
   461 	}
       
   462 
       
   463 void CSmsSendRecvTest::SendReplaceTypeMessageL()
       
   464 /**
       
   465  *  Handles the replace type sms messages in sendrecv.script
       
   466  */
       
   467 	{	
       
   468 	iSmsTest.Printf(_L("\nSend Replace Type Message\n"));
       
   469 	const TMsvId id = iSelection->At(iCurrentMessageNum);
       
   470 	CSmsHeader* header = iSmsTest.GetHeaderLC(id);
       
   471 	CSmsSubmit& submit = header->Submit();
       
   472 	submit.SetPIDType(TSmsProtocolIdentifier::ESmsPIDShortMessageType);
       
   473 	submit.SetShortMessageType(TSmsProtocolIdentifier::ESmsReplaceShortMessageType1);
       
   474 	StoreMessageL(id, *header);
       
   475 	CleanupStack::PopAndDestroy(header);
       
   476 	}
       
   477 
       
   478 void CSmsSendRecvTest::SendMessageIndicationL(TUint8 aMessageType, TUint8 aMessageCount)
       
   479 /**
       
   480  * Sends an SMS message with Special SMS Message Indication set in the user data header.
       
   481  * 
       
   482  * @param aMessageType The type of the Special SMS Message Indication
       
   483  * @param aMessageCount The number of "messages" waiting
       
   484  */
       
   485 	{
       
   486 	iSmsTest.Printf(_L("\nSendMessageIndicationL\n"));
       
   487 	const TMsvId id = iSelection->At(iCurrentMessageNum);
       
   488 	CSmsHeader* header = iSmsTest.GetHeaderLC(id);
       
   489 	TBuf8<2> data;
       
   490 	data.SetLength(2);
       
   491 				
       
   492 	data[0] = aMessageType;
       
   493 	data[1] = aMessageCount;
       
   494 
       
   495 	header->Submit().UserData().AddInformationElementL(CSmsInformationElement::ESmsIEISpecialSMSMessageIndication, data);
       
   496 	StoreMessageL(id, *header);
       
   497 	CleanupStack::PopAndDestroy(header);
       
   498 	}
       
   499 
       
   500 void CSmsSendRecvTest::StoreMessageL(TMsvId aId, const CSmsHeader& aHeader)
       
   501 /**
       
   502  * Stores the header against a message
       
   503  *
       
   504  * @param aId ID of the message
       
   505  * @param aHeader The CSmsHeader to store against the message
       
   506  */
       
   507 	{
       
   508 	iSmsTest.SetEntryL(aId);
       
   509 	CMsvStore* store = iSmsTest.EditStoreL();
       
   510 	CleanupStack::PushL(store);
       
   511 	aHeader.StoreL(*store);
       
   512 	store->StoreBodyTextL(*iSmsTest.iRichText);
       
   513 	store->CommitL();
       
   514 	CleanupStack::PopAndDestroy(store);
       
   515 	}
       
   516 
       
   517 void CSmsSendRecvTest::TestWaitForReceiveL()
       
   518 /**
       
   519 	Waits to receive message
       
   520  */
       
   521 	{
       
   522 	iSmsTest.Test().Next(_L("Waiting to receive message"));
       
   523 	iState = EStateWaitingToReceive;
       
   524 	TRequestStatus* status = &iStatus;
       
   525 	User::RequestComplete(status, KErrNone);
       
   526 	SetActive();
       
   527 	}
       
   528 
       
   529 CSmsSendRecvTest::CSmsSendRecvTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
   530 : CSmsTestBase(aSmsTest, aScriptFile, aNextTest), iCurrentMessageNum(-1), iState(EStateWaiting)
       
   531 /**
       
   532 	Constructor
       
   533  */
       
   534 	{
       
   535 	TBuf<256> command;
       
   536 		User::CommandLine(command);
       
   537 	
       
   538 	command.Trim();
       
   539 	iParse = (command.FindF(KParseAfterReceive) != KErrNotFound);
       
   540 	iSaveToFile = (command.FindF(KSaveAfterReceive) != KErrNotFound);
       
   541 	iTestBifs = (command.FindF(KTestBifs) != KErrNotFound);
       
   542 	iWaitForever = (command.FindF(KWaitForever) != KErrNotFound);
       
   543 
       
   544 	iMsgVCalenderIndex = KErrNotFound;
       
   545 	// check to see if we want to run EMS tests
       
   546 	if (command.FindF(KRunEmsTests) != KErrNotFound)
       
   547 		{
       
   548 		iScriptFile = KSendRecvEmsScript;
       
   549 		}
       
   550 	}
       
   551 
       
   552 void CSmsSendRecvTest::RunAutoL()
       
   553 /**
       
   554 	Runs tests in sequence, checks iStatus
       
   555  */
       
   556 	{	
       
   557 	iSmsTest.TestStart(++iNextTest, _L("Start Watcher"));
       
   558 	StartWatcherL();
       
   559 	User::LeaveIfError(iStatus.Int());
       
   560 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   561 	
       
   562 	if (!WatchersAlreadyRunningL())
       
   563 		{
       
   564 		iSmsTest.Printf(_L("WARNING: NBS Watcher has not started yet\n"));
       
   565 		}
       
   566 
       
   567 	if (!iSmsTest.iSmokeTest && iTestBifs)
       
   568 		{
       
   569 		iSmsTest.TestStart(++iNextTest, _L("Add Remove Bifs"));
       
   570 		TestBifsL();
       
   571 		User::LeaveIfError(iStatus.Int());
       
   572 		iSmsTest.TestFinish(iNextTest, KErrNone);
       
   573 		}
       
   574 
       
   575 	if (!WatchersAlreadyRunningL())
       
   576 		{
       
   577 		iSmsTest.Printf(_L("WARNING: NBS Watcher has not started yet\n"));
       
   578 		}
       
   579 
       
   580 	// Change the description length to be shorter then the default - actual
       
   581 	// value is not important only that it is different to the default of
       
   582 	// KSmsDescriptionLength (32).
       
   583 
       
   584 	iSmsTest.Printf(_L("\nChanging the description length to %d\n"), KTestDescriptionLength);
       
   585 	
       
   586 	// Restore settings first...	
       
   587 	CSmsAccount* account = CSmsAccount::NewLC();
       
   588 	account->LoadSettingsL(*iSmsTest.iServiceSettings);
       
   589 
       
   590 	// Set the description length to 1
       
   591 	iSmsTest.iServiceSettings->SetDescriptionLength(KTestDescriptionLength);
       
   592 
       
   593 	// Store the sms settings
       
   594 	account->SaveSettingsL(*iSmsTest.iServiceSettings);
       
   595 	CleanupStack::PopAndDestroy(account);
       
   596 
       
   597 	// Ok, now start real tests...
       
   598 
       
   599 	iSmsTest.TestStart(++iNextTest, _L("Read Script"));
       
   600 	TestSendingL();
       
   601 	User::LeaveIfError(iStatus.Int());
       
   602 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   603 
       
   604 	FOREVER
       
   605 		{
       
   606 		iSmsTest.TestStart(++iNextTest, _L("Send Message"));
       
   607 		TBool sendNext = SendNextMessageL();
       
   608 		if (sendNext)
       
   609 			{
       
   610 			User::LeaveIfError(iStatus.Int());
       
   611 			iSmsTest.TestFinish(iNextTest, KErrNone);
       
   612 			}
       
   613 		else
       
   614 			{
       
   615 			iSmsTest.Printf(_L("No more messages to send!"));
       
   616 			iSmsTest.TestFinish(iNextTest, KErrNone);
       
   617  			// Testing Reply to Bio-Messages
       
   618   			TestReplyL();
       
   619 			break;
       
   620 			}
       
   621 		}
       
   622 
       
   623 	iSmsTest.TestStart(++iNextTest, _L("Wait to receive extra message(s)"));
       
   624 	WaitForExtraL();
       
   625 	User::LeaveIfError(iStatus.Int());
       
   626 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   627 	iSmsTest.Printf(_L("\nDisplay Final Log:\n"));
       
   628 	DisplayLogL();
       
   629 	}
       
   630 
       
   631 void CSmsSendRecvTest::SetSmsSettingsL()
       
   632  	{
       
   633  	MsvEntry().SetEntryL(iSmsTest.iSmsServiceId);
       
   634  
       
   635 // Lets create sms settings to set it for reply
       
   636  	CSmsSettings* settings = CSmsSettings::NewL();
       
   637  	CleanupStack::PushL(settings);
       
   638  	
       
   639  	settings->SetReplyQuoted(ETrue);
       
   640  
       
   641  	CSmsAccount* account = CSmsAccount::NewLC();
       
   642  	account->SaveSettingsL(*settings);
       
   643  	CleanupStack::PopAndDestroy(account);
       
   644  
       
   645  	iSmsTest.iServiceSettings->CopyL(*settings);
       
   646  	CleanupStack::PopAndDestroy();  //settings
       
   647  	}
       
   648  
       
   649 // Now testing replying to received messages
       
   650 void CSmsSendRecvTest::TestReplyL()
       
   651  	{
       
   652  	// Test cannot be performed as no vCalender message received in the inbox
       
   653  	if(iMsgVCalenderIndex == KErrNotFound)
       
   654  		return;
       
   655  	
       
   656 	iSmsTest.TestStart(++iNextTest, _L("CSmsClientMtm Reply"));
       
   657 	iSmsTest.Printf(_L("This test is to test Reply for bio-messages(vCalender)\n"));
       
   658 		
       
   659  	SetSmsSettingsL();
       
   660  
       
   661  	iSmsTest.InstantiateClientMtmsL();
       
   662  
       
   663  	const TMsvId id = iEntryObserver->ItemReceived(iMsgVCalenderIndex);
       
   664 
       
   665 	if(id == KErrNotFound)
       
   666 		{
       
   667 		iSmsTest.TestFinish(iNextTest, KErrNotFound);
       
   668 		return;
       
   669 		}
       
   670  	iSmsTest.SetEntryL(id);
       
   671  
       
   672  	Client().SwitchCurrentEntryL(id); // Lets point at the received message
       
   673  	Client().LoadMessageL();
       
   674 	iSmsTest.Printf(_L("Display vCalender Message\n"));
       
   675 	iSmsTest.DisplayMessageL(id);
       
   676  	
       
   677 	TMsvPartList part=0;
       
   678  	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   679  	// Replying the vCalender message
       
   680  	CMsvOperation* op=Client().ReplyL(KMsvDraftEntryId, part, wait->iStatus);
       
   681  	CleanupStack::PushL(op);
       
   682  	wait->Start();
       
   683  	CActiveScheduler::Start();
       
   684  
       
   685  	TPckgBuf<TMsvId> pkg;
       
   686  	pkg.Copy(op->ProgressL());
       
   687  	TMsvId progress = pkg();
       
   688  
       
   689  	CleanupStack::PopAndDestroy(2); //op, wait
       
   690 
       
   691 	CSmsHeader* header = iSmsTest.GetHeaderLC(progress);
       
   692 
       
   693 	// extract the replying message
       
   694 	iSmsTest.SetEntryL(progress);
       
   695 	CMsvStore* store = iSmsTest.ReadStoreL();
       
   696 	CleanupStack::PushL(store);
       
   697 	header->RestoreL(*store);
       
   698 	CleanupStack::PopAndDestroy(); //store
       
   699 
       
   700 	const CSmsBufferBase& buffer = header->Message().Buffer();
       
   701 	
       
   702 	// let's check to see if the reply message has any body in it
       
   703 	TInt bufLen=buffer.Length();
       
   704 	CleanupStack::PopAndDestroy(); //header
       
   705 	
       
   706  	if (bufLen)
       
   707  		{
       
   708  		iSmsTest.Printf(_L("vCalender Reply Message having junk data\n"));
       
   709 		iSmsTest.TestFinish(iNextTest, KErrNotFound);
       
   710 		}
       
   711  	else
       
   712 		{
       
   713  		iSmsTest.Printf(_L("vCalender Reply Message is a Empty SMS message\n"));
       
   714 		Client().SwitchCurrentEntryL(progress);
       
   715 		Client().LoadMessageL();
       
   716   		Client().Body().InsertL(0,_L("This is reply"));
       
   717  		Client().SaveMessageL();
       
   718 		iSmsTest.TestFinish(iNextTest, KErrNone);
       
   719   		}
       
   720   	}
       
   721 
       
   722 
       
   723 void CSmsSendRecvTest::ConstructL()
       
   724 	{
       
   725 	SetTestNameL(KSmsSendRecvTestName);
       
   726 	iSmsTest.SetLogToFile();
       
   727 
       
   728 	TBuf<256> command;	
       
   729 		User::CommandLine(command);
       
   730 	
       
   731 	command.Trim();
       
   732 	iSmsTest.Printf(_L("Command Line: \"%S\" (Parse %d, Save %d, Wait %d, Bifs %d)\n"), &command, iParse, iSaveToFile, iWaitForever, iTestBifs);
       
   733 
       
   734 	iSelection = new (ELeave) CMsvEntrySelection();
       
   735 	iTimer = CTestTimer::NewL();
       
   736 	CActiveScheduler::Add(this);
       
   737 
       
   738 	iSmsTest.SetCommDbServiceCenterFromScriptL(iScriptFile);
       
   739 
       
   740 	iEntryObserver = CEntryObserver::NewL(iSmsTest, iCurrentMessageNum);
       
   741 
       
   742 	iEntryForObserver = Session().GetEntryL(KMsvGlobalInBoxIndexEntryId);
       
   743 	iEntryForObserver->AddObserverL(*iEntryObserver);
       
   744 
       
   745 	ClearLogL();
       
   746 
       
   747 	User::LeaveIfError(iSocketServ.Connect());
       
   748 	TProtocolDesc protoinfo;
       
   749 	TProtocolName protocolname(KSmsDatagram);
       
   750 	User::LeaveIfError(iSocketServ.FindProtocol(protocolname,protoinfo));
       
   751 	User::LeaveIfError(iSocket.Open(iSocketServ,protoinfo.iAddrFamily,protoinfo.iSockType,protoinfo.iProtocol));
       
   752 	
       
   753 	TSmsAddr smsaddr;
       
   754 	smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly);
       
   755 	User::LeaveIfError(iSocket.Bind(smsaddr));
       
   756 	}
       
   757 
       
   758 void CSmsSendRecvTest::ShowMenuL()
       
   759 	{
       
   760 	iSmsTest.ResetMenu();
       
   761 
       
   762 	iSmsTest.AppendToMenuL(_L("Start"));
       
   763 	iSmsTest.AppendToMenuL(_L("Display Log"));
       
   764 	iSmsTest.AppendToMenuL(_L("Clear Log"));
       
   765 	iSmsTest.AppendToMenuL(_L("Navigate Message Store"));
       
   766 
       
   767 	TInt result = iSmsTest.DisplayMenu(_L("SMS Send Receive Test"));
       
   768 
       
   769 	if (result <= 0)
       
   770 		return;
       
   771 
       
   772 	switch (result)
       
   773 		{
       
   774 		case 1:
       
   775 			RunAutoL();
       
   776 			return;
       
   777 		case 2:
       
   778 			DisplayLogL();
       
   779 			break;
       
   780 		case 3:
       
   781 			ClearLogL();
       
   782 			break;
       
   783 		case 4:
       
   784 			iSmsTest.NavigateMessageStoreL();
       
   785 			break;
       
   786 		default:
       
   787 			User::Leave(KErrArgument);
       
   788 			break;
       
   789 		}
       
   790 
       
   791 	ShowMenuL();
       
   792 	}
       
   793 
       
   794 void CSmsSendRecvTest::RunComplete()
       
   795 	{
       
   796 	if (!IsActive())
       
   797 		CActiveScheduler::Stop();
       
   798 	}
       
   799 
       
   800 void CSmsSendRecvTest::RunL()
       
   801 /**
       
   802 	Handles completed async operations
       
   803  */
       
   804 	{
       
   805 	switch (iState)
       
   806 		{
       
   807 		case EStateSending:
       
   808 			{
       
   809 			DoRunSendingL();
       
   810 			delete iOperation;
       
   811 			iOperation = NULL;
       
   812 			break;
       
   813 			}
       
   814 		case EStateWaitingToReceive:
       
   815 			{
       
   816 			DoRunWaitingToReceiveL();
       
   817 			break;
       
   818 			}
       
   819 		case EStateWaitingToReceiveAnyExtra:
       
   820 			{
       
   821 			DoRunWaitForExtraL();
       
   822 			break;
       
   823 			}
       
   824 		case EStateMessageReceived:
       
   825 			{
       
   826 			TestParseL();
       
   827 			break;
       
   828 			}
       
   829 		case EStateParsing:
       
   830 			{
       
   831 			DoRunTestParseL();
       
   832 			break;
       
   833 			}
       
   834 		default:
       
   835 			{
       
   836 			break;
       
   837 			}
       
   838 		}
       
   839 
       
   840 	RunComplete();
       
   841 	}
       
   842 
       
   843 TInt CSmsSendRecvTest::RunError(TInt aError)
       
   844 	{
       
   845 	aError = CSmsTestBase::RunError(aError);
       
   846 	RunComplete();
       
   847 	return aError;
       
   848 	}
       
   849 
       
   850 void CSmsSendRecvTest::DoRunTestParseL()
       
   851 /**
       
   852 	Checks status
       
   853  */
       
   854 	{
       
   855 	TBioProgress progress;
       
   856 	TBioProgressBuf progressBuf;
       
   857 	progressBuf.Copy(iOperation->ProgressL());
       
   858 	progress = progressBuf();
       
   859 
       
   860 	if (iStatus == KErrNone)
       
   861 		iStatus = progress.iErrorCode;
       
   862 
       
   863 	delete iOperation;
       
   864 	iOperation = NULL;
       
   865 	}
       
   866 
       
   867 void CSmsSendRecvTest::TestParseL()
       
   868 /**
       
   869 	Parses BIO messages
       
   870  */
       
   871 	{
       
   872 	const TMsvId id = iEntryObserver->LastReceived();
       
   873 
       
   874 	iSmsTest.SetEntryL(id);
       
   875 
       
   876 	if (iSaveToFile)
       
   877 		{
       
   878 		iSmsTest.Printf(_L("\tSaving BIO message to file\n"));
       
   879 		iSmsTest.SaveBodyToFileL(id);
       
   880 		}
       
   881 
       
   882 	if (!iParse)
       
   883 		return;
       
   884 
       
   885 	if (!iSmsTest.Entry().iBioType)
       
   886 		return;
       
   887 
       
   888 	iState = EStateParsing;
       
   889 	
       
   890 	iSmsTest.Printf(_L("Parsing BIO message\n"));
       
   891 
       
   892 	CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
   893 	CleanupStack::PushL(sel);
       
   894 
       
   895 	sel->AppendL(id);
       
   896 
       
   897 	delete iOperation;
       
   898 	iOperation = NULL;
       
   899 	
       
   900 	iOperation = Session().TransferCommandL(*sel, KBiosMtmParse, KNullDesC8, iStatus);
       
   901 	SetActive();
       
   902 
       
   903 	CleanupStack::PopAndDestroy(sel);
       
   904 	}
       
   905 
       
   906 void CSmsSendRecvTest::DoCancel()
       
   907 	{
       
   908 	if (iOperation)
       
   909 		{
       
   910 		iOperation->Cancel();
       
   911 		iSmsTest.Printf(_L("Operation Cancelled!\n"));
       
   912 		}
       
   913 	delete iOperation;
       
   914 	iOperation = NULL;
       
   915 	}
       
   916 
       
   917 void CSmsSendRecvTest::DoRunSendingL()
       
   918 /**
       
   919 	Checks the status and displays the sending states
       
   920  */
       
   921 	{
       
   922 	if (iOperation)
       
   923 		iSmsTest.SetProgressL(*iOperation);
       
   924 
       
   925 	TInt count = iSelection->Count();
       
   926 	TBool wait = EFalse;
       
   927 
       
   928 	while (iStatus == KErrNone && count--)
       
   929 		{
       
   930 		TRAPD(err, iSmsTest.SetEntryL(iSelection->At(count)));
       
   931 
       
   932 		if (err == KErrNone)
       
   933 			{
       
   934 			TMsvEntry entry = MsvEntry().Entry();
       
   935 			iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   936 
       
   937 			TBuf<0x100> output;
       
   938 			TBuf<0x50>  nowBuf;
       
   939 
       
   940 			switch (entry.SendingState())
       
   941 				{
       
   942 				case KMsvSendStateSending:
       
   943 					output.AppendFormat(_L("Message %d Sending with error %d\n"), entry.Id(), entry.iError);
       
   944 					wait = ETrue;
       
   945 					break;
       
   946 				case KMsvSendStateResend:
       
   947 					output.AppendFormat(_L("Message %d Resend with error %d at "), entry.Id(), entry.iError);
       
   948 					entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
   949 					output.Append(nowBuf);
       
   950 					output.Append(_L("\n"));
       
   951 					wait = ETrue;
       
   952 					break;
       
   953 				case KMsvSendStateScheduled:
       
   954 					output.AppendFormat(_L("Message %d Scheduled at "), entry.Id());					entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
   955 					entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
   956 					output.Append(nowBuf);
       
   957 					output.Append(_L("\n"));
       
   958 					wait = ETrue;
       
   959 					break;
       
   960 				case KMsvSendStateFailed:
       
   961 					output.AppendFormat(_L("Message %d Failed with error %d\n"), entry.Id(), entry.iError);
       
   962 					if (entry.iError)
       
   963 						iStatus = entry.iError;
       
   964 					else
       
   965 						iStatus = KErrGeneral;
       
   966 
       
   967 					break;
       
   968 				case KMsvSendStateWaiting:
       
   969 					output.AppendFormat(_L("Message %d Waiting with error %d\n"), entry.Id(), entry.iError);
       
   970 					wait = ETrue;
       
   971 					break;
       
   972 				case KMsvSendStateSent:
       
   973 				default:
       
   974 					break;
       
   975 					//nothing
       
   976 				}
       
   977 
       
   978 			iSmsTest.Printf(output);
       
   979 			}
       
   980 		}
       
   981 
       
   982 	if (wait)
       
   983 		{
       
   984 		iTimer->AfterReq(10000000, iStatus);
       
   985 		SetActive();
       
   986 		iState = EStateSending;
       
   987 //		CActiveScheduler::Start();
       
   988 		}
       
   989 	else
       
   990 		{
       
   991 		iSmsTest.Printf(_L("Sending completed with %d\n"), iStatus);
       
   992 		
       
   993 		if (iStatus == KErrNone)
       
   994 			{
       
   995 			TestWaitForReceiveL();
       
   996 			}
       
   997 		else
       
   998 			{
       
   999 			iState = EStateWaiting;
       
  1000 			}
       
  1001 		}
       
  1002 	}
       
  1003 
       
  1004 void CSmsSendRecvTest::WaitForExtraL()
       
  1005 /**
       
  1006 	Waits for any extra messages to arrive 
       
  1007  */
       
  1008 	{
       
  1009 	iSmsTest.Printf(_L("Waiting for any extra to arrive...\n"));
       
  1010 	iWaitForever = EFalse;
       
  1011 	iCountWaits = 0;
       
  1012 	iState = EStateWaitingToReceiveAnyExtra;
       
  1013 	TRequestStatus* status = &iStatus;
       
  1014 	User::RequestComplete(status, KErrNone);
       
  1015 	SetActive();
       
  1016 	CActiveScheduler::Start();
       
  1017 	}
       
  1018 
       
  1019 void CSmsSendRecvTest::DoRunWaitForExtraL()
       
  1020 /**
       
  1021 	Checks if it has received all messages sent
       
  1022  */
       
  1023 	{
       
  1024 	iCountWaits++;
       
  1025 
       
  1026 	TInt recvCount = iEntryObserver->Count();
       
  1027 
       
  1028 	if (recvCount > iSent)
       
  1029 		{
       
  1030 		iSmsTest.Printf(_L("Too many messages received:\nSent %d Rcvd %d\n"), iSent, recvCount);
       
  1031 		iStatus = KErrOverflow;
       
  1032 		}
       
  1033 	else
       
  1034 		DoWaitL();
       
  1035 	}
       
  1036 
       
  1037 void CSmsSendRecvTest::DoRunWaitingToReceiveL()
       
  1038 /**
       
  1039 	Checks if it has received all messages sent
       
  1040  */
       
  1041 	{
       
  1042 	iCountWaits++;
       
  1043 
       
  1044 	const TInt recvCount = iEntryObserver->Count();
       
  1045 
       
  1046 	if (recvCount == iSent)
       
  1047 		{
       
  1048 		//Message received
       
  1049 		if (!iSmsTest.AreMessagesSameTextL((*iSelection)[iCurrentMessageNum], iEntryObserver->Received(iSent - 1), ETrue))
       
  1050 			{
       
  1051 			//Do something?
       
  1052 			}
       
  1053 		}
       
  1054 
       
  1055 	if (recvCount > iSent)
       
  1056 		{
       
  1057 		iSmsTest.Printf(_L("Too many messages received:\nSent %d Rcvd %d\n"), iSent, recvCount);
       
  1058 		iStatus = KErrOverflow;
       
  1059 		}
       
  1060 	else 
       
  1061 		{
       
  1062 		if (iTotal == recvCount || recvCount == iSent)
       
  1063 			{
       
  1064 			if (iTotal == recvCount)
       
  1065 				iSmsTest.Printf(_L("All Messages Received!!\n"));
       
  1066 
       
  1067 			//Message received
       
  1068 			iState = EStateMessageReceived;
       
  1069 			iCountWaits = 0;
       
  1070 			TRequestStatus* status = &iStatus;
       
  1071 			User::RequestComplete(status, KErrNone);
       
  1072 			SetActive();
       
  1073 			}
       
  1074 		else
       
  1075 			{
       
  1076 			DoWaitL();
       
  1077 			}
       
  1078 		}
       
  1079 	}
       
  1080 	
       
  1081 void CSmsSendRecvTest::DoWaitL()
       
  1082 /**
       
  1083 	Waits to receive the messages sent
       
  1084  */
       
  1085 	{
       
  1086 	TInt recvCount = iEntryObserver->Count();
       
  1087 	
       
  1088 	TInt maxCount = KMaxWaitForMsg.Int() / KWaitForReceiveIteration.Int();
       
  1089 	TInt waitSecs = KWaitForReceiveIteration.Int() * (maxCount - iCountWaits) / 1000000;
       
  1090 	
       
  1091 	if (iWaitForever && iCountWaits <= 1)
       
  1092 		{
       
  1093 		iSmsTest.Printf(_L("Waiting forever to recv msg\n"));
       
  1094 		}
       
  1095 	else if (!iWaitForever)
       
  1096 		{
       
  1097 		iSmsTest.Printf(_L("Waiting %d secs to recv msg\n"), waitSecs);
       
  1098 		}
       
  1099 	
       
  1100 	if (iWaitForever || iCountWaits < maxCount)
       
  1101 		{
       
  1102 		iTimer->AfterReq(KWaitForReceiveIteration, iStatus);
       
  1103 		SetActive();
       
  1104 		}
       
  1105 	else
       
  1106 		{
       
  1107 		if (iSent != recvCount)
       
  1108 			{
       
  1109 			iSmsTest.Printf(_L("Time Out: Message NOT Received\n"));
       
  1110 			iStatus = KErrTimedOut;
       
  1111 			}
       
  1112 		}
       
  1113 	}
       
  1114 	
       
  1115 void CSmsSendRecvTest::TestBifsL()
       
  1116 /**
       
  1117 	todo Comments
       
  1118  */
       
  1119 	{
       
  1120 	iSmsTest.Printf(_L("Remove 2 Bifs if already exist\n"));	
       
  1121 	TestRemoveBifL(KTestBif1);
       
  1122 	TestRemoveBifL(KTestBif2);
       
  1123 	
       
  1124 	//Test add bif
       
  1125 	iSmsTest.Printf(_L("Test Add 2 Bifs\n"));	
       
  1126 	TestAddBifL(KTestBif1);
       
  1127 	TestAddBifL(KTestBif2);
       
  1128 
       
  1129 	//Test remove bif
       
  1130 	iSmsTest.Printf(_L("Test Remove 2 Bifs\n"));	
       
  1131 	TestRemoveBifL(KTestBif1);
       
  1132 	TestRemoveBifL(KTestBif2);
       
  1133 
       
  1134 	//Test change bif
       
  1135 	iSmsTest.Printf(_L("Test Change 2 Bifs\n"));	
       
  1136 	TestAddBifL(KTestBif1);
       
  1137 	TestAddBifL(KTestBif2);
       
  1138 	TestAddBifL(KTestBif1);
       
  1139 	TestAddBifL(KTestBif2);
       
  1140 
       
  1141 	//Test remove bif
       
  1142 	iSmsTest.Printf(_L("Test Remove 2 Bifs\n"));	
       
  1143 	TestRemoveBifL(KTestBif1);
       
  1144 	TestRemoveBifL(KTestBif2);
       
  1145 	}
       
  1146 
       
  1147 void CSmsSendRecvTest::TestAddBifL(const TDesC& aBifName)
       
  1148 /**
       
  1149 	Comments
       
  1150  */
       
  1151 	{
       
  1152 	iSmsTest.Printf(_L("\tAdd BIF: %S\n"), &aBifName);	
       
  1153 	
       
  1154 	RFs& fs = iSmsTest.FileSession();
       
  1155 	TInt err = fs.MkDir(KBifDir);
       
  1156 
       
  1157 	if (err != KErrAlreadyExists)
       
  1158 		User::LeaveIfError(err);
       
  1159 
       
  1160 	TParse fileOut;
       
  1161 	err = iSmsTest.ResolveFile(KSmsComponent, aBifName, fileOut);
       
  1162 
       
  1163 	if (err)
       
  1164 		{
       
  1165 		iSmsTest.Printf(_L("Test BIF %S not found! Continuing without this test\n"), &aBifName);
       
  1166 		return;
       
  1167 		}
       
  1168 
       
  1169 	CFileMan* fileMan = CFileMan::NewL(fs);
       
  1170 	CleanupStack::PushL(fileMan);
       
  1171 
       
  1172 	err = fileMan->Copy(fileOut.FullName(), KBifDir);
       
  1173 
       
  1174 	if (err != KErrAlreadyExists)
       
  1175 		User::LeaveIfError(err);
       
  1176 
       
  1177 	CleanupStack::PopAndDestroy(fileMan);
       
  1178 
       
  1179 	User::After(KBifWait);
       
  1180 	}
       
  1181 
       
  1182 void CSmsSendRecvTest::TestRemoveBifL(const TDesC& aBifName)
       
  1183 /**
       
  1184 	todo Comments
       
  1185  */
       
  1186 	{
       
  1187 	iSmsTest.Printf(_L("\tRemove Bif: %S\n"), &aBifName);	
       
  1188 
       
  1189 	RFs& fs = iSmsTest.FileSession();
       
  1190 	TFileName fileName(KBifDir);
       
  1191 	fileName.Append(aBifName);
       
  1192 
       
  1193 	TInt err = fs.Delete(fileName);
       
  1194 
       
  1195 	if (err)
       
  1196 		{
       
  1197 		iSmsTest.Printf(_L("\t\tfs.Delete() returned %d\n"), err);	
       
  1198 		
       
  1199 		if (err != KErrNotFound && err != KErrPathNotFound)
       
  1200 			User::Leave(err);
       
  1201 		}
       
  1202 
       
  1203 	User::After(KBifWait);
       
  1204 	}
       
  1205