messagingfw/msgtest/integration/email/src/imaptests.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 "imaptests.h"
       
    17 #include <imapconnectionobserver.h>
       
    18 #include <cemailaccounts.h>
       
    19 #include <iapprefs.h>
       
    20 
       
    21 
       
    22 //Provides access to Settings flag for seen flag tests 
       
    23 LOCAL_D CImImap4Settings* isaveSettings;
       
    24 _LIT(KImapAccountName, "IMAP");
       
    25 
       
    26 // Strings....
       
    27 _LIT(KErrUseService, "[%4d] Error! you have to select a service for use before you can access it!");
       
    28 
       
    29 
       
    30 //
       
    31 //
       
    32 // CImapClientTest
       
    33 //
       
    34 
       
    35 CImapClientTest* CImapClientTest::NewL(CEmailTestUtils& aTestUtils, RTest& aTest)
       
    36 	{
       
    37 	CImapClientTest* self = new (ELeave) CImapClientTest(aTestUtils, aTest);
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CImapClientTest::~CImapClientTest()
       
    45 	{
       
    46 	}
       
    47 
       
    48 void CImapClientTest::ConstructL()
       
    49 	{
       
    50 	CEmailClientTest::ConstructL();
       
    51 	}
       
    52 
       
    53 CImapClientTest::CImapClientTest(CEmailTestUtils& aTestUtils, RTest& aTest) : CEmailClientTest(aTestUtils, aTest)
       
    54 	{
       
    55 	}
       
    56 
       
    57 
       
    58 
       
    59 //
       
    60 //
       
    61 // CCreateImapService
       
    62 //
       
    63 
       
    64 void CCreateImapService::StartL(TRequestStatus& aStatus)
       
    65 	{
       
    66 	// create imap account
       
    67 	CEmailAccounts* account = CEmailAccounts::NewLC();
       
    68 
       
    69 	CImIAPPreferences* imapIAP = CImIAPPreferences::NewLC();
       
    70 	
       
    71 	iSettings->SetDisconnectedUserMode(ETrue);
       
    72 	iSettings->SetSynchronise(EUseLocal);
       
    73 	iSettings->SetSubscribe(EUpdateNeither);	
       
    74 	TImapAccount accountId = account->CreateImapAccountL(*iDetails, *iSettings, *imapIAP,EFalse);
       
    75 
       
    76 	//save settings address
       
    77 	isaveSettings = iSettings;
       
    78 
       
    79 	// get imap service for the account
       
    80 	TMsvId service = accountId.iImapService;
       
    81 	
       
    82 	// select this service
       
    83 	CMsvEntry& msvEntry = *(iTestHarness.EmailTestUtils().iMsvEntry);
       
    84 	msvEntry.SetEntryL(service);
       
    85 	iEntry = msvEntry.Entry();
       
    86 	iTestHarness.iCurrentServiceId = service;
       
    87 	iTestHarness.EmailTestUtils().iImapServiceId = service;
       
    88 
       
    89 	CleanupStack::PopAndDestroy(2, account); // imapIAP, account
       
    90 
       
    91 	if(iTestHarness.EmailTestUtils().iImapClientMtm == NULL)
       
    92 		iTestHarness.EmailTestUtils().InstantiateImapClientMtmL();
       
    93 	else // no need to create a new one, reuse the existing one
       
    94 		iTestHarness.EmailTestUtils().iImapClientMtm->SwitchCurrentEntryL(iTestHarness.iCurrentServiceId);
       
    95 
       
    96 	TRequestStatus* status = &aStatus;
       
    97 	User::RequestComplete(status, KErrNone);
       
    98 	}
       
    99 
       
   100 CCreateImapService* CCreateImapService::NewL(CEmailClientTest& aTestHarness)
       
   101 	{
       
   102 	CCreateImapService* self = new (ELeave) CCreateImapService(aTestHarness);
       
   103 	CleanupStack::PushL(self);
       
   104 	self->ConstructL();
       
   105 	CleanupStack::Pop(self);
       
   106 	return self;
       
   107 	}
       
   108 
       
   109 CCreateImapService::CCreateImapService(CEmailClientTest& aTestHarness) : CCreateEmailService(aTestHarness), iTestHarness(aTestHarness)
       
   110 	{
       
   111 	}
       
   112 
       
   113 void CCreateImapService::ConstructL()
       
   114 	{
       
   115 	iSettings = new(ELeave) CImImap4Settings();
       
   116 	}
       
   117 
       
   118 CCreateImapService::~CCreateImapService()
       
   119 	{
       
   120 	delete iSettings;
       
   121 	}
       
   122 
       
   123 CImImap4Settings& CCreateImapService::Settings()
       
   124 	{
       
   125 	return *iSettings;
       
   126 	}
       
   127 
       
   128 
       
   129 //
       
   130 //
       
   131 // CImapUseService
       
   132 //
       
   133 
       
   134 CImapUseService::CImapUseService(CImapClientTest& aTestHarness) : iTestHarness(aTestHarness)
       
   135 	{
       
   136 	}
       
   137 
       
   138 void CImapUseService::StartL(TRequestStatus& aStatus)
       
   139 	{
       
   140 	TInt err = KErrNone;
       
   141 
       
   142 	// Select current folder
       
   143 	CMsvEntry& entry = *(iTestHarness.EmailTestUtils().iMsvEntry);
       
   144 	entry.SetEntryL(iTestHarness.iSelectedFolder);
       
   145 		
       
   146 	// first make sure it is a service which is selected
       
   147 	//  then change the test utils service id
       
   148 	if(entry.Entry().iType == KUidMsvServiceEntry)
       
   149 		{
       
   150 		iTestHarness.EmailTestUtils().iImapServiceId = entry.Entry().Id();
       
   151 		if(iTestHarness.EmailTestUtils().iImapClientMtm == NULL)
       
   152 			iTestHarness.EmailTestUtils().InstantiateImapClientMtmL();
       
   153 		else // no need to create a new one, reuse the existing one
       
   154 			iTestHarness.EmailTestUtils().iImapClientMtm->SwitchCurrentEntryL(entry.Entry().Id());
       
   155 		}
       
   156 	else
       
   157 		{
       
   158 		TBuf<100> logString;
       
   159 		logString.Format(KErrUseService, iDebugInfo.LineNumber());
       
   160 		iTestHarness.LogComment(logString);
       
   161 
       
   162 		err = KErrUnknown;
       
   163 		}
       
   164 
       
   165 	TRequestStatus* status = &aStatus;
       
   166 	User::RequestComplete(status, err);
       
   167 	}
       
   168 
       
   169 
       
   170 
       
   171 //
       
   172 //
       
   173 // CCreateImapClientMtm
       
   174 //
       
   175 
       
   176 CCreateImapClientMtm::CCreateImapClientMtm(CEmailClientTest& aTest) : iTest(aTest)
       
   177 	{
       
   178 	}
       
   179 
       
   180 void CCreateImapClientMtm::StartL(TRequestStatus& aStatus)
       
   181 	{
       
   182 	iTest.EmailTestUtils().InstantiatePopClientMtmL();
       
   183 	TRequestStatus* status = &aStatus;
       
   184 	User::RequestComplete(status, KErrNone);
       
   185 	}
       
   186 
       
   187 //
       
   188 //
       
   189 // CImapConnect
       
   190 //
       
   191 
       
   192 ImapConnectionObserver::ImapConnectionObserver(CImapConnect* aImapConnect) : iImapConnect(aImapConnect), iCount(0)
       
   193 	{
       
   194 	}
       
   195 
       
   196 void ImapConnectionObserver::HandleImapConnectionEvent(TImapConnectionEvent)
       
   197 	{
       
   198 //	if (aConnectionState == ESynchronisationComplete)
       
   199 //		if (++iCount == 2)
       
   200 		if (++iCount == 1)
       
   201 			iImapConnect->DummyRun();
       
   202 	}
       
   203 
       
   204 CImapConnect::CImapConnect(CEmailClientTest& aParentTestHarness, TSyncStatus aSynchronise) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness), iSynchronise(aSynchronise)
       
   205 	{
       
   206 	CActiveScheduler::Add(this);
       
   207 	}
       
   208 
       
   209 void CImapConnect::StartL(TRequestStatus& aStatus)
       
   210 	{
       
   211 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   212 	CMsvEntry& msvEntry = *(iParentTestHarness.MsvTestUtils().iMsvEntry);
       
   213 	msvEntry.SetEntryL(serviceId);
       
   214 	iReportStatus = &aStatus;
       
   215 	// check that current entry is a service
       
   216 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   217 	TBuf8<1> param;
       
   218 
       
   219 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   220 	CleanupStack::PushL(selection);
       
   221 	selection->AppendL(serviceId);
       
   222 
       
   223 	if(iSynchronise == EConnectAndSync) 
       
   224 		iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMConnectAndSynchronise, *selection, param, iStatus));
       
   225 	else if (iSynchronise == EConnectAndPeriodicSync) 
       
   226 		{
       
   227 		iObserver = new(ELeave) ImapConnectionObserver(this);
       
   228 		TPckg<MMsvImapConnectionObserver*> paramPeriodic(iObserver);
       
   229 		iParentTestHarness.SetCurrentOperation(imapMtm.
       
   230 		InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterDisconnect, *selection, paramPeriodic, iStatus));
       
   231 		}
       
   232 
       
   233 //	KIMAP4MTMConnectAndSyncCompleteAfterConnect,
       
   234 //	KIMAP4MTMConnectAndSyncCompleteAfterFullSync,
       
   235 //	KIMAP4MTMConnectAndSyncCompleteAfterDisconnect,
       
   236 	else
       
   237 		iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMConnect, *selection, param, iStatus));
       
   238 
       
   239 	CleanupStack::PopAndDestroy(selection);
       
   240 	aStatus = KRequestPending;
       
   241 	SetActive();
       
   242 	}
       
   243 
       
   244 void CImapConnect::RunL()
       
   245 	{
       
   246 	if (iDummyComplete == EFalse)
       
   247 		User::RequestComplete(iReportStatus, iStatus.Int());
       
   248 	}
       
   249 
       
   250 void CImapConnect::DummyRun()
       
   251 	{
       
   252 	User::RequestComplete(iReportStatus, KErrNone);
       
   253 	iDummyComplete = ETrue;
       
   254 	}
       
   255 
       
   256 void CImapConnect::DoCancel()
       
   257 	{
       
   258 	iParentTestHarness.CurrentOperation().Cancel();
       
   259 	}
       
   260 
       
   261 
       
   262 CImapConnect::~CImapConnect()
       
   263 	{
       
   264 	if (iObserver)
       
   265 		delete iObserver;
       
   266 	iObserver=0; 
       
   267 	}
       
   268 
       
   269 
       
   270 //
       
   271 //
       
   272 // CImapConnect
       
   273 //
       
   274 // Connect an monitor connection progress.
       
   275 //
       
   276 CImapConnectAndMonitor::CImapConnectAndMonitor(CEmailClientTest& aParentTestHarness, TBool aSynchronise) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness), iSynchronise(aSynchronise)
       
   277 	{
       
   278 	CActiveScheduler::Add(this);
       
   279 	}
       
   280 
       
   281 void CImapConnectAndMonitor::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   282 	{
       
   283 	// Build parameter list.
       
   284 	VA_LIST list;
       
   285 	VA_START(list, format);
       
   286 	TBuf<0x100> buf;
       
   287 	buf.FormatList(format, list);
       
   288 
       
   289 	// Log the debug buffer.
       
   290 	iParentTestHarness.EmailTestUtils().WriteComment(buf);
       
   291 	}
       
   292 
       
   293 void CImapConnectAndMonitor::StartL(TRequestStatus& aStatus)
       
   294 	{
       
   295 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   296 	CMsvEntry& msvEntry = *(iParentTestHarness.MsvTestUtils().iMsvEntry);
       
   297 	msvEntry.SetEntryL(serviceId);
       
   298 	iReportStatus = &aStatus;
       
   299 
       
   300 	// Check that current entry is a service
       
   301 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   302 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   303 	CleanupStack::PushL(selection);
       
   304 	selection->AppendL(serviceId);
       
   305 	TPckg<MMsvImapConnectionObserver*> parameter(this);
       
   306 
       
   307 	if (iSynchronise)
       
   308 		{
       
   309 		iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterFullSync, *selection, parameter, iStatus));
       
   310 		}
       
   311 	else
       
   312 		{
       
   313 		iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMConnect, *selection, parameter, iStatus));
       
   314 		}
       
   315 
       
   316 	CleanupStack::PopAndDestroy(selection);
       
   317 	*iReportStatus = KRequestPending;
       
   318 	SetActive();
       
   319 
       
   320 	MonitorConnectionL();
       
   321 	}
       
   322 
       
   323 void CImapConnectAndMonitor::MonitorConnectionL()
       
   324 	{
       
   325 	//Initialise to unused values
       
   326 	TInt progressState = KInvalidState;
       
   327 	TInt connectState = KInvalidState;
       
   328 	TInt iap = KInvalidIAP;
       
   329 	TInt connection_progress_state = 0;
       
   330 
       
   331 	RTimer timer; 
       
   332 	TRequestStatus timerStatus; // Request status associated with timer
       
   333 	timer.CreateLocal(); // Create for this thread
       
   334 
       
   335 	do
       
   336 		{	
       
   337 		// Call funtion to return IAP and Poll to find connection state 
       
   338 		TImap4GenericProgress temp;	
       
   339 		TPckgC<TImap4GenericProgress> paramPack(temp);
       
   340 		paramPack.Set(iParentTestHarness.CurrentOperation().ProgressL());
       
   341 		TImap4GenericProgress progress = paramPack();	
       
   342 
       
   343 		progressState = progress.iState;
       
   344 		if((connectState != progress.ConnectionState()) || (iap != progress.ConnectionIAP()) )
       
   345 			{
       
   346 			connectState = progress.ConnectionState();
       
   347 			iap = progress.ConnectionIAP();
       
   348 			LogCommentFormat(_L("[%4d] Progress state =  %d, Connect State = %d, IAP = %d"), iDebugInfo.LineNumber(), progressState, connectState, iap);
       
   349 			
       
   350 			//Check that the relevant states are reached in the correct order
       
   351 			if ((connectState == ECsdStartingDialling) || (connectState == ECsdStartingConnect))
       
   352 					connection_progress_state = 1;
       
   353 			if (connectState == ECsdConnectionOpen && connection_progress_state == 1)
       
   354 					connection_progress_state = 2;
       
   355 			if (connectState == KLinkLayerOpen && connection_progress_state == 2)
       
   356 					connection_progress_state = 3;
       
   357 			}
       
   358 
       
   359 		// wait 50 microseconds and then re-test progress!
       
   360 		timer.After(timerStatus,50);
       
   361 		User::WaitForRequest(timerStatus); 
       
   362 	
       
   363 		} while (progressState == TImap4GenericProgress::EConnecting);
       
   364 
       
   365 	timer.Close();
       
   366 	if (connection_progress_state != 3)
       
   367 		{
       
   368 		LogCommentFormat(_L("[%4d] Local Connection Progress state =  %d, Connect State = %d, IAP = %d"), iDebugInfo.LineNumber(), connection_progress_state, connectState, iap);
       
   369 		iConnectionError = ETrue;
       
   370 		}
       
   371 	}
       
   372 
       
   373 void CImapConnectAndMonitor::RunL()
       
   374 	{
       
   375 	if (iConnectionError)
       
   376 		User::RequestComplete(iReportStatus, KErrUnknown);	
       
   377 	else
       
   378 		User::RequestComplete(iReportStatus, iStatus.Int());
       
   379 	}
       
   380 
       
   381 // HandleImapConnectionEvent Callback (from MMsvImapConnectionObserver)
       
   382 void CImapConnectAndMonitor::HandleImapConnectionEvent(TImapConnectionEvent)
       
   383 	{
       
   384 	}
       
   385 
       
   386 void CImapConnectAndMonitor::DoCancel()
       
   387 	{
       
   388 	iParentTestHarness.CurrentOperation().Cancel();
       
   389 	}
       
   390 
       
   391 CImapConnectAndMonitor::~CImapConnectAndMonitor()
       
   392 	{
       
   393 	}
       
   394 
       
   395 //
       
   396 //
       
   397 // CImapConnectAndCancel
       
   398 //
       
   399 // Connect then disconnect before sync completes
       
   400 //
       
   401 CImapConnectAndCancel::CImapConnectAndCancel(CEmailClientTest& aParentTestHarness, TUint aCancelDelay) : CActive(EPriorityNormal),iParentTestHarness(aParentTestHarness), iCancelDelay(aCancelDelay)
       
   402 	{
       
   403 	CActiveScheduler::Add(this);
       
   404 	}
       
   405 
       
   406 void CImapConnectAndCancel::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   407 	{
       
   408 	// Build parameter list.
       
   409 	VA_LIST list;
       
   410 	VA_START(list, format);
       
   411 	TBuf<0x100> buf;
       
   412 	buf.FormatList(format, list);
       
   413 
       
   414 	// Log the debug buffer.
       
   415 	iParentTestHarness.EmailTestUtils().WriteComment(buf);
       
   416 	}
       
   417 
       
   418 
       
   419 void CImapConnectAndCancel::StartL(TRequestStatus& aStatus)
       
   420 	{
       
   421 	iReportStatus = &aStatus;
       
   422 
       
   423 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   424 	TBuf8<1> param;
       
   425 	iSelection = new (ELeave) CMsvEntrySelection;
       
   426 	iSelection->AppendL(serviceId);
       
   427 
       
   428 	// Call the Async Connect & Sync funtion
       
   429 	iParentTestHarness.SetCurrentOperation(iParentTestHarness.EmailTestUtils().iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnect, 
       
   430 											*iSelection, param, iStatus));
       
   431 
       
   432 	iCommandState=EFirstConnect;
       
   433 	aStatus = KRequestPending;
       
   434 	SetActive();
       
   435 	LogCommentFormat(_L("First connect started"));
       
   436 	}
       
   437 
       
   438 void CImapConnectAndCancel::RunL()
       
   439 	{
       
   440 	TBuf8<1> param;
       
   441 	//LogCommentFormat(_L("CImapConnectAndCancel::RunL().  State = %d"), iCommandState);	
       
   442 
       
   443 	switch (iCommandState)
       
   444 		{
       
   445 		case EFirstConnect:
       
   446 			{
       
   447 			// The first connect has completed.  Now Disconnect.
       
   448 			iParentTestHarness.SetCurrentOperation(iParentTestHarness.EmailTestUtils().iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMDisconnect,  
       
   449 													*iSelection, param, iStatus));
       
   450 			
       
   451 			iCommandState = EDisconnect;
       
   452 			*iReportStatus = KRequestPending;
       
   453 			SetActive();
       
   454 			LogCommentFormat(_L("Disconnecting"));
       
   455 			break;
       
   456 			}
       
   457 		case EDisconnect:
       
   458 			{
       
   459 			// We have now disconnected after the first sync. 
       
   460 			// Start a new connect and sync which we will cancel after 
       
   461 			//  the specified interval
       
   462 			iParentTestHarness.SetCurrentOperation(iParentTestHarness.EmailTestUtils().iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSynchronise, 
       
   463 													*iSelection, param, iStatus));
       
   464 
       
   465 			iCommandState=ESecondSyncCancelled;		// This sync is about to be cancelled
       
   466 			*iReportStatus = KRequestPending;
       
   467 			SetActive();
       
   468 			LogCommentFormat(_L("Second Connect and Sync started"));
       
   469 
       
   470 			// This is where is gets a bit messy...
       
   471 
       
   472 			// Define a timer so we can cancel after a specified period.
       
   473 			// We can't wait for the connect to complete because it's too late by then.
       
   474 			// We need to cancel during the stage when the IMAP server Capabilities 
       
   475 			//  are being returned
       
   476 			RTimer timer; 
       
   477 			TRequestStatus timerStatus; // Request status associated with timer
       
   478 			timer.CreateLocal(); // Create for this thread
       
   479 			LogCommentFormat(_L("Waiting for %d msecs"), iCancelDelay);
       
   480 
       
   481 			// Wait for the defined interval
       
   482 			// OK, so this suspends the current thread which isn't great but the
       
   483 			//  server is running in a different thread, so that continues as normal
       
   484 			timer.After(timerStatus, iCancelDelay * 1000);
       
   485 			User::WaitForRequest(timerStatus); 
       
   486 			timer.Close();
       
   487 
       
   488 			// Cancel the connect & sync
       
   489 			DoCancel();
       
   490 			LogCommentFormat(_L("Second connect & sync cancelled"));
       
   491 			break;
       
   492 			}
       
   493 		case ESecondSyncCancelled: 
       
   494 			// The second sync should have completed when the connect occured, but
       
   495 			// we cancelled it before it had chance to complete.
       
   496 			// Now start the final sync to check that all is still OK
       
   497 			{
       
   498 			iParentTestHarness.SetCurrentOperation(iParentTestHarness.EmailTestUtils().iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSynchronise, 
       
   499 													*iSelection, param, iStatus));
       
   500 
       
   501 			iCommandState=EThirdSync;
       
   502 			*iReportStatus = KRequestPending;
       
   503 			SetActive();
       
   504 			LogCommentFormat(_L("Third Connect and Sync started"));
       
   505 
       
   506 			break;
       
   507 			}
       
   508 		case EThirdSync:
       
   509 			{
       
   510 			// At this point the third ConnectAndSync reports that it is completed, but actually 
       
   511 			//  only the connect has.  The sync continues in background, so create an operation
       
   512 			//  to wait for it to complete.
       
   513 			iParentTestHarness.SetCurrentOperation(iParentTestHarness.EmailTestUtils().iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMWaitForBackground,  
       
   514 													*iSelection, param, iStatus));
       
   515 			
       
   516 			iCommandState = EComplete;
       
   517 			*iReportStatus = KRequestPending;
       
   518 			SetActive();
       
   519 			LogCommentFormat(_L("Waiting for third sync to complete"));
       
   520 			break;
       
   521 			}
       
   522 		case EComplete:
       
   523 			{
       
   524 			// Everything has completed.  Success!
       
   525 			LogCommentFormat(_L("Completed"));
       
   526 			User::RequestComplete(iReportStatus, KErrNone);
       
   527 			break;
       
   528 			}
       
   529 		default:
       
   530 			{
       
   531 			//  This shouldn't happen...
       
   532 			LogCommentFormat(_L("Unknown state in ConnectAndCancel"));
       
   533 			User::RequestComplete(iReportStatus, KErrUnknown);
       
   534 			break;
       
   535 			}
       
   536 		}
       
   537 	}
       
   538 
       
   539 
       
   540 
       
   541 void CImapConnectAndCancel::DoCancel()
       
   542 	{
       
   543 	iParentTestHarness.CurrentOperation().Cancel();
       
   544 	}
       
   545 
       
   546 
       
   547 CImapConnectAndCancel::~CImapConnectAndCancel()
       
   548 	{
       
   549 	delete iSelection;
       
   550 	}
       
   551 
       
   552 
       
   553 //
       
   554 //
       
   555 // CImapDisconnect
       
   556 //
       
   557 
       
   558 CImapDisconnect::CImapDisconnect(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   559 	{
       
   560 	CActiveScheduler::Add(this);
       
   561 	}
       
   562 
       
   563 void CImapDisconnect::StartL(TRequestStatus& aStatus)
       
   564 	{
       
   565 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   566 	CMsvEntry& msvEntry = *(iParentTestHarness.MsvTestUtils().iMsvEntry);
       
   567 	msvEntry.SetEntryL(serviceId);
       
   568 	iReportStatus = &aStatus;
       
   569 	// check that current entry is a service
       
   570 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   571 	TBuf8<1> param;
       
   572 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   573 	CleanupStack::PushL(selection);
       
   574 	selection->AppendL(serviceId);
       
   575 	iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMDisconnect, *selection, param, iStatus));
       
   576 	CleanupStack::PopAndDestroy(selection);
       
   577 	aStatus = KRequestPending;
       
   578 	SetActive();
       
   579 	}
       
   580 
       
   581 void CImapDisconnect::RunL()
       
   582 	{
       
   583 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   584 	}
       
   585 
       
   586 void CImapDisconnect::DoCancel()
       
   587 	{
       
   588 	iParentTestHarness.CurrentOperation().Cancel();
       
   589 	}
       
   590 
       
   591 
       
   592 CImapDisconnect::~CImapDisconnect()
       
   593 	{
       
   594 	}
       
   595 
       
   596 
       
   597 //
       
   598 //
       
   599 // CImapSetSyncLimits
       
   600 //
       
   601 
       
   602 CImapSetSyncLimits::CImapSetSyncLimits(TInt aInboxSyncLimit, TInt aFolderSyncLimit, CImapClientTest& aTestHarness) : 
       
   603 	iTestHarness(aTestHarness), iInboxSyncLimit(aInboxSyncLimit), iFolderSyncLimit(aFolderSyncLimit)
       
   604 	{
       
   605 	}
       
   606 
       
   607 void CImapSetSyncLimits::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   608 	{
       
   609 	// Build parameter list.
       
   610 	VA_LIST list;
       
   611 	VA_START(list, format);
       
   612 	TBuf<0x100> buf;
       
   613 	buf.FormatList(format, list);
       
   614 
       
   615 	// Log the debug buffer.
       
   616 	iTestHarness.EmailTestUtils().WriteComment(buf);
       
   617 	}
       
   618 
       
   619 void CImapSetSyncLimits::StartL(TRequestStatus& aStatus)
       
   620 	{
       
   621 // Assumes that IMAP service currently selected.
       
   622 
       
   623 	LogCommentFormat(_L("[%4d] Setting sync limits (inbox=%d) (folders=%d)"), iDebugInfo.LineNumber(), iInboxSyncLimit, iFolderSyncLimit);
       
   624 	
       
   625 	CImImap4Settings* settings = new(ELeave) CImImap4Settings();
       
   626 	CleanupStack::PushL(settings);	
       
   627 	
       
   628 	CEmailAccounts* account = CEmailAccounts::NewLC();
       
   629 	
       
   630 	TImapAccount imapAccountId;
       
   631 	account->GetImapAccountL(iTestHarness.EmailTestUtils().iMsvEntry->EntryId(),imapAccountId); 
       
   632 	account->LoadImapSettingsL(imapAccountId, *settings);
       
   633 						
       
   634 	settings->SetInboxSynchronisationLimit(iInboxSyncLimit);
       
   635 	settings->SetMailboxSynchronisationLimit(iFolderSyncLimit);
       
   636 	account->SaveImapSettingsL(imapAccountId, *settings);
       
   637 
       
   638 	CleanupStack::PopAndDestroy(account);
       
   639 	CleanupStack::PopAndDestroy(settings);
       
   640 
       
   641 	TRequestStatus* status = &aStatus;
       
   642 	User::RequestComplete(status, KErrNone);
       
   643 	}
       
   644 
       
   645 //
       
   646 //
       
   647 // CCheckImapOperation
       
   648 //
       
   649 
       
   650 CCheckImapOperation::CCheckImapOperation(TInt aExpectedStatus, CImapClientTest& aTestHarness) : iTestHarness(aTestHarness), iExpectedStatus(aExpectedStatus)
       
   651 	{
       
   652 	}
       
   653 
       
   654 void CCheckImapOperation::StartL(TRequestStatus& aStatus)
       
   655 	{
       
   656 	TInt err = KErrNone;
       
   657 
       
   658 	TImap4GenericProgress temp;	
       
   659 	TPckgC<TImap4GenericProgress> paramPack(temp);
       
   660 	paramPack.Set(iTestHarness.CurrentOperation().ProgressL());
       
   661 	TImap4GenericProgress progress=paramPack();	
       
   662 
       
   663 	if (progress.iErrorCode != iExpectedStatus)
       
   664 		{
       
   665 		TBuf<100> logString;
       
   666 		logString.Format(_L("Operation didn't complete as expected. Expected status: %d, actual status: %d"), iExpectedStatus, progress.iErrorCode);
       
   667 		iTestHarness.LogComment(logString);
       
   668 		err = KErrUnknown;
       
   669 		}
       
   670 
       
   671 	TRequestStatus* status = &aStatus;
       
   672 	User::RequestComplete(status, err);
       
   673 	}
       
   674 
       
   675 
       
   676 //
       
   677 //
       
   678 // CImapSyncTree
       
   679 //
       
   680 
       
   681 CImapSyncTree::CImapSyncTree(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   682 	{
       
   683 	CActiveScheduler::Add(this);
       
   684 	}
       
   685 
       
   686 void CImapSyncTree::StartL(TRequestStatus& aStatus)
       
   687 	{
       
   688 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   689 	iReportStatus = &aStatus;
       
   690 	// check that current entry is a service
       
   691 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   692 	TBuf8<1> param;
       
   693 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   694 	CleanupStack::PushL(selection);
       
   695 	selection->AppendL(serviceId);
       
   696 	iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMSyncTree, *selection, param, iStatus));
       
   697 	CleanupStack::PopAndDestroy(selection);
       
   698 	aStatus = KRequestPending;
       
   699 	SetActive();
       
   700 	}
       
   701 
       
   702 void CImapSyncTree::RunL()
       
   703 	{
       
   704 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   705 	}
       
   706 
       
   707 void CImapSyncTree::DoCancel()
       
   708 	{
       
   709 	iParentTestHarness.CurrentOperation().Cancel();
       
   710 	}
       
   711 
       
   712 
       
   713 CImapSyncTree::~CImapSyncTree()
       
   714 	{
       
   715 	}
       
   716 
       
   717 
       
   718 
       
   719 //
       
   720 //
       
   721 // CImapInboxNewSync
       
   722 //
       
   723 
       
   724 CImapInboxNewSync::CImapInboxNewSync(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   725 	{
       
   726 	CActiveScheduler::Add(this);
       
   727 	}
       
   728 
       
   729 void CImapInboxNewSync::StartL(TRequestStatus& aStatus)
       
   730 	{
       
   731 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   732 	iReportStatus = &aStatus;
       
   733 	// check that current entry is a service
       
   734 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   735 	TBuf8<1> param;
       
   736 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   737 	CleanupStack::PushL(selection);
       
   738 	selection->AppendL(serviceId);
       
   739 	iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMInboxNewSync, *selection, param, iStatus));
       
   740 	CleanupStack::PopAndDestroy(selection);
       
   741 	aStatus = KRequestPending;
       
   742 	SetActive();
       
   743 	}
       
   744 
       
   745 void CImapInboxNewSync::RunL()
       
   746 	{
       
   747 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   748 	}
       
   749 
       
   750 void CImapInboxNewSync::DoCancel()
       
   751 	{
       
   752 	iParentTestHarness.CurrentOperation().Cancel();
       
   753 	}
       
   754 
       
   755 
       
   756 CImapInboxNewSync::~CImapInboxNewSync()
       
   757 	{
       
   758 	}
       
   759 
       
   760 //
       
   761 //
       
   762 // CImapFolderSync
       
   763 //
       
   764 
       
   765 CImapFolderSync::CImapFolderSync(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   766 	{
       
   767 	CActiveScheduler::Add(this);
       
   768 	}
       
   769 
       
   770 void CImapFolderSync::StartL(TRequestStatus& aStatus)
       
   771 	{
       
   772 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   773 	iReportStatus = &aStatus;
       
   774 	// check that current entry is a service
       
   775 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   776 	TBuf8<1> param;
       
   777 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   778 	CleanupStack::PushL(selection);
       
   779 	selection->AppendL(serviceId);
       
   780 	iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMFolderFullSync, *selection, param, iStatus));
       
   781 	CleanupStack::PopAndDestroy(selection);
       
   782 	aStatus = KRequestPending;
       
   783 	SetActive();
       
   784 	}
       
   785 
       
   786 void CImapFolderSync::RunL()
       
   787 	{
       
   788 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   789 	}
       
   790 
       
   791 void CImapFolderSync::DoCancel()
       
   792 	{
       
   793 	iParentTestHarness.CurrentOperation().Cancel();
       
   794 	}
       
   795 
       
   796 
       
   797 CImapFolderSync::~CImapFolderSync()
       
   798 	{
       
   799 	}
       
   800 
       
   801 //
       
   802 //
       
   803 // CImapPerformFullSync
       
   804 //
       
   805 
       
   806 CImapPerformFullSync::CImapPerformFullSync(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   807 	{
       
   808 	CActiveScheduler::Add(this);
       
   809 	}
       
   810 
       
   811 void CImapPerformFullSync::StartL(TRequestStatus& aStatus)
       
   812 	{
       
   813 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   814 	iReportStatus = &aStatus;
       
   815 	// check that current entry is a service
       
   816 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   817 	TBuf8<1> param;
       
   818 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   819 	CleanupStack::PushL(selection);
       
   820 	selection->AppendL(serviceId);
       
   821 	iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMFullSync, *selection, param, iStatus));
       
   822 	CleanupStack::PopAndDestroy(selection);
       
   823 	aStatus = KRequestPending;
       
   824 	SetActive();
       
   825 	}														
       
   826 
       
   827 void CImapPerformFullSync::RunL()
       
   828 	{
       
   829 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   830 	}
       
   831 
       
   832 void CImapPerformFullSync::DoCancel()
       
   833 	{
       
   834 	iParentTestHarness.CurrentOperation().Cancel();
       
   835 	}
       
   836 
       
   837 CImapPerformFullSync::~CImapPerformFullSync()
       
   838 	{
       
   839 	}
       
   840 
       
   841 //
       
   842 //
       
   843 // CImapPopulateFolder
       
   844 //
       
   845 
       
   846 CImapPopulateFolder::CImapPopulateFolder(CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness)
       
   847 	{
       
   848 	CActiveScheduler::Add(this);
       
   849 	}
       
   850 
       
   851 void CImapPopulateFolder::StartL(TRequestStatus& aStatus)
       
   852 	{
       
   853 	iReportStatus = &aStatus;
       
   854 	// check that current entry is a service
       
   855 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   856 	TBuf8<1> param;
       
   857 	iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMPopulate, *(iParentTestHarness.iCurrentSelection), param, iStatus));
       
   858 	aStatus = KRequestPending;
       
   859 	SetActive();
       
   860 	}
       
   861 
       
   862 void CImapPopulateFolder::RunL()
       
   863 	{
       
   864 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   865 	}
       
   866 
       
   867 void CImapPopulateFolder::DoCancel()
       
   868 	{
       
   869 	iParentTestHarness.CurrentOperation().Cancel();
       
   870 	}
       
   871 
       
   872 
       
   873 CImapPopulateFolder::~CImapPopulateFolder()
       
   874 	{
       
   875 	}
       
   876 
       
   877 
       
   878 
       
   879 //
       
   880 //
       
   881 // CImapSubscribeFolder
       
   882 //
       
   883 
       
   884 CImapSubscribeFolder::CImapSubscribeFolder(TBool aSubscribe, CEmailClientTest& aParentTestHarness) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness), iSubscribe(aSubscribe)
       
   885 	{
       
   886 	CActiveScheduler::Add(this);
       
   887 	}
       
   888 
       
   889 void CImapSubscribeFolder::StartL(TRequestStatus& aStatus)
       
   890 	{
       
   891 	TMsvId serviceId = iParentTestHarness.iSelectedFolder;
       
   892 	iReportStatus = &aStatus;
       
   893 	// check that current entry is a service
       
   894 	CImap4ClientMtm& imapMtm = *(iParentTestHarness.EmailTestUtils().iImapClientMtm);
       
   895 	TBuf8<1> param;
       
   896 	CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
       
   897 	CleanupStack::PushL(selection);
       
   898 	selection->AppendL(serviceId);
       
   899 	if (iSubscribe)
       
   900 		iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMLocalSubscribe, *selection, param, iStatus));
       
   901 	else
       
   902 		iParentTestHarness.SetCurrentOperation(imapMtm.InvokeAsyncFunctionL(KIMAP4MTMLocalUnsubscribe, *selection, param, iStatus));
       
   903 	CleanupStack::PopAndDestroy(selection);
       
   904 	aStatus = KRequestPending;
       
   905 	SetActive();
       
   906 	}
       
   907 
       
   908 void CImapSubscribeFolder::RunL()
       
   909 	{
       
   910 	User::RequestComplete(iReportStatus, iStatus.Int());
       
   911 	}
       
   912 
       
   913 void CImapSubscribeFolder::DoCancel()
       
   914 	{
       
   915 	iParentTestHarness.CurrentOperation().Cancel();
       
   916 	}
       
   917 
       
   918 
       
   919 CImapSubscribeFolder::~CImapSubscribeFolder()
       
   920 	{
       
   921 	}
       
   922 
       
   923 
       
   924 //
       
   925 //
       
   926 // CImapMarkSelectionUnRead
       
   927 //
       
   928 
       
   929 CImapMarkSelection::CImapMarkSelection(TBool aUnreadflag, CMsvEntrySelection& aSelection, CMsvTestUtils& aTestUtils) 
       
   930 : iTestUtils(aTestUtils),
       
   931   iSelection(aSelection),
       
   932   iUnreadflag(aUnreadflag)
       
   933 	{
       
   934 	}
       
   935 
       
   936 void CImapMarkSelection::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   937 	{
       
   938 	// Build parameter list.
       
   939 	VA_LIST list;
       
   940 	VA_START(list, format);
       
   941 	TBuf<0x100> buf;
       
   942 	buf.FormatList(format, list);
       
   943 
       
   944 	// Log the debug buffer.
       
   945 	iTestUtils.WriteComment(buf);
       
   946 	}
       
   947 
       
   948 void CImapMarkSelection::StartL(TRequestStatus& aStatus)
       
   949 	{
       
   950 	// check that current entry is a service
       
   951 	CMsvEntry& msvEntry = *(iTestUtils.iMsvEntry);	
       
   952 	
       
   953 	CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active);
       
   954 
       
   955 	LogCommentFormat(_L("[%4d] Unread mark Folder contains %d children"), iDebugInfo.LineNumber(), iSelection.Count());
       
   956 
       
   957 	TInt count=iSelection.Count();
       
   958 	// Set the Unread flag of each message
       
   959 	while(count--)
       
   960 		{
       
   961 		msvEntry.SetEntryL(iSelection.At(count));
       
   962 		TMsvEntry message = msvEntry.Entry();
       
   963 		
       
   964 		message.SetUnread(iUnreadflag);	// true - sets message to unread and false to read.
       
   965 
       
   966 		CMsvOperation *op=msvEntry.ChangeL(message,active->iStatus);
       
   967 		CleanupStack::PushL(op);
       
   968 		active->StartL();
       
   969 		CActiveScheduler::Start();
       
   970 		CleanupStack::PopAndDestroy(op);
       
   971 
       
   972 		}
       
   973 
       
   974 	LogCommentFormat(_L("[%4d] Unread mark: Set things read"), iDebugInfo.LineNumber());
       
   975 
       
   976 	CleanupStack::PopAndDestroy(active);
       
   977 
       
   978 	LogCommentFormat(_L("[%4d] Unread mark: Completing parent"), iDebugInfo.LineNumber());
       
   979 
       
   980 	TRequestStatus* status = &aStatus;
       
   981 	User::RequestComplete(status, KErrNone);
       
   982 	}														
       
   983 
       
   984 
       
   985 CImapMarkSelection::~CImapMarkSelection()
       
   986 	{
       
   987 	}
       
   988 
       
   989 
       
   990 //
       
   991 //
       
   992 // CImapCheckSelectionUnread
       
   993 //
       
   994 
       
   995 CImapCheckSelectionUnread::CImapCheckSelectionUnread(TInt aTestType, CMsvEntrySelection& aSelection, CMsvTestUtils& aTestUtils) 
       
   996 : iTestUtils(aTestUtils),
       
   997   iSelection(aSelection),
       
   998   iTestType(aTestType)
       
   999   	{
       
  1000 	}
       
  1001 
       
  1002 void CImapCheckSelectionUnread::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
  1003 	{
       
  1004 	// Build parameter list.
       
  1005 	VA_LIST list;
       
  1006 	VA_START(list, format);
       
  1007 	TBuf<0x100> buf;
       
  1008 	buf.FormatList(format, list);
       
  1009 
       
  1010 	// Log the debug buffer.
       
  1011 	iTestUtils.WriteComment(buf);
       
  1012 	}
       
  1013 
       
  1014 void CImapCheckSelectionUnread::StartL(TRequestStatus& aStatus)
       
  1015 	{
       
  1016 	TInt err = KErrNone;
       
  1017 	// check that current entry is a service
       
  1018 	CMsvEntry& msvEntry = *(iTestUtils.iMsvEntry);	
       
  1019 	
       
  1020 	CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active);
       
  1021 
       
  1022 	LogCommentFormat(_L("[%4d] Unread mark Folder contains %d children"), iDebugInfo.LineNumber(), iSelection.Count());
       
  1023 
       
  1024 	TInt count=iSelection.Count();
       
  1025 
       
  1026 	//Check unseen and imap4 flag
       
  1027 	TBool imapUnread, Seen, Answered, Flagged, Deleted, Draft, Recent;
       
  1028 	TBool Unreadflag;	
       
  1029 	// Check the Unread flag of each message
       
  1030 
       
  1031 	while(count--)
       
  1032 		{
       
  1033 		msvEntry.SetEntryL(iSelection.At(count));
       
  1034 		TMsvEmailEntry emailmessage = msvEntry.Entry();
       
  1035 
       
  1036 		/* get seen flag */
       
  1037 		emailmessage.GetIMAP4Flags(imapUnread, Seen, Answered, Flagged, Deleted, Draft, Recent);
       
  1038 		/* get relevant unread flag */
       
  1039 		Unreadflag = emailmessage.Unread();
       
  1040 		
       
  1041 		switch (iTestType)
       
  1042 			{
       
  1043 			case 0:
       
  1044 				/* read test */	
       
  1045 				if (imapUnread)
       
  1046 					{
       
  1047 					LogCommentFormat(_L("[%4d] Error: Unread flag wrongly set to true "), iDebugInfo.LineNumber());
       
  1048 					err = KErrUnknown;
       
  1049 					}
       
  1050 			break;
       
  1051 			case 1:	
       
  1052 				/* unread test */
       
  1053 				if (!Unreadflag)
       
  1054 					{
       
  1055 					LogCommentFormat(_L("[%4d] Error: Unread flag wrongly set to false "), iDebugInfo.LineNumber());
       
  1056 					err = KErrUnknown;
       
  1057 					}	
       
  1058 				break;
       
  1059 			}
       
  1060 		}
       
  1061 	
       
  1062 	LogCommentFormat(_L("[%4d] all flags checked"), iDebugInfo.LineNumber());
       
  1063 
       
  1064 	CleanupStack::PopAndDestroy(active);
       
  1065 
       
  1066 	TRequestStatus* status = &aStatus;
       
  1067 	User::RequestComplete(status, err);
       
  1068 	}														
       
  1069 
       
  1070 
       
  1071 CImapCheckSelectionUnread::~CImapCheckSelectionUnread()
       
  1072 	{
       
  1073 	}
       
  1074 
       
  1075 
       
  1076 //
       
  1077 //
       
  1078 // CImapCheckSelectionSeen
       
  1079 //
       
  1080 
       
  1081 CImapCheckSelectionSeen::CImapCheckSelectionSeen(TInt aSeenflag, CMsvEntrySelection& aSelection, CMsvTestUtils& aTestUtils) 
       
  1082 : iTestUtils(aTestUtils),
       
  1083   iSelection(aSelection),
       
  1084   iSeenflag(aSeenflag)
       
  1085   	{
       
  1086 	}
       
  1087 
       
  1088 void CImapCheckSelectionSeen::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
  1089 	{
       
  1090 	// Build parameter list.
       
  1091 	VA_LIST list;
       
  1092 	VA_START(list, format);
       
  1093 	TBuf<0x100> buf;
       
  1094 	buf.FormatList(format, list);
       
  1095 
       
  1096 	// Log the debug buffer.
       
  1097 	iTestUtils.WriteComment(buf);
       
  1098 	}
       
  1099 
       
  1100 void CImapCheckSelectionSeen::StartL(TRequestStatus& aStatus)
       
  1101 	{
       
  1102 	TInt err = KErrNone;
       
  1103 	// check that current entry is a service
       
  1104 	CMsvEntry& msvEntry = *(iTestUtils.iMsvEntry);	
       
  1105 	
       
  1106 	CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active);
       
  1107 
       
  1108 	LogCommentFormat(_L("[%4d] Unread mark Folder contains %d children"), iDebugInfo.LineNumber(), iSelection.Count());
       
  1109 
       
  1110 	TInt count=iSelection.Count();
       
  1111 
       
  1112 	//Check unseen and imap4 flag
       
  1113 	TBool imapUnread, Seen, Answered, Flagged, Deleted, Draft, Recent;
       
  1114 
       
  1115 	TBool updateSeenflag = isaveSettings->UpdatingSeenFlags();
       
  1116 	
       
  1117 	if (updateSeenflag)
       
  1118 	{
       
  1119 		while(count--)
       
  1120 			{
       
  1121 			msvEntry.SetEntryL(iSelection.At(count));
       
  1122 			TMsvEmailEntry emailmessage = msvEntry.Entry();
       
  1123 
       
  1124 			/* get seen flag */
       
  1125 			emailmessage.GetIMAP4Flags(imapUnread, Seen, Answered, Flagged, Deleted, Draft, Recent);
       
  1126 			
       
  1127 			switch (iSeenflag)
       
  1128 				{
       
  1129 				case 0:	
       
  1130 					/* unread test */
       
  1131 					if(Seen)
       
  1132 						{
       
  1133 						LogCommentFormat(_L("[%4d] Error: seenImap4 flag set to true "), iDebugInfo.LineNumber());
       
  1134 						err = KErrUnknown;
       
  1135 						}		
       
  1136 				break;
       
  1137 				case 1:
       
  1138 					/* read test */		
       
  1139 					if(Seen)
       
  1140 						{
       
  1141 						LogCommentFormat(_L("[%4d] Error: seenImap4 flag set to false "), iDebugInfo.LineNumber());
       
  1142 						err = KErrUnknown;
       
  1143 						}		
       
  1144 				break;	
       
  1145 				}
       
  1146 			}
       
  1147 	}
       
  1148 	else
       
  1149 	{
       
  1150 		LogCommentFormat(_L("[%4d] Error: this test should not be called when updateseenflag false "), iDebugInfo.LineNumber());
       
  1151 		err = KErrUnknown;
       
  1152 	}
       
  1153 	
       
  1154 	LogCommentFormat(_L("[%4d] all flags checked"), iDebugInfo.LineNumber());
       
  1155 
       
  1156 	CleanupStack::PopAndDestroy(active);
       
  1157 
       
  1158 	TRequestStatus* status = &aStatus;
       
  1159 	User::RequestComplete(status, err);
       
  1160 	}														
       
  1161 
       
  1162 
       
  1163 CImapCheckSelectionSeen::~CImapCheckSelectionSeen()
       
  1164 	{
       
  1165 	}
       
  1166 
       
  1167 
       
  1168 
       
  1169 
       
  1170 //
       
  1171 //
       
  1172 // CImapMarkSelectedMail
       
  1173 //
       
  1174 
       
  1175 CImapMarkSelectedMail::CImapMarkSelectedMail(CMsvEntrySelection& aSelection, CMsvTestUtils& aTestUtils) 
       
  1176 : iTestUtils(aTestUtils),
       
  1177   iSelection(aSelection)
       
  1178 	{
       
  1179 	}
       
  1180 
       
  1181 void CImapMarkSelectedMail::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
  1182 	{
       
  1183 	// Build parameter list.
       
  1184 	VA_LIST list;
       
  1185 	VA_START(list, format);
       
  1186 	TBuf<0x100> buf;
       
  1187 	buf.FormatList(format, list);
       
  1188 
       
  1189 	// Log the debug buffer.
       
  1190 	iTestUtils.WriteComment(buf);
       
  1191 	}
       
  1192 
       
  1193 void CImapMarkSelectedMail::StartL(TRequestStatus& aStatus)
       
  1194 	{
       
  1195 	// check that current entry is a service
       
  1196 	
       
  1197 	CMsvEntry& msvEntry = *(iTestUtils.iMsvEntry);	
       
  1198 	
       
  1199 	CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active);
       
  1200 
       
  1201 	LogCommentFormat(_L("[%4d] Unread mark Folder contains %d children"), iDebugInfo.LineNumber(), iSelection.Count());
       
  1202 
       
  1203 	TInt count=iSelection.Count();
       
  1204 
       
  1205 	while(count--)
       
  1206 		{
       
  1207 		msvEntry.SetEntryL(iSelection.At(count));
       
  1208 		TMsvEntry message = msvEntry.Entry();
       
  1209 		
       
  1210 		//Set every other message to read and unread!
       
  1211 		if ((count & 1) == 0)
       
  1212 			message.SetUnread(ETrue);
       
  1213 		else
       
  1214 			message.SetUnread(EFalse);	
       
  1215 
       
  1216 		CMsvOperation *op=msvEntry.ChangeL(message,active->iStatus);
       
  1217 		CleanupStack::PushL(op);
       
  1218 		active->StartL();
       
  1219 		CActiveScheduler::Start();
       
  1220 		CleanupStack::PopAndDestroy(op);
       
  1221 
       
  1222 		}
       
  1223 	LogCommentFormat(_L("[%4d] Flag settings done"), iDebugInfo.LineNumber());
       
  1224 
       
  1225 	CleanupStack::PopAndDestroy(active);
       
  1226 
       
  1227 	TRequestStatus* status = &aStatus;
       
  1228 	User::RequestComplete(status, KErrNone);
       
  1229 	}														
       
  1230 
       
  1231 
       
  1232 CImapMarkSelectedMail::~CImapMarkSelectedMail()
       
  1233 	{
       
  1234 	}
       
  1235 
       
  1236 
       
  1237 
       
  1238 //
       
  1239 //
       
  1240 // CImapCheckSelectedMail
       
  1241 //
       
  1242 
       
  1243 CImapCheckSelectedMail::CImapCheckSelectedMail(CMsvEntrySelection& aSelection, CMsvTestUtils& aTestUtils) 
       
  1244 : iTestUtils(aTestUtils),
       
  1245   iSelection(aSelection)
       
  1246 	{
       
  1247 	}
       
  1248 
       
  1249 void CImapCheckSelectedMail::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
  1250 	{
       
  1251 	// Build parameter list.
       
  1252 	VA_LIST list;
       
  1253 	VA_START(list, format);
       
  1254 	TBuf<0x100> buf;
       
  1255 	buf.FormatList(format, list);
       
  1256 
       
  1257 	// Log the debug buffer.
       
  1258 	iTestUtils.WriteComment(buf);
       
  1259 	}
       
  1260 void CImapCheckSelectedMail::StartL(TRequestStatus& aStatus)
       
  1261 	{
       
  1262 	TInt err = KErrNone;
       
  1263 	// check that current entry is a service
       
  1264 	CMsvEntry& msvEntry = *(iTestUtils.iMsvEntry);	
       
  1265 	
       
  1266 	CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active);
       
  1267 
       
  1268 	LogCommentFormat(_L("[%4d] Selection test. Unread mark Folder contains %d children"), iDebugInfo.LineNumber(), iSelection.Count());
       
  1269 
       
  1270 	TInt count=iSelection.Count();
       
  1271 
       
  1272 	//Check unseen and imap4 flag
       
  1273 	TBool imapUnread, Seen, Answered, Flagged, Deleted, Draft, Recent;
       
  1274 	TBool Unreadflag;	
       
  1275 	
       
  1276 	TBool updateSeenflag = isaveSettings->UpdatingSeenFlags();
       
  1277 
       
  1278 	while(count--)
       
  1279 		{
       
  1280 		msvEntry.SetEntryL(iSelection.At(count));
       
  1281 		
       
  1282 		TMsvEmailEntry emailmessage = msvEntry.Entry();
       
  1283 		emailmessage.GetIMAP4Flags(imapUnread, Seen, Answered, Flagged, Deleted, Draft, Recent);
       
  1284 		
       
  1285 		Unreadflag = emailmessage.Unread();
       
  1286 
       
  1287 		if ((count & 1) == 0)
       
  1288 			{
       
  1289 			if (Unreadflag)
       
  1290 				{
       
  1291 				LogCommentFormat(_L("[%4d] Error: Unread flag wrongly set to false, Message No. = %d  "), iDebugInfo.LineNumber(), count);
       
  1292 				err = KErrUnknown;
       
  1293 				}
       
  1294 			if (updateSeenflag)
       
  1295 				{
       
  1296 				if(!Seen)
       
  1297 					{
       
  1298 					LogCommentFormat(_L("[%4d] Error: seenImap4 flag wrongly set to true, Message No. = %d  "), iDebugInfo.LineNumber(), count);
       
  1299 					err = KErrUnknown;
       
  1300 					}
       
  1301 				}
       
  1302 			}
       
  1303 		else
       
  1304 			{
       
  1305 			if (!Unreadflag)
       
  1306 				{
       
  1307 				LogCommentFormat(_L("[%4d] Error: Unread flag wrongly set to true, Message No. = %d "), iDebugInfo.LineNumber(), count);
       
  1308 				err = KErrUnknown;
       
  1309 				}
       
  1310 			if (updateSeenflag)
       
  1311 				{
       
  1312 				if(Seen)
       
  1313 					{
       
  1314 					LogCommentFormat(_L("[%4d] Error: seenImap4 flag wrongly set to true, Message No. = %d  "), iDebugInfo.LineNumber(), count);
       
  1315 					err = KErrUnknown;
       
  1316 					}
       
  1317 				}		
       
  1318 			}
       
  1319 		}
       
  1320 	
       
  1321 	LogCommentFormat(_L("[%4d] all flags checked"), iDebugInfo.LineNumber());
       
  1322 
       
  1323 	CleanupStack::PopAndDestroy(active);
       
  1324 
       
  1325 	TRequestStatus* status = &aStatus;
       
  1326 	User::RequestComplete(status, err);
       
  1327 	}														
       
  1328 
       
  1329 
       
  1330 CImapCheckSelectedMail::~CImapCheckSelectedMail()
       
  1331 	{
       
  1332 	}
       
  1333 
       
  1334 
       
  1335 //
       
  1336 //
       
  1337 // CImapSetSyncRate
       
  1338 //
       
  1339 
       
  1340 CImapSetSyncRate::CImapSetSyncRate(TInt aSyncRate, CImapClientTest& aTestHarness) : iTestHarness(aTestHarness), iSyncRate(aSyncRate)
       
  1341 	{
       
  1342 	}
       
  1343 
       
  1344 void CImapSetSyncRate::StartL(TRequestStatus& aStatus)
       
  1345 	{
       
  1346 	TInt err = KErrNone;
       
  1347 
       
  1348 	CImImap4Settings* settings = new(ELeave) CImImap4Settings();
       
  1349 	CleanupStack::PushL(settings);
       
  1350 
       
  1351 	CEmailAccounts* account = CEmailAccounts::NewLC();				
       
  1352 		
       
  1353 	TImapAccount imapAccountId;
       
  1354 	account->GetImapAccountL(iTestHarness.EmailTestUtils().iMsvEntry->EntryId(),imapAccountId); 
       
  1355 	account->LoadImapSettingsL(imapAccountId, *settings);
       
  1356 		
       
  1357 	settings->SetSyncRateL(iSyncRate);
       
  1358 	account->SaveImapSettingsL(imapAccountId, *settings);
       
  1359 
       
  1360 	CleanupStack::PopAndDestroy(2, settings); // account, settings
       
  1361 
       
  1362 	TBuf<100> logString;
       
  1363 	logString.Format(_L("Set sync rate: %d seconds"), iSyncRate);
       
  1364 	iTestHarness.LogComment(logString);
       
  1365 
       
  1366 	TRequestStatus* status = &aStatus;
       
  1367 	User::RequestComplete(status, err);
       
  1368 	}
       
  1369 
       
  1370 //
       
  1371 //
       
  1372 // CImapGetSyncRate
       
  1373 //
       
  1374 
       
  1375 CImapGetSyncRate::CImapGetSyncRate(TInt aSyncRate, CImapClientTest& aTestHarness) : iTestHarness(aTestHarness), iSyncRate(aSyncRate)
       
  1376 	{
       
  1377 	}
       
  1378 
       
  1379 void CImapGetSyncRate::StartL(TRequestStatus& aStatus)
       
  1380 	{
       
  1381 	TInt err = KErrNone;
       
  1382 
       
  1383 	CImImap4Settings* settings = new(ELeave) CImImap4Settings();
       
  1384 	CleanupStack::PushL(settings);
       
  1385 
       
  1386 	CEmailAccounts* account = CEmailAccounts::NewLC();				
       
  1387 	
       
  1388 	TImapAccount imapAccountId;
       
  1389 	account->GetImapAccountL(iTestHarness.EmailTestUtils().iMsvEntry->EntryId(),imapAccountId); 
       
  1390 	account->LoadImapSettingsL(imapAccountId, *settings);
       
  1391 			
       
  1392 	TUint syncRate = settings->SyncRate();
       
  1393 	
       
  1394 	account->SaveImapSettingsL(imapAccountId, *settings);
       
  1395 
       
  1396 	CleanupStack::PopAndDestroy(2, settings); // account, settings
       
  1397 
       
  1398 	TBuf<100> logString;
       
  1399 	logString.Format(_L("Expected sync rate: %d seconds Obtained: %d"), iSyncRate,syncRate);
       
  1400 	iTestHarness.LogComment(logString);
       
  1401 
       
  1402 	TRequestStatus* status = &aStatus;
       
  1403 	User::RequestComplete(status, err);
       
  1404 	}
       
  1405