messagingfw/msgtest/integration/sms/src/T_SmsSendRecv.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1999-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 "T_SmsSendRecv.h"
       
    17 #include <watcher.h>
       
    18 #include <smuthdr.h>
       
    19 #include <txtrich.h>
       
    20 #include <bioscmds.h>
       
    21 #include "biosmtm.h"
       
    22 #include <e32std.h>
       
    23 
       
    24 CEntryObserver* CEntryObserver::NewL(CSmsTestUtils& aTestUtils, const TInt& aCurrentMessageNum)
       
    25 	{
       
    26 	CEntryObserver* self = new (ELeave) CEntryObserver(aTestUtils, aCurrentMessageNum);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->iReceived = new (ELeave) CMsvEntrySelection();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CEntryObserver::CEntryObserver(CSmsTestUtils& aTestUtils, const TInt& aCurrentMessageNum)
       
    34 : CBase(), iCurrentMessageNum(aCurrentMessageNum), iSmsTest(aTestUtils)
       
    35 	{
       
    36 	}
       
    37 
       
    38 
       
    39 CEntryObserver::~CEntryObserver() 
       
    40 	{
       
    41 	delete iReceived;
       
    42 	}
       
    43 
       
    44 void CEntryObserver::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* aArg1, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    45 	{
       
    46 	if (aEvent == EMsvNewChildren && iCurrentMessageNum > -1)
       
    47 		{
       
    48 		CMsvEntrySelection* msgs = (CMsvEntrySelection*)aArg1;
       
    49 
       
    50 		TInt count = msgs->Count();
       
    51 
       
    52 		TInt msgRecv = 0;
       
    53 
       
    54 		while (count--)
       
    55 			{
       
    56 			TMsvId id = (*msgs)[count];
       
    57 
       
    58 			CSmsHeader* header = iSmsTest.GetHeaderLC(id);
       
    59 
       
    60 			if (header->Type() == CSmsPDU::ESmsDeliver)
       
    61 				{
       
    62 				iReceived->AppendL(id);
       
    63 				msgRecv++;
       
    64 				}
       
    65 
       
    66 			CleanupStack::PopAndDestroy(header);
       
    67 			}
       
    68 
       
    69 		if (msgRecv)	
       
    70 			iSmsTest.Printf(_L("%d Messages Received in inbox\n"), msgRecv);
       
    71 		}
       
    72 	}
       
    73 
       
    74 CSmsSendRecvTest::~CSmsSendRecvTest()
       
    75 	{
       
    76 	delete iEntryObserver;
       
    77 	delete iEntryForObserver;
       
    78 	}
       
    79 
       
    80 CSmsSendRecvTest* CSmsSendRecvTest::NewLC(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
    81 	{
       
    82 	CSmsSendRecvTest* self = new (ELeave) CSmsSendRecvTest(aSmsTest, aScriptFile, aNextTest);
       
    83 	CleanupStack::PushL(self);
       
    84 	self->ConstructL();
       
    85 	return self;
       
    86 	}
       
    87 
       
    88 
       
    89 void CSmsSendRecvTest::TestSendingL()
       
    90 	{
       
    91 	iSmsTest.Test().Next(_L("Sending"));
       
    92 
       
    93 	TTime now;
       
    94 	now.HomeTime();
       
    95 	now += (TTimeIntervalSeconds) 5;
       
    96 
       
    97 	iSelection->Reset();
       
    98 
       
    99 	iSmsTest.DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId);
       
   100 
       
   101 	TBool read = EFalse;
       
   102 	iSmsTest.Printf(_L("Creating msgs in outbox from script:"));
       
   103 	iSmsTest.Printf(iScriptFile);
       
   104 	TRAPD(err, read = iSmsTest.ReadScriptL(iScriptFile, KMsvGlobalOutBoxIndexEntryId, *iSelection, now));
       
   105 
       
   106 	iSmsTest.Test()(!err && read);
       
   107 
       
   108 	iSmsTest.Printf(_L("Send and Receive %d messages...\n"), iSelection->Count());
       
   109 
       
   110 	TInt count = iSelection->Count();
       
   111 	iTotal = 0;
       
   112 	iSent = 0;
       
   113 	while (count--)
       
   114 		{
       
   115 		iTotal += CountRecipientsL(iSelection->At(count));
       
   116 		}
       
   117 
       
   118 	iCurrentMessageNum = -1;
       
   119 	}
       
   120 
       
   121 TInt CSmsSendRecvTest::CountRecipientsL(TMsvId aId)
       
   122 	{
       
   123 	CSmsHeader* header = iSmsTest.GetHeaderLC(aId);
       
   124 	const TInt count = header->Recipients().Count();
       
   125 	CleanupStack::PopAndDestroy(header);
       
   126 	return count;
       
   127 	}
       
   128 
       
   129 TBool CSmsSendRecvTest::SendNextMessageL()
       
   130 	{
       
   131 	iCurrentMessageNum++;
       
   132 	const TInt count = iSelection->Count();
       
   133 
       
   134 	if (iCurrentMessageNum < count)
       
   135 		{
       
   136 		iSmsTest.Printf(_L("Sending message %d of %d\n"), iCurrentMessageNum + 1, count);
       
   137 
       
   138 
       
   139 		delete iOperation;
       
   140 		iOperation = NULL;
       
   141 
       
   142 		CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
   143 		CleanupStack::PushL(sel);
       
   144 		const TMsvId id = iSelection->At(iCurrentMessageNum);
       
   145 		sel->AppendL(id);
       
   146 		iSent += CountRecipientsL(id);
       
   147 		iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   148 		iOperation = MsvEntry().CopyL(*sel, iSmsTest.iSmsServiceId, iStatus);
       
   149 		CleanupStack::PopAndDestroy(); //sel
       
   150 		
       
   151 		iState = EStateSending;
       
   152 		SetActive();
       
   153 		CActiveScheduler::Start();
       
   154 		return ETrue;
       
   155 		}
       
   156 
       
   157 	return EFalse;
       
   158 	}
       
   159 
       
   160 void CSmsSendRecvTest::TestWaitForReceiveL()
       
   161 	{
       
   162 	iSmsTest.Test().Next(_L("Waiting to receive message"));
       
   163 	iState = EStateWaitingToReceive;
       
   164 	TRequestStatus* status = &iStatus;
       
   165 	User::RequestComplete(status, KErrNone);
       
   166 	SetActive();
       
   167 	}
       
   168 
       
   169 CSmsSendRecvTest::CSmsSendRecvTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest)
       
   170 : CSmsTestBase(aSmsTest, aScriptFile, aNextTest), iCurrentMessageNum(-1), iState(EStateWaiting)
       
   171 	{
       
   172 	TBuf<256> command;
       
   173 	User::CommandLine(command);
       
   174 	command.Trim();
       
   175 	iParse = (command.FindF(KParseAfterReceive) != KErrNotFound);
       
   176 	iSaveToFile = (command.FindF(KSaveAfterReceive) != KErrNotFound);
       
   177 	iTestBifs = (command.FindF(KTestBifs) != KErrNotFound);
       
   178 	iWaitForever = (command.FindF(KWaitForever) != KErrNotFound);
       
   179 	}
       
   180 
       
   181 void CSmsSendRecvTest::RunAutoL()
       
   182 	{	
       
   183 	if (!iSmsTest.iSmokeTest && iTestBifs)
       
   184 		{
       
   185 		iSmsTest.TestStart(++iNextTest, _L("Add Remove Bifs"));
       
   186 		TestBifsL();
       
   187 		User::LeaveIfError(iStatus.Int());
       
   188 		iSmsTest.TestFinish(iNextTest, KErrNone);
       
   189 		}
       
   190 
       
   191 	iSmsTest.TestStart(++iNextTest, _L("Read Script"));
       
   192 	TestSendingL();
       
   193 	User::LeaveIfError(iStatus.Int());
       
   194 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   195 
       
   196 	FOREVER
       
   197 		{
       
   198 		iSmsTest.TestStart(++iNextTest, _L("Send Message"));
       
   199 		TBool sendNext = SendNextMessageL();
       
   200 		if (sendNext)
       
   201 			{
       
   202 			User::LeaveIfError(iStatus.Int());
       
   203 			iSmsTest.TestFinish(iNextTest, KErrNone);
       
   204 			}
       
   205 		else
       
   206 			{
       
   207 			iSmsTest.Printf(_L("No more messages to send!"));
       
   208 			iSmsTest.TestFinish(iNextTest, KErrNone);
       
   209 			break;
       
   210 			}
       
   211 		}
       
   212 
       
   213 	iSmsTest.TestStart(++iNextTest, _L("Wait to receive extra message(s)"));
       
   214 	WaitForExtraL();
       
   215 	User::LeaveIfError(iStatus.Int());
       
   216 	iSmsTest.TestFinish(iNextTest, KErrNone);
       
   217 
       
   218 	iSmsTest.Printf(_L("\nDisplay Final Log:\n"));
       
   219 	DisplayLogL();
       
   220 	}
       
   221 
       
   222 void CSmsSendRecvTest::ConstructL()
       
   223 	{
       
   224 	SetTestNameL(KSmsSendRecvTestName);
       
   225 	iSmsTest.SetLogToFile();
       
   226 
       
   227 	TBuf<256> command;
       
   228 	User::CommandLine(command);
       
   229 	command.Trim();
       
   230 	iSmsTest.Printf(_L("Command Line: \"%S\" (Parse %d, Save %d, Wait %d, Bifs %d)\n"), &command, iParse, iSaveToFile, iWaitForever, iTestBifs);
       
   231 
       
   232 	iSelection = new (ELeave) CMsvEntrySelection();
       
   233 	iTimer = CTestTimer::NewL();
       
   234 	CActiveScheduler::Add(this);
       
   235 
       
   236 	iSmsTest.SetCommDbServiceCenterFromScriptL(iScriptFile);
       
   237 
       
   238   	iEntryObserver = CEntryObserver::NewL(iSmsTest, iCurrentMessageNum);
       
   239   	iEntryForObserver = Session().GetEntryL(KMsvGlobalInBoxIndexEntryId);
       
   240   	iEntryForObserver->AddObserverL(*iEntryObserver);
       
   241 
       
   242 	ClearLogL();
       
   243 	}
       
   244 
       
   245 void CSmsSendRecvTest::ShowMenuL()
       
   246 	{
       
   247 	iSmsTest.ResetMenu();
       
   248 
       
   249 	iSmsTest.AppendToMenuL(_L("Start"));
       
   250 	iSmsTest.AppendToMenuL(_L("Display Log"));
       
   251 	iSmsTest.AppendToMenuL(_L("Clear Log"));
       
   252 
       
   253 	TInt result = iSmsTest.DisplayMenu(_L("SMS Send Receive Test"));
       
   254 
       
   255 	if (result <= 0)
       
   256 		return;
       
   257 
       
   258 	switch (result)
       
   259 		{
       
   260 		case 1:
       
   261 			RunAutoL();
       
   262 			return;
       
   263 		case 2:
       
   264 			DisplayLogL();
       
   265 			break;
       
   266 		case 3:
       
   267 			ClearLogL();
       
   268 			break;
       
   269 		default:
       
   270 			User::Leave(KErrArgument);
       
   271 			break;
       
   272 		}
       
   273 
       
   274 	ShowMenuL();
       
   275 	}
       
   276 
       
   277 void CSmsSendRecvTest::RunComplete()
       
   278 	{
       
   279 	if (!IsActive())
       
   280 		CActiveScheduler::Stop();
       
   281 	}
       
   282 
       
   283 void CSmsSendRecvTest::RunL()
       
   284 	{
       
   285 	switch (iState)
       
   286 		{
       
   287 		case EStateSending:
       
   288 			{
       
   289 			DoRunSendingL();
       
   290 			delete iOperation;
       
   291 			iOperation = NULL;
       
   292 			break;
       
   293 			}
       
   294 		case EStateWaitingToReceive:
       
   295 			{
       
   296 			DoRunWaitingToReceiveL();
       
   297 			break;
       
   298 			}
       
   299 		case EStateWaitingToReceiveAnyExtra:
       
   300 			{
       
   301 			DoRunWaitForExtraL();
       
   302 			break;
       
   303 			}
       
   304 		case EStateMessageReceived:
       
   305 			{
       
   306 			TestParseL();
       
   307 			break;
       
   308 			}
       
   309 		case EStateParsing:
       
   310 			{
       
   311 			DoRunTestParseL();
       
   312 			break;
       
   313 			}
       
   314 		default:
       
   315 			{
       
   316 			break;
       
   317 			}
       
   318 		}
       
   319 
       
   320 	RunComplete();
       
   321 	}
       
   322 
       
   323 TInt CSmsSendRecvTest::RunError(TInt aError)
       
   324 	{
       
   325 	aError = CSmsTestBase::RunError(aError);
       
   326 	RunComplete();
       
   327 	return aError;
       
   328 	}
       
   329 
       
   330 void CSmsSendRecvTest::DoRunTestParseL()
       
   331 	{
       
   332 	TBioProgress progress;
       
   333 	TBioProgressBuf progressBuf;
       
   334 	progressBuf.Copy(iOperation->ProgressL());
       
   335 	progress = progressBuf();
       
   336 
       
   337 	if (iStatus == KErrNone)
       
   338 		iStatus = progress.iErrorCode;
       
   339 
       
   340 	delete iOperation;
       
   341 	iOperation = NULL;
       
   342 	}
       
   343 
       
   344 void CSmsSendRecvTest::TestParseL()
       
   345 	{
       
   346 	const TMsvId id = iEntryObserver->LastReceived();
       
   347 
       
   348 	iSmsTest.SetEntryL(id);
       
   349 
       
   350 	if (iSaveToFile)
       
   351 		{
       
   352 		iSmsTest.Printf(_L("Saving BIO message to file\n"));
       
   353 		iSmsTest.SaveBodyToFileL(id);
       
   354 		}
       
   355 
       
   356 	CSmsHeader* header = iSmsTest.GetHeaderLC(id);
       
   357  	CSmsDeliver& pdu = header->Deliver();
       
   358 
       
   359 	TBool found = EFalse;
       
   360 	TInt destination, originator, is16Bit;
       
   361 	destination = originator = is16Bit = 0;
       
   362 	if (pdu.UserDataPresent())
       
   363 		{
       
   364 		const CSmsUserData& userData = pdu.UserData();
       
   365 		TInt count = userData.NumInformationElements();
       
   366 		iSmsTest.Printf(_L("Pdu contains %d information elements\n"), count);
       
   367 		while (!found && count--)
       
   368 			{
       
   369 			CSmsInformationElement& nextIE=userData.InformationElement(count);
       
   370 			switch(nextIE.Identifier())
       
   371 				{
       
   372 				case CSmsInformationElement::ESmsIEIApplicationPortAddressing8Bit:
       
   373 				case CSmsInformationElement::ESmsIEIApplicationPortAddressing16Bit:
       
   374 					{
       
   375 					pdu.ApplicationPortAddressing(destination, originator, &is16Bit);
       
   376 					found = ETrue;
       
   377 					break;
       
   378 					}
       
   379 				default:
       
   380 					break;
       
   381 				}
       
   382 			}
       
   383 		}
       
   384 
       
   385 	CleanupStack::PopAndDestroy(header);
       
   386 
       
   387 	if (found)
       
   388 		iSmsTest.Printf(_L("Application Port Addressing: Dest %d, Origin %d, is16Bit %d\n"), destination, originator, is16Bit);
       
   389 	else
       
   390 		iSmsTest.Printf(_L("Application Port Addressing: Not Found\n"));
       
   391 
       
   392 	if (!iParse)
       
   393 		return;
       
   394 
       
   395 	if (!iSmsTest.Entry().iBioType)
       
   396 		return;
       
   397 
       
   398 	iState = EStateParsing;
       
   399 	
       
   400 	iSmsTest.Printf(_L("Parsing BIO message\n"));
       
   401 
       
   402 	CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
   403 	CleanupStack::PushL(sel);
       
   404 
       
   405 	sel->AppendL(id);
       
   406 
       
   407 	delete iOperation;
       
   408 	iOperation = NULL;
       
   409 	
       
   410 	iOperation = Session().TransferCommandL(*sel, KBiosMtmParse, KNullDesC8, iStatus);
       
   411 	SetActive();
       
   412 
       
   413 	CleanupStack::PopAndDestroy(sel);
       
   414 	}
       
   415 
       
   416 void CSmsSendRecvTest::DoCancel()
       
   417 	{
       
   418 	if (iOperation)
       
   419 		{
       
   420 		iOperation->Cancel();
       
   421 		iSmsTest.Printf(_L("Operation Cancelled!\n"));
       
   422 		}
       
   423 	delete iOperation;
       
   424 	iOperation = NULL;
       
   425 	}
       
   426 
       
   427 void CSmsSendRecvTest::DoRunSendingL()
       
   428 	{
       
   429 	if (iOperation)
       
   430 		iSmsTest.SetProgressL(*iOperation);
       
   431 
       
   432 	TInt count = iSelection->Count();
       
   433 	TBool wait = EFalse;
       
   434 
       
   435 	while (iStatus == KErrNone && count--)
       
   436 		{
       
   437 		TRAPD(err, iSmsTest.SetEntryL(iSelection->At(count)));
       
   438 
       
   439 		if (err == KErrNone)
       
   440 			{
       
   441 			TMsvEntry entry = MsvEntry().Entry();
       
   442 			iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   443 
       
   444 			TBuf<0x100> output;
       
   445 			TBuf<0x50>  nowBuf;
       
   446 
       
   447 			switch (entry.SendingState())
       
   448 				{
       
   449 				case KMsvSendStateSending:
       
   450 					output.AppendFormat(_L("Message %d Sending with error %d\n"), entry.Id(), entry.iError);
       
   451 					wait = ETrue;
       
   452 					break;
       
   453 				case KMsvSendStateResend:
       
   454 					output.AppendFormat(_L("Message %d Resend at "), entry.Id());
       
   455 					entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
   456 					output.Append(nowBuf);
       
   457 					output.Append(_L("\n"));
       
   458 					wait = ETrue;
       
   459 					break;
       
   460 				case KMsvSendStateScheduled:
       
   461 					output.AppendFormat(_L("Message %d Scheduled at "), entry.Id());					entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
   462 					entry.iDate.FormatL(nowBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
       
   463 					output.Append(nowBuf);
       
   464 					output.Append(_L("\n"));
       
   465 					wait = ETrue;
       
   466 					break;
       
   467 				case KMsvSendStateFailed:
       
   468 					output.AppendFormat(_L("Message %d Failed with error %d\n"), entry.Id(), entry.iError);
       
   469 					if (entry.iError)
       
   470 						iStatus = entry.iError;
       
   471 					else
       
   472 						iStatus = KErrGeneral;
       
   473 
       
   474 					break;
       
   475 				case KMsvSendStateWaiting:
       
   476 					output.AppendFormat(_L("Message %d Waiting with error %d\n"), entry.Id(), entry.iError);
       
   477 					wait = ETrue;
       
   478 					break;
       
   479 				case KMsvSendStateSent:
       
   480 				default:
       
   481 					break;
       
   482 					//nothing
       
   483 				}
       
   484 
       
   485 			iSmsTest.Printf(output);
       
   486 			}
       
   487 		}
       
   488 
       
   489 	if (wait)
       
   490 		{
       
   491 		iTimer->AfterReq(10000000, iStatus);
       
   492 		SetActive();
       
   493 		iState = EStateSending;
       
   494 //		CActiveScheduler::Start();
       
   495 		}
       
   496 	else
       
   497 		{
       
   498 		iSmsTest.Printf(_L("Sending completed with %d\n"), iStatus);
       
   499 		
       
   500 		if (iStatus == KErrNone)
       
   501 			{
       
   502 			TestWaitForReceiveL();
       
   503 			}
       
   504 		else
       
   505 			{
       
   506 			iState = EStateWaiting;
       
   507 			}
       
   508 		}
       
   509 	}
       
   510 
       
   511 void CSmsSendRecvTest::WaitForExtraL()
       
   512 	{
       
   513 	iSmsTest.Printf(_L("Waiting for any extra to arrive...\n"));
       
   514 	iWaitForever = EFalse;
       
   515 	iCountWaits = 0;
       
   516 	iState = EStateWaitingToReceiveAnyExtra;
       
   517 	TRequestStatus* status = &iStatus;
       
   518 	User::RequestComplete(status, KErrNone);
       
   519 	SetActive();
       
   520 	CActiveScheduler::Start();
       
   521 	}
       
   522 
       
   523 void CSmsSendRecvTest::DoRunWaitForExtraL()
       
   524 	{
       
   525 	iCountWaits++;
       
   526 
       
   527 	TInt recvCount = iEntryObserver->Count();
       
   528 
       
   529 	if (recvCount > iSent)
       
   530 		{
       
   531 		iSmsTest.Printf(_L("Too many messages received:\nSent %d Rcvd %d\n"), iSent, recvCount);
       
   532 		iStatus = KErrOverflow;
       
   533 		}
       
   534 	else
       
   535 		DoWaitL();
       
   536 	}
       
   537 
       
   538 void CSmsSendRecvTest::DoRunWaitingToReceiveL()
       
   539 	{
       
   540 	iCountWaits++;
       
   541 
       
   542 	const TInt recvCount = iEntryObserver->Count();
       
   543 
       
   544 	if (recvCount == iSent)
       
   545 		{
       
   546 		//Message received
       
   547 		if (!iSmsTest.AreMessagesSameTextL((*iSelection)[iCurrentMessageNum], iEntryObserver->Received(iSent - 1), ETrue))
       
   548 			{
       
   549 			//Do something?
       
   550 			}
       
   551 		}
       
   552 
       
   553 	if (recvCount > iSent)
       
   554 		{
       
   555 		iSmsTest.Printf(_L("Too many messages received:\nSent %d Rcvd %d\n"), iSent, recvCount);
       
   556 		iStatus = KErrOverflow;
       
   557 		}
       
   558 	else 
       
   559 		{
       
   560 		if (iTotal == recvCount || recvCount == iSent)
       
   561 			{
       
   562 			if (iTotal == recvCount)
       
   563 				iSmsTest.Printf(_L("All Messages Received!!\n"));
       
   564 
       
   565 			//Message received
       
   566 			iState = EStateMessageReceived;
       
   567 			iCountWaits = 0;
       
   568 			TRequestStatus* status = &iStatus;
       
   569 			User::RequestComplete(status, KErrNone);
       
   570 			SetActive();
       
   571 			}
       
   572 		else
       
   573 			{
       
   574 			DoWaitL();
       
   575 			}
       
   576 		}
       
   577 	}
       
   578 
       
   579 void CSmsSendRecvTest::DoWaitL()
       
   580 	{
       
   581 	TInt recvCount = iEntryObserver->Count();
       
   582 
       
   583 	TInt maxCount = KMaxWaitForMsg.Int() / KWaitForReceiveIteration.Int();
       
   584 	TInt waitSecs = KWaitForReceiveIteration.Int() * (maxCount - iCountWaits) / 1000000;
       
   585 
       
   586 	if (iWaitForever && iCountWaits <= 1)
       
   587 		{
       
   588 		iSmsTest.Printf(_L("Waiting forever to recv msg\n"));
       
   589 		}
       
   590 	else if (!iWaitForever)
       
   591 		{
       
   592 		iSmsTest.Printf(_L("Waiting %d secs to recv msg\n"), waitSecs);
       
   593 		}
       
   594 
       
   595 	if (iWaitForever || iCountWaits < maxCount)
       
   596 		{
       
   597 		iTimer->AfterReq(KWaitForReceiveIteration, iStatus);
       
   598 		SetActive();
       
   599 		}
       
   600 	else
       
   601 		{
       
   602 		if (iSent != recvCount)
       
   603 			{
       
   604 			iSmsTest.Printf(_L("Time Out: Message NOT Received\n"));
       
   605 			iStatus = KErrTimedOut;
       
   606 			}
       
   607 		}
       
   608 	}
       
   609 
       
   610 void CSmsSendRecvTest::TestBifsL()
       
   611 	{
       
   612 	iSmsTest.Printf(_L("Remove 2 Bifs if already exist\n"));	
       
   613 	TestRemoveBifL(KTestBif1);
       
   614 	TestRemoveBifL(KTestBif2);
       
   615 	
       
   616 	//Test add bif
       
   617 	iSmsTest.Printf(_L("Test Add 2 Bifs\n"));	
       
   618 	TestAddBifL(KTestBif1);
       
   619 	TestAddBifL(KTestBif2);
       
   620 
       
   621 	//Test remove bif
       
   622 	iSmsTest.Printf(_L("Test Remove 2 Bifs\n"));	
       
   623 	TestRemoveBifL(KTestBif1);
       
   624 	TestRemoveBifL(KTestBif2);
       
   625 
       
   626 	//Test change bif
       
   627 	iSmsTest.Printf(_L("Test Change 2 Bifs\n"));	
       
   628 	TestAddBifL(KTestBif1);
       
   629 	TestAddBifL(KTestBif2);
       
   630 	TestAddBifL(KTestBif1);
       
   631 	TestAddBifL(KTestBif2);
       
   632 
       
   633 	//Test remove bif
       
   634 	iSmsTest.Printf(_L("Test Remove 2 Bifs\n"));	
       
   635 	TestRemoveBifL(KTestBif1);
       
   636 	TestRemoveBifL(KTestBif2);
       
   637 	}
       
   638 
       
   639 void CSmsSendRecvTest::TestAddBifL(const TDesC& aBifName)
       
   640 	{
       
   641 	iSmsTest.Printf(_L("\tAdd BIF: %S\n"), &aBifName);	
       
   642 	
       
   643 	RFs& fs = iSmsTest.FileSession();
       
   644 	TInt err = fs.MkDir(KBifDir);
       
   645 
       
   646 	if (err != KErrAlreadyExists)
       
   647 		User::LeaveIfError(err);
       
   648 
       
   649 	TParse fileOut;
       
   650 	err = iSmsTest.ResolveFile(KSmsComponent, aBifName, fileOut);
       
   651 
       
   652 	if (err)
       
   653 		{
       
   654 		iSmsTest.Printf(_L("Test BIF %S not found! Continuing without this test\n"), &aBifName);
       
   655 		return;
       
   656 		}
       
   657 
       
   658 	CFileMan* fileMan = CFileMan::NewL(fs);
       
   659 	CleanupStack::PushL(fileMan);
       
   660 
       
   661 	err = fileMan->Copy(fileOut.FullName(), KBifDir);
       
   662 
       
   663 	if (err != KErrAlreadyExists)
       
   664 		User::LeaveIfError(err);
       
   665 
       
   666 	CleanupStack::PopAndDestroy(fileMan);
       
   667 
       
   668 	User::After(KBifWait);
       
   669 	}
       
   670 
       
   671 void CSmsSendRecvTest::TestRemoveBifL(const TDesC& aBifName)
       
   672 	{
       
   673 	iSmsTest.Printf(_L("\tRemove Bif: %S\n"), &aBifName);	
       
   674 
       
   675 	RFs& fs = iSmsTest.FileSession();
       
   676 	TFileName fileName(KBifDir);
       
   677 	fileName.Append(aBifName);
       
   678 
       
   679 	TInt err = fs.Delete(fileName);
       
   680 
       
   681 	if (err)
       
   682 		{
       
   683 		iSmsTest.Printf(_L("\t\tfs.Delete() returned %d\n"), err);	
       
   684 		
       
   685 		if (err != KErrNotFound && err != KErrPathNotFound)
       
   686 			User::Leave(err);
       
   687 		}
       
   688 
       
   689 	User::After(KBifWait);
       
   690 	}
       
   691