messagingfw/msgtest/integration/email/pefromance/src/T_Performance421Client.cpp
changeset 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "T_Performance421Client.h"
       
    17 
       
    18 void TDummySessionObserver::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    19 	{
       
    20 	}
       
    21 
       
    22 CPerformance421Client::CPerformance421Client(CPerformanceStepBase& aStepBase) 
       
    23 : CActive(EPriorityStandard), iStepBase(aStepBase)
       
    24 	{
       
    25 	CActiveScheduler::Add(this);
       
    26 	}
       
    27 
       
    28 CPerformance421Client* CPerformance421Client::NewL(CPerformanceStepBase& aStepBase)
       
    29 	{
       
    30 	CPerformance421Client* self = NewLC(aStepBase);
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CPerformance421Client* CPerformance421Client::NewLC(CPerformanceStepBase& aStepBase)
       
    36 	{
       
    37 	CPerformance421Client* self = new(ELeave) CPerformance421Client(aStepBase);
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL();
       
    40 	return self;
       
    41 	}
       
    42 	
       
    43 CPerformance421Client::~CPerformance421Client()
       
    44 	{
       
    45 	iConnection.Stop();
       
    46 	iConnection.Close();
       
    47 	
       
    48 	Cancel();
       
    49 	delete iMsvOperation;	
       
    50 	delete iSelection;
       
    51 	delete iClientMtm;
       
    52 	delete iClientRegistry;	
       
    53 	delete iSession;
       
    54 	delete iSessionObserver;
       
    55 	}
       
    56 	
       
    57 void CPerformance421Client::ConstructL()
       
    58 	{
       
    59 	//open the imap account that the test step has created
       
    60 	CEmailAccounts* emailAccounts;
       
    61 	emailAccounts = CEmailAccounts::NewLC();	
       
    62 	RArray<TImapAccount> imapAccounts;
       
    63 	CleanupClosePushL(imapAccounts);
       
    64 	emailAccounts->GetImapAccountsL(imapAccounts);
       
    65 	iImapAccount=imapAccounts[0];
       
    66 	CleanupStack::PopAndDestroy(2,emailAccounts);
       
    67 	
       
    68 	// Session observer. Needed to create a session
       
    69 	iSessionObserver = new (ELeave) TDummySessionObserver;
       
    70 	// Session. Needed to create a client registry.
       
    71 	iSession=CMsvSession::OpenSyncL(*iSessionObserver);
       
    72 	// Client registry. Needed to get the MTM component
       
    73 	iClientRegistry=CClientMtmRegistry::NewL(*iSession,KMsvDefaultTimeoutMicroSeconds32);
       
    74 	//get the client mtm
       
    75 	iClientMtm=iClientRegistry->NewMtmL(KUidMsgTypeIMAP4);	
       
    76 	
       
    77 	// Load the serial comms device drivers.  If this is not done,
       
    78 	// connecting via NT-RAS returns KErrNotFound (-1).
       
    79 	TInt driverErr;
       
    80 	driverErr=User::LoadPhysicalDevice(PDD_NAME);
       
    81 	if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists)
       
    82 		{
       
    83 		User::Leave(driverErr);	
       
    84 		}
       
    85 	driverErr=User::LoadLogicalDevice(LDD_NAME);
       
    86 	if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists)
       
    87 		{
       
    88 		User::Leave(driverErr);	
       
    89 		}
       
    90 		
       
    91 	//initialise package object
       
    92 	TImImap4GetMailInfo imap4GetMailInfo;
       
    93 	imap4GetMailInfo.iMaxEmailSize = KMaxTInt;
       
    94 	imap4GetMailInfo.iDestinationFolder = KMsvGlobalInBoxIndexEntryIdValue;
       
    95 	imap4GetMailInfo.iGetMailBodyParts = EGetImap4EmailBodyTextAndAttachments;
       
    96 	iPackage=imap4GetMailInfo;
       
    97 	
       
    98 	iSocketServ.Connect();
       
    99 	User::LeaveIfError(iConnection.Open(iSocketServ));	
       
   100 	
       
   101 	}
       
   102 
       
   103 void CPerformance421Client::StartL()
       
   104 	{
       
   105 	iStepBase.INFO_PRINTF1(_L("Starting test..."));
       
   106 	//if we are to collect the whole email then the next operation will be to fetch it
       
   107 	iSelection = new (ELeave) CMsvEntrySelection;
       
   108 	
       
   109 	//select the imap service entry
       
   110 	iSelection->AppendL(iImapAccount.iImapService);
       
   111 	//make the service entry the current context
       
   112 	iClientMtm->SwitchCurrentEntryL(iImapAccount.iImapService);
       
   113 	
       
   114 	//start the connection
       
   115 	iState=EStart;
       
   116 	iConnection.Start(iStatus);
       
   117 	SetActive();
       
   118 	}
       
   119 	
       
   120 void CPerformance421Client::DoCancel()
       
   121 	{	
       
   122 	__ASSERT_DEBUG(iMsvOperation!=NULL, User::Invariant());
       
   123 	iMsvOperation->Cancel();
       
   124 	}
       
   125 
       
   126 void CPerformance421Client::CompleteSelf()
       
   127 	{
       
   128 	TRequestStatus* pStat = &iStatus;
       
   129 	User::RequestComplete(pStat, KErrNone);
       
   130 	SetActive();
       
   131 	}
       
   132 
       
   133 void CPerformance421Client::RunL()
       
   134 	{
       
   135 	
       
   136 	User::LeaveIfError(iStatus.Int());
       
   137 	TBuf8<4> buf;	
       
   138 	TPckg<MMsvImapConnectionObserver*> param(this);
       
   139 		
       
   140 	switch(iState)
       
   141 		{
       
   142 		case EStart:
       
   143 		
       
   144 			delete iMsvOperation;
       
   145 			iMsvOperation=NULL;
       
   146 			iStepBase.StartTimer();
       
   147 			iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterConnect,*iSelection,param,iStatus);
       
   148 			SetActive();
       
   149 			iState=EWait;
       
   150 			break;	
       
   151 			
       
   152 		case EWait:
       
   153 			iStepBase.StopTimer();
       
   154 			delete iMsvOperation;
       
   155 			iMsvOperation=NULL;
       
   156 			iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMWaitForBackground,*iSelection,buf,iStatus);	
       
   157 			SetActive();
       
   158 			iState=EDisconnect;
       
   159 			break;	
       
   160 			
       
   161 		case EDisconnect:
       
   162 			delete iMsvOperation;
       
   163 			iMsvOperation=NULL;
       
   164 			iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMDisconnect,*iSelection,buf,iStatus);	
       
   165 			SetActive();
       
   166 			iState=EComplete;
       
   167 			break;
       
   168 
       
   169 		case EComplete:
       
   170 			iStepBase.INFO_PRINTF1(_L("Test complete."));
       
   171 			//inform the owning object that the process is complete
       
   172 			iStepBase.TestComplete(KErrNone);
       
   173 			break;
       
   174 			
       
   175 		default:
       
   176 			__ASSERT_DEBUG(0, User::Panic(_L("CPerformance421Client unknown state"), KErrUnknown));
       
   177 			break;			
       
   178 		}
       
   179 	
       
   180 	}
       
   181 	
       
   182 TInt CPerformance421Client::RunError(TInt aError)
       
   183 	{
       
   184 	iStepBase.TestComplete(aError);
       
   185 	return KErrNone;
       
   186 	}
       
   187 	
       
   188 void CPerformance421Client::HandleImapConnectionEvent(TImapConnectionEvent /*aConnectionState*/)
       
   189 	{
       
   190 	//this method does nothing
       
   191 	}
       
   192 
       
   193 
       
   194