email/email/pop/src/T_ComparePopEmailMsgs.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // [TestStep Name]
       
    15 // ComparePopEmailMsgs
       
    16 // [Paramaters]
       
    17 // PopAccountName		: 		Name of the POP account
       
    18 // Compares the recieved mails with the expected numbers of lines to test POP3 TOP command
       
    19 // 
       
    20 //
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @file
       
    26 */
       
    27 
       
    28 // User includes
       
    29 #include "CExpMailInfo.h"
       
    30 #include "T_ComparePopEmailMsgs.h"
       
    31 #include <t_utils.h>
       
    32 #include <t_utilscentralrepository.h>
       
    33 #include <t_utilsenumconverter.h>
       
    34 
       
    35 
       
    36 // Epoc includes
       
    37 #include <imcm.rsg>
       
    38 #include <miutmsg.h>
       
    39 #include <mmsvattachmentmanager.h>
       
    40 
       
    41 
       
    42 // Literals Used
       
    43 _LIT(KPopAccountName,"PopAccountName");
       
    44 
       
    45 
       
    46 /**
       
    47 ConstructL()
       
    48 Used to ensure that MMsvAttachmentManager is not destroyed until we want it to be.
       
    49 To do this we need to preserve certain objects of CImEmailMessage, which if disappeared
       
    50 would invalidate MMsvAttachmentManager. But this should be deleted in a controlled manner.
       
    51 
       
    52 @param aSession
       
    53 An object of type CMsvSession object.
       
    54 
       
    55 @param aEntry
       
    56 An object of type TMsvEntry used to get the entry ID. 
       
    57 */
       
    58 void CAttachmentItem::ConstructL(CMsvSession& aSession, TMsvEntry aEntry)
       
    59 	{
       
    60 	iMsvEntry = aSession.GetEntryL(aEntry.Id());
       
    61 
       
    62 	iMsvEntry->SetEntryL(aEntry.Id());
       
    63 	iEmailMsg = CImEmailMessage::NewL(*iMsvEntry);
       
    64 		
       
    65 	CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC();
       
    66  	iEmailMsg->GetAttachmentsListL(waiter->iStatus, aEntry.Id(),
       
    67 								   CImEmailMessage::EAllAttachments, 
       
    68 								   CImEmailMessage::EThisMessageOnly);
       
    69 	waiter->Start();
       
    70 
       
    71 	CleanupStack::PopAndDestroy(1, waiter); //waiter		
       
    72 	}
       
    73 
       
    74 
       
    75 /**
       
    76 NewL()
       
    77 Allocates and creates a new CAttachmentItem object
       
    78 
       
    79 @param aSession
       
    80 An object of type CMsvSession object.
       
    81 
       
    82 @param aEntry
       
    83 An object of type TMsvEntry
       
    84 
       
    85 @leave KErrNoMemory
       
    86 
       
    87 @return 
       
    88 A pointer to an object of type CAttachmentItem
       
    89 
       
    90 */
       
    91 CAttachmentItem* CAttachmentItem::NewL(CMsvSession& aSession, TMsvEntry aEntry)
       
    92 	{
       
    93 	CAttachmentItem* self=CAttachmentItem::NewLC(aSession, aEntry);
       
    94 	CleanupStack::Pop(self);
       
    95 
       
    96 	return self;
       
    97 	}
       
    98 
       
    99 
       
   100 /**
       
   101 NewLC()
       
   102 Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
       
   103 
       
   104 
       
   105 @param aSession
       
   106 An object of type CMsvSession object.
       
   107 
       
   108 @param aEntry
       
   109 An object of type TMsvEntry
       
   110 
       
   111 @leave KErrNoMemory
       
   112 @return
       
   113 A pointer to the newly created CAttachmentItem object.
       
   114 
       
   115 */
       
   116 CAttachmentItem* CAttachmentItem::NewLC(CMsvSession& aSession, TMsvEntry aEntry)
       
   117 	{
       
   118 	CAttachmentItem* self=new (ELeave) CAttachmentItem;
       
   119 	CleanupStack::PushL(self);
       
   120 	
       
   121 	self->ConstructL(aSession, aEntry);
       
   122 	
       
   123 	return self;
       
   124 	}
       
   125 
       
   126 
       
   127 /**
       
   128 ~CAttachmentItem()
       
   129 Destroy the data members.
       
   130 */
       
   131 CAttachmentItem::~CAttachmentItem()
       
   132 	{
       
   133 	delete iEmailMsg;
       
   134 	iEmailMsg=NULL;
       
   135 
       
   136 	delete iMsvEntry;
       
   137 	iMsvEntry=NULL;
       
   138 	}
       
   139 
       
   140 
       
   141 /**
       
   142 MMsvAttachmentManager()
       
   143 
       
   144 @return
       
   145 An object of MMsvAttachmentManager
       
   146 */
       
   147 MMsvAttachmentManager& CAttachmentItem::MMsvAttachmentManager() const
       
   148 	{			
       
   149 	return (iEmailMsg->AttachmentManager());		
       
   150 	}
       
   151 
       
   152 
       
   153 /**
       
   154 GetExpPop3MailInfoLC()
       
   155 Sets the CExpPop3MailInfo attributes reading from the INI file
       
   156 
       
   157 @param  aIndx
       
   158 Index in the selection list.
       
   159 
       
   160 @leave KErrNotReady
       
   161 
       
   162 @return
       
   163 A pointer to an object of type CExpPop3MailInfo
       
   164 */
       
   165 CExpPop3MailInfo* CT_MsgComparePopEmailMsgs::GetExpPop3MailInfoLC(TInt aIndx)
       
   166 	{
       
   167 	CExpPop3MailInfo* expMailInfo  = new (ELeave) CExpPop3MailInfo;
       
   168 	CleanupStack::PushL(expMailInfo);
       
   169 	
       
   170 	TInt comInt = -1;
       
   171 	_LIT(KNumOfLines,"NumOfLines%d");
       
   172 	TBuf<256> param;
       
   173 	param.Format(KNumOfLines,aIndx);
       
   174 	
       
   175 	if (!GetIntFromConfig(ConfigSection(), param, comInt))
       
   176 		{
       
   177 		ERR_PRINTF1(_L("No Input for NumOfLines"));
       
   178 		User::Leave(KErrNotReady);
       
   179 		}
       
   180 	
       
   181 	expMailInfo->SetNumLinesBodyText(comInt);
       
   182 	comInt = -1;
       
   183 	
       
   184 	_LIT(KFooterExpected, "FooterExpected%d");
       
   185 	param.Format(KFooterExpected,aIndx);
       
   186 	if (!GetIntFromConfig(ConfigSection(), param, comInt))
       
   187 		{
       
   188 		ERR_PRINTF1(_L("No Input for Footer Expected"));
       
   189 		User::Leave(KErrNotReady);
       
   190 		}
       
   191 	expMailInfo->SetFooterExpected(comInt);
       
   192 	
       
   193 	comInt = -1;
       
   194 	_LIT(KNumOfLinesHtml, "NumOfLinesHtml%d");
       
   195 	param.Format(KNumOfLinesHtml, aIndx);
       
   196 	if (!GetIntFromConfig(ConfigSection(), param, comInt))
       
   197 		{
       
   198 		ERR_PRINTF1(_L("No Input For NumOfLinesHtml"));
       
   199 		User::Leave(KErrNotReady);
       
   200 		}
       
   201 	expMailInfo->SetNumLinesHtml(comInt);
       
   202 	
       
   203 	TPtrC ptrDes;
       
   204 	_LIT(KDescription, "Description%d");
       
   205 	param.Format(KDescription, aIndx);
       
   206 	if(!GetStringFromConfig(ConfigSection(), param, ptrDes))
       
   207 		{
       
   208 		ERR_PRINTF1(_L("No Input for Description"));
       
   209 		User::Leave(KErrNotReady);
       
   210 		}
       
   211 	expMailInfo->SetDescription(ptrDes);
       
   212 		
       
   213 	_LIT(KNumOfAttachments, "NumOfAttachments%d");
       
   214 	param.Format(KNumOfAttachments, aIndx);
       
   215 	if (!GetIntFromConfig(ConfigSection(), param, comInt))
       
   216 		{
       
   217 		ERR_PRINTF1(_L("No Input for NumOfAttachments"));
       
   218 		User::Leave(KErrNotReady);
       
   219 		}
       
   220 	expMailInfo->SetNumAttachments(comInt);
       
   221 	
       
   222 	comInt = -1;
       
   223 	if(expMailInfo->GetFooterExpected())
       
   224 		{
       
   225 		_LIT(KFooterSize, "FooterSize%d");
       
   226 		param.Format(KFooterSize, aIndx);
       
   227 		if (!GetIntFromConfig(ConfigSection(), param, comInt))
       
   228 			{
       
   229 			ERR_PRINTF1(_L("No Input for FooterSize"));
       
   230 			User::Leave(KErrNotReady);
       
   231 			}
       
   232 		expMailInfo->SetFooterSize(comInt);
       
   233 		}
       
   234 	else
       
   235 		{
       
   236 		expMailInfo->SetFooterSize(0);
       
   237 		}
       
   238 	
       
   239 	return expMailInfo;
       
   240 	}
       
   241 
       
   242 
       
   243 
       
   244 /**
       
   245 LoadParametersL()
       
   246 Loads the test parameters 
       
   247 
       
   248 @leave KErrNotReady
       
   249 @return
       
   250 ETrue if parameters loaded, Efalse on failure.
       
   251 */
       
   252 TBool CT_MsgComparePopEmailMsgs::LoadParametersL()
       
   253 	{
       
   254 	TPtrC sentFolder;
       
   255 	_LIT(KSentFolder, "SentFolder");
       
   256 	if(!GetStringFromConfig(ConfigSection(), KSentFolder, sentFolder))
       
   257 		{
       
   258 		ERR_PRINTF1(_L("No Input for Sent Folder"));
       
   259 		User::Leave(KErrNotReady);
       
   260 		}
       
   261 			
       
   262 	iSentSelectionList = CT_MsgUtils ::CreateChildrenSelectionL(iSharedDataPOP.iSession, CT_MsgUtilsEnumConverter::FindFolderIdByName(sentFolder));
       
   263 	if(! iSentSelectionList)
       
   264 		{
       
   265 		ERR_PRINTF1(_L("Invalid sentSelectionList"));
       
   266 		SetTestStepResult(EFail);
       
   267 		return EFalse;
       
   268 		}
       
   269 	
       
   270 	TPtrC inboxFolder;
       
   271 	_LIT(KInboxFolder, "InboxFolder");
       
   272 	if(!GetStringFromConfig(ConfigSection(), KInboxFolder, inboxFolder))
       
   273 		{
       
   274 		ERR_PRINTF1(_L("No Input for Inbox Folder"));
       
   275 		User::Leave(KErrNotReady);
       
   276 		}
       
   277 	
       
   278 	
       
   279 	TPtrC popAccountName;
       
   280 	if(!GetStringFromConfig(ConfigSection(), KPopAccountName, popAccountName))
       
   281 		{
       
   282 		ERR_PRINTF1(_L("Account name not specified"));
       
   283 		SetTestStepResult(EFail);
       
   284 		}
       
   285 	if (CT_MsgUtilsEnumConverter::FindFolderIdByName(inboxFolder) == KMsvLocalServiceIndexEntryId)
       
   286 		{
       
   287 		// We are expecting to get a selection of remote Folder(which is the serviceId)
       
   288 		TMsvId popServiceId = CT_MsgUtilsCentralRepository::GetPopServiceIdL((TDes&)popAccountName);
       
   289 		
       
   290 		CMsvEntry* entry = iSharedDataPOP.iSession->GetEntryL(popServiceId);
       
   291 		CleanupStack::PushL(entry);
       
   292 		
       
   293 		entry->SetEntryL(popServiceId); // Setting the context to remote folder.
       
   294 		
       
   295 		iInboxSelectionList = CT_MsgUtils ::CreateChildrenSelectionL(iSharedDataPOP.iSession, popServiceId);
       
   296 		
       
   297 		CleanupStack::PopAndDestroy(entry);
       
   298 		}
       
   299 	else
       
   300 		{
       
   301 		iInboxSelectionList = CT_MsgUtils ::CreateChildrenSelectionL(iSharedDataPOP.iSession, CT_MsgUtilsEnumConverter::FindFolderIdByName(inboxFolder));
       
   302 		}
       
   303 
       
   304 	if(! iInboxSelectionList)
       
   305 		{
       
   306 		ERR_PRINTF1(_L("Invalid inboxSelectionList"));
       
   307 		SetTestStepResult(EFail);
       
   308 		return EFalse;
       
   309 		}
       
   310 	//Starting the comparision
       
   311 	if(iInboxSelectionList->Count() != iSentSelectionList->Count())
       
   312 		{
       
   313 		ERR_PRINTF3(_L("iInboxSelectionList->Count(%d) != iSentSelectionList->Count(%d)"),
       
   314 								 iInboxSelectionList->Count(), iSentSelectionList->Count());
       
   315 		SetTestStepResult(EFail);
       
   316 		return EFalse;
       
   317 		}
       
   318 
       
   319 	TInt comInt = -1;
       
   320 	_LIT(KNumTest, "NumTest");
       
   321 	if (!GetIntFromConfig(ConfigSection(), KNumTest, comInt))
       
   322 		{
       
   323 		ERR_PRINTF1(_L("No Input for NumTests"));
       
   324 		User::Leave(KErrNotReady);
       
   325 		}
       
   326 	TInt numTests = comInt;
       
   327 	if(numTests != iInboxSelectionList->Count())
       
   328 		{
       
   329 		ERR_PRINTF1(_L("iNumTests != iInboxSelectionList"));
       
   330 		SetTestStepResult(EFail);
       
   331 		return EFalse;
       
   332 		}
       
   333 		
       
   334 	iExpResults.Reset();
       
   335 	for(TInt i = 0;i < numTests; i++) 
       
   336 		{
       
   337 		
       
   338 		CExpPop3MailInfo* pExp = GetExpPop3MailInfoLC(i);
       
   339 		if(! pExp)
       
   340 			{
       
   341 			ERR_PRINTF1(_L("Invalid expected mail Info"));
       
   342 			SetTestStepResult(EFail);
       
   343 			return EFalse;
       
   344 			}
       
   345 		else
       
   346 			{
       
   347 			CleanupStack::Pop(pExp); // pExp			
       
   348 			iExpResults.Append(pExp);
       
   349 			}
       
   350 		}
       
   351 	return ETrue;
       
   352 	}
       
   353 
       
   354 
       
   355 /**
       
   356 DoCompareL()
       
   357 Comparison of 2 email messages identified by TMsvEntry
       
   358 
       
   359 @param  aRecvEntry
       
   360 The recieved email identifier.
       
   361 
       
   362 @param  aMailInfo
       
   363 Expected state of the recieved email.
       
   364 
       
   365 @param  aSentEntry
       
   366 Identifier of the original sent email foir comparison purposes.
       
   367 
       
   368 @return
       
   369 ETrue if emails match EFalse otherwise
       
   370 */
       
   371 TBool CT_MsgComparePopEmailMsgs::DoCompareL(TMsvEntry& aRecvEntry, CExpPop3MailInfo& aMailInfo, TMsvEntry& aSentEntry)
       
   372 	{
       
   373 	TBool ret = ETrue;
       
   374 	TBool footerExists = EFalse;
       
   375 	TInt footersize = 0;
       
   376 		
       
   377 			
       
   378 	TInt nLines = GetMessageLinesL(aRecvEntry, KUidMsvEmailTextEntry, footerExists, footersize);
       
   379 	if(nLines != aMailInfo.GetNumLinesBodyText())
       
   380 		{
       
   381 		ERR_PRINTF3(_L("Lines of body text wrong actual = %d expected = %d!"), nLines, aMailInfo.GetNumLinesBodyText());
       
   382 		ret = EFalse;
       
   383 		}
       
   384 	nLines = GetMessageLinesL(aRecvEntry, KUidMsvEmailHtmlEntry, footerExists, footersize);
       
   385 
       
   386 	if(nLines != aMailInfo.GetNumLinesHtml())
       
   387 		{		
       
   388 		ERR_PRINTF3(_L("HTML size wrong actual = %d expected = %d!"), nLines, aMailInfo.GetNumLinesHtml());
       
   389 		ret = EFalse;
       
   390 		}
       
   391 
       
   392 	else if(! CheckAttachmentsL(aRecvEntry, aMailInfo, aSentEntry))
       
   393 		{
       
   394 		ERR_PRINTF1(_L("Attachment comparison failed !"));
       
   395 		ret = EFalse;
       
   396 		}
       
   397 
       
   398 	else if(! footerExists && aMailInfo.GetFooterExpected())
       
   399 		{
       
   400 		ERR_PRINTF1(_L("An expected footer was missing !"));
       
   401 		ret = EFalse;
       
   402 		}
       
   403 	else if(footerExists && ! aMailInfo.GetFooterExpected())
       
   404 		{
       
   405 		ERR_PRINTF1(_L("An unexpected footer was found !"));
       
   406 		ret = EFalse;
       
   407 		}
       
   408 	else if(aMailInfo.GetFooterExpected() && aMailInfo.GetFooterSize()!=0 
       
   409 			&& aMailInfo.GetFooterSize() != footersize)
       
   410 		{
       
   411 		ERR_PRINTF3(_L("KB left on server size wrong = %d expected = %d!"), footersize, aMailInfo.GetFooterSize());
       
   412 		ret = EFalse;			
       
   413 		}
       
   414 	return ret;
       
   415 	}
       
   416 
       
   417 
       
   418 
       
   419 
       
   420 /**
       
   421 CheckAttachmentsL()
       
   422 Compares attachments for the email messages aRecvEntry and aSentEntry using
       
   423 expected results in aMailInfo
       
   424 
       
   425 @param aRecvEntry
       
   426 An identifier for the recieved email
       
   427 
       
   428 @param aMailInfo
       
   429 Expected state of recieved email attachments
       
   430 
       
   431 @param aSentEntry
       
   432 An identifier for the original email
       
   433 
       
   434 @return
       
   435 ETrue if attachments match otherwise EFalse
       
   436 */
       
   437 TBool CT_MsgComparePopEmailMsgs::CheckAttachmentsL(TMsvEntry& aRecvEntry, CExpPop3MailInfo& aMailInfo, TMsvEntry& aSentEntry)
       
   438 	{
       
   439 	TBool ret = ETrue;
       
   440 	CAttachmentItem* recvManager = CAttachmentItem::NewLC(*iSharedDataPOP.iSession, aRecvEntry);
       
   441 	CAttachmentItem* sentManager = CAttachmentItem::NewLC(*iSharedDataPOP.iSession, aSentEntry);
       
   442 
       
   443 	TInt recvCount = recvManager->MMsvAttachmentManager().AttachmentCount();	
       
   444 	TInt sentCount = sentManager->MMsvAttachmentManager().AttachmentCount();
       
   445 
       
   446 	TFileName recvFileName;
       
   447 	TFileName sentFileName;
       
   448 
       
   449 	if(recvCount == aMailInfo.GetNumAttachments())
       
   450 		{
       
   451 		for(TInt i=0;i<recvCount;i++)
       
   452 			{
       
   453 			for(TInt j=0;j<sentCount;j++)
       
   454 				{
       
   455 				CMsvAttachment* recvAttInfo = recvManager->MMsvAttachmentManager().GetAttachmentInfoL(i);
       
   456 				CleanupStack::PushL(recvAttInfo);
       
   457 
       
   458 				CMsvAttachment* sentAttInfo = sentManager->MMsvAttachmentManager().GetAttachmentInfoL(j);
       
   459 				CleanupStack::PushL(sentAttInfo);
       
   460 
       
   461 				if(recvAttInfo->AttachmentName().Compare(sentAttInfo->AttachmentName()) == 0)
       
   462 					{
       
   463 					recvFileName = recvAttInfo->FilePath();
       
   464 					sentFileName = sentAttInfo->FilePath();
       
   465 					ret = CompareFilesL(recvFileName, sentFileName);
       
   466 					}
       
   467 				CleanupStack::PopAndDestroy(2, recvAttInfo);		
       
   468 				}
       
   469 			}
       
   470 		}
       
   471 	else
       
   472 		{
       
   473 		INFO_PRINTF3(_L("Warning - Expected attachments mismatch recieved (%d) expected (%d)"),
       
   474 								 recvCount, aMailInfo.GetNumAttachments());
       
   475 		ret = EFalse;
       
   476 		}
       
   477 	CleanupStack::PopAndDestroy(2, recvManager); // recvManager,sentManager
       
   478 	return ret;
       
   479 	}
       
   480 
       
   481 
       
   482 
       
   483 /**
       
   484 CompareFilesL()
       
   485 Performs byte for byte copmparison of the files indicated by aFileName1 and aFileName2
       
   486 
       
   487 @param aFileName1
       
   488 Filename of first file to be compared
       
   489 
       
   490 @param aFileName2
       
   491 Filename of second file to be compared
       
   492 
       
   493 @return
       
   494 ETrue if files match, EFalse otherwise
       
   495 */
       
   496 TBool CT_MsgComparePopEmailMsgs::CompareFilesL(TFileName& aFileName1, TFileName& aFileName2)
       
   497 	{
       
   498 	TBool ret = ETrue;
       
   499 	RFile file1, file2;
       
   500 
       
   501 	User::LeaveIfError(file1.Open(iFs, aFileName1, EFileRead));
       
   502 	User::LeaveIfError(file2.Open(iFs, aFileName2, EFileRead));
       
   503 
       
   504 	TInt sz1, sz2;
       
   505 	User::LeaveIfError(file1.Size(sz1));
       
   506 	User::LeaveIfError(file2.Size(sz2));
       
   507 	
       
   508 	if(sz1 != sz2)
       
   509 		{
       
   510 		ERR_PRINTF3(_L("File size mismatch 1(%d)   2(%d)"), sz1, sz2);
       
   511 		ret = EFalse;
       
   512 		}
       
   513 	else
       
   514 		{
       
   515 		TBuf8<1> char1;
       
   516 		TBuf8<1> char2;
       
   517 		TInt len1, len2;
       
   518 		do
       
   519 			{
       
   520 			file1.Read(char1);
       
   521 			file2.Read(char2);
       
   522 			len1 = char1.Length();
       
   523 			len2 = char2.Length();
       
   524 			if(char1.Compare(char2) != 0)
       
   525 				{
       
   526 				ret = EFalse;
       
   527 				break;
       
   528 				}
       
   529 			}
       
   530 		while(len1 && len2);
       
   531 		}
       
   532 	file1.Close();
       
   533 	file2.Close();
       
   534 	return ret;
       
   535 	}
       
   536 
       
   537 
       
   538 /**
       
   539 GetMessageLinesL()
       
   540 Counts the number of lines in a message's HTML or body text
       
   541 
       
   542 @param aEntry
       
   543 Email message identifier
       
   544 
       
   545 @param aUid
       
   546 Request identifier KUidMsvEmailHtmlEntry or KUidMsvEmailTextEntry at present
       
   547 
       
   548 @param aFooterExists
       
   549 Reference to a boolean variable only used when aUid == KUidMsvEmailTextEntry
       
   550 
       
   551 @param aFooterSize
       
   552 Expected KB left on server inserted into footer string if present 
       
   553 
       
   554 @return
       
   555 Returns the number of lines in the requested message part
       
   556 */
       
   557 TInt CT_MsgComparePopEmailMsgs::GetMessageLinesL(TMsvEntry& aEntry, TUid aUid, TBool& aFooterExists, TInt &aFooterSize)
       
   558 	{
       
   559 	TInt lines = 0; 
       
   560 	
       
   561 	TMsvId msgPartIndex = GetMessagePartIndexL(aEntry,aUid);
       
   562 	
       
   563 	if(msgPartIndex)
       
   564 		{
       
   565 		CMsvEntry* msvEntry = iSharedDataPOP.iSession->GetEntryL(msgPartIndex);
       
   566 		CleanupStack::PushL(msvEntry);
       
   567 	
       
   568 		msvEntry->SetEntryL(msgPartIndex);
       
   569 		if(aUid == KUidMsvEmailTextEntry)
       
   570 			{
       
   571 			lines = CountLinesOfBodyTextL(*msvEntry, aFooterExists, aFooterSize);
       
   572 			}
       
   573 		else if(aUid == KUidMsvEmailHtmlEntry)
       
   574 			{
       
   575 			lines = CountLinesOfHtmlL(*msvEntry);
       
   576 			}
       
   577 		CleanupStack::PopAndDestroy(msvEntry);
       
   578 		}
       
   579 	return lines;
       
   580 	}
       
   581 
       
   582 
       
   583 /**
       
   584 CountLinesOfBodyTextL()
       
   585 Counts the lines of body text in the email aEntry
       
   586 
       
   587 @param aEntry
       
   588 A reference to an object representing the email
       
   589 
       
   590 @param aFooterExists
       
   591 Reference to a boolean variable - set to ETrue if the footer string is found in the body text
       
   592 
       
   593 @param aFooterSize
       
   594 Expected KB left on server inserted into footer string if present 
       
   595 
       
   596 @return
       
   597 Number of lines in the body text 
       
   598 */
       
   599 TInt CT_MsgComparePopEmailMsgs::CountLinesOfBodyTextL(CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize)
       
   600 	{
       
   601 	TInt lines = 0;
       
   602 	aFooterExists=EFalse;
       
   603 	aFooterSize=0;
       
   604 	aEntry.SetEntryL(aEntry.EntryId());
       
   605 	if(aEntry.HasStoreL())
       
   606 		{
       
   607 		CMsvStore*	msvStore1= aEntry.ReadStoreL();
       
   608 		CleanupStack::PushL(msvStore1);
       
   609 		CParaFormatLayer*	paraFormatLayer1 = CParaFormatLayer::NewL();
       
   610 		CleanupStack::PushL(paraFormatLayer1);
       
   611 		CCharFormatLayer*	charFormatLayer1 = CCharFormatLayer::NewL(); 
       
   612 		CleanupStack::PushL(charFormatLayer1);
       
   613 		CRichText*	bodyText1=CRichText::NewL(paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256);
       
   614 		CleanupStack::PushL(bodyText1);
       
   615 
       
   616 		bodyText1->Reset();
       
   617 		if (msvStore1->HasBodyTextL())
       
   618 			{
       
   619 			msvStore1->RestoreBodyTextL(*bodyText1);
       
   620 			TUint16 val = CEditableText::ELineBreak;
       
   621 			TInt n = 0;
       
   622 			TInt pos = 0;
       
   623 			for(;;)
       
   624 				{
       
   625 				TPtrC bodyText = bodyText1->Read(pos);
       
   626 				n = bodyText.Find(&val, 1);
       
   627 				if(n < 0)
       
   628 					break;
       
   629 				lines++;
       
   630 				pos += n+1;
       
   631 				
       
   632 				//This Check is needed to delete the extra line introduced by communigate Pro Server
       
   633 				TInt fpos = CheckIfServerMessageExists(bodyText);
       
   634 				if (fpos != KErrNotFound)
       
   635 					{
       
   636 					lines--;
       
   637 					}
       
   638 				}
       
   639 			TPtrC	pBt = bodyText1->Read(0);
       
   640 			aFooterExists = CheckIfFooterMessageExistsL(pBt , aFooterSize);
       
   641 			}		
       
   642 		CleanupStack::PopAndDestroy(4, msvStore1);  //bodyText1,charFormatLayer1,paraFormatLayer1,msvStore1.
       
   643 		}
       
   644 	return lines;
       
   645 	}
       
   646 
       
   647 
       
   648 /**
       
   649 CheckIfServerMessageExists()
       
   650 Checks if any server message has been added to the Body text returns the 
       
   651 position of the server message in the buffer and the length of the server
       
   652 message.This function can be enhanced to check for any other server message encountered.
       
   653 If not found, returns KErrNotFound.
       
   654 
       
   655 @param aBodyText
       
   656 The body text of the message
       
   657 
       
   658 @return
       
   659 Position of the message, if not found returns KErrNotFound
       
   660 */
       
   661  TInt CT_MsgComparePopEmailMsgs::CheckIfServerMessageExists(TPtrC aBodyText)
       
   662 	{
       
   663 	_LIT(KServerMessage,"*This message was transferred with a trial version of CommuniGate(tm) Pro*");
       
   664 
       
   665 	TInt pos = aBodyText.FindC(KServerMessage);
       
   666 	
       
   667 	return pos;
       
   668 	}
       
   669 
       
   670 
       
   671 /**
       
   672 CountLinesOfHtmlL()
       
   673 Counts the number of lines of HTML
       
   674 
       
   675 @param aEntry
       
   676 A reference to an object representing the email
       
   677 
       
   678 @return
       
   679 Number of lines of HTML
       
   680 */
       
   681 TInt CT_MsgComparePopEmailMsgs::CountLinesOfHtmlL(CMsvEntry& aEntry)
       
   682 	{ 
       
   683 	TInt lines = 0;
       
   684 	aEntry.SetEntryL(aEntry.EntryId());
       
   685 	
       
   686 	
       
   687 	CMsvStore* store = aEntry.ReadStoreL();
       
   688 	CleanupStack::PushL(store);
       
   689 	
       
   690 	MMsvAttachmentManager& attManager = store->AttachmentManagerL();
       
   691 	
       
   692 	RFile htmlFile = attManager.GetAttachmentFileL(0);
       
   693 	CleanupClosePushL(htmlFile);
       
   694 	
       
   695 	_LIT8(KFindData, "\r\n");
       
   696 	TInt htmlSize = 0;
       
   697 	User::LeaveIfError(htmlFile.Size(htmlSize));
       
   698 	HBufC8* fBuf = HBufC8::NewLC(htmlSize);
       
   699 	TPtr8 p = fBuf->Des();
       
   700 	htmlFile.Read(p);
       
   701 	TInt pos = 0;
       
   702 	for(;;)
       
   703 		{
       
   704 		pos = p.Find(KFindData);
       
   705 		if(pos < 0)
       
   706 			{
       
   707 			break;
       
   708 			}
       
   709 		p = p.Mid(pos+2);
       
   710 		lines++;
       
   711 		}
       
   712 		
       
   713 	CleanupStack::PopAndDestroy(fBuf);
       
   714 	CleanupStack::PopAndDestroy(); // htmlFile
       
   715 	CleanupStack::PopAndDestroy(store);
       
   716 	
       
   717 	return lines;
       
   718 	}
       
   719 
       
   720 
       
   721 
       
   722 /**
       
   723 GetMessagePartIndexL()
       
   724 Retrieves the part index id for the email identified by aEntry
       
   725 
       
   726 @param aEntry
       
   727 A valid email identifier
       
   728 
       
   729 @param aUid
       
   730 An identifier tfor the type of message part to be retrieved
       
   731 
       
   732 @return
       
   733 TMsvId - message part identifier
       
   734 */
       
   735 TMsvId CT_MsgComparePopEmailMsgs::GetMessagePartIndexL(TMsvEntry& aEntry, TUid aUid)
       
   736 	{
       
   737 	static TBool msgPartFound = EFalse;	
       
   738 	TMsvId msgPartId = 0;
       
   739 	CMsvEntry*	baseEntry  = iSharedDataPOP.iSession->GetEntryL(aEntry.Id());
       
   740 	CleanupStack::PushL(baseEntry);
       
   741 	CMsvEntrySelection*	selection =  baseEntry->ChildrenL();
       
   742 	CleanupStack::PushL(selection);
       
   743 	TInt count = selection->Count();
       
   744 	TInt ind1;
       
   745 	CMsvEntry* entry = iSharedDataPOP.iSession->GetEntryL(KMsvRootIndexEntryId);
       
   746 	CleanupStack::PushL(entry);
       
   747 	for (ind1=0, msgPartFound=EFalse; ind1 < count; ind1++)
       
   748 		{
       
   749 		if(msgPartFound)
       
   750 			{
       
   751 			break;
       
   752 			}		
       
   753 		TMsvId	childId  = selection->At(ind1);
       
   754 		entry->SetEntryL(childId);
       
   755 
       
   756 		if (entry->Entry().iType  == aUid)
       
   757 			{
       
   758 			msgPartId = childId;
       
   759 			break;
       
   760 			}
       
   761 		else if (entry->Entry().iType  == KUidMsvFolderEntry)
       
   762 			{
       
   763 			TMsvEntry ent = entry->Entry();
       
   764 			msgPartId = GetMessagePartIndexL(ent, aUid);
       
   765 			}
       
   766 		}
       
   767 	CleanupStack::PopAndDestroy(3, baseEntry);  // entry,selection,baseEntry
       
   768 	return msgPartId;
       
   769 	}
       
   770 
       
   771 
       
   772 
       
   773 
       
   774 /**
       
   775 CheckIfFooterMessageExistsL()
       
   776 Checks the email for the presence of the footer string
       
   777 
       
   778 @param aRecvBodyText
       
   779 Reference to a descriptor holding the body text
       
   780 
       
   781 @param aFooterSize
       
   782 The expected number of KB remaining on the server which has been inserted into the footer string
       
   783 
       
   784 @return
       
   785 ETrue if footer string found otherwise EFalse 
       
   786 */
       
   787 TBool CT_MsgComparePopEmailMsgs::CheckIfFooterMessageExistsL(TPtrC& aRecvBodyText , TInt& aFooterSize)
       
   788 	{
       
   789 	RResourceFile resFile;
       
   790 	CT_MsgUtils ::OpenResourceFileL(resFile, iFs, KImEngineResourceFile);	// NB leaves if file not found
       
   791 	TCleanupItem close(CT_MsgUtils ::CloseResourceFile, &resFile);
       
   792 	CleanupStack::PushL(close);
       
   793 	
       
   794 	HBufC8* buf = NULL;
       
   795 	buf = resFile.AllocReadLC(PARTIAL_DOWNLOAD_FOOTER_MESSAGE);
       
   796 	TResourceReader reader;
       
   797 	reader.SetBuffer(buf);
       
   798 
       
   799 	HBufC* resourceBuf = (reader.ReadTPtrC()).AllocL();
       
   800 	CleanupStack::PushL(resourceBuf);
       
   801 
       
   802 	TInt len = resourceBuf->Find(_L("%d"));
       
   803 	const TInt KBufLen = 256;
       
   804 	TBuf<KBufLen> findBuf;
       
   805 
       
   806 	if(len == KErrNotFound)
       
   807 		{
       
   808 		len = resourceBuf->Length();
       
   809 		}
       
   810 
       
   811 	if(len > KBufLen)
       
   812 		{
       
   813 		len = KBufLen;
       
   814 		}
       
   815 	
       
   816 	findBuf.Copy(resourceBuf->Ptr(), len);
       
   817 	len = aRecvBodyText.Find(findBuf);
       
   818 
       
   819 	if(len>=0)
       
   820 		{
       
   821 		TPtrC rest=aRecvBodyText.Right(aRecvBodyText.Length()-len-findBuf.Length());
       
   822 		TLex lex(rest.Left(rest.Locate(TChar(' '))));
       
   823 		lex.Val(aFooterSize);
       
   824 		}
       
   825 	else
       
   826 		{
       
   827 		aFooterSize=0;
       
   828 		}
       
   829 
       
   830 	CT_MsgUtils ::CloseResourceFile(&resFile);
       
   831 	CleanupStack::PopAndDestroy(3); // buf, resourceBuf, close
       
   832 	return (len != KErrNotFound);
       
   833 	}
       
   834 
       
   835 //const TInt KGranuality = 5;
       
   836 
       
   837 /**
       
   838 CT_MsgComparePopEmailMsgs()
       
   839 Constructor
       
   840 
       
   841 @param  aSharedDataPOP
       
   842 Data shared across the POP test steps. Ex. SessionF
       
   843 */
       
   844 CT_MsgComparePopEmailMsgs::CT_MsgComparePopEmailMsgs(CT_MsgSharedDataPop& aSharedDataPOP)
       
   845 :	CT_MsgAsyncStepPOP(aSharedDataPOP)  
       
   846 	{
       
   847 	iSentSelectionList = NULL;
       
   848 	iInboxSelectionList = NULL;
       
   849 	SetTestStepName(KComparePopEmailMsgs);
       
   850 	}
       
   851 
       
   852 
       
   853 /**
       
   854 NewL()
       
   855 Allocates and creates a new CT_MsgComparePopEmailMsgs object
       
   856 
       
   857 @param aSharedDataPOP
       
   858 Data shared across the POP test steps. Ex. Session
       
   859 
       
   860 @leave KErrNoMemory
       
   861 @return
       
   862 Returns pointer to an object of CT_MsgComparePopEmailMsgs.
       
   863 */
       
   864 CT_MsgComparePopEmailMsgs* CT_MsgComparePopEmailMsgs::NewL(CT_MsgSharedDataPop& aSharedDataPOP)
       
   865 	{
       
   866 	CT_MsgComparePopEmailMsgs* self = new(ELeave) CT_MsgComparePopEmailMsgs(aSharedDataPOP);
       
   867 	CleanupStack::PushL(self);
       
   868 	self->ConstructL(); 					 // Call CT_AsyncStep::ConstructL()
       
   869 	CleanupStack::Pop(self);
       
   870 	return self;
       
   871 	}		
       
   872 
       
   873 
       
   874 /**
       
   875 ProgressL()
       
   876 
       
   877 */
       
   878 
       
   879 //////////////////////////
       
   880 ////
       
   881 ////	I have no idea what this code is doing.
       
   882 ////	It looks very messy.
       
   883 ////	Someone is going to have to reowrk this code so that we can cancel and do progress
       
   884 ////
       
   885 //////////////////////////
       
   886 void CT_MsgComparePopEmailMsgs::ProgressL(TBool bFinal)
       
   887 	{
       
   888 	//	TODO
       
   889 	if (bFinal)
       
   890 		{
       
   891 		//	Display final progress
       
   892 		}
       
   893 	else
       
   894 		{
       
   895 		//	Display current progress
       
   896 		}
       
   897 	}
       
   898 
       
   899 
       
   900 /**
       
   901 CancelStep()
       
   902 
       
   903 */
       
   904 void CT_MsgComparePopEmailMsgs::CancelStep()
       
   905 	{
       
   906 	//	TODO
       
   907 	}
       
   908 
       
   909 
       
   910 /**
       
   911 ~CT_MsgComparePopEmailMsgs()
       
   912 Deletes all the data members.
       
   913 */
       
   914 CT_MsgComparePopEmailMsgs::~CT_MsgComparePopEmailMsgs()
       
   915 	{
       
   916 	// To delete each element in the array
       
   917 	for(TInt i=0; i < iExpResults.Count(); i++)
       
   918 		{
       
   919 		CExpPop3MailInfo* pExp = iExpResults[i];
       
   920 		delete pExp;
       
   921 		pExp=NULL;
       
   922 		}
       
   923 	iExpResults.Reset();
       
   924 	iExpResults.Close();
       
   925 
       
   926 	delete iSentSelectionList;
       
   927 	iSentSelectionList=NULL;
       
   928 	delete iInboxSelectionList;
       
   929 	iInboxSelectionList=NULL;
       
   930 	}
       
   931 
       
   932 
       
   933 /**
       
   934 doTestStepL()
       
   935 Performs the comparison of POP messages
       
   936 
       
   937 @return
       
   938 Returns the teststep result.
       
   939 */
       
   940 TVerdict CT_MsgComparePopEmailMsgs::doTestStepL()
       
   941 	{
       
   942 	INFO_PRINTF1(_L("Test Step: Compare Pop Email Msgs"));
       
   943 		
       
   944 	if(LoadParametersL())
       
   945 		{
       
   946 		User::LeaveIfError(iFs.Connect());
       
   947 		CleanupClosePushL(iFs);
       
   948 		
       
   949 			// Normally do not push an object that is a data member of another object.
       
   950 			// But in this case we want to close early if we get a leave.
       
   951 			// Otherwise the iFs would be open till the thread had begun to die.
       
   952 		if(TestStepResult() == EPass)
       
   953 			{
       
   954 			CMsvEntry* recvMsvEntry = iSharedDataPOP.iSession->GetEntryL(KMsvRootIndexEntryId);
       
   955 			CleanupStack::PushL(recvMsvEntry);
       
   956 			CMsvEntry* sentMsvEntry = iSharedDataPOP.iSession->GetEntryL(KMsvRootIndexEntryId);
       
   957 			CleanupStack::PushL(sentMsvEntry);
       
   958 
       
   959 			for(TInt i = 0;i < iInboxSelectionList->Count();i++)
       
   960 				{
       
   961 				recvMsvEntry->SetEntryL(iInboxSelectionList->At(i));
       
   962 				TMsvEntry recvEntry = recvMsvEntry->Entry();
       
   963 				for(TInt j = 0;j < iSentSelectionList->Count();j++)
       
   964 					{
       
   965 					sentMsvEntry->SetEntryL(iSentSelectionList->At(j));
       
   966 					TMsvEntry sentEntry = sentMsvEntry->Entry();
       
   967 					if(recvEntry.iDescription.Compare(sentEntry.iDescription) == 0) 
       
   968 						{
       
   969 						CExpPop3MailInfo* pExpMailInfo = NULL;
       
   970 						for(int k = 0;k < iExpResults.Count();k++)
       
   971 							{
       
   972 							if(iExpResults[k]->GetDescription().Compare(recvEntry.iDescription) == 0)
       
   973 								{
       
   974 								pExpMailInfo =  iExpResults[k];
       
   975 								break;
       
   976 								}
       
   977 							}
       
   978 						if(! pExpMailInfo)
       
   979 							{
       
   980 							ERR_PRINTF2(_L("Test %d failed could not retrieve expected mail info"), j+1);
       
   981 							SetTestStepResult(EFail);
       
   982 							break;
       
   983 							}
       
   984 
       
   985 						if(! DoCompareL(recvEntry, *pExpMailInfo, sentEntry))
       
   986 							{
       
   987 							INFO_PRINTF2(_L("Test %d failed"), j + 1);
       
   988 							SetTestStepResult(EFail);
       
   989 							}														
       
   990 						}
       
   991 					}
       
   992 				}
       
   993 			CleanupStack::PopAndDestroy(2, recvMsvEntry); // recvMsvEntry, sentMsvEntry
       
   994 			}		
       
   995 		CleanupStack::PopAndDestroy();
       
   996 		}		
       
   997 	INFO_PRINTF1(_L("T_ComparePopEmailMsgs Completed"));
       
   998 	return TestStepResult();
       
   999 	}