messagingfw/msgtest/integration/email/src/poptests.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 "poptests.h"
       
    17 #include <cemailaccounts.h>
       
    18 #include <iapprefs.h>
       
    19 
       
    20 // Strings....
       
    21 _LIT(KErrUseService, "[%4d] Error! you have to select a service for use before you can access it!");
       
    22 _LIT(KPopAccountName, "POP");
       
    23 
       
    24 //
       
    25 //
       
    26 // CPop3ClientTest
       
    27 //
       
    28 
       
    29 CPop3ClientTest* CPop3ClientTest::NewL(CEmailTestUtils& aTestUtils, RTest& aTest)
       
    30 	{
       
    31 	CPop3ClientTest* self = new (ELeave) CPop3ClientTest(aTestUtils, aTest);
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL();
       
    34 	CleanupStack::Pop(self);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 CPop3ClientTest::~CPop3ClientTest()
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CPop3ClientTest::ConstructL()
       
    43 	{
       
    44 	CEmailClientTest::ConstructL();
       
    45 	}
       
    46 
       
    47 CPop3ClientTest::CPop3ClientTest(CEmailTestUtils& aTestUtils, RTest& aTest) : CEmailClientTest(aTestUtils, aTest)
       
    48 	{
       
    49 	}
       
    50 
       
    51 
       
    52 //
       
    53 //
       
    54 // CCreatePop3Service
       
    55 //
       
    56 
       
    57 void CCreatePop3Service::StartL(TRequestStatus& aStatus)
       
    58 	{
       
    59 
       
    60 	// create pop account				
       
    61 	TPopAccount accountId = iAccount->CreatePopAccountL(*iDetails, *iSettings, *iPopIAP,EFalse);
       
    62 	
       
    63 	// select this service
       
    64 	CMsvEntry& msvEntry = *(iTestHarness.EmailTestUtils().iMsvEntry);
       
    65 	msvEntry.SetEntryL(accountId.iPopService);
       
    66 	iEntry = msvEntry.Entry();
       
    67 
       
    68 	iTestHarness.iCurrentServiceId = accountId.iPopService;
       
    69 	iTestHarness.EmailTestUtils().iPopServiceId = accountId.iPopService;
       
    70  
       
    71  	// If the Pop Client MTM doesn't already exist, then Instantiate it 
       
    72  	if (!iTestHarness.EmailTestUtils().iPopClientMtm)
       
    73  		iTestHarness.EmailTestUtils().InstantiatePopClientMtmL();
       
    74  	
       
    75  	// The account needs to be deleted to close the session with the message server
       
    76  	// If this session is kept open, the test will get in an infinite loop when sending
       
    77  	// an email (because of implementation of CMsvTestUtils::GoServerSideL())
       
    78  	delete iAccount;
       
    79  	iAccount = NULL;
       
    80  
       
    81  	TRequestStatus* status = &aStatus;
       
    82  	User::RequestComplete(status, KErrNone);
       
    83 
       
    84 	}
       
    85 
       
    86 CCreatePop3Service* CCreatePop3Service::NewL(CEmailClientTest& aTestHarness)
       
    87 	{
       
    88 	CCreatePop3Service* self = new (ELeave) CCreatePop3Service(aTestHarness);
       
    89 	CleanupStack::PushL(self);
       
    90 	self->ConstructL();
       
    91 	CleanupStack::Pop(self);
       
    92 	return self;
       
    93 	}
       
    94 
       
    95 CCreatePop3Service::CCreatePop3Service(CEmailClientTest& aTestHarness) : CCreateEmailService(aTestHarness), iTestHarness(aTestHarness)
       
    96 	{
       
    97 	}
       
    98 
       
    99 void CCreatePop3Service::ConstructL()
       
   100 	{
       
   101 	iAccount = CEmailAccounts::NewL();
       
   102 	iSettings = new(ELeave) CImPop3Settings();		
       
   103 	iPopIAP = CImIAPPreferences::NewLC();
       
   104 	CleanupStack::Pop();
       
   105 	
       
   106 	iAccount->PopulateDefaultPopSettingsL(*iSettings, *iPopIAP);
       
   107 	iSettings->SetDisconnectedUserMode(ETrue);
       
   108 	iSettings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
   109 
       
   110 	}
       
   111 
       
   112 CCreatePop3Service::~CCreatePop3Service()
       
   113 	{
       
   114 	delete iAccount;
       
   115  	delete iSettings;
       
   116 	delete iPopIAP;
       
   117 	}
       
   118 
       
   119 CImPop3Settings& CCreatePop3Service::Settings()
       
   120 	{
       
   121 	return *iSettings;
       
   122 	}
       
   123 
       
   124 
       
   125 
       
   126 //
       
   127 //
       
   128 // CCreatePop3ClientMtm
       
   129 //
       
   130 
       
   131 CCreatePop3ClientMtm::CCreatePop3ClientMtm(CEmailClientTest& aTest) : iTest(aTest)
       
   132 	{
       
   133 	}
       
   134 
       
   135 void CCreatePop3ClientMtm::StartL(TRequestStatus& aStatus)
       
   136 	{
       
   137 	iTest.EmailTestUtils().InstantiatePopClientMtmL();
       
   138 	TRequestStatus* status = &aStatus;
       
   139 	User::RequestComplete(status, KErrNone);
       
   140 	}
       
   141 
       
   142 
       
   143 
       
   144 
       
   145 //
       
   146 //
       
   147 // CPop3Connect
       
   148 //
       
   149 
       
   150 CPop3Connect::CPop3Connect(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   151 	{
       
   152 	CActiveScheduler::Add(this);
       
   153 	}
       
   154 
       
   155 void CPop3Connect::StartL(TRequestStatus& aStatus)
       
   156 	{
       
   157 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   158 	CMsvEntry& msvEntry = *(iParentTestHarness.MsvTestUtils().iMsvEntry);
       
   159 	msvEntry.SetEntryL(serviceId);
       
   160 	iReportStatus = &aStatus;
       
   161 
       
   162 	// If the Pop Client MTM doesn't already exist, then Instantiate it 
       
   163 	if (!iParentTestHarness.EmailTestUtils().iPopClientMtm)
       
   164 		iParentTestHarness.EmailTestUtils().InstantiatePopClientMtmL();
       
   165 
       
   166 	// check that current entry is a service
       
   167 	CPop3ClientMtm& pop3Mtm = *(iParentTestHarness.EmailTestUtils().iPopClientMtm);
       
   168 	TBuf8<1> param;
       
   169 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   170 	CleanupStack::PushL(selection);
       
   171 	selection->AppendL(serviceId);
       
   172 	iParentTestHarness.SetCurrentOperation(pop3Mtm.InvokeAsyncFunctionL(KPOP3MTMConnect, *selection, param, iStatus));
       
   173 	CleanupStack::PopAndDestroy(selection);
       
   174 	aStatus = KRequestPending;
       
   175 	SetActive();
       
   176 	}
       
   177 
       
   178 void CPop3Connect::RunL()
       
   179 	{
       
   180 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   181 	}
       
   182 
       
   183 void CPop3Connect::DoCancel()
       
   184 	{
       
   185 	iParentTestHarness.CurrentOperation().Cancel();
       
   186 	}
       
   187 
       
   188 
       
   189 CPop3Connect::~CPop3Connect()
       
   190 	{
       
   191 	}
       
   192 
       
   193 
       
   194 
       
   195 
       
   196 //
       
   197 //
       
   198 // CPop3Disconnect
       
   199 //
       
   200 
       
   201 CPop3Disconnect::CPop3Disconnect(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   202 	{
       
   203 	CActiveScheduler::Add(this);
       
   204 	}
       
   205 
       
   206 void CPop3Disconnect::StartL(TRequestStatus& aStatus)
       
   207 	{
       
   208 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   209 	CMsvEntry& msvEntry = *(iParentTestHarness.MsvTestUtils().iMsvEntry);
       
   210 	msvEntry.SetEntryL(serviceId);
       
   211 	iReportStatus = &aStatus;
       
   212 	// check that current entry is a service
       
   213 	CPop3ClientMtm& pop3Mtm = *(iParentTestHarness.EmailTestUtils().iPopClientMtm);
       
   214 	TBuf8<1> param;
       
   215 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   216 	CleanupStack::PushL(selection);
       
   217 	selection->AppendL(serviceId);
       
   218 	iParentTestHarness.SetCurrentOperation(pop3Mtm.InvokeAsyncFunctionL(KPOP3MTMDisconnect, *selection, param, iStatus));
       
   219 	CleanupStack::PopAndDestroy(selection);
       
   220 	aStatus = KRequestPending;
       
   221 	SetActive();
       
   222 	}
       
   223 
       
   224 void CPop3Disconnect::RunL()
       
   225 	{
       
   226 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   227 	}
       
   228 
       
   229 void CPop3Disconnect::DoCancel()
       
   230 	{
       
   231 	iParentTestHarness.CurrentOperation().Cancel();
       
   232 	}
       
   233 
       
   234 
       
   235 CPop3Disconnect::~CPop3Disconnect()
       
   236 	{
       
   237 	}
       
   238 
       
   239 
       
   240 
       
   241 
       
   242 
       
   243 //
       
   244 //
       
   245 // CCheckPop3Operation
       
   246 //
       
   247 
       
   248 CCheckPop3Operation::CCheckPop3Operation(TInt aExpectedStatus, CPop3ClientTest& aTestHarness) : iTestHarness(aTestHarness), iExpectedStatus(aExpectedStatus)
       
   249 	{
       
   250 	}
       
   251 
       
   252 void CCheckPop3Operation::StartL(TRequestStatus& aStatus)
       
   253 	{
       
   254 	TInt err = KErrNone;
       
   255 
       
   256 	TPop3Progress temp;	
       
   257 	TPckgC<TPop3Progress> paramPack(temp);
       
   258 
       
   259 	//if(iTestHarness.CurrentOperation().Id() != NULL)
       
   260 		{
       
   261 		paramPack.Set(iTestHarness.CurrentOperation().ProgressL());
       
   262 			
       
   263 		TPop3Progress progress=paramPack();	
       
   264 
       
   265 		if (progress.iErrorCode != iExpectedStatus)
       
   266 			{
       
   267 			TBuf<100> logString;
       
   268 			logString.Format(_L("Operation didn't complete as expected. Expected status: %d, actual status: %d"), iExpectedStatus, progress.iErrorCode);
       
   269 			iTestHarness.LogComment(logString);
       
   270 			err = KErrUnknown;
       
   271 			}
       
   272 
       
   273 		TRequestStatus* status = &aStatus;
       
   274 		User::RequestComplete(status, err);
       
   275 		}
       
   276 	}
       
   277 
       
   278 
       
   279 //
       
   280 //
       
   281 // CPop3UseService
       
   282 //
       
   283 
       
   284 CPop3UseService::CPop3UseService(CPop3ClientTest& aTestHarness) : iTestHarness(aTestHarness)
       
   285 	{
       
   286 	}
       
   287 
       
   288 void CPop3UseService::StartL(TRequestStatus& aStatus)
       
   289 	{
       
   290 	TInt err = KErrNone;
       
   291 
       
   292 	// Select current folder
       
   293 	CMsvEntry& entry = *(iTestHarness.EmailTestUtils().iMsvEntry);
       
   294 	entry.SetEntryL(iTestHarness.iSelectedFolder);
       
   295 		
       
   296 	// first make sure it is a service which is selected
       
   297 	//  then change the test utils service id
       
   298 	if(entry.Entry().iType == KUidMsvServiceEntry)
       
   299 		{
       
   300 		iTestHarness.EmailTestUtils().iPopServiceId = entry.Entry().Id();
       
   301 
       
   302 		// If the Pop Client MTM doesn't already exist, then Instantiate it 
       
   303 		if (!iTestHarness.EmailTestUtils().iPopClientMtm)
       
   304 			iTestHarness.EmailTestUtils().InstantiatePopClientMtmL();
       
   305 		}
       
   306 	else
       
   307 		{
       
   308 		TBuf<100> logString;
       
   309 		logString.Format(KErrUseService, iDebugInfo.LineNumber());
       
   310 		iTestHarness.LogComment(logString);
       
   311 
       
   312 		err = KErrUnknown;
       
   313 		}
       
   314 
       
   315 	TRequestStatus* status = &aStatus;
       
   316 	User::RequestComplete(status, err);
       
   317 	}
       
   318 
       
   319 
       
   320 
       
   321 //
       
   322 //
       
   323 //
       
   324 //
       
   325 // CPop3Connect
       
   326 //
       
   327 // Connect an monitor connection progress.
       
   328 //
       
   329 CPop3ConnectAndMonitor::CPop3ConnectAndMonitor(CEmailClientTest& aParentTestHarness, TBool aSynchronise) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness), iSynchronise(aSynchronise)
       
   330 	{
       
   331 	CActiveScheduler::Add(this);
       
   332 	}
       
   333 
       
   334 void CPop3ConnectAndMonitor::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   335 	{
       
   336 	// Build parameter list.
       
   337 	VA_LIST list;
       
   338 	VA_START(list, format);
       
   339 	TBuf<0x100> buf;
       
   340 	buf.FormatList(format, list);
       
   341 
       
   342 	// Log the debug buffer.
       
   343 	iParentTestHarness.EmailTestUtils().WriteComment(buf);
       
   344 	}
       
   345 
       
   346 void CPop3ConnectAndMonitor::StartL(TRequestStatus& aStatus)
       
   347 	{
       
   348 	iConnectionError = EFalse;
       
   349 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   350 	CMsvEntry& msvEntry = *(iParentTestHarness.MsvTestUtils().iMsvEntry);
       
   351 	msvEntry.SetEntryL(serviceId);
       
   352 	iReportStatus = &aStatus;
       
   353 	// check that current entry is a service
       
   354 	CPop3ClientMtm& pop3Mtm = *(iParentTestHarness.EmailTestUtils().iPopClientMtm);
       
   355 	TBuf8<1> param;
       
   356 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   357 	CleanupStack::PushL(selection);
       
   358 	selection->AppendL(serviceId);
       
   359 
       
   360 	
       
   361 	iParentTestHarness.SetCurrentOperation(pop3Mtm.InvokeAsyncFunctionL(KPOP3MTMConnect, *selection, param, iStatus));
       
   362 
       
   363 	// Call funtion to return IAP and Poll to find connection state 
       
   364 
       
   365 	RTimer timer; 
       
   366 	TRequestStatus timerStatus; // Request status associated with timer
       
   367 	timer.CreateLocal(); // Create for this thread
       
   368 
       
   369 	TInt progressState = KInvalidState;
       
   370 	TInt connectState = KInvalidState;
       
   371 	TInt iap = KInvalidIAP;
       
   372 	TInt connection_progress_state = 0;
       
   373 
       
   374 
       
   375 	do
       
   376 		{
       
   377 		TPop3Progress temp;	
       
   378 		TPckgC<TPop3Progress> paramPack(temp);
       
   379 		paramPack.Set(iParentTestHarness.CurrentOperation().ProgressL());
       
   380 		TPop3Progress progress = paramPack();	
       
   381 
       
   382 		progressState = progress.iPop3Progress;
       
   383 				
       
   384 		if((connectState != progress.ConnectionState()) || (iap != progress.ConnectionIAP()) )
       
   385 			{
       
   386 			connectState = progress.ConnectionState();
       
   387 			iap = progress.ConnectionIAP();
       
   388 			LogCommentFormat(_L("[%4d] Progress state =  %d, Connect State = %d, IAP = %d"), iDebugInfo.LineNumber(), progressState, connectState, iap);
       
   389 			
       
   390 			//Check that the relevant states are reached in the correct order
       
   391 			if ((connectState == ECsdStartingDialling) || (connectState == ECsdStartingConnect))
       
   392 					connection_progress_state = 1;
       
   393 			if (connectState == ECsdConnectionOpen && connection_progress_state == 1)
       
   394 					connection_progress_state = 2;
       
   395 			if (connectState == KLinkLayerOpen && connection_progress_state == 2)
       
   396 					connection_progress_state = 3;
       
   397 				
       
   398 			}
       
   399 
       
   400 		// wait 50 microseconds and then re-test progress!
       
   401 		timer.After(timerStatus,50);
       
   402 		User::WaitForRequest(timerStatus); 
       
   403 	
       
   404 		} while (progressState == TPop3Progress::EPopConnecting);
       
   405 	
       
   406 	    timer.Close();
       
   407 
       
   408 	if (connection_progress_state != 3)
       
   409 		{
       
   410 		LogCommentFormat(_L("[%4d] Local Connection Progress state =  %d, Connect State = %d, IAP = %d"), iDebugInfo.LineNumber(), connection_progress_state, connectState, iap);
       
   411 		iConnectionError = ETrue;
       
   412 		}
       
   413 	
       
   414 	CleanupStack::PopAndDestroy(selection);
       
   415 	aStatus = KRequestPending;
       
   416 	SetActive();
       
   417 	}
       
   418 
       
   419 void CPop3ConnectAndMonitor::RunL()
       
   420 	{
       
   421 	if (iConnectionError)
       
   422 		User::RequestComplete(iReportStatus, KErrUnknown);	
       
   423 	else
       
   424 		User::RequestComplete(iReportStatus, iStatus.Int());
       
   425 	}	
       
   426 
       
   427 void CPop3ConnectAndMonitor::DoCancel()
       
   428 	{
       
   429 	iParentTestHarness.CurrentOperation().Cancel();
       
   430 	}
       
   431 
       
   432 
       
   433 CPop3ConnectAndMonitor::~CPop3ConnectAndMonitor()
       
   434 	{
       
   435 	}
       
   436 // CPop3SetSyncLimits
       
   437 //
       
   438 
       
   439 CPop3SetSyncLimits::CPop3SetSyncLimits(TInt aInboxSyncLimit, CPop3ClientTest& aTestHarness) : 
       
   440 	iTestHarness(aTestHarness), iInboxSyncLimit(aInboxSyncLimit)
       
   441 	{
       
   442 	}
       
   443 
       
   444 void CPop3SetSyncLimits::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   445 	{
       
   446 	// Build parameter list.
       
   447 	VA_LIST list;
       
   448 	VA_START(list, format);
       
   449 	TBuf<0x100> buf;
       
   450 	buf.FormatList(format, list);
       
   451 
       
   452 	// Log the debug buffer.
       
   453 	iTestHarness.EmailTestUtils().WriteComment(buf);
       
   454 	}
       
   455 
       
   456 void CPop3SetSyncLimits::StartL(TRequestStatus& aStatus)
       
   457 	{
       
   458 	// Assumes that Pop3 service currently selected.
       
   459 
       
   460 	LogCommentFormat(_L("[%4d] Setting sync limits (inbox=%d)"), iDebugInfo.LineNumber(), iInboxSyncLimit);
       
   461 
       
   462 	CImPop3Settings* settings = new(ELeave) CImPop3Settings();
       
   463 	CleanupStack::PushL(settings);
       
   464 
       
   465 	CEmailAccounts* account = CEmailAccounts::NewLC();				
       
   466 
       
   467 	TPopAccount popAccountId;
       
   468 	account->GetPopAccountL(iTestHarness.EmailTestUtils().iMsvEntry->EntryId(),popAccountId); 
       
   469 	account->LoadPopSettingsL(popAccountId, *settings);
       
   470 	settings->SetInboxSynchronisationLimit(iInboxSyncLimit);		
       
   471 	account->SavePopSettingsL(popAccountId, *settings);
       
   472 
       
   473 	CleanupStack::PopAndDestroy(account);
       
   474 	CleanupStack::PopAndDestroy(settings);
       
   475 
       
   476 	TRequestStatus* status = &aStatus;
       
   477 	User::RequestComplete(status, KErrNone);
       
   478 	}
       
   479 
       
   480