messagingfw/msgtest/integration/email/src/smtptests.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "smtptests.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(KErrOperation,  "Operation didn't complete as expected. Expected status: [%d], actual status: [%d]");
       
    23 _LIT(KPopAccountName, "POP");
       
    24 
       
    25 const TInt KMaxErrorText = 100;
       
    26 
       
    27 //
       
    28 //
       
    29 // CSmtpClientTest
       
    30 //
       
    31 
       
    32 CSmtpClientTest* CSmtpClientTest::NewL(CEmailTestUtils& aTestUtils, RTest& aTest)
       
    33 	{
       
    34 	CSmtpClientTest* self = new (ELeave) CSmtpClientTest(aTestUtils, aTest);
       
    35 	CleanupStack::PushL(self);
       
    36 	self->ConstructL();
       
    37 	CleanupStack::Pop(self);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 CSmtpClientTest::~CSmtpClientTest()
       
    42 	{
       
    43 	}
       
    44 
       
    45 void CSmtpClientTest::ConstructL()
       
    46 	{
       
    47 	CEmailClientTest::ConstructL();
       
    48 	}
       
    49 
       
    50 CSmtpClientTest::CSmtpClientTest(CEmailTestUtils& aTestUtils, RTest& aTest) : CEmailClientTest(aTestUtils, aTest)
       
    51 	{
       
    52 	}
       
    53 
       
    54 
       
    55 
       
    56 //
       
    57 //
       
    58 // CCreateSmtpService
       
    59 //
       
    60 
       
    61 void CCreateSmtpService::StartL(TRequestStatus& aStatus)
       
    62 	{
       
    63 	// create pop account (pop account also creates smtp service)
       
    64 	CEmailAccounts* account = CEmailAccounts::NewLC();
       
    65 
       
    66 	CImIAPPreferences* smtpIAP = CImIAPPreferences::NewLC();
       
    67 				
       
    68 	TSmtpAccount accountId = account->CreateSmtpAccountL(*iDetails,*iSettings, *smtpIAP, EFalse);
       
    69 
       
    70 	// get pop service for the account
       
    71 	TMsvId service = accountId.iSmtpService;
       
    72 	
       
    73 	// select this service
       
    74 	CMsvEntry& msvEntry = *(iTestHarness.EmailTestUtils().iMsvEntry);
       
    75 	msvEntry.SetEntryL(service);
       
    76 	iEntry = msvEntry.Entry();
       
    77 	iEntry.SetVisible(ETrue);
       
    78 	iTestHarness.iCurrentServiceId = service;
       
    79 	iTestHarness.EmailTestUtils().iSmtpServiceId = service;
       
    80 
       
    81 	CleanupStack::PopAndDestroy(2, account); // smtpIAP, account
       
    82 
       
    83 	// If the SMTP Client MTM doesn't already exist, then Instantiate it 
       
    84 	if (!iTestHarness.EmailTestUtils().iSmtpClientMtm)
       
    85 		iTestHarness.EmailTestUtils().InstantiateSmtpClientMtmL();
       
    86 
       
    87 	TRequestStatus* status = &aStatus;
       
    88 	User::RequestComplete(status, KErrNone);
       
    89 	}
       
    90 
       
    91 CCreateSmtpService* CCreateSmtpService::NewL(CEmailClientTest& aTestHarness)
       
    92 	{
       
    93 	CCreateSmtpService* self = new (ELeave) CCreateSmtpService(aTestHarness);
       
    94 	CleanupStack::PushL(self);
       
    95 	self->ConstructL();
       
    96 	CleanupStack::Pop(self);
       
    97 	return self;
       
    98 	}
       
    99 
       
   100 CCreateSmtpService::CCreateSmtpService(CEmailClientTest& aTestHarness) : CCreateEmailService(aTestHarness), iTestHarness(aTestHarness)
       
   101 	{
       
   102 	}
       
   103 
       
   104 void CCreateSmtpService::ConstructL()
       
   105 	{
       
   106 	iSettings = new(ELeave) CImSmtpSettings();
       
   107 	}
       
   108 
       
   109 CCreateSmtpService::~CCreateSmtpService()
       
   110 	{
       
   111 	delete iSettings;
       
   112 	}
       
   113 
       
   114 CImSmtpSettings& CCreateSmtpService::Settings()
       
   115 	{
       
   116 	return *iSettings;
       
   117 	}
       
   118 
       
   119 
       
   120 //
       
   121 //
       
   122 // CCreateSmtpClientMtm
       
   123 //
       
   124 
       
   125 CCreateSmtpClientMtm::CCreateSmtpClientMtm(CEmailClientTest& aTest) : iTest(aTest)
       
   126 	{
       
   127 	}
       
   128 
       
   129 void CCreateSmtpClientMtm::StartL(TRequestStatus& aStatus)
       
   130 	{
       
   131 	iTest.EmailTestUtils().InstantiatePopClientMtmL();
       
   132 	TRequestStatus* status = &aStatus;
       
   133 	User::RequestComplete(status, KErrNone);
       
   134 	}
       
   135 
       
   136 
       
   137 
       
   138 //
       
   139 //
       
   140 // CCheckSmtpOperation
       
   141 //
       
   142 
       
   143 CCheckSmtpOperation::CCheckSmtpOperation(TInt aExpectedStatus, CSmtpClientTest& aTestHarness) : iTestHarness(aTestHarness), iExpectedStatus(aExpectedStatus)
       
   144 	{
       
   145 	}
       
   146 
       
   147 void CCheckSmtpOperation::StartL(TRequestStatus& aStatus)
       
   148 	{
       
   149 	TInt err = KErrNone;
       
   150 
       
   151 	TImSmtpProgress temp;	
       
   152 	TPckgC<TImSmtpProgress> paramPack(temp);
       
   153 	paramPack.Set(iTestHarness.CurrentOperation().ProgressL());
       
   154 	TImSmtpProgress progress=paramPack();	
       
   155 
       
   156 	if (progress.Error() != iExpectedStatus)
       
   157 		{
       
   158 		TBuf<KMaxErrorText> logString;
       
   159 		logString.Format(KErrOperation, iExpectedStatus, progress.Error());
       
   160 		iTestHarness.LogComment(logString);
       
   161 		err = KErrUnknown;
       
   162 		}
       
   163 
       
   164 	TRequestStatus* status = &aStatus;
       
   165 	User::RequestComplete(status, err);
       
   166 	}
       
   167 
       
   168 
       
   169 //
       
   170 //
       
   171 // CSmtpUseService
       
   172 //
       
   173 
       
   174 CSmtpUseService::CSmtpUseService(CSmtpClientTest& aTestHarness) : iTestHarness(aTestHarness)
       
   175 	{
       
   176 	}
       
   177 
       
   178 void CSmtpUseService::StartL(TRequestStatus& aStatus)
       
   179 	{
       
   180 	TInt err = KErrNone;
       
   181 
       
   182 	// Select current folder
       
   183 	CMsvEntry& entry = *(iTestHarness.EmailTestUtils().iMsvEntry);
       
   184 	entry.SetEntryL(iTestHarness.iSelectedFolder);
       
   185 		
       
   186 	// Check it is a service which is selected
       
   187 	if(entry.Entry().iType == KUidMsvServiceEntry)
       
   188 		{
       
   189 		// Make sure that the Root folder is selected
       
   190 		iTestHarness.iSelectedFolder = KMsvRootIndexEntryId;
       
   191 
       
   192 		// Change the Harness & Test Utils to use this SMTP service id
       
   193 		iTestHarness.EmailTestUtils().iSmtpServiceId = entry.Entry().Id();
       
   194 		iTestHarness.iCurrentServiceId = entry.Entry().Id();
       
   195 
       
   196 		// If the Smtp Client MTM doesn't already exist, then Instantiate it 
       
   197 		if (!iTestHarness.EmailTestUtils().iSmtpClientMtm)
       
   198 			iTestHarness.EmailTestUtils().InstantiateSmtpClientMtmL();
       
   199 		}
       
   200 	else
       
   201 		{
       
   202 		TBuf<KMaxErrorText> logString;
       
   203 		logString.Format(KErrUseService, iDebugInfo.LineNumber());
       
   204 		iTestHarness.LogComment(logString);
       
   205 
       
   206 		err = KErrUnknown;
       
   207 		}
       
   208 
       
   209 	TRequestStatus* status = &aStatus;
       
   210 	User::RequestComplete(status, err);
       
   211 	}
       
   212 
       
   213 //
       
   214 //
       
   215 // CCopySelectionAndMonitor
       
   216 //
       
   217 CCopySelectionAndMonitor::CCopySelectionAndMonitor(CEmailClientTest& aParentTestHarness, TBool aSynchronise) : CActive(EPriorityNormal), iParentTestHarness(aParentTestHarness), iSynchronise(aSynchronise)
       
   218 	{
       
   219 	CActiveScheduler::Add(this);
       
   220 	}
       
   221 
       
   222 
       
   223 
       
   224 void CCopySelectionAndMonitor::LogCommentFormat(TRefByValue<const TDesC> format,...)
       
   225 	{
       
   226 	// Build parameter list.
       
   227 	VA_LIST list;
       
   228 	VA_START(list, format);
       
   229 	TBuf<0x100> buf;
       
   230 	buf.FormatList(format, list);
       
   231 
       
   232 	// Log the debug buffer.
       
   233 	iParentTestHarness.EmailTestUtils().WriteComment(buf);
       
   234 	}
       
   235 
       
   236 
       
   237 void CCopySelectionAndMonitor::StartL(TRequestStatus& aStatus)
       
   238 	{
       
   239 	iParentTestHarness.MsvTestUtils().iMsvEntry->SetEntryL(iParentTestHarness.iSelectedFolder);
       
   240 	iReportStatus = &aStatus;
       
   241 	iParentTestHarness.SetCurrentOperation(iParentTestHarness.MsvTestUtils().iMsvEntry->CopyL(*(iParentTestHarness.iCurrentSelection), iParentTestHarness.iDestinationFolder, iStatus));
       
   242 	
       
   243 	// Call funtion to return IAP and Poll to find connection state 
       
   244 	RTimer timer; 
       
   245 	TRequestStatus timerStatus; // Request status associated with timer
       
   246 	timer.CreateLocal(); // Create for this thread
       
   247 	
       
   248 	//initialise to unused values
       
   249 	TInt progressState = KInvalidState;
       
   250 	TInt connectState = KInvalidState;
       
   251 	TInt iap = KInvalidIAP;
       
   252 	TInt connection_progress_state = 0;
       
   253 
       
   254 	do
       
   255 		{
       
   256 		TImSmtpProgress temp;	
       
   257 		TPckgC<TImSmtpProgress> paramPack(temp);
       
   258 		paramPack.Set(iParentTestHarness.CurrentOperation().ProgressL());
       
   259 		TImSmtpProgress progress = paramPack();	
       
   260 
       
   261 		progressState = progress.Status();
       
   262 		if((connectState != progress.ConnectionState()) || (iap != progress.ConnectionIAP()) )
       
   263 			{
       
   264 			connectState = progress.ConnectionState();
       
   265 			iap = progress.ConnectionIAP();
       
   266 			LogCommentFormat(_L("[%4d] Progress state =  %d, Connect State = %d, IAP = %d"), iDebugInfo.LineNumber(), progressState, connectState, iap);
       
   267 			
       
   268 			//Check that the relevant states are reached in the correct order
       
   269 			if ((connectState == ECsdStartingDialling) || (connectState == ECsdStartingConnect))
       
   270 					connection_progress_state = 1;
       
   271 			if (connectState == ECsdConnectionOpen && connection_progress_state == 1)
       
   272 					connection_progress_state = 2;
       
   273 			if (connectState == KLinkLayerOpen && connection_progress_state == 2)
       
   274 					connection_progress_state = 3;
       
   275 
       
   276 		}
       
   277 
       
   278 		
       
   279 		// wait 500 microseconds and then re-test progress!
       
   280 		timer.After(timerStatus,500);
       
   281 		User::WaitForRequest(timerStatus); 
       
   282 
       
   283 	
       
   284 		} while (progressState == EMsgOutboxProgressConnecting);
       
   285 
       
   286 	timer.Close();
       
   287 
       
   288 	if (connection_progress_state != 3)
       
   289 		{
       
   290 		LogCommentFormat(_L("[%4d] Local Connection Progress state =  %d, Connect State = %d, IAP = %d"), iDebugInfo.LineNumber(), connection_progress_state, connectState, iap);
       
   291 		iConnectionError = ETrue;
       
   292 		}
       
   293 
       
   294 	aStatus = KRequestPending;
       
   295 	SetActive();
       
   296 	}
       
   297 
       
   298 void CCopySelectionAndMonitor::RunL()
       
   299 	{
       
   300 	if (iConnectionError)
       
   301 		User::RequestComplete(iReportStatus, KErrUnknown);	
       
   302 	else
       
   303 		User::RequestComplete(iReportStatus, iStatus.Int());
       
   304 	}
       
   305 
       
   306 void CCopySelectionAndMonitor::DoCancel()
       
   307 	{
       
   308 	iParentTestHarness.CurrentOperation().Cancel();
       
   309 	}
       
   310 
       
   311 
       
   312 CCopySelectionAndMonitor::~CCopySelectionAndMonitor()
       
   313 	{
       
   314 	}
       
   315 
       
   316 
       
   317