messagingfw/biomsgfw/T_BIOMSG/SRC/harness.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2003-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 "harness.h"
       
    17 #include "testframeutils.h"
       
    18 #include "msvtestutils.h"
       
    19 #include "biotestutils.h"
       
    20 #include <cemailaccounts.h>
       
    21 #include <csmsaccount.h>
       
    22 #include <iapprefs.h>
       
    23 
       
    24 CBaseTestHarness::~CBaseTestHarness()
       
    25 {
       
    26 	iStateList->ResetAndDestroy();
       
    27 	delete iStateList;
       
    28 }
       
    29 
       
    30 void CBaseTestHarness::StartL(TRequestStatus& aStatus)
       
    31 {
       
    32 	iCurrentState = 0;
       
    33 	iReportStatus = &aStatus;
       
    34 	aStatus = KRequestPending;
       
    35 
       
    36 	TInt err = KErrNone;
       
    37 	if (iCurrentState < iStateList->Count())
       
    38 	{
       
    39 		//
       
    40 		// We have to handle the error handeling ourselfs for the 1st request
       
    41 		// every other request will be handled by AS
       
    42 		if(iMarkTestStarts)
       
    43 			TestStart(iCurrentState);
       
    44 
       
    45 		TRAP(err, (iStateList->At(iCurrentState))->StartL(iStatus));
       
    46 		if(err != KErrNone)
       
    47 			RunError(err);
       
    48 	}
       
    49 	else
       
    50 	{
       
    51 		//
       
    52 		// Nothing to do!
       
    53 		TRequestStatus* status = &iStatus;
       
    54 		User::RequestComplete(status, KErrNone);
       
    55 	}
       
    56 
       
    57 	if(err == KErrNone)
       
    58 		SetActive();
       
    59 }
       
    60 
       
    61 
       
    62 void CBaseTestHarness::AddStateL(MBaseTestState* aTestState, TTestDebugInfo aDebugInfo)
       
    63 {
       
    64 	aTestState->SetDebugInfo(aDebugInfo);
       
    65 	TRAPD(err, iStateList->AppendL(aTestState));
       
    66 	if (err != KErrNone)
       
    67 	{
       
    68 		//
       
    69 		// If the state can't be added then delete it.
       
    70 		// We do this because we have taken ownership of the state.
       
    71 		delete aTestState;
       
    72 		User::Leave(err);
       
    73 	}
       
    74 }
       
    75 
       
    76 //
       
    77 // From CActive
       
    78 void CBaseTestHarness::RunL()
       
    79 {
       
    80 	if(iOldCurrentState != iCurrentState && iMarkTestStarts)
       
    81 	{
       
    82 		iOldCurrentState = iCurrentState;
       
    83 		TestFinish(iCurrentState, iStatus);
       
    84 	}
       
    85 
       
    86 	//
       
    87 	// Was there an error?
       
    88 	if (iStatus == KErrNone)
       
    89 	{
       
    90 		//
       
    91 		// Any more states?
       
    92 		iCurrentState++;
       
    93 		if(iCurrentState < iStateList->Count())
       
    94 		{
       
    95 			// If there are any more states, start them.  If StartL leaves, RunErrorL is called
       
    96 			// and we complete the request, and move to the next state.
       
    97 			if(iMarkTestStarts)
       
    98 				TestStart(iCurrentState);
       
    99 
       
   100 			(*iStateList)[iCurrentState]->StartL(iStatus);
       
   101 
       
   102 			SetActive();
       
   103 		}
       
   104 		else
       
   105 		{
       
   106 			//
       
   107 			// If this is the last state, complete the parents request
       
   108 			User::RequestComplete(iReportStatus, iStatus.Int());
       
   109 		}
       
   110 	}
       
   111 	else
       
   112 	{
       
   113 		//
       
   114 		// Handle the error
       
   115 		OnStateError();
       
   116 	}
       
   117 }
       
   118 
       
   119 void CBaseTestHarness::OnStateError()
       
   120 {
       
   121 	//
       
   122 	// Log the error
       
   123 	LogStateError();
       
   124 
       
   125 	//
       
   126 	// Move to the next state
       
   127 	RunError(KErrNone);
       
   128 }
       
   129 
       
   130 TInt CBaseTestHarness::RunError(TInt aError)
       
   131 {
       
   132 	// 
       
   133 	// Called when StartL leaves.  Complete the request.  The next call
       
   134 	// of RunL will log the error.
       
   135 	TRequestStatus* i = &iStatus;
       
   136 
       
   137 	// If the cmd is expected to fail, pass test.
       
   138 	if ((KErrNone != iExpectedError) && (aError == iExpectedError))
       
   139 		{
       
   140 		User::RequestComplete(i, KErrNone);
       
   141 		iExpectedError = KErrNone;
       
   142 		}
       
   143 	else
       
   144 		User::RequestComplete(i, aError);
       
   145 
       
   146 	SetActive();
       
   147 	return KErrNone;
       
   148 }
       
   149 
       
   150 TInt CBaseTestHarness::LogStateError()
       
   151 {
       
   152 	//
       
   153 	// Get the error message for the state
       
   154 	TTestDebugInfo debugInfo = (*iStateList)[iCurrentState]->GetDebugInfo();
       
   155 
       
   156 	//
       
   157 	// Get the test failed string (section name etc)
       
   158 	TInt err;
       
   159 	HBufC* errorText = NULL;
       
   160 	TRAP(err, errorText = debugInfo.TestFailedStringL(iStatus.Int()));
       
   161 	if (err != KErrNone)
       
   162 		return err;
       
   163 
       
   164 	//
       
   165 	// Log it
       
   166 	TRAP(err, LogCommentL(*errorText));
       
   167 	if (err != KErrNone)
       
   168 		return err;
       
   169 	TestConsole().Printf(*errorText);
       
   170 	TestConsole().Printf(_L("\r"));
       
   171 	delete errorText;
       
   172 
       
   173 	return KErrNone;
       
   174 }
       
   175 
       
   176 void CBaseTestHarness::ConstructL()
       
   177 {
       
   178 	CActiveScheduler::Add(this);
       
   179 	iStateList = new (ELeave) CArrayPtrFlat<MBaseTestState>(10);
       
   180 }
       
   181 
       
   182 //
       
   183 //
       
   184 // CMainTestHarness
       
   185 //
       
   186 
       
   187 CMainTestHarness* CMainTestHarness::NewL(RTest& aTest)
       
   188 {
       
   189 	CMainTestHarness* self = new (ELeave) CMainTestHarness(aTest);
       
   190 	CleanupStack::PushL(self);
       
   191 	self->ConstructL();
       
   192 	CleanupStack::Pop(self);
       
   193 	return self;
       
   194 }
       
   195 
       
   196 void CMainTestHarness::ConstructL()
       
   197 {
       
   198 	CBaseTestHarness::ConstructL();
       
   199 
       
   200 	iBioUtils = CBioTestUtils::NewL(iTest);
       
   201 	iAllTestsSuccessful = ETrue;
       
   202 }
       
   203 
       
   204 CMainTestHarness::~CMainTestHarness()
       
   205 {
       
   206 	if(iAllTestsSuccessful)
       
   207 		iBioUtils->TestHarnessCompleted();
       
   208 
       
   209 	else
       
   210 		iBioUtils->TestHarnessFailed(KErrGeneral);
       
   211 
       
   212 	delete iBioUtils;
       
   213 }
       
   214 
       
   215 void CMainTestHarness::TestStart(TInt& aState)
       
   216 {
       
   217 	if(iBioUtils != NULL)
       
   218 		iBioUtils->TestStart(aState);
       
   219 }
       
   220 
       
   221 void CMainTestHarness::TestFinish(TInt& aState, TRequestStatus& aStatus)
       
   222 {
       
   223 	if(iBioUtils != NULL)
       
   224 		iBioUtils->TestFinish(aState, aStatus.Int());
       
   225 
       
   226 	if (aStatus != KErrNone)
       
   227 		iAllTestsSuccessful = EFalse;
       
   228 }
       
   229 
       
   230 //
       
   231 //
       
   232 // CClientTestHarness
       
   233 //
       
   234 CClientTestHarness* CClientTestHarness::NewL(CBioTestUtils& aTestUtils, RTest& aTest)
       
   235 {
       
   236 	CClientTestHarness* self = new (ELeave) CClientTestHarness(aTestUtils, aTest);
       
   237 	CleanupStack::PushL(self);
       
   238 	self->ConstructL();
       
   239 	CleanupStack::Pop(self);
       
   240 	return self;
       
   241 }
       
   242 
       
   243 void CClientTestHarness::ConstructL()
       
   244 {
       
   245 	CBaseTestHarness::ConstructL();
       
   246 }
       
   247 
       
   248 void CClientTestHarness::LogCommentL(const TDesC& aComment)
       
   249 {
       
   250 	iBioUtils.WriteComment(aComment);
       
   251 }
       
   252 
       
   253 //
       
   254 // Custom error handeling
       
   255 void CClientTestHarness::OnStateError()
       
   256 {
       
   257 	//
       
   258 	// Get the base class to log the error
       
   259 	CBaseTestHarness::LogStateError();
       
   260 
       
   261 	//
       
   262 	// Complete the parents request - this has the net effect of skipping any
       
   263 	// remaing tests in this section.  This is because if one test failes, the chances
       
   264 	// are the remaining tests are dependent on it and fail too - worse still, they normall panic...
       
   265 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   266 }
       
   267 
       
   268 void CClientTestHarness::InstantiateSmsSettingsL()
       
   269 {
       
   270 	InstantiateClientMtmL();
       
   271 	delete iSmsSettings;
       
   272 	CSmsAccount* account = CSmsAccount::NewLC();
       
   273 	iSmsSettings = CSmsSettings::NewL();
       
   274 	account->LoadSettingsL(*iSmsSettings);
       
   275 	CleanupStack::PopAndDestroy(account);
       
   276 }
       
   277 
       
   278 TMsvId CClientTestHarness::GetImapServiceL(CEmailAccounts& aAccounts)
       
   279 	{
       
   280 	TMsvId imapService;
       
   281 	
       
   282 	RArray<TImapAccount> imapAccounts;
       
   283 	CleanupClosePushL(imapAccounts);
       
   284 	
       
   285 	aAccounts.GetImapAccountsL(imapAccounts);
       
   286 	if(imapAccounts.Count()>0)
       
   287 		{
       
   288 		// if a account exist take the first
       
   289 		imapService = imapAccounts[0].iImapService;
       
   290 		}
       
   291 	else
       
   292 		{
       
   293 		CImImap4Settings* imapSettings = new(ELeave) CImImap4Settings();
       
   294 		CleanupStack::PushL(imapSettings);
       
   295 
       
   296 		CImIAPPreferences* imapIAP = CImIAPPreferences::NewLC();
       
   297 				
       
   298 		aAccounts.PopulateDefaultImapSettingsL(*imapSettings, *imapIAP);
       
   299 
       
   300 		_LIT(KImapServer, "imap.dial.pipex.com");
       
   301 		imapSettings->SetServerAddressL(KImapServer);
       
   302 		_LIT8(KImapLoginName, "abf75");
       
   303 		imapSettings->SetLoginNameL(KImapLoginName);
       
   304 		_LIT8(KImapPassword, "oodifama");
       
   305 		imapSettings->SetPasswordL(KImapPassword);
       
   306 		imapSettings->SetPort(143);
       
   307 		
       
   308 		TImapAccount imapAccount = aAccounts.CreateImapAccountL(KNullDesC, *imapSettings, *imapIAP, EFalse);
       
   309 		imapService = imapAccount.iImapService;
       
   310 		
       
   311 		CleanupStack::PopAndDestroy(2, imapSettings); // imapIAP, imapSettings
       
   312 		}
       
   313 	CleanupStack::PopAndDestroy();
       
   314 	return imapService;
       
   315 	}
       
   316 
       
   317 void CClientTestHarness::InstantiateImapSettingsL()
       
   318 {
       
   319 	InstantiateClientMtmL();
       
   320 
       
   321 	if (iImapSettings==NULL)
       
   322 	{
       
   323 		TMsvId serviceId(KMsvNullIndexEntryId);
       
   324 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   325 		TRAPD(err, serviceId = GetImapServiceL(*accounts));
       
   326 		//
       
   327 		// If no default service
       
   328 		if((err==KErrNotFound) || (serviceId==KMsvUnknownServiceIndexEntryId))
       
   329 		{
       
   330 			_LIT(KUhOh,"ERROR Default IMAP4Settings Not Found");
       
   331 			TestUtils().WriteComment(KUhOh);
       
   332 			User::Leave(KErrNotFound);
       
   333 		}
       
   334 		else
       
   335 		{
       
   336 			iImapSettings = new(ELeave)CImImap4Settings();
       
   337 
       
   338 			TImapAccount imapAccount;
       
   339 			accounts->GetImapAccountL(serviceId, imapAccount);
       
   340  			accounts->LoadImapSettingsL(imapAccount, *iImapSettings);
       
   341 
       
   342 		}
       
   343 		
       
   344 		CleanupStack::PopAndDestroy(accounts);
       
   345 	}
       
   346 }
       
   347 
       
   348 void CClientTestHarness::InstantiateSmtpSettingsL()
       
   349 {
       
   350 	InstantiateClientMtmL();
       
   351 
       
   352 	if (iSmtpSettings==NULL)
       
   353 	{
       
   354 		TMsvId serviceId(KMsvNullIndexEntryId);
       
   355 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   356 		
       
   357 		TSmtpAccount smtpAccount;
       
   358 		TRAPD(err, accounts->DefaultSmtpAccountL(smtpAccount));
       
   359 		serviceId = smtpAccount.iSmtpService;
       
   360 
       
   361 		//
       
   362 		// if no default service
       
   363 		if((err==KErrNotFound) || (serviceId==KMsvUnknownServiceIndexEntryId))
       
   364 		{
       
   365 			_LIT(KUhOh,"ERROR Default SMTPSettings Not Found");
       
   366 			TestUtils().WriteComment(KUhOh);
       
   367 			User::Leave(KErrNotFound);
       
   368 		}
       
   369 		else
       
   370 		{
       
   371 			iSmtpSettings = new(ELeave)CImSmtpSettings();
       
   372 
       
   373 			
       
   374 			accounts->GetSmtpAccountL(serviceId, smtpAccount);
       
   375 			accounts->LoadSmtpSettingsL(smtpAccount, *iSmtpSettings);
       
   376 		}
       
   377 
       
   378 		CleanupStack::PopAndDestroy(accounts);
       
   379 	}
       
   380 }
       
   381 
       
   382 void CClientTestHarness::InstantiateNamedPop3SettingsL(const TDesC& aName)
       
   383 {
       
   384 	delete iPop3Settings;
       
   385 	iPop3Settings = NULL;
       
   386 
       
   387 	InstantiateClientMtmL();
       
   388 
       
   389 	TMsvId aPop3EntryId=KMsvNullIndexEntryId;
       
   390 
       
   391 	CMsvEntrySelection *msvSelection = NULL;
       
   392 
       
   393 	TMsvSelectionOrdering order;
       
   394 	order.SetShowInvisibleEntries( ETrue );
       
   395 	TestUtils().iMsvEntry->SetSortTypeL(order);
       
   396 
       
   397 	// Get list of children IDs
       
   398 	TestUtils().iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
       
   399 
       
   400 	msvSelection = TestUtils().iMsvEntry->ChildrenL();
       
   401 	CleanupStack::PushL(msvSelection);
       
   402 
       
   403 	
       
   404 	TMsvEntry entry;
       
   405 	TInt count = msvSelection->Count(); 
       
   406 	for (TInt j = 0; j < count; j++)
       
   407 	{
       
   408 		// set context to service entry
       
   409 		TestUtils().iMsvEntry->SetEntryL((*msvSelection)[j]);
       
   410 		entry = TestUtils().iMsvEntry->Entry(); 
       
   411 		
       
   412 		if (entry.iType == KUidMsvServiceEntry)
       
   413 		{
       
   414 			if(entry.iDetails.Length() == aName.Length())
       
   415 			{
       
   416 				if(entry.iDetails.CompareF(aName)==0 )
       
   417 				{
       
   418 					if(entry.iMtm == KUidMsgTypePOP3)
       
   419 					{
       
   420 						aPop3EntryId= entry.Id();						
       
   421 					}
       
   422 				}
       
   423 			}
       
   424 		}
       
   425 	}
       
   426 
       
   427 	CleanupStack::PopAndDestroy(msvSelection);
       
   428 
       
   429 	if(aPop3EntryId==KMsvNullIndexEntryId)
       
   430 	{
       
   431 		_LIT(KUhOh,"ERROR Matching Pop3Settings Not Found");
       
   432 		TestUtils().WriteComment(KUhOh);
       
   433 		User::Leave(KErrNotFound);
       
   434 	}
       
   435 	else
       
   436 	{
       
   437 		iPop3Settings = new(ELeave)CImPop3Settings();
       
   438 		
       
   439 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   440 
       
   441 		TPopAccount popAccount;
       
   442 		accounts->GetPopAccountL(aPop3EntryId, popAccount);
       
   443 		accounts->LoadPopSettingsL(popAccount, *iPop3Settings);
       
   444 
       
   445 		CleanupStack::PopAndDestroy(accounts);
       
   446 	}
       
   447 }
       
   448 
       
   449 void CClientTestHarness::InstantiateNamedSmtpSettingsL(const TDesC& aName)
       
   450 {
       
   451 	if (iSmtpSettings)
       
   452 	{
       
   453 		delete iSmtpSettings;
       
   454 		iSmtpSettings = NULL;
       
   455 	}
       
   456 
       
   457 	InstantiateClientMtmL();
       
   458 
       
   459 	//TestUtils().iMsvEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
   460 
       
   461 	TMsvId aSmtpEntryId=KMsvNullIndexEntryId;
       
   462 
       
   463 	CMsvEntrySelection *msvSelection = NULL;
       
   464 
       
   465 	TMsvSelectionOrdering order;
       
   466 	order.SetShowInvisibleEntries( ETrue );
       
   467 	TestUtils().iMsvEntry->SetSortTypeL(order);
       
   468 
       
   469 	// Get list of children IDs
       
   470 	TestUtils().iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
       
   471 
       
   472 	msvSelection = TestUtils().iMsvEntry->ChildrenL();
       
   473 	CleanupStack::PushL(msvSelection);
       
   474 
       
   475 	
       
   476 	TMsvEntry entry;
       
   477 	TInt count = msvSelection->Count(); 
       
   478 	for (TInt j = 0; j < count; j++)
       
   479 		{
       
   480 		// set context to service entry
       
   481 		TestUtils().iMsvEntry->SetEntryL((*msvSelection)[j]);
       
   482 		entry = TestUtils().iMsvEntry->Entry(); 
       
   483 
       
   484 		if (entry.iType == KUidMsvServiceEntry)
       
   485 		    if(entry.iDetails.Length() == aName.Length())
       
   486 				if(entry.iDetails.CompareF(aName)==0 )
       
   487 					{
       
   488 					if(entry.iMtm == KUidMsgTypeSMTP)
       
   489 						{
       
   490 						aSmtpEntryId= entry.Id();						
       
   491 						}
       
   492 					}
       
   493 
       
   494 		}
       
   495 
       
   496 	CleanupStack::PopAndDestroy(msvSelection);
       
   497 
       
   498 	if(aSmtpEntryId==KMsvNullIndexEntryId)
       
   499 			{
       
   500 				_LIT(KUhOh,"ERROR Matching SmtpSettings Not Found");
       
   501 				TestUtils().WriteComment(KUhOh);
       
   502 				User::Leave(KErrNotFound);
       
   503 			}
       
   504 			else
       
   505 			{
       
   506 				iSmtpSettings = new(ELeave)CImSmtpSettings();
       
   507 				
       
   508 				CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   509 
       
   510 				TSmtpAccount smtpAccount;
       
   511 				accounts->GetSmtpAccountL(aSmtpEntryId, smtpAccount);
       
   512 				accounts->LoadSmtpSettingsL(smtpAccount, *iSmtpSettings);
       
   513 
       
   514 				CleanupStack::PopAndDestroy(accounts);
       
   515 			}
       
   516 	
       
   517 	//Successful
       
   518 }
       
   519 
       
   520 void CClientTestHarness::InstantiateNamedImapSettingsL(const TDesC& aName)
       
   521 {
       
   522 	if (iImapSettings)
       
   523 	{
       
   524 		delete iImapSettings;
       
   525 		iImapSettings = NULL;
       
   526 	}
       
   527 
       
   528 	InstantiateClientMtmL();
       
   529 
       
   530 	//TestUtils().iMsvEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
   531 
       
   532 	TMsvId aImapEntryId=KMsvNullIndexEntryId;
       
   533 
       
   534 	CMsvEntrySelection *msvSelection = NULL;
       
   535 
       
   536 	TMsvSelectionOrdering order;
       
   537 	order.SetShowInvisibleEntries( ETrue );
       
   538 	TestUtils().iMsvEntry->SetSortTypeL(order);
       
   539 
       
   540 	// Get list of children IDs
       
   541 	TestUtils().iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
       
   542 
       
   543 	msvSelection = TestUtils().iMsvEntry->ChildrenL();
       
   544 	CleanupStack::PushL(msvSelection);
       
   545 
       
   546 	
       
   547 	TMsvEntry entry;
       
   548 	TInt count = msvSelection->Count(); 
       
   549 	for (TInt j = 0; j < count; j++)
       
   550 		{
       
   551 		// set context to service entry
       
   552 		TestUtils().iMsvEntry->SetEntryL((*msvSelection)[j]);
       
   553 		entry = TestUtils().iMsvEntry->Entry(); 
       
   554 
       
   555 		if (entry.iType == KUidMsvServiceEntry)
       
   556 		    if(entry.iDetails.Length() == aName.Length())
       
   557 				if(entry.iDetails.CompareF(aName)==0 )
       
   558 					{
       
   559 					if(entry.iMtm == KUidMsgTypeIMAP4)
       
   560 						{
       
   561 						aImapEntryId= entry.Id();						
       
   562 						}
       
   563 					}
       
   564 
       
   565 		}
       
   566 
       
   567 	CleanupStack::PopAndDestroy(msvSelection);
       
   568 
       
   569 	if(aImapEntryId==KMsvNullIndexEntryId)
       
   570 			{
       
   571 				_LIT(KUhOh,"ERROR Matching ImapSettings Not Found");
       
   572 				TestUtils().WriteComment(KUhOh);
       
   573 				User::Leave(KErrNotFound);
       
   574 			}
       
   575 			else
       
   576 			{
       
   577 				iImapSettings = new(ELeave)CImImap4Settings();
       
   578 				
       
   579 				CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   580 
       
   581 				TImapAccount imapAccount;
       
   582 				accounts->GetImapAccountL(aImapEntryId, imapAccount);
       
   583 				accounts->LoadImapSettingsL(imapAccount, *iImapSettings);
       
   584 
       
   585 				CleanupStack::PopAndDestroy(accounts);
       
   586 			}
       
   587 	
       
   588 	//Successful
       
   589 }
       
   590 
       
   591 void CClientTestHarness::UnInstantiatePop3SettingsL()
       
   592 {
       
   593 	if (iPop3Settings)
       
   594 	{
       
   595 		delete iPop3Settings;
       
   596 		iPop3Settings = NULL;
       
   597 	}
       
   598 	
       
   599 }
       
   600 
       
   601 void CClientTestHarness::UnInstantiateSmtpSettingsL()
       
   602 {
       
   603 	if (iSmtpSettings)
       
   604 	{
       
   605 		delete iSmtpSettings;
       
   606 		iSmtpSettings = NULL;
       
   607 	}
       
   608 	
       
   609 }
       
   610 
       
   611 void CClientTestHarness::UnInstantiateImapSettingsL()
       
   612 {
       
   613 	if (iImapSettings)
       
   614 	{
       
   615 		delete iImapSettings;
       
   616 		iImapSettings = NULL;
       
   617 	}
       
   618 	
       
   619 }
       
   620 
       
   621 TMsvId CClientTestHarness::GetPopServiceL(CEmailAccounts& aAccounts)
       
   622 	{
       
   623 	TMsvId popService;
       
   624 	
       
   625 	RArray<TPopAccount> popAccounts;
       
   626 	CleanupClosePushL(popAccounts);
       
   627 	
       
   628 	aAccounts.GetPopAccountsL(popAccounts);
       
   629 	if(popAccounts.Count()>0)
       
   630 		{
       
   631 		// if a account exist take the first
       
   632 		popService = popAccounts[0].iPopService;
       
   633 		}
       
   634 	else
       
   635 		{
       
   636 		CImPop3Settings* popSettings = new(ELeave) CImPop3Settings();
       
   637 		CleanupStack::PushL(popSettings);
       
   638 
       
   639 		CImIAPPreferences* popIAP = CImIAPPreferences::NewLC();
       
   640 				
       
   641 		aAccounts.PopulateDefaultPopSettingsL(*popSettings, *popIAP);
       
   642 
       
   643 		TPopAccount popAccount = aAccounts.CreatePopAccountL(KNullDesC, *popSettings, *popIAP, EFalse);
       
   644 		popService = popAccount.iPopService;
       
   645 		
       
   646 		CleanupStack::PopAndDestroy(2, popSettings); // imapIAP, imapSettings
       
   647 		}
       
   648 	CleanupStack::PopAndDestroy();
       
   649 	return popService;
       
   650 	}
       
   651 
       
   652 void CClientTestHarness::InstantiatePop3SettingsL()
       
   653 {
       
   654 	
       
   655 	InstantiateClientMtmL();
       
   656 
       
   657 	if (iPop3Settings==NULL)
       
   658 	{
       
   659 		TestUtils().iMsvEntry->SetEntryL(KMsvRootIndexEntryIdValue);
       
   660 
       
   661 		TMsvId serviceId(KMsvNullIndexEntryId);
       
   662 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   663 		TRAPD(err, serviceId = GetPopServiceL(*accounts));
       
   664 
       
   665 		// if no default service
       
   666 			if((err==KErrNotFound) || (serviceId==KMsvUnknownServiceIndexEntryId))
       
   667 			{
       
   668 				_LIT(KUhOh,"ERROR Default Pop3Settings Not Found");
       
   669 				TestUtils().WriteComment(KUhOh);
       
   670 				User::Leave(KErrNotFound);
       
   671 			}
       
   672 			else
       
   673 			{
       
   674 				iPop3Settings = new(ELeave)CImPop3Settings();
       
   675 				
       
   676 				TPopAccount popAccount;
       
   677 				accounts->GetPopAccountL(serviceId, popAccount);
       
   678 				accounts->LoadPopSettingsL(popAccount, *iPop3Settings);
       
   679 			}
       
   680 	
       
   681 		CleanupStack::PopAndDestroy(accounts);
       
   682 		}
       
   683 }
       
   684 
       
   685 void CClientTestHarness::InstantiateClientMtmL()
       
   686 {
       
   687 	//
       
   688 	// To speed up creation, share a static connection to client side MTM
       
   689 	// set that connection up now
       
   690 	TInt nRetryCount = 2;
       
   691 	TInt err = KErrGeneral;
       
   692 
       
   693 	if(iBioUtils.iBioClientMtm == NULL)
       
   694 	{
       
   695 		while(iBioUtils.iBioClientMtm == NULL && nRetryCount > 0)
       
   696 		{
       
   697 			//
       
   698 			// Start up client side stuff
       
   699 			TRAP(err, iBioUtils.GoClientSideL());
       
   700 			if(err == KErrNone)
       
   701 			{
       
   702 				//
       
   703 				// Create services
       
   704 				TRAP(err, iBioUtils.CreateServicesL());
       
   705 				if(err == KErrNone)
       
   706 				{
       
   707 					//
       
   708 					// Instantiate client MTM
       
   709 					// (this in its self is a test, but must be done before we can do anything else)
       
   710 					TRAP(err, iBioUtils.InstantiateClientMtmsL());
       
   711 				}
       
   712 			}
       
   713 			nRetryCount--;
       
   714 		}
       
   715 		User::LeaveIfNull(iBioUtils.iBioClientMtm);
       
   716 		User::LeaveIfError(err);
       
   717 	}
       
   718 }
       
   719 
       
   720 void CClientTestHarness::InstantiateServerMtmL()
       
   721 {
       
   722 	
       
   723 
       
   724 	//
       
   725 	// To speed up creation, share a static connection to server side MTM
       
   726 	// set that connection up now
       
   727 	TInt nRetryCount = 5;
       
   728 	TInt err = KErrGeneral;
       
   729 
       
   730 	if(iBioUtils.iBioServerMtm == NULL)
       
   731 	{
       
   732 		while(iBioUtils.iBioServerMtm == NULL && nRetryCount > 0)
       
   733 		{
       
   734 			//
       
   735 			// Start up server side stuff
       
   736 			TRAP(err, iBioUtils.GoServerSideL());
       
   737 			if(err == KErrNone)
       
   738 			{			
       
   739 				//
       
   740 				// Create services
       
   741 				TRAP(err, iBioUtils.CreateServicesL());
       
   742 				if(err == KErrNone)
       
   743 				{
       
   744 					//
       
   745 					// Instantiate server MTM
       
   746 					// (this in its self is a test, but must be done before we can do anything else)
       
   747 					TRAP(err, iBioUtils.InstantiateServerMtmsL());
       
   748 				}
       
   749 			}
       
   750 			nRetryCount--;
       
   751 		}
       
   752 		User::LeaveIfNull(iBioUtils.iBioServerMtm);	// was out
       
   753 		User::LeaveIfError(err);
       
   754 	}
       
   755 }