messagingfw/msgtestfw/TestActions/Email/Imap4/src/CMtfTestActionCompareEmailMessages.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__
       
    15 // [Action Name]
       
    16 // CompareEmailMessages
       
    17 // [Action Parameters]
       
    18 // CMsvSession&			session   <input>			: Reference to the session.
       
    19 // CMsvEntrySelection&	SentMailSelection <input>	: Reference to the
       
    20 // sent mail selection
       
    21 // CMsvEntrySelection&	RecvMailSelection <input>	: Reference to the
       
    22 // received mail selection
       
    23 // CMtfTestParameter&	Download limits <input>		: The CMTfTestParameter object
       
    24 // which stores either full download
       
    25 // limits or partial download limits
       
    26 // that was set during mail download
       
    27 // [Action Description]
       
    28 // Compares the sent and received email messages for size and contents based on
       
    29 // the download limits set.  The sent and received messages with the same 
       
    30 // Subject field are compared.  The Complete and Partial download flags set for 
       
    31 // the message parts are verified.
       
    32 // Restrictions:
       
    33 // 1. The Test Action supports comparison of simple emails messages with Body Text,
       
    34 // Html part and attachments of B64 encoding format.  Needs to be enhanced to 
       
    35 // support emails with embedded messages, all attachment types and MHTML messages.
       
    36 // 2. The size of the encoded message parts (Body text, Attachment and Html) are not 
       
    37 // available as there are no APIs available to get this information
       
    38 // Workarounds in the Test Action:
       
    39 // For Body Text part:
       
    40 // 1. [WorkAround for Body Text Ref1]
       
    41 // The size of the encoded body text is not available. Hence the size of the 
       
    42 // body text in the message store will be used.  In the Test Case, care has
       
    43 // to be taken to have the limits set, such that, the limits considers the 
       
    44 // size of the encoded body text part and not the size of the body text present
       
    45 // in the store.
       
    46 // 2. [WorkAround for Body Text Ref2]
       
    47 // For the defect "The CRLF characters is NOT interpreted  correctly".
       
    48 // The body text size is reduced by the tolerance length to overcome
       
    49 // the message comparison failure
       
    50 // 3. [WorkAround for Body Text Ref3]
       
    51 // The Communigate Pro server adds a disclaimer at the beginning
       
    52 // of the body text in the received message.  This message has to be removed 
       
    53 // from the body text of the received message before comparison.  The function
       
    54 // needs to be enhanced to handle different server messages.
       
    55 // 4. [WorkAround for Body Text Ref4]
       
    56 // For the defect "The size of the body text in the sent and the received emails
       
    57 // differ by 2 bytes.".  The size of the sent message's body text is set to
       
    58 // that of the received message's body text size.
       
    59 // 5. [WorkAround for Body Text Ref5]
       
    60 // For the defect "For partially downloaded Body text of a message, 
       
    61 // the corresponding TMsvEntry.iSize represents the size present in the 
       
    62 // RFC822 message body text size. It does NOT indicate the partially downloaded
       
    63 // body text size".  The size of the set message is set to that of partially
       
    64 // downloaded body text before comparing.  It is required to manually verify
       
    65 // the size of the partially downloaded message text in the email log files.
       
    66 // 6. [WorkAround for Body Text Ref6]
       
    67 // The remaining size of the body text or Html part on the server 
       
    68 // is not available, hence expected remaining size of the Body text on
       
    69 // the server cannot be calculated.  Hence verification of the footer message
       
    70 // information is not possible.  The value of the remaining size
       
    71 // of the body text size on the server needs to be manually verified 
       
    72 // by checking the email logs. In the test action, the footer message present
       
    73 // in the buffer is printed in the log file.
       
    74 // 7. [WorkAround for Body Text Ref7]
       
    75 // When a message with only attachment is created, one byte of body text is
       
    76 // getting added.  To take care of this conditions, the sent body text size
       
    77 // is checked for being greater than 1 instead of 0.  This means the Body text
       
    78 // part used for testing should be greater than 1 Byte.
       
    79 // For Html part:
       
    80 // 1. [WorkAround for Html Part Ref1]
       
    81 // Not verifying relative URIs, since message with only one Html part considered
       
    82 // 2. [WorkAround for Html Part Ref2]
       
    83 // The size of the encoded html part is not available, hence the size of the Html 
       
    84 // file in the message store is considered.  Test Case need to ensure that the 
       
    85 // download limits consider the encoded Html size rather than the size got from the store
       
    86 // For Attachments:
       
    87 // 1.	[WorkAround for Attachments Ref1]
       
    88 // The attachment download limits refers to the encoded attachment 
       
    89 // size.  This size is not available through any of the APIs.  The
       
    90 // available size of the attachment is the size of the file that 
       
    91 // is present in the message store. This size is smaller than the 
       
    92 // encoded size. Hence adding a correction value to get the approximate
       
    93 // size of the encoded attachment.
       
    94 // Note: this correction holds good for only B64 encoding.
       
    95 // For All Message Parts:
       
    96 // 1.   [WorkAround for general Ref1]
       
    97 // Though the TMsvEntry::Complete() and TMsvEmailEntry::PartialDownloaded()
       
    98 // returns a TBool value, the returned value will not equal to the value of 
       
    99 // ETrue and EFalse.  Hence the direct comparison of the set flag value 
       
   100 // and the expected flag value is not possible
       
   101 // [APIs Used]
       
   102 // CImEmailMessage::AttachmentSelection()
       
   103 // CMsvEntry::SetEntry()
       
   104 // __ACTION_INFO_END__
       
   105 // 
       
   106 //
       
   107 
       
   108 /**
       
   109  @file
       
   110 */
       
   111 
       
   112 
       
   113 
       
   114 #include <cemailaccounts.h>
       
   115 #include <iapprefs.h>
       
   116 #include <imapset.h>
       
   117 #include <cmsvattachment.h>
       
   118 #include <mmsvattachmentmanager.h>
       
   119 #include <miutmsg.h>
       
   120 
       
   121 // User include
       
   122 #include "CMtfTestActionCompareEmailMessages.h"
       
   123 #include "CMtfTestActionParameters.h"
       
   124 #include "TestFrameworkActionsUtils.h"
       
   125 
       
   126 
       
   127 //Granularity for CArrayFixFlat arrays
       
   128 const TInt KArrayGranularity = 8;
       
   129 
       
   130 // Correction to attachment size
       
   131 const TReal ATTACHMENT_SIZE_CORRECTION = 1.32;
       
   132 
       
   133 /**
       
   134   NewL()
       
   135   Constructs a CMtfTestActionCompareEmailMessages object.
       
   136   Uses two phase construction and leaves nothing on the CleanupStack.
       
   137   @internalTechnology
       
   138   @param  aTestCase          Test Case to which the Test Action belongs
       
   139   @param  aActionParameters  Action parameters, must not be NULL
       
   140   @return Created object of type CMtfTestAction
       
   141   @pre    None
       
   142   @post   None
       
   143 */
       
   144 CMtfTestAction* CMtfTestActionCompareEmailMessages::NewL(CMtfTestCase& aTestCase,
       
   145 													CMtfTestActionParameters* aActionParameters)
       
   146 	{
       
   147 	CMtfTestActionCompareEmailMessages* self = 
       
   148 					new (ELeave) CMtfTestActionCompareEmailMessages(aTestCase);
       
   149 
       
   150 	CleanupStack::PushL(self);
       
   151 	self->ConstructL(aActionParameters);
       
   152 	CleanupStack::Pop(self);
       
   153 	return self;
       
   154 	}
       
   155 	
       
   156 /**
       
   157   Constructor
       
   158   Constructs a CMtfTestActionCompareEmailMessages object and initialises the member variables.
       
   159   @internalTechnology
       
   160   @param  aTestCase  Test Case to which the Test Action belongs
       
   161   @pre    None
       
   162   @post   None
       
   163 */
       
   164 CMtfTestActionCompareEmailMessages::CMtfTestActionCompareEmailMessages(CMtfTestCase& aTestCase)
       
   165 	: CMtfSynchronousTestAction(aTestCase), iParamSession(NULL), iDownloadType(EFullDownload),
       
   166   	  iCumulativeSize(0), iSentMessageInfo(NULL), iRecvMessageInfo(NULL)
       
   167 	{
       
   168 	}
       
   169 
       
   170 /**
       
   171   Destructor
       
   172   Destructor of the class CMtfTestActionCompareEmailMessages.
       
   173   Deletes the message information stored in the CMtfTestActionUtilsEmailMessage
       
   174   objects
       
   175   @internalTechnology
       
   176   @param  None
       
   177   @pre    None
       
   178   @post   None
       
   179 */
       
   180 CMtfTestActionCompareEmailMessages::~CMtfTestActionCompareEmailMessages()
       
   181 	{
       
   182 	delete 	iSentMessageInfo;
       
   183 	delete 	iRecvMessageInfo;
       
   184 	}
       
   185 
       
   186 
       
   187 /**
       
   188   ExecuteActionL
       
   189   Obtains the parameters for the test action and then calls CompareEmailMessagesL()
       
   190   function to compare the sent and the received messages, based on the download
       
   191   limits set.
       
   192   @internalTechnology 
       
   193   @pre    None
       
   194   @post   None
       
   195 */
       
   196 void CMtfTestActionCompareEmailMessages::ExecuteActionL()
       
   197 	{
       
   198 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCompareEmailMessages);
       
   199 
       
   200 	// Get the session object 
       
   201 	iParamSession				= ObtainParameterReferenceL<CMsvSession>
       
   202 									(TestCase(),ActionParameters().Parameter(0));
       
   203 	
       
   204 		
       
   205 	// Get the selection object of messages in sent folder - Sent
       
   206 	CMsvEntrySelection*	sentMsgSelectionList = 
       
   207 									ObtainParameterReferenceL<CMsvEntrySelection>
       
   208 									(TestCase(), ActionParameters().Parameter(1)); 
       
   209 
       
   210 	// Get the selection object of messages in received folder - Inbox
       
   211 	CMsvEntrySelection*	recvMsgSelectionList = 
       
   212 									ObtainParameterReferenceL<CMsvEntrySelection>
       
   213 									(TestCase(), ActionParameters().Parameter(2)); 
       
   214 	
       
   215 
       
   216 	if( iParamSession == NULL || sentMsgSelectionList == NULL ||
       
   217 		 recvMsgSelectionList == NULL)
       
   218 		{
       
   219 		// Invalid input parameter value
       
   220 		TestCase().ERR_PRINTF1(_L("Invalid session or message selection object found"));
       
   221 		TestCase().SetTestStepResult(EFail);
       
   222 		}
       
   223 	else
       
   224 		{
       
   225 		if(IsTestCaseStatusPass())
       
   226 			{
       
   227 			// Get the download limits provided as the test action input and
       
   228 			// store the limit values
       
   229 			SetDownloadLimits();
       
   230 
       
   231 			if(IsTestCaseStatusPass())
       
   232 				{
       
   233 				// Compare sent and received messages
       
   234 				CompareEmailMessagesL(*sentMsgSelectionList, *recvMsgSelectionList);
       
   235 				}
       
   236 			}
       
   237 		}
       
   238 	// Test Action is complete
       
   239 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCompareEmailMessages);
       
   240 	TestCase().ActionCompletedL(*this);
       
   241 	}	
       
   242 
       
   243 
       
   244 /**
       
   245   SetDownloadLimitsL
       
   246   Obtains the parameter that contians download limits.  Checks for the type of
       
   247   the download limits being set.  Retrieves the values of the limits and stores
       
   248   them in member variables.
       
   249   @internalTechnology
       
   250   @pre    None
       
   251   @post   None
       
   252 */
       
   253 
       
   254 
       
   255 void CMtfTestActionCompareEmailMessages::SetDownloadLimits()
       
   256 	{
       
   257 	// Get the Partial download limits or  full download limits
       
   258 	const CMtfTestParameter& paramDownloadLimits = TestCase().ObtainParameterL
       
   259 										  	 (ActionParameters().Parameter(3));
       
   260 
       
   261 	// Buffer to store the download limits set
       
   262 	HBufC8* buf=reinterpret_cast<HBufC8*>(paramDownloadLimits.Parameter());
       
   263 
       
   264 
       
   265 	// Verify CMtfTestParameter object - Partial/Complete 
       
   266 	if ( paramDownloadLimits.SpecificTypeId() == EMtfTImImap4GetPartialMailInfo)
       
   267 		{
       
   268 		// Partial download limits set
       
   269 		TImImap4GetPartialMailInfo value;
       
   270 		TPckgC<TImImap4GetPartialMailInfo> unpack(value);
       
   271 		unpack.Set(*buf);
       
   272 		iImapPartialDownloadLimits = unpack();
       
   273 		
       
   274 	
       
   275 		
       
   276 		
       
   277 		// Set the download type as partial download
       
   278 		iDownloadType = EPartialDownload;
       
   279 
       
   280 		TestCase().INFO_PRINTF1(_L("TImImap4GetPartialMailInfo received as input"));
       
   281 		TestCase().INFO_PRINTF4(_L("TotalSizeLimit = %d, BodyTextSizeLimit %d, AttachmentSizeLimit %d"),
       
   282 								iImapPartialDownloadLimits.iTotalSizeLimit,
       
   283 								iImapPartialDownloadLimits.iBodyTextSizeLimit,
       
   284 								iImapPartialDownloadLimits.iAttachmentSizeLimit);
       
   285 		}
       
   286 	else if(paramDownloadLimits.SpecificTypeId() == EMtfTImImap4GetMailInfo)
       
   287 		{
       
   288 		// Full download limits set
       
   289 		TImImap4GetMailInfo value;
       
   290 		TPckgC<TImImap4GetMailInfo> unpack(value);
       
   291 		unpack.Set(*buf);
       
   292 		iImapCompleteDownloadLimits = unpack();
       
   293 
       
   294 		// Set the download type as full download
       
   295 		iDownloadType = EFullDownload;
       
   296 
       
   297 		TestCase().INFO_PRINTF1(_L("TImImap4GetMailInfo received as input"));
       
   298 		TestCase().INFO_PRINTF2(_L("iMaxEmailSize = %d"),
       
   299 									iImapCompleteDownloadLimits.iMaxEmailSize);
       
   300 		}	
       
   301 	else
       
   302 		{
       
   303 		// No specified download type mentioned 
       
   304 		TestCase().ERR_PRINTF1(_L("Incorrect Download type provided as input"));
       
   305 		TestCase().SetTestStepResult(EFail);
       
   306 		}
       
   307 	}
       
   308 
       
   309 
       
   310 /**
       
   311   CompareEmailMessagesL
       
   312   For the sent messages, searches for the received message with the same 
       
   313   Subject field.  If the received message is found, sets the sent and received
       
   314   message information and then calls CompareMessagesL() function to compare the 
       
   315   contents of the message based on the download limits set.
       
   316   @internalTechnology 
       
   317   @param  aSentMsgSelection  Selection of sent email messages
       
   318   @param  aRecvMsgSelection  Selection of received email messages
       
   319   @pre    None
       
   320   @post   None
       
   321 */
       
   322 void CMtfTestActionCompareEmailMessages::CompareEmailMessagesL(
       
   323 										 const CMsvEntrySelection& aSentMsgSelection,
       
   324 										 const CMsvEntrySelection& aRecvMsgSelection)
       
   325 	{
       
   326 	// Verify the input parameters
       
   327 	if( (!&aSentMsgSelection) || (!&aRecvMsgSelection))	
       
   328 		{
       
   329 		TestCase().ERR_PRINTF1(_L("Invalid Message selection"));
       
   330 		User::LeaveIfError(KErrArgument);
       
   331 		}
       
   332 
       
   333 	// Get the count of messages in both the selection object.
       
   334 	TInt sentMsgCount = aSentMsgSelection.Count();
       
   335 	TInt recvMsgCount = aRecvMsgSelection.Count();
       
   336 
       
   337 	TestCase().INFO_PRINTF2(_L("Sent Message count = %d"),sentMsgCount);
       
   338 	TestCase().INFO_PRINTF2(_L("Received Message count = %d"),recvMsgCount);
       
   339 
       
   340 	// Check if all the sent messages have to be received.
       
   341 	if(recvMsgCount != sentMsgCount)
       
   342 		{
       
   343 		// Number of received messages is not equal to number of sent messages
       
   344 		TestCase().ERR_PRINTF1(_L("Sent and Received message count not equal"));
       
   345 		TestCase().SetTestStepResult(EFail);
       
   346 		}
       
   347 
       
   348 	/* Loop through the list of sent messages.  For each of the sent messages,
       
   349 	   verify if the message has been received.  The comparison is done based
       
   350 	   on the subject field.  If message is not received - ERROR
       
   351 			
       
   352 	   Obtain the message entry with the session object, setting it to root 
       
   353 	   entry now, will be changed to the sent and received messages entries during 
       
   354 	   message comparison 
       
   355 	*/
       
   356 	
       
   357 	if(IsTestCaseStatusPass())
       
   358 		{
       
   359 		CMsvEntry* sentMsvEntry = iParamSession->GetEntryL(KMsvRootIndexEntryId);
       
   360 		CleanupStack::PushL(sentMsvEntry);
       
   361 
       
   362 		CMsvEntry* recvMsvEntry = iParamSession->GetEntryL(KMsvRootIndexEntryId);
       
   363 		CleanupStack::PushL(recvMsvEntry);
       
   364 
       
   365 		if((!sentMsvEntry) || (!recvMsvEntry))
       
   366 			{
       
   367 			TestCase().ERR_PRINTF1(_L("Invalid Message Entry"));
       
   368 			User::LeaveIfError(KErrGeneral);
       
   369 			}
       
   370 	
       
   371 		// Loop through the list of sent messages
       
   372 		for ( TInt sentMsgIndex = 0 ; (sentMsgIndex < sentMsgCount) &&
       
   373 									  (IsTestCaseStatusPass());
       
   374 									   sentMsgIndex ++)
       
   375 			{
       
   376 			// Get the sent message Id
       
   377 			TMsvId sentMsgId = aSentMsgSelection.At(sentMsgIndex);
       
   378 			// Set the context to the sent message entry
       
   379 			sentMsvEntry->SetEntryL(sentMsgId);
       
   380 
       
   381 			TBool found = EFalse;
       
   382 
       
   383 			TestCase().INFO_PRINTF3(_L("Comparison of Message: %d,  Subject: %S"),
       
   384 							(sentMsgIndex + 1), &(sentMsvEntry->Entry().iDescription));
       
   385 
       
   386 			// Loop through the list received messages - Inbox folder
       
   387 			for(TInt recvMsgIndex= 0; recvMsgIndex < recvMsgCount && !found
       
   388 														    ; recvMsgIndex++)	
       
   389 				{
       
   390 				// Get the received message entry
       
   391 				TMsvId recvMsgId = aRecvMsgSelection.At(recvMsgIndex);
       
   392 
       
   393 				// Set the context to the received message entry
       
   394 				recvMsvEntry->SetEntryL(recvMsgId);
       
   395 				
       
   396 				// Compare the subject field of the two messages
       
   397 				if (sentMsvEntry->Entry().iDescription.
       
   398 								Compare(recvMsvEntry->Entry().iDescription) == 0)
       
   399 					{
       
   400 					TestCase().INFO_PRINTF2(_L("Message with Subject field in the received selection: %S found "),
       
   401 												  &(recvMsvEntry->Entry().iDescription));
       
   402 
       
   403 					// Sent message has been received
       
   404 					found = ETrue;
       
   405 
       
   406 					// Set the email information with the sent and received emails
       
   407 					// to be compared
       
   408 					SetEmailMessageInfoL(*sentMsvEntry, *recvMsvEntry);
       
   409 					}
       
   410 				}	
       
   411 	
       
   412 			if ( found )
       
   413 				{
       
   414 				if(IsTestCaseStatusPass())
       
   415 					{
       
   416 					// Message is found now compare the two messages
       
   417 					if( iDownloadType == EPartialDownload )
       
   418 						{
       
   419 						CompareMessagesWithPartialDownloadLimitsSetL();
       
   420 						}
       
   421 					else 
       
   422 						{
       
   423 						CompareMessagesWithFullDownloadLimitsSetL();
       
   424 						}
       
   425 
       
   426 					if(IsTestCaseStatusPass())
       
   427 						{
       
   428 						// Delete the email information
       
   429 						DeleteEmailMessageInfo();
       
   430 						}
       
   431 					}
       
   432 				}
       
   433 			else{
       
   434 				TestCase().ERR_PRINTF2(_L("Email with subject %S is not received"), &sentMsvEntry->Entry().iDescription);
       
   435 				TestCase().SetTestStepResult(EFail);
       
   436 				}
       
   437 			}
       
   438 		// Cleanup the stack
       
   439 		CleanupStack::PopAndDestroy(recvMsvEntry);
       
   440 		CleanupStack::PopAndDestroy(sentMsvEntry);
       
   441 		}
       
   442 	}
       
   443 
       
   444 
       
   445 
       
   446 
       
   447 /**
       
   448   DeleteEmailMessageInfo
       
   449   If any message information was stored for sent and received messages,
       
   450   delete the infromation.
       
   451   @internalTechnology 
       
   452   @pre    None
       
   453   @post   None
       
   454 */
       
   455 void CMtfTestActionCompareEmailMessages::DeleteEmailMessageInfo()
       
   456 	{
       
   457 	// Delete sent message information
       
   458 	delete 	iSentMessageInfo;
       
   459 	iSentMessageInfo = NULL;
       
   460 	
       
   461 	// Delete received message information
       
   462 	delete 	iRecvMessageInfo ;
       
   463 	iRecvMessageInfo = NULL;
       
   464 	}
       
   465 
       
   466 
       
   467 
       
   468 
       
   469 /**
       
   470   SetEmailMessageInfoL
       
   471   Stores the message informationsent and received messages
       
   472   @internalTechnology 
       
   473   @param  aSentMsvEntry Entry for the sent message
       
   474   @param  aRecvMsvEntry Entry for the received message
       
   475   @pre    None
       
   476   @post   None
       
   477 */
       
   478 void CMtfTestActionCompareEmailMessages::SetEmailMessageInfoL(
       
   479 											CMsvEntry& aSentMsvEntry,
       
   480 											CMsvEntry& aRecvMsvEntry)
       
   481 	{
       
   482 	// Store sent message info
       
   483 	TestCase().INFO_PRINTF1(_L("Setting information for SENT message"));
       
   484 	iSentMessageInfo = CMtfTestActionUtilsEmailMessage::NewL(aSentMsvEntry, TestCase());
       
   485 	
       
   486 	// Store received message info
       
   487 	TestCase().INFO_PRINTF1(_L("Setting information for RECEIVED message"));
       
   488 	
       
   489 	iRecvMessageInfo = CMtfTestActionUtilsEmailMessage::NewL(aRecvMsvEntry, TestCase());
       
   490 	}
       
   491 
       
   492 
       
   493 
       
   494 /**
       
   495   CompareMessagesWithPartialDownloadLimitsSetL
       
   496   Compares the sent and the received message based on the partial download limits set
       
   497   @internalTechnology 
       
   498   @pre    None
       
   499   @post   None
       
   500 */
       
   501 void CMtfTestActionCompareEmailMessages::CompareMessagesWithPartialDownloadLimitsSetL()
       
   502 	{
       
   503 	// Partial download limits set
       
   504 	switch( iImapPartialDownloadLimits.iPartialMailOptions )
       
   505 		{
       
   506 		case ENoSizeLimits:
       
   507 			// No limits, the entire message was to be downloaded
       
   508 			TestCase().INFO_PRINTF1(_L("PartailDownloadLimits ENoSizeLimits option set"));
       
   509 			
       
   510 			CompareCompleteDownloadOfMessageL();
       
   511 			break;
       
   512 
       
   513 		case EAttachmentsOnly:
       
   514 			// Only attachments to be downloaded based on the attachment size limit
       
   515 			// Body text and html parts should not be downloaded
       
   516 			TestCase().INFO_PRINTF1(_L("PartailDownloadLimits EAttachmentsOnly option set"));
       
   517 			
       
   518 			CompareMessageWithAttachmentsOnlyOptionSetL();
       
   519 			break;
       
   520 
       
   521 		case EBodyTextOnly:
       
   522 			/*  When EBodyTextOnly option is set, Body text and html part should
       
   523 				be downloaded based on the body text limit set. The attachments
       
   524 				should not be downloaded. CompareAttachmentsL() is a generic
       
   525 				function which compares the attachments for any download option set.
       
   526 				So this case makes use of the function 
       
   527 				CompareMessagePartialDownloadWithBodyTextAndAttachmentsL() to compare 
       
   528 				the body text and html contents based on the body text limit set. The 
       
   529 				CompareAttachmentsL() function verifies that the attachments were not
       
   530 				downloaded.
       
   531 			*/
       
   532 				TestCase().INFO_PRINTF1(_L("PartailDownloadLimits EBodyTextOnly option set"));
       
   533 			// NO BREAK
       
   534 		case EBodyAlternativeText:
       
   535 			// Check for Body text and html based on the body text size limit
       
   536 			// Check for the dowmload of text attachments
       
   537 			if(iImapPartialDownloadLimits.iPartialMailOptions  == 
       
   538 															   EBodyAlternativeText)
       
   539 				{
       
   540 				TestCase().INFO_PRINTF1(_L("PartailDownloadLimits EBodyAlternativeText option set"));
       
   541 				}
       
   542 			// NO BREAK
       
   543 		case EBodyTextAndAttachments:
       
   544 			// Check for body text and html based on the body text size limit
       
   545 			// Check for the download of attachment based on the attachment size limit
       
   546 			if(iImapPartialDownloadLimits.iPartialMailOptions  ==  
       
   547 															   EBodyTextAndAttachments)
       
   548 				{
       
   549 				TestCase().INFO_PRINTF1(_L("PartailDownloadLimits EBodyTextAndAttachments option set"));
       
   550 				}
       
   551 
       
   552 			CompareMessagePartialDownloadWithBodyTextAndAttachmentsL();
       
   553 			break;
       
   554 
       
   555 		case ECumulative:
       
   556 			/* The message parts are downloaded with the following priority
       
   557 				1. Body Text 2. Attachments  3.Html part.  The total message size limit
       
   558 				is used for the deciding the download of message parts.  The download of 
       
   559 				the message part is stopped when the cumulative size of the downloded parts
       
   560 				exceed the total size limit
       
   561 			*/
       
   562 			TestCase().INFO_PRINTF1(_L("PartailDownloadLimits ECumulative option set"));
       
   563 
       
   564 			// Set the cumulative size
       
   565 			iCumulativeSize = iImapPartialDownloadLimits.iTotalSizeLimit;
       
   566 			CompareMessageDownloadWithCumulativeOptionSetL();
       
   567 			break;
       
   568 
       
   569 		default:
       
   570 			// TImap4GetMailOptions	iGetMailBodyParts set is not a valid value
       
   571 			TestCase().ERR_PRINTF1(_L("Invalid TImImap4GetPartialMailInfo.iPartialMailOptions set"));
       
   572 			TestCase().SetTestStepResult(EFail);
       
   573 		break;
       
   574 		}
       
   575 	}
       
   576 
       
   577 /**
       
   578   CompareMessagesWithFullDownloadLimitsSetL
       
   579   Compares the sent and the received message based on the full download limits set
       
   580   @internalTechnology 
       
   581   @pre    None
       
   582   @post   None
       
   583 */
       
   584 void CMtfTestActionCompareEmailMessages::CompareMessagesWithFullDownloadLimitsSetL()
       
   585 	{
       
   586 	// Full download limits set
       
   587 	TestCase().INFO_PRINTF1(_L("Full download limits set."));
       
   588 	
       
   589 	/* If the size of the message is greater than the toal mail size limit,'
       
   590 		then the message should not be downloaded
       
   591 	*/
       
   592 
       
   593 	// Get the total message size of the sent message
       
   594 	TInt32 sentMsgSize = 0;
       
   595 	User::LeaveIfError(iSentMessageInfo->GetMessageSize(sentMsgSize));
       
   596 	TestCase().INFO_PRINTF2(_L("Sent Message Size = %d"), sentMsgSize);
       
   597 	
       
   598 	if(sentMsgSize <= iImapCompleteDownloadLimits.iMaxEmailSize)
       
   599 		{
       
   600 		// Sent message size is smaller than the limit, the message should be 
       
   601 		// downloaded based on the download option set
       
   602 		switch(iImapCompleteDownloadLimits.iGetMailBodyParts)
       
   603 			{
       
   604 			case EGetImap4EmailHeaders:
       
   605 				// Message headers only, entry should not be created for any message part
       
   606 				TestCase().INFO_PRINTF1(_L("FullDownloadLimits EGetImap4EmailHeaders option set"));
       
   607 
       
   608 				CompareMessageWithGetHeadersOptionSetL();
       
   609 				break;
       
   610 
       
   611 			case EGetImap4EmailAttachments:
       
   612 				// Download attachments only.  All attachments should be downloaded
       
   613 				// Body text and html parts should not be downloaded
       
   614 				TestCase().INFO_PRINTF1(_L("FullDownloadLimits EGetImap4EmailAttachments option set"));
       
   615 
       
   616 				CompareMessageWithAttachmentsOnlyOptionSetL();
       
   617 				break;
       
   618 
       
   619 			case EGetImap4EmailBodyText:
       
   620 				/*  When EGetImap4EmailBodyText option is set, Body text and 
       
   621 					html part should be downloaded, and the attachments should not
       
   622 					be downloaded. CompareAttachmentsL() is a generic function
       
   623 					that compares the attachments for any download option set.
       
   624 					So this case makes use of the function 
       
   625 					CompareCompleteDownloadOfMessageL() to compare the body text
       
   626 					and html contents. The CompareAttachmentsL() function verifies
       
   627 					that the attachments were not downloaded.
       
   628 				*/
       
   629 				TestCase().INFO_PRINTF1(_L("FullDownloadLimits EGetImap4EmailBodyText option set"));
       
   630 				// NO BREAK
       
   631 			case EGetImap4EmailBodyAlternativeText:
       
   632 				if(iImapCompleteDownloadLimits.iGetMailBodyParts ==  
       
   633 											EGetImap4EmailBodyAlternativeText)
       
   634 					{
       
   635 					TestCase().INFO_PRINTF1(_L("FullDownloadLimits EGetImap4EmailBodyAlternativeText option set"));
       
   636 					}
       
   637 				// NO BREAK
       
   638 			case EGetImap4EmailBodyTextAndAttachments:
       
   639 				// The entire message was to be downloaded	
       
   640 				if(iImapCompleteDownloadLimits.iGetMailBodyParts ==  
       
   641 											EGetImap4EmailBodyTextAndAttachments)
       
   642 					{
       
   643 					TestCase().INFO_PRINTF1(_L("FullDownloadLimits EGetImap4EmailBodyTextAndAttachments option set"));
       
   644 					}
       
   645 
       
   646 				CompareCompleteDownloadOfMessageL();
       
   647 				break;
       
   648 
       
   649 			default:
       
   650 				// TImap4GetMailOptions	iGetMailBodyParts set is not a valid value
       
   651 				TestCase().ERR_PRINTF1(_L("Invalid TImap4GetMailOptions.iGetMailBodyParts set"));
       
   652 				TestCase().SetTestStepResult(EFail);
       
   653 			break;
       
   654 			}
       
   655 		}
       
   656 	else
       
   657 		{
       
   658 		// The message size was greater than the total mail size limit.
       
   659 		// Message parts should not be downloaded.
       
   660 		TestCase().INFO_PRINTF1(_L("Full download limits: Message size greater than mail size limit"));
       
   661 		CompareMessageFullDownloadWhenMsgSizeGreaterThanLimitL();
       
   662 		}
       
   663 	}
       
   664 
       
   665 
       
   666 /**
       
   667   CompareCompleteDownloadOfMessageL
       
   668   Check if complete message was downloaded.  The Body text, Html part and all the
       
   669   attachmens should have been downloaded, if they are present in the sent message.
       
   670   @internalTechnology 
       
   671   @pre    None
       
   672   @post   None
       
   673 */
       
   674 void CMtfTestActionCompareEmailMessages::CompareCompleteDownloadOfMessageL()
       
   675 	{
       
   676 	// The Body text, Html and Attachments of the message should be downloaded.
       
   677 
       
   678 	// Compare Body Text contents
       
   679 	if(IsTestCaseStatusPass())
       
   680 		{
       
   681 		ComparePlainBodyTextL(ETrue);
       
   682 		}
       
   683 	// Comapre Html contents
       
   684 	if(IsTestCaseStatusPass())
       
   685 		{
       
   686 		CompareHtmlL();
       
   687 		}
       
   688 	// Compare Attachments
       
   689 	if(IsTestCaseStatusPass())
       
   690 		{
       
   691 		CompareAttachmentsL();
       
   692 		}
       
   693 	}
       
   694 
       
   695 
       
   696 /**
       
   697   CompareMessageWithAttachmentsOnlyOptionSetL
       
   698   Checks whether only attachments are downloaded.  If Body Text or Html part is
       
   699   downloaded, the test fails.
       
   700   @internalTechnology 
       
   701   @pre    None
       
   702   @post   None
       
   703 */
       
   704 void CMtfTestActionCompareEmailMessages::CompareMessageWithAttachmentsOnlyOptionSetL()
       
   705 	{
       
   706 	/* Only attachments have to be downloaded.  
       
   707 	   Body Text and Html part should not be downloaded
       
   708 	*/
       
   709 
       
   710 	// Body Text
       
   711 	if (iRecvMessageInfo->GetBodyTextSize() > 0) 
       
   712 		{
       
   713 		// Error : body text was downloaded when not expected
       
   714 		TestCase().ERR_PRINTF1(_L("Body Text was downloaded when Attachment only option is set"));
       
   715 		TestCase().SetTestStepResult(EFail);
       
   716 		}
       
   717 	else
       
   718 		{
       
   719 		if(iSentMessageInfo->GetBodyTextSize() > 1) 
       
   720 			{
       
   721 			/* [WorkAround for Body Text Ref7]
       
   722 				When a message with only attachment is created,one byte of body text
       
   723 				is getting added.  To take care of this conditions, the sent body text
       
   724 				size is checked to be greater than 1 instead of 0
       
   725 			*/
       
   726 
       
   727 			// Check for the correctness of Complete and Partial flags set for Body Text entry
       
   728 			TestCase().INFO_PRINTF1(_L("Body Text was not downloaded"));
       
   729 			TestCase().INFO_PRINTF1(_L("Expected flag values for Body Text part: Complete flag = EFalse, Partial download flag = EFalse"));
       
   730 			CheckFlagSettingsL( iRecvMessageInfo->GetBodyTextId(),EFalse,EFalse);
       
   731 			}
       
   732 		else
       
   733 			{
       
   734 			if(iRecvMessageInfo->GetBodyTextId() > 0)
       
   735 				{
       
   736 				// No Body text part present, compelte flag should be set to ETrue
       
   737 				// to avoid download of Body text part
       
   738 				TestCase().INFO_PRINTF1(_L("Body Text was not downloaded"));
       
   739 				TestCase().INFO_PRINTF1(_L("Expected flag values for Body Text part: Complete flag = ETrue, Partial download flag = EFalse"));
       
   740 				CheckFlagSettingsL( iRecvMessageInfo->GetBodyTextId(),ETrue,EFalse);
       
   741 				}
       
   742 			}
       
   743 		}
       
   744 	
       
   745 	// Html part
       
   746 	if(IsTestCaseStatusPass())
       
   747 		{
       
   748 		if(iRecvMessageInfo->GetHtmlSize() > 0)
       
   749 			{
       
   750 			// Error : Html part was downloaded when not expected
       
   751 			TestCase().ERR_PRINTF1(_L("Html part was downloaded when Attachments Only option is set"));
       
   752 			TestCase().SetTestStepResult(EFail);
       
   753 			}
       
   754 		else if(iSentMessageInfo->GetHtmlSize() > 0)
       
   755 			{
       
   756 			TestCase().INFO_PRINTF1(_L("Html part was not downloaded"));
       
   757 			TestCase().INFO_PRINTF1(_L("Expected flag values for Html part: Complete flag = EFalse, Partial download flag = EFalse"));
       
   758 			CheckFlagSettingsL( iRecvMessageInfo->GetHtmlEntryId(), EFalse, EFalse);
       
   759 			}
       
   760 		else 
       
   761 			{
       
   762 			if(iRecvMessageInfo->GetHtmlEntryId() > 0)
       
   763 				{
       
   764 				// No Html part present, compelte flag should be set to ETrue
       
   765 				// to avoid download of Html part
       
   766 				TestCase().INFO_PRINTF1(_L("Html part was not downloaded"));
       
   767 				TestCase().INFO_PRINTF1(_L("Expected flag values for Html part: Complete flag = ETrue, Partial download flag = EFalse"));
       
   768 				CheckFlagSettingsL( iRecvMessageInfo->GetHtmlEntryId(), ETrue, EFalse);
       
   769 				}
       
   770 			}
       
   771 		}
       
   772 	// Attachments
       
   773 	if(IsTestCaseStatusPass())
       
   774 		{
       
   775 		CompareAttachmentsL();
       
   776 		}
       
   777 	}
       
   778 
       
   779 
       
   780 /**
       
   781   CompareMessagePartialDownloadWithBodyTextAndAttachmentsL
       
   782   Checks for the download of Body text and Html part based on the Body text size limit
       
   783   Calls CompareAttachment() to check the attachment download based on the attachment 
       
   784   size limit.
       
   785   @internalTechnology 
       
   786   @pre    None
       
   787   @post   None
       
   788 */
       
   789 void CMtfTestActionCompareEmailMessages::CompareMessagePartialDownloadWithBodyTextAndAttachmentsL()
       
   790 	{
       
   791 	if(IsTestCaseStatusPass())
       
   792 		{
       
   793 		// [WorkAround for Body Text Ref1] and [WorkAround for Html Part Ref2] Begin
       
   794 		
       
   795 		// Get the size of Body Text part of the sent and the received messages
       
   796 		TInt32 sentBodyTextSize = iSentMessageInfo->GetBodyTextSize();
       
   797 		TInt32 sentHtmlSize		= iSentMessageInfo->GetHtmlSize();
       
   798 
       
   799 		// [WorkAround for Body Text Ref1] and [WorkAround for Html Part Ref2] End
       
   800 		
       
   801 		// If both Body text and html part fit into the Body text limit, it is a complete
       
   802 		// download of Body text. Html should also be downloaded
       
   803 		if((sentBodyTextSize + sentHtmlSize) <= iImapPartialDownloadLimits.iBodyTextSizeLimit)
       
   804 			{
       
   805 			TestCase().INFO_PRINTF1(_L("Both Body text and html part fit into the Body text limit"));
       
   806 			
       
   807 			// Compare Body Text contents
       
   808 			ComparePlainBodyTextL(ETrue);
       
   809 
       
   810 			if(IsTestCaseStatusPass())
       
   811 				{
       
   812 				// Compare Html contents
       
   813 				CompareHtmlL();
       
   814 				}
       
   815 			}
       
   816 		else
       
   817 			{
       
   818 			// If both Body text and Html does not fit in, then it is a partial download of 
       
   819 			// Body text, Html part should not be downloaded
       
   820 			TestCase().INFO_PRINTF1(_L("Partial Download of Body text"));
       
   821 
       
   822 			ComparePlainBodyTextL(EFalse);
       
   823 
       
   824 			if(IsTestCaseStatusPass())
       
   825 				{
       
   826 				if(iRecvMessageInfo->GetHtmlSize() > 0)
       
   827 					{
       
   828 					// Error : Html was downloaded when not expected
       
   829 					TestCase().ERR_PRINTF1(_L("Html part was downloaded when Body Text+ Html size > Body text limit"));
       
   830 					TestCase().SetTestStepResult(EFail);
       
   831 					}
       
   832 
       
   833 				if(IsTestCaseStatusPass())
       
   834 					{
       
   835 					if(iSentMessageInfo->GetHtmlSize() > 0)
       
   836 						{
       
   837 						// When Html is not downloaded, check the correctness of the 
       
   838 						// complete and the partial download flags set for the Html entry
       
   839 						TestCase().INFO_PRINTF1(_L("Html part was not downloaded"));
       
   840 
       
   841 						TestCase().INFO_PRINTF1(_L("Expected flag values for Html part:  Complete flag = EFalse, Partial download flag = EFalse"));
       
   842 						CheckFlagSettingsL( iRecvMessageInfo->GetHtmlEntryId(), EFalse, EFalse);
       
   843 						}
       
   844 					}
       
   845 				}
       
   846 			}
       
   847 		}
       
   848 	
       
   849 	if(IsTestCaseStatusPass())
       
   850 		{
       
   851 		// Check if the attachments are downloaded if the size of the attachment
       
   852 		// is less than or equal to the attachment size limit
       
   853 		CompareAttachmentsL();
       
   854 		}
       
   855 	}
       
   856 
       
   857 
       
   858 /**
       
   859   CompareMessageWithGetHeadersOptionSetL
       
   860   Checks if any message part was downloaded when Full download limits
       
   861   with EGetImap4EmailHeaders option is set.  If any message part is downloaded,
       
   862   the test fails.
       
   863   @internalTechnology 
       
   864   @pre    None
       
   865   @post   None
       
   866 */
       
   867 void CMtfTestActionCompareEmailMessages::CompareMessageWithGetHeadersOptionSetL()
       
   868 	{
       
   869 	/* Download headers only.  The Body text, Html or Attachments of the message
       
   870 	  should not be downloaded.  The entries for the message parts should not be created.
       
   871 	*/
       
   872 	if(IsTestCaseStatusPass())
       
   873 		{
       
   874 		TMsvId recvBodyTextId = iRecvMessageInfo->GetBodyTextId();
       
   875 
       
   876 		if(recvBodyTextId > 0)
       
   877 			{
       
   878 			// Error : Entry created for Body Text
       
   879 			TestCase().ERR_PRINTF1(_L("Entry for Html part is created when Headers Only option is set"));
       
   880 			TestCase().SetTestStepResult(EFail);
       
   881 			}
       
   882 		else
       
   883 			{
       
   884 			TestCase().INFO_PRINTF1(_L("Body Text was not downloaded"));
       
   885 			}
       
   886 
       
   887 		if(IsTestCaseStatusPass())
       
   888 			{
       
   889 			TMsvId recvHtmlId = iRecvMessageInfo->GetHtmlEntryId();
       
   890 			if( recvHtmlId > 0 )
       
   891 				{
       
   892 				// Error : Entry created for Html part
       
   893 				TestCase().ERR_PRINTF1(_L("Entry for Html part is created when Headers Only option is set"));
       
   894 				TestCase().SetTestStepResult(EFail);
       
   895 				}
       
   896 			else
       
   897 				{
       
   898 				TestCase().INFO_PRINTF1(_L("Html part was not downloaded"));
       
   899 				}
       
   900 			}
       
   901 		if(IsTestCaseStatusPass())
       
   902 			{
       
   903 			// Compare attachments
       
   904 			CompareAttachmentsL();
       
   905 			}
       
   906 		}
       
   907 	}	
       
   908 
       
   909 
       
   910 
       
   911 
       
   912 /**
       
   913   CompareMessageFullDownloadWhenMsgSizeGreaterThanLimitL
       
   914   The message size is greater than the message size limit. No message parts should be
       
   915   downloaded.  Fails if any message part was downloaded.
       
   916   @internalTechnology 
       
   917   @pre    None
       
   918   @post   None
       
   919 */
       
   920 void CMtfTestActionCompareEmailMessages::CompareMessageFullDownloadWhenMsgSizeGreaterThanLimitL()
       
   921 	{
       
   922 	// Body Text
       
   923 	if(iRecvMessageInfo->GetBodyTextSize() > 0) 
       
   924 		{
       
   925 		TestCase().ERR_PRINTF1(_L("Body text downloaded when mail size is greater than the iMaxEmailSize"));
       
   926 		TestCase().SetTestStepResult(EFail);
       
   927 		}
       
   928 	else
       
   929 		{
       
   930 		TestCase().INFO_PRINTF1(_L("Body text not was downloaded"));
       
   931 		}	
       
   932 
       
   933 	// Html
       
   934 	if(IsTestCaseStatusPass())
       
   935 		{
       
   936 		if(iRecvMessageInfo->GetHtmlSize() > 0) 
       
   937 			{
       
   938 			TestCase().ERR_PRINTF1(_L("Html part downloaded when mail size is greater than the iMaxEmailSize"));
       
   939 			TestCase().SetTestStepResult(EFail);
       
   940 			}
       
   941 		else
       
   942 			{
       
   943 			TestCase().INFO_PRINTF1(_L("Html part not was downloaded"));
       
   944 			}
       
   945 		}
       
   946 
       
   947 	// Attachments
       
   948 	if(IsTestCaseStatusPass())
       
   949 		{
       
   950 		CompareAttachmentsL();
       
   951 		}
       
   952 	}
       
   953 
       
   954 
       
   955 
       
   956 
       
   957 /**
       
   958   CompareMessageDownloadWithCumulativeOptionSetL
       
   959   Checks for the download of message parts when Partial download ECumulative options is set
       
   960   @internalTechnology 
       
   961   @pre    None
       
   962   @post   None
       
   963 */
       
   964 void CMtfTestActionCompareEmailMessages::CompareMessageDownloadWithCumulativeOptionSetL()
       
   965 	{
       
   966 
       
   967 	/*	When Partial download with Cumulative option is set, 
       
   968 		
       
   969 		The message body text part will be downloaded first. If the body text
       
   970 		size is greater than the total size limit, the body text will be 
       
   971 		downloaded partially and none of the other parts are downloaded.
       
   972 		If the body text size is lesser than the total size limit,
       
   973 		the attachment that fits into the remaining size will be downloaded.
       
   974 
       
   975 		After download of attachments, if Html part can fit in, the Html part 
       
   976 		should be downloaded
       
   977 	*/
       
   978 
       
   979 	// Get the size of the sent message
       
   980 	TInt32 sentMsgSize = 0;
       
   981 	User::LeaveIfError(iSentMessageInfo->GetMessageSize(sentMsgSize));
       
   982 	
       
   983 	TestCase().INFO_PRINTF2(_L("Sent message size = %d"), sentMsgSize);
       
   984 
       
   985 	// If the message is lesser than the limit, the complete message has to be downloaded
       
   986 	if(sentMsgSize  <= iImapPartialDownloadLimits.iTotalSizeLimit )
       
   987 		{
       
   988 		CompareCompleteDownloadOfMessageL();
       
   989 		}
       
   990 	else
       
   991 		{
       
   992 		// Set the cumulative size
       
   993 		iCumulativeSize = iCumulativeSize - iSentMessageInfo->GetBodyTextSize();
       
   994 
       
   995 		/* Compare the attachments first. This will help in knowing the remaining cumulative
       
   996 		   size after attachment download.  To decide whether the Body text was to be completely
       
   997 		   downloaded or not, we need to know if Html part fits in the cumulative size.
       
   998 		   Based on the remaining cumulative size after attachment comparison, decide whether
       
   999 		   Body text was to be completely downloaded or pariatlly downlaoded
       
  1000 		*/
       
  1001 
       
  1002 		if(IsTestCaseStatusPass())
       
  1003 			{
       
  1004 			CompareAttachmentsL();
       
  1005 			}
       
  1006 
       
  1007 		if(IsTestCaseStatusPass())
       
  1008 			{
       
  1009 			// Check if Html part fits in
       
  1010 			if( (iSentMessageInfo->GetHtmlSize()) <= iCumulativeSize )
       
  1011 				{
       
  1012 				// Compare the complete download of Body Text
       
  1013 				ComparePlainBodyTextL(ETrue);
       
  1014 
       
  1015 				if(IsTestCaseStatusPass())
       
  1016 					{
       
  1017 					// Compare Htmp contents
       
  1018 					CompareHtmlL();
       
  1019 					}
       
  1020 				}
       
  1021 			else
       
  1022 				{
       
  1023 				// Partial download of body text
       
  1024 				TestCase().INFO_PRINTF1(_L("Partial download of Body Text"));
       
  1025 				ComparePlainBodyTextL(EFalse);
       
  1026 
       
  1027 				if(IsTestCaseStatusPass())
       
  1028 					{
       
  1029 					// Check if Html part was received. If received, fail the Test Case
       
  1030 					if(iRecvMessageInfo->GetHtmlSize() > 0)
       
  1031 						{
       
  1032 						// Error : Html was downloaded when not expected
       
  1033 						TestCase().ERR_PRINTF1(_L("Html part was downloaded when cumulative size is lesser than Html size"));
       
  1034 						TestCase().SetTestStepResult(EFail);
       
  1035 						}
       
  1036 					else
       
  1037 						{
       
  1038 						TestCase().INFO_PRINTF1(_L("Html part was not downloaded"));
       
  1039 						}
       
  1040 
       
  1041 					if(IsTestCaseStatusPass())
       
  1042 						{
       
  1043 						// If Html part is not received, verify the complete and partial download flag
       
  1044 						// set for the Html part
       
  1045 						if(iSentMessageInfo->GetHtmlSize() > 0)
       
  1046 							{
       
  1047 							TestCase().INFO_PRINTF1(_L("Expected flag values for Html part:  Complete flag = EFalse, Partial download flag = EFalse"));
       
  1048 							CheckFlagSettingsL( iRecvMessageInfo->GetHtmlEntryId(), EFalse, EFalse);
       
  1049 							}
       
  1050 						}
       
  1051 					}
       
  1052 				}
       
  1053 			}
       
  1054 		}
       
  1055 	}
       
  1056 
       
  1057 /**
       
  1058   ComparePlainBodyTextL
       
  1059   Compares the contents of the received body text with that of the sent message.
       
  1060   Checks if the footer message is present and verifies the complete and partial 
       
  1061   download flags set for the Body text entry.
       
  1062   @internalTechnology 
       
  1063   @param  TBool ETrue for complete download of Body text, EFalse when partail download
       
  1064   @pre    None
       
  1065   @post   None
       
  1066 */
       
  1067 void CMtfTestActionCompareEmailMessages::ComparePlainBodyTextL(TBool aCompleteDownload)
       
  1068 	{
       
  1069 	//[WorkAround for Body Text Ref2]
       
  1070 	const TInt KPartialBodyTextCompareTolerance = 5;
       
  1071 
       
  1072 	TestCase().INFO_PRINTF1(_L("Comparing Plain text part of the message"));
       
  1073 		
       
  1074 	// Comapre the contents when sent message had Body Text
       
  1075 	if( iSentMessageInfo->GetBodyTextSize() > 0)
       
  1076 		{
       
  1077 		if( iRecvMessageInfo->GetBodyTextSize() > 0)
       
  1078 			{
       
  1079 			// Get the Body Text contents of sent and received messages
       
  1080 
       
  1081 			// Get message body text for sent message
       
  1082 			CParaFormatLayer*	sentParaFormatLayer = CParaFormatLayer::NewL();
       
  1083 			CleanupStack::PushL(sentParaFormatLayer);
       
  1084 
       
  1085 			CCharFormatLayer*	sentCharFormatLayer = CCharFormatLayer::NewL(); 
       
  1086 			CleanupStack::PushL(sentCharFormatLayer);
       
  1087 
       
  1088 			CRichText*	sentPlainBodyText  = CRichText::NewL( sentParaFormatLayer,
       
  1089 											  sentCharFormatLayer,   
       
  1090 											  CEditableText::EFlatStorage, 256);
       
  1091 			CleanupStack::PushL(sentPlainBodyText);
       
  1092 			
       
  1093 			iSentMessageInfo->GetBodyTextL(*sentPlainBodyText, *sentParaFormatLayer,
       
  1094 															*sentCharFormatLayer);	
       
  1095 
       
  1096 			// Get message body text for received message
       
  1097 			CParaFormatLayer*	recvParaFormatLayer = CParaFormatLayer::NewL();
       
  1098 			CleanupStack::PushL(recvParaFormatLayer);
       
  1099 
       
  1100 			CCharFormatLayer*	recvCharFormatLayer = CCharFormatLayer::NewL(); 
       
  1101 			CleanupStack::PushL(recvCharFormatLayer);
       
  1102 
       
  1103 			CRichText*	recvPlainBodyText = CRichText::NewL( recvParaFormatLayer, 
       
  1104 															 recvCharFormatLayer, 
       
  1105 										     CEditableText::EFlatStorage, 256);
       
  1106 
       
  1107 			CleanupStack::PushL(recvPlainBodyText);
       
  1108 
       
  1109 			//[WorkAround Ref1 Start]
       
  1110 			iRecvMessageInfo->GetBodyTextL(*recvPlainBodyText, *recvParaFormatLayer,
       
  1111 															*recvCharFormatLayer);
       
  1112 			//[WorkAround Ref1 End]
       
  1113 			
       
  1114 			// If the body text buffer is not available, fail the test case
       
  1115 			if(sentPlainBodyText == NULL || recvPlainBodyText == NULL)
       
  1116 				{
       
  1117 				// Error : Body text buffer not available
       
  1118 				TestCase().ERR_PRINTF1(_L("Body text buffer not available"));
       
  1119 				TestCase().SetTestStepResult(EFail);
       
  1120 				}			
       
  1121 
       
  1122 			if(IsTestCaseStatusPass())
       
  1123 				{
       
  1124 				TPtrC sentBodyText = sentPlainBodyText->Read(0);
       
  1125 				TPtrC recvBodyText = recvPlainBodyText->Read(0);
       
  1126 
       
  1127 				TestCase().INFO_PRINTF3(_L("Sent body text size: %d, Received body text size = %d"),
       
  1128 											sentBodyText.Length(), recvBodyText.Length());
       
  1129 						
       
  1130 				TInt serverMsgPos = -1;
       
  1131 				TInt serverMsgLength = 0;
       
  1132 
       
  1133 				// Check if server has added any message to the beginning of the
       
  1134 				// Body Text Part
       
  1135 
       
  1136 				// [WorkAround for Body Text Ref3] Begin
       
  1137 				CheckIfServerMessageExists(recvBodyText, serverMsgLength, serverMsgPos);
       
  1138 				
       
  1139 				// Get the Body text size of the received messagge
       
  1140 				TInt totalBodyTextSize = recvBodyText.Length();
       
  1141 
       
  1142 				// If server message is present, set the buffer to ignore the server message
       
  1143 				if ( serverMsgPos >= 0 )
       
  1144 					{
       
  1145 					totalBodyTextSize = totalBodyTextSize - serverMsgLength;
       
  1146 					}
       
  1147 				TPtrC recvBodyTextPtr = recvBodyText.Right(totalBodyTextSize);
       
  1148 				
       
  1149 				// [WorkAround for Body Text Ref3] End
       
  1150 
       
  1151 				// Check if Footer message is present
       
  1152 				TInt footerMsgPos = CheckIfFooterMessageExists(recvBodyText);
       
  1153 				
       
  1154 				if( aCompleteDownload)
       
  1155 					{
       
  1156 					// Complete download of body text expected.  Both Body Text and Html part
       
  1157 					// downloaded.  The Body text should not contian the footer message
       
  1158 
       
  1159 					if (footerMsgPos != KErrNotFound)
       
  1160 						{
       
  1161 						// Error : Footer message exists when complete download of body text expected
       
  1162 						TestCase().ERR_PRINTF1(_L("Footer message exists when complete download of body text expected"));
       
  1163 						TestCase().SetTestStepResult(EFail);
       
  1164 						}
       
  1165 
       
  1166 					if(IsTestCaseStatusPass())
       
  1167 						{
       
  1168 						// [WorkAround for Body Text Ref2] Begin
       
  1169 						TPtrC recvBodyText1 = recvBodyTextPtr.Left(recvBodyTextPtr.Length()
       
  1170 														- KPartialBodyTextCompareTolerance);
       
  1171 						// [WorkAround for Body Text Ref2] End
       
  1172 
       
  1173 						// [WorkAround for Body Text Ref3] Begin
       
  1174 						TPtrC sentBodyText1 = sentBodyText.Left(recvBodyText1.Length());
       
  1175 						// [WorkAround for Body Text Ref3] End
       
  1176 
       
  1177 						// Compare the sent and received message's body text contents
       
  1178 						if( (recvBodyText1.Compare(sentBodyText1)) != 0)
       
  1179 							{
       
  1180 							// Error : Comparison of body text failed
       
  1181 							TestCase().ERR_PRINTF1(_L("Comparison of body text failed"));
       
  1182 							TestCase().SetTestStepResult(EFail);
       
  1183 							}
       
  1184 
       
  1185 						if(IsTestCaseStatusPass())
       
  1186 							{
       
  1187 							TestCase().INFO_PRINTF1(_L("Comparison of Body text was successful"));
       
  1188 							// Verify the complete and partial download flags set
       
  1189 							TestCase().INFO_PRINTF1(_L("Expected flag values for Body Text part:  Complete flag = ETrue, Partial download flag = EFalse"));
       
  1190 							CheckFlagSettingsL( iRecvMessageInfo->GetBodyTextId(),
       
  1191 																 ETrue, EFalse );
       
  1192 							}
       
  1193 						}
       
  1194 					}
       
  1195 				else
       
  1196 					{
       
  1197 					//Partial download of body text
       
  1198 					/* The Body Text may be downloaded partially or completely 
       
  1199 					   based on the body text size limit (iCumulative size in  
       
  1200 					   case of ECumulative option).  In this case, the Html part
       
  1201 					   should not be downloaded, hence the footer message should be
       
  1202 					   present in the received message's body text.
       
  1203 					*/
       
  1204 					if(IsTestCaseStatusPass())
       
  1205 						{
       
  1206 						if (footerMsgPos == KErrNotFound)
       
  1207 							{
       
  1208 							// Error : Footer message expected, but does not exists
       
  1209 							TestCase().ERR_PRINTF1(_L("Footer message expected, but does not exists"));
       
  1210 							TestCase().SetTestStepResult(EFail);
       
  1211 							}
       
  1212 	
       
  1213 						if(IsTestCaseStatusPass())
       
  1214 							{
       
  1215 							TPtrC recvBodyText1 = recvBodyTextPtr.Left(
       
  1216 												  recvBodyTextPtr.Length() - (footerMsgPos));
       
  1217 
       
  1218 							// [WorkAround for Body Text Ref5] Begin
       
  1219 							TPtrC sentBodyText1 = sentBodyText.Left(recvBodyText1.Length());
       
  1220 							// [WorkAround for Body Text Ref5] End
       
  1221 							
       
  1222 							if( (recvBodyText1.Compare(sentBodyText1)) != 0)
       
  1223 								{
       
  1224 								// Error : Comparison of body text failed
       
  1225 								TestCase().ERR_PRINTF1(_L("Comparison of body text failed"));
       
  1226 								TestCase().SetTestStepResult(EFail);
       
  1227 								}
       
  1228 
       
  1229 							if(IsTestCaseStatusPass())
       
  1230 								{
       
  1231 								TestCase().INFO_PRINTF1(_L("Comparison of Body text was successful"));
       
  1232 
       
  1233 								// Verify the complete and the partial download flags set
       
  1234 								TestCase().INFO_PRINTF1(_L("Expected flag values for Body Text part: Complete flag = ETrue, Partial download flag = ETrue"));
       
  1235 
       
  1236 								CheckFlagSettingsL( iRecvMessageInfo->GetBodyTextId(),
       
  1237 																	  ETrue, ETrue);
       
  1238 								}
       
  1239 							}
       
  1240 						}
       
  1241 					}
       
  1242 				}
       
  1243 			CleanupStack::PopAndDestroy(6, sentParaFormatLayer);
       
  1244 			}
       
  1245 		else
       
  1246 			{
       
  1247 			// Error : Sent message contains Body text. But Body text was not received
       
  1248 			TestCase().ERR_PRINTF1(_L("Sent message contains Body text. But Body text was not received"));
       
  1249 			TestCase().SetTestStepResult(EFail);
       
  1250 			}
       
  1251 		}
       
  1252 	else
       
  1253 		{
       
  1254 		TestCase().INFO_PRINTF1(_L("Sent message does not contain Body text part"));
       
  1255 		if(iRecvMessageInfo->GetBodyTextSize() > 0)
       
  1256 			{
       
  1257 			// Error : Sent message does not contains Body text. But Body text was received
       
  1258 			TestCase().ERR_PRINTF1(_L("Sent message does not contains Body text. But Body text was received"));
       
  1259 			TestCase().SetTestStepResult(EFail);
       
  1260 			}
       
  1261 		}
       
  1262 	}
       
  1263 
       
  1264 
       
  1265 
       
  1266 /**
       
  1267   CheckIfFooterMessageExists
       
  1268   Checks for the footer message in the specified buffer.  If footer message
       
  1269   is found, returns the position of the footer message in the buffer.
       
  1270   If not found, returns KErrNotFound
       
  1271   @internalTechnology 
       
  1272   @param  aBodyText Pointer descriptor of the  buffer
       
  1273   @return TInt Position of the start of footer message in the buffer, KErrNotFound
       
  1274 				if the footer message is not found
       
  1275   @pre    None
       
  1276   @post   None
       
  1277 */
       
  1278 TInt CMtfTestActionCompareEmailMessages::CheckIfFooterMessageExists(TPtrC aBodyText)
       
  1279 	{
       
  1280 		// Look for the footer message in the received email message. 
       
  1281 	_LIT(KFooterMsg1,"This message has not been fully downloaded. There is still ");
       
  1282 	
       
  1283 	//Find for the footer message in the received message
       
  1284 	TInt found = aBodyText.Find(KFooterMsg1);
       
  1285 
       
  1286 	if(found != KErrNotFound)
       
  1287 		{
       
  1288 		// [WorkAround for Body Text Ref6] Begin
       
  1289 		TPtrC footerMsg = aBodyText.Right(aBodyText.Length() - found);
       
  1290 		TestCase().INFO_PRINTF2(_L("Footer message: %S"), &footerMsg);
       
  1291 		// [WorkAround for Body Text Ref6] End
       
  1292 		}
       
  1293 	return found;
       
  1294 	}
       
  1295 
       
  1296 
       
  1297 /**
       
  1298   CheckIfServerMessageExists
       
  1299   Checks if any server message has been added to the Body text,
       
  1300   returns the position of the server message in the buffer and the 
       
  1301   length of the server message.  This function can be enhanced 
       
  1302   to check for any other server message encountered
       
  1303   If not found, returns KErrNotFound
       
  1304   @internalTechnology 
       
  1305   @param  aBodyText			- Pointer descriptor of the  buffer
       
  1306   @param  aServerMsgLength	- Length of the server message
       
  1307   @param  aServerMsgPosition - Position of the server message in the buffer
       
  1308   @pre    None		
       
  1309   @post   None
       
  1310 */
       
  1311 void CMtfTestActionCompareEmailMessages::CheckIfServerMessageExists(
       
  1312 										TPtrC aBodyText, TInt& aServerMsgLength,
       
  1313 										TInt& aServerMsgPosition)
       
  1314 	{
       
  1315 	_LIT(KServerMessage,"*This message was transferred with a trial version of CommuniGate(r) Pro*");
       
  1316 	
       
  1317 	aServerMsgLength = KServerMessage().Length()+1;
       
  1318 
       
  1319 	aServerMsgPosition = aBodyText.Find(KServerMessage);
       
  1320 	}
       
  1321 
       
  1322 
       
  1323 
       
  1324 /**
       
  1325   CheckFlagSettingsL
       
  1326   Checks if the complete and the partial download flags for the specified message part
       
  1327   is same as the expected value. Fails the test case if the flags set for the message
       
  1328   part does not match with the expected value
       
  1329   @internalTechnology 
       
  1330   @param  aMsgPartId  TMsvId of the message part
       
  1331   @param  aExpectedCompleteFlagVal  Expected value of the Complete flag
       
  1332   @param  aExpectedPartialFlagVal   Expected value of the Parital download flag
       
  1333   @pre    None
       
  1334   @post   None
       
  1335 */
       
  1336 void CMtfTestActionCompareEmailMessages::CheckFlagSettingsL(TMsvId aMsgPartId, 
       
  1337 														   TBool aExpectedCompleteFlagVal,
       
  1338 														   TBool aExpectedPartialFlagVal)
       
  1339 	{
       
  1340 	// [WorkAround for general Ref1] Begin
       
  1341 	if( aMsgPartId > 0)
       
  1342 		{
       
  1343 		// Check the complete and partial flag settings
       
  1344 		TBool completeFlag	= EFalse;
       
  1345 		User::LeaveIfError(iRecvMessageInfo->CheckCompleteFlagL( aMsgPartId,completeFlag));
       
  1346 		
       
  1347 		// Compare the set and the expected complete flag value
       
  1348 		if(aExpectedCompleteFlagVal && completeFlag)
       
  1349 			{
       
  1350 			TestCase().INFO_PRINTF1(_L("Complete Flag is set to ETrue"));
       
  1351 			}
       
  1352 		else if((aExpectedCompleteFlagVal == 0) && (completeFlag == 0))
       
  1353 			{
       
  1354 			TestCase().INFO_PRINTF1(_L("Complete Flag is set to EFalse"));
       
  1355 			}
       
  1356 		else
       
  1357 			{
       
  1358 			TestCase().ERR_PRINTF1(_L("Error: Incorrect Compelte flag setting"));
       
  1359 			TestCase().INFO_PRINTF2(_L("Complete Flag is set to %d "), completeFlag);
       
  1360 			TestCase().SetTestStepResult(EFail);
       
  1361 			}
       
  1362 
       
  1363 		if(IsTestCaseStatusPass())
       
  1364 			{
       
  1365 			TBool partialDownloadFlag = EFalse;
       
  1366 			User::LeaveIfError(	iRecvMessageInfo->CheckPartialDownloadFlagL
       
  1367 												   (aMsgPartId, partialDownloadFlag)); 
       
  1368 			
       
  1369 			// Compare the set and the expected partial download flag value
       
  1370 			if(aExpectedPartialFlagVal && partialDownloadFlag)
       
  1371 				{
       
  1372 				TestCase().INFO_PRINTF1(_L("Partial download flag is set to ETrue"));
       
  1373 				}
       
  1374 			else if((aExpectedPartialFlagVal == 0)  && (partialDownloadFlag == 0))
       
  1375 				{
       
  1376 				TestCase().INFO_PRINTF1(_L("Partial download flag is set to EFalse"));
       
  1377 				}
       
  1378 			else
       
  1379 				{	
       
  1380 				TestCase().ERR_PRINTF1(_L("Error: Incorrect Partial download flag setting"));
       
  1381 				TestCase().INFO_PRINTF2(_L("Partial download is set to %d "), partialDownloadFlag);
       
  1382 				TestCase().SetTestStepResult(EFail);
       
  1383 				}
       
  1384 			}
       
  1385 		} 
       
  1386 	else
       
  1387 		{
       
  1388 		TestCase().ERR_PRINTF1(_L("Invalid TMsvId provided for checking complete and partial download flags"));
       
  1389 		TestCase().SetTestStepResult(EFail);
       
  1390 		}
       
  1391 	// [WorkAround for general Ref1] End
       
  1392 	}
       
  1393 
       
  1394 
       
  1395 /**
       
  1396   CheckFlagSettingsL
       
  1397   Checks if the complete download flag for the specified message attachment is same as
       
  1398   the expected value. Fails the test case if the flags set for the message part does not
       
  1399   match with the expected value. 
       
  1400   @internalTechnology 
       
  1401   @param  aMsgPart  CMsvAttachment of the message part
       
  1402   @param  aExpectedCompleteFlagVal  Expected value of the Complete flag
       
  1403   @pre    None
       
  1404   @post   None
       
  1405 */
       
  1406 
       
  1407 
       
  1408 void CMtfTestActionCompareEmailMessages::CheckFlagSettingsL(CMsvAttachment& aMsgPart, 
       
  1409 														   TBool aExpectedCompleteFlagVal)
       
  1410 	{
       
  1411 	// Check the complete flag settings
       
  1412 	TBool completeFlag	= aMsgPart.Complete();
       
  1413 	
       
  1414 	// Compare the set and the expected complete flag value
       
  1415 	if(aExpectedCompleteFlagVal && completeFlag)
       
  1416 		{
       
  1417 		TestCase().INFO_PRINTF1(_L("Complete Flag is set to ETrue"));
       
  1418 		}
       
  1419 	else if((aExpectedCompleteFlagVal == 0) && (completeFlag == 0))
       
  1420 		{
       
  1421 		TestCase().INFO_PRINTF1(_L("Complete Flag is set to EFalse"));
       
  1422 		}
       
  1423 	else
       
  1424 		{
       
  1425 		TestCase().ERR_PRINTF1(_L("Error: Incorrect Complete flag setting"));
       
  1426 		TestCase().INFO_PRINTF2(_L("Complete Flag is set to %d "), completeFlag);
       
  1427 		TestCase().SetTestStepResult(EFail);
       
  1428 		}
       
  1429 	}
       
  1430 
       
  1431 
       
  1432 /**
       
  1433   CompareHtmlL
       
  1434   Compares the contents of the sent and received html parts. Verifies the complete
       
  1435   and the partial download flags set for the received message's html part.
       
  1436   @internalTechnology 
       
  1437   @pre    None
       
  1438   @post   None
       
  1439 */
       
  1440 void CMtfTestActionCompareEmailMessages::CompareHtmlL()
       
  1441 	{
       
  1442 	// [WorkAround for Html Part Ref1] Begin
       
  1443 
       
  1444 	// Get the Html file names for the sent and the received messages
       
  1445 	TPtrC sentHtmlFileName;
       
  1446 	TInt err1 = iSentMessageInfo->HtmlFileName(sentHtmlFileName);
       
  1447 	TPtrC recvHtmlFileName;
       
  1448 	TInt err2 = iRecvMessageInfo->HtmlFileName(recvHtmlFileName);
       
  1449 	
       
  1450 	// [WorkAround for Html Part Ref1] End
       
  1451 
       
  1452 	// If the sent message has Html part, compare the received message's html part
       
  1453 	if((iSentMessageInfo->GetHtmlSize() > 0) && (err1 == KErrNone))
       
  1454 		{
       
  1455 		if( err2 == KErrNone)
       
  1456 			{
       
  1457 			TInt errorVal;
       
  1458 			TBool diffFlag = EFalse;
       
  1459 
       
  1460 			// Compare the html files
       
  1461 			CompareFilesL(sentHtmlFileName, recvHtmlFileName, errorVal, diffFlag);
       
  1462 			
       
  1463 			if (errorVal == KErrNone )
       
  1464 				{
       
  1465 				if ( diffFlag == EFalse )
       
  1466 					{
       
  1467 					TestCase().INFO_PRINTF1(_L("Comparison of Html files was successful"));
       
  1468 					TestCase().INFO_PRINTF2(_L("Sent Html file : %S"),&sentHtmlFileName );
       
  1469 					TestCase().INFO_PRINTF2(_L("Received Html file : %S"),&recvHtmlFileName );
       
  1470 					
       
  1471 					// Verify the complete and the partial download flags set
       
  1472 					TestCase().INFO_PRINTF1(_L("Expected flag values for Html part:  Complete flag = ETrue, Partial download flag = EFalse"));
       
  1473 					CheckFlagSettingsL( iRecvMessageInfo->GetBodyTextId(), ETrue, EFalse);
       
  1474 					}
       
  1475 				else
       
  1476 					{
       
  1477 					// Comparison of Html files failed
       
  1478 					TestCase().ERR_PRINTF1(_L("Comparison of Html files failed"));
       
  1479 					TestCase().SetTestStepResult(EFail);
       
  1480 					}
       
  1481 				}
       
  1482 			else
       
  1483 				{
       
  1484 				// An error occured while comparing the html files
       
  1485 				TestCase().ERR_PRINTF1(_L("Error occurred while comparing Html files"));
       
  1486 				TestCase().SetTestStepResult(EFail);
       
  1487 				}
       
  1488 			}
       
  1489 		else
       
  1490 			{
       
  1491 			// Received message's html path was not found
       
  1492 			TestCase().ERR_PRINTF1(_L("Html file path not found in the received message"));
       
  1493 			TestCase().SetTestStepResult(EFail);
       
  1494 			}
       
  1495 		}
       
  1496 	else
       
  1497 		{
       
  1498 		TestCase().INFO_PRINTF1(_L("Html file path not found for the sent message"));
       
  1499 		}
       
  1500 	}
       
  1501 
       
  1502 			
       
  1503 /**
       
  1504   CompareFilesL
       
  1505   Compare the contents of two files where the complete path of the two file are provided
       
  1506   @internalTechnology
       
  1507   @param  aSentFilePath		- Pointer buffer contianing file path of the sent message 
       
  1508   @param  aRecvFilePath		- Pointer buffer contianing file path of the received message 
       
  1509   @param  aError			- Any error value set during comparison of files
       
  1510   @param  aDiffFlag			- Set to ETrue if the files differ, else set ot EFalse
       
  1511   @pre    None
       
  1512   @post   None
       
  1513 */
       
  1514 void CMtfTestActionCompareEmailMessages::CompareFilesL(const TPtrC aSentFilePath,
       
  1515 													   const TPtrC aRecvFilePath,
       
  1516 													   TInt& aError, TBool& aDiffFlag)
       
  1517 	{
       
  1518 	aDiffFlag = EFalse;
       
  1519 	CArrayFixFlat<TUint16> *ignoreCharList = new (ELeave)
       
  1520 											CArrayFixFlat<TUint16>(KArrayGranularity);
       
  1521 	CleanupStack::PushL(ignoreCharList);
       
  1522 
       
  1523 	// Compare the content of the attachment files
       
  1524 	aError = TestFrameworkActionsUtils::CompareFilesL(aSentFilePath, aRecvFilePath,
       
  1525 														 EFalse, ignoreCharList, aDiffFlag);
       
  1526 						
       
  1527 	CleanupStack::PopAndDestroy(ignoreCharList);
       
  1528 	}
       
  1529 
       
  1530 
       
  1531 /**
       
  1532   CompareAttachmentsL
       
  1533   Checks if the attachments download for all options of download limits set.
       
  1534   Verifies the Complete and Partial download flag settings for the attachments
       
  1535   in the received message based on the download option and download limits set.
       
  1536   @internalTechnology
       
  1537   @pre    None
       
  1538   @post   None
       
  1539 */
       
  1540 void CMtfTestActionCompareEmailMessages::CompareAttachmentsL()
       
  1541 	{
       
  1542 	TestCase().INFO_PRINTF1(_L("Comparing Attachments"));
       
  1543 
       
  1544 	if(IsTestCaseStatusPass())
       
  1545 		{
       
  1546 		// Get attachment list for Sent and Received message
       
  1547 		CImEmailMessage* sentEmailMessage = iSentMessageInfo->GetEmailMessageL();
       
  1548 		
       
  1549 		CImEmailMessage* recvEmailMessage = iRecvMessageInfo->GetEmailMessageL();
       
  1550 				
       
  1551 		// Call the asynchronous function to get the attachment list
       
  1552 		User::LeaveIfError(iSentMessageInfo->GetMessageAttachmentListL());
       
  1553 		
       
  1554 		//Get the list of attachments present in sent message
       
  1555 		MMsvAttachmentManager& sentManager = sentEmailMessage->AttachmentManager();
       
  1556 		// Get attachment list for Received message
       
  1557 		
       
  1558 		
       
  1559 		// Call the asynchronous function to get the attachment list
       
  1560 		User::LeaveIfError(iRecvMessageInfo->GetMessageAttachmentListL());
       
  1561 
       
  1562 		//Get the list of attachments present in received message
       
  1563 		MMsvAttachmentManager& recvManager = recvEmailMessage->AttachmentManager();
       
  1564 		
       
  1565 		TInt sentMsgAttachmentCount = sentManager.AttachmentCount();
       
  1566 		TInt recvMsgAttachmentCount = recvManager.AttachmentCount();
       
  1567 
       
  1568 		TestCase().INFO_PRINTF3(_L("Sent Attachments: %d, Received Attachments: %d"),
       
  1569 		sentMsgAttachmentCount,recvMsgAttachmentCount); 
       
  1570 
       
  1571 		// Check for the attachment count
       
  1572 		CheckAttachmentCountL(sentMsgAttachmentCount, recvMsgAttachmentCount);
       
  1573 		if(IsTestCaseStatusPass() && recvMsgAttachmentCount)
       
  1574 			{
       
  1575 			TBool toBeDownloaded ;
       
  1576 			TBool downloaded	 ;
       
  1577 			TBool attachmentFound;
       
  1578 
       
  1579 			// Loop through Sent attachment list
       
  1580 			for ( TInt index1 = 0, index2 = 0 ; ( IsTestCaseStatusPass()) && 
       
  1581 						(index1 < sentMsgAttachmentCount) ; index1++)
       
  1582 				{
       
  1583 
       
  1584 				// Get the name of the attachment
       
  1585 				CMsvAttachment* sentAttInfo1 = sentManager.GetAttachmentInfoL(index1);
       
  1586 				CleanupStack::PushL(sentAttInfo1);
       
  1587 				TFileName fileName1 = sentAttInfo1->AttachmentName();
       
  1588 				
       
  1589 				toBeDownloaded	= EFalse;	
       
  1590 				downloaded		= EFalse;
       
  1591 				attachmentFound = EFalse;
       
  1592 
       
  1593 				// Based on the download type set, check if the attachment 
       
  1594 				// was supposed to be downloaded or not
       
  1595 				if(iDownloadType == EPartialDownload)
       
  1596 					{
       
  1597 					// Partial download limits set
       
  1598 					toBeDownloaded = CheckIfAttachmentTobeDownloadedWithPartialDownloadSet
       
  1599 													(sentAttInfo1->AttachmentName(), sentAttInfo1->Size());
       
  1600 													
       
  1601 					}
       
  1602 				else
       
  1603 					{
       
  1604 					// Full download limits set
       
  1605 					toBeDownloaded = CheckIfAttachmentTobeDownloadedWithCompleteDownloadSet(sentAttInfo1->AttachmentName());	
       
  1606 					}
       
  1607 
       
  1608 				// Loop through the received messages to search for the attachment
       
  1609 				// with the same name
       
  1610 				for ( index2 = 0; index2 < recvMsgAttachmentCount; index2++ )
       
  1611 					{
       
  1612 					// Get the attachment name
       
  1613 					CMsvAttachment* recvAttInfo2 = recvManager.GetAttachmentInfoL(index2);
       
  1614 					CleanupStack::PushL(recvAttInfo2);
       
  1615 					TFileName fileName2 = recvAttInfo2->AttachmentName();
       
  1616 
       
  1617 					// Compare the name of the attachment in the sent message with the
       
  1618 					// received message's attachment name
       
  1619 					if ( fileName2.Compare(fileName1) == 0 )
       
  1620 						{
       
  1621 						// Comparison was success, the attachment found in the
       
  1622 						// received message
       
  1623 						attachmentFound = ETrue;
       
  1624 						
       
  1625 						// Check if the attachment was downloaded
       
  1626 						if ( recvAttInfo2->Complete() )
       
  1627 							{
       
  1628 							// Complete flag set to True ==> attachment is downloaded
       
  1629 							downloaded	 = ETrue;
       
  1630 							TestCase().INFO_PRINTF2(_L("Attachment %S is downloaded"),
       
  1631 																		   &fileName2);
       
  1632 							}
       
  1633 						CleanupStack::PopAndDestroy(recvAttInfo2);
       
  1634 						break;
       
  1635 						}						
       
  1636 					CleanupStack::PopAndDestroy(recvAttInfo2);	
       
  1637 					}
       
  1638 				if(attachmentFound == EFalse)
       
  1639 					{
       
  1640 					// Expected attachment is not downloaded
       
  1641 					TestCase().ERR_PRINTF2(_L("Attachment %S was not received"), &fileName1);
       
  1642 					// Test step result is set to EFail
       
  1643 					TestCase().SetTestStepResult(EFail);
       
  1644 					}
       
  1645 				else
       
  1646 					{
       
  1647 					CMsvAttachment* recvAttInfo2 = recvManager.GetAttachmentInfoL(index2);
       
  1648 					CleanupStack::PushL(recvAttInfo2);
       
  1649 					if ( toBeDownloaded && downloaded )
       
  1650 						{
       
  1651 						//compare sent and received attachment contents
       
  1652 						TInt error = 0;
       
  1653 						TBool diffFlag = EFalse;
       
  1654 
       
  1655 						CompareFilesL(sentAttInfo1->FilePath(),
       
  1656 									  recvAttInfo2->FilePath(), error, diffFlag);
       
  1657 						
       
  1658 						if ((error != KErrNone) || (diffFlag) )
       
  1659 							{
       
  1660 							// Comparison of sent and received attachment fails
       
  1661 							TestCase().ERR_PRINTF2(_L("Comparison of %S attachment failed"), 
       
  1662 														&fileName1);
       
  1663 							// Test step result is set to EFail
       
  1664 							TestCase().SetTestStepResult(EFail);
       
  1665 							}
       
  1666 
       
  1667 						if(IsTestCaseStatusPass())
       
  1668 							{
       
  1669 							// The attachments contents are same
       
  1670 							TestCase().INFO_PRINTF2(_L("Comparison of attachment %S was success"),
       
  1671 														&fileName1);
       
  1672 							}
       
  1673 
       
  1674 						// Verify the complete and the partial download flags set
       
  1675 						TestCase().INFO_PRINTF1(_L("Expected flag values for Attachment:  Complete flag = ETrue, Partial download flag = EFalse"));
       
  1676 						CheckFlagSettingsL(*recvAttInfo2 , ETrue);
       
  1677 						}
       
  1678 					else if(toBeDownloaded  && (downloaded == EFalse))
       
  1679 						{
       
  1680 						// Expected attachment is not downloaded
       
  1681 						TestCase().ERR_PRINTF2(_L("Attachment %S was not downloaded"), 
       
  1682 																		&fileName1);
       
  1683 						// Test step result is set to EFail
       
  1684 						TestCase().SetTestStepResult(EFail);
       
  1685 
       
  1686 						}
       
  1687 					else if( (toBeDownloaded == EFalse)  && (downloaded)) 
       
  1688 						{
       
  1689 						
       
  1690 						// Unexpected attachment has been downloaded
       
  1691 						TestCase().ERR_PRINTF2(_L("Attachment %S was received, but not expected"), 
       
  1692 																					&fileName1);
       
  1693 						// Test step result is set to EFail
       
  1694 						TestCase().SetTestStepResult(EFail);
       
  1695 						}	
       
  1696 					else if((toBeDownloaded == EFalse)  && (downloaded == EFalse)) 
       
  1697 						{
       
  1698 						// Verify the flags
       
  1699 						TestCase().INFO_PRINTF2(_L("The attachment %S was not downloaded"),&fileName1);	
       
  1700 						TestCase().INFO_PRINTF1(_L("Expected flag values for Attachment:  Complete flag = EFalse, Partial download flag = EFalse"));
       
  1701 						CheckFlagSettingsL(*recvAttInfo2, EFalse);
       
  1702 						}
       
  1703 				CleanupStack::PopAndDestroy(recvAttInfo2);	
       
  1704 					}
       
  1705 				CleanupStack::PopAndDestroy(sentAttInfo1);	
       
  1706 				}
       
  1707 			}
       
  1708 		}
       
  1709 	}
       
  1710 
       
  1711 
       
  1712 /**
       
  1713   CheckAttachmentCountL
       
  1714   Checks if the number of attachments in the received message is correct. 
       
  1715   Otherwise, fails the Test Case.
       
  1716   @internalTechnology
       
  1717   @param  aSentMsgAttachmentCount - Number of attachments in the sent message 
       
  1718   @param  aRecvMsgAttachmentCount - Number of attachments in the sent message
       
  1719   @pre    None
       
  1720   @post   None
       
  1721 */
       
  1722 
       
  1723 	
       
  1724 void CMtfTestActionCompareEmailMessages::CheckAttachmentCountL(TInt aSentMsgAttachmentCount, TInt aRecvMsgAttachmentCount)
       
  1725 	{
       
  1726 	TInt32 sentMsgSize;
       
  1727 	
       
  1728 	User::LeaveIfError( iSentMessageInfo->GetMessageSize(sentMsgSize) );	
       
  1729 	if( iDownloadType == EFullDownload )
       
  1730 		{	
       
  1731 		// if attachment download allowed
       
  1732 		if( iImapCompleteDownloadLimits.iGetMailBodyParts != EGetImap4EmailHeaders && 
       
  1733 			iImapCompleteDownloadLimits.iGetMailBodyParts != EGetImap4EmailBodyText ) 
       
  1734 			{
       
  1735 			if( sentMsgSize <= iImapCompleteDownloadLimits.iMaxEmailSize && aSentMsgAttachmentCount != aRecvMsgAttachmentCount )
       
  1736 				{
       
  1737 				TestCase().ERR_PRINTF1(_L("Full Download Number of attachments are not equal"));
       
  1738 				TestCase().SetTestStepResult(EFail);
       
  1739 				}			
       
  1740 			}
       
  1741 		else if( aRecvMsgAttachmentCount > 0 )  // no attachment downloads allowed -should not recieve any attachments
       
  1742 			{
       
  1743 			TestCase().ERR_PRINTF1(_L("Download with EGetImap4EmailHeaders or EGetImap4EmailBodyText Attachment count is not equal to 0"));
       
  1744 			TestCase().SetTestStepResult(EFail);			
       
  1745 			}
       
  1746 		
       
  1747 		
       
  1748 		/*
       
  1749 		// if only downloading headers or body text just check we havent recieved any attachments				
       
  1750 	    if( ( iImapCompleteDownloadLimits.iGetMailBodyParts == EGetImap4EmailHeaders || 
       
  1751 	    	iImapCompleteDownloadLimits.iGetMailBodyParts == EGetImap4EmailBodyText )  &&
       
  1752 			aRecvMsgAttachmentCount > 0 )
       
  1753 			{		
       
  1754 			TestCase().ERR_PRINTF1(_L("Download with EGetImap4EmailHeaders, Attachment count is not equal to 0"));
       
  1755 			TestCase().SetTestStepResult(EFail);
       
  1756 			}
       
  1757 		// check that the total size limit should allow all attachments to be 
       
  1758 		// downloaded and that the attachment counts are equal
       
  1759 		else if( sentMsgSize <= iImapCompleteDownloadLimits.iMaxEmailSize && aSentMsgAttachmentCount != aRecvMsgAttachmentCount )
       
  1760 			{
       
  1761 			TestCase().ERR_PRINTF1(_L("Full Download Number of attachments are not equal"));
       
  1762 			TestCase().SetTestStepResult(EFail);
       
  1763 			}			
       
  1764 			*/
       
  1765 		}
       
  1766 	else if( iDownloadType == EPartialDownload )
       
  1767 		{
       
  1768 		// if attatchment download allowed
       
  1769 		if( iImapPartialDownloadLimits.iPartialMailOptions != EBodyTextOnly )
       
  1770 			{			
       
  1771 			// if message size is below the max then attchments downloaded should match attachments sent
       
  1772 			if( sentMsgSize <= iImapPartialDownloadLimits.iTotalSizeLimit && 
       
  1773 			    aSentMsgAttachmentCount != aRecvMsgAttachmentCount )
       
  1774 				{
       
  1775 				TestCase().ERR_PRINTF1(_L("Partial Download Number of attachments are not equal"));
       
  1776 				TestCase().SetTestStepResult(EFail);
       
  1777 				}
       
  1778 			}
       
  1779 		else if( aRecvMsgAttachmentCount > 0 )  // body text only - should not recieve any attachments
       
  1780 			{
       
  1781 			TestCase().ERR_PRINTF1(_L("Download with EBodyTextOnly, Attachments will not be downloaded"));
       
  1782 			}		
       
  1783 		}
       
  1784 	else
       
  1785 		{
       
  1786 		TestCase().ERR_PRINTF1(_L("Unknown value for iDownloadType"));
       
  1787 		TestCase().SetTestStepResult(EFail);
       
  1788 		}					
       
  1789 	}
       
  1790 
       
  1791 
       
  1792 /**
       
  1793   CheckIfAttachmentTobeDownloadedWithCompleteDownloadSet
       
  1794   Checks if the attachment download when Full download options is set.
       
  1795   @internalTechnology
       
  1796   @return TBool  ETrue if attachment is to be downloaded, EFalse otherwise
       
  1797   @pre    None
       
  1798   @post   None
       
  1799 */
       
  1800 TBool CMtfTestActionCompareEmailMessages::
       
  1801 							CheckIfAttachmentTobeDownloadedWithCompleteDownloadSet(const TDesC& aAttachmentName /*const TDesC8& aMimeType*/)
       
  1802 	{
       
  1803 	TBool toBeCompletelyDownloadedFlag = EFalse;
       
  1804 
       
  1805 	if(iDownloadType == EFullDownload)
       
  1806 		{		
       
  1807 		switch(iImapCompleteDownloadLimits.iGetMailBodyParts)
       
  1808 			{
       
  1809 			case EGetImap4EmailHeaders:
       
  1810 				toBeCompletelyDownloadedFlag = EFalse;
       
  1811 			break;
       
  1812 
       
  1813 			case EGetImap4EmailBodyText:
       
  1814 				toBeCompletelyDownloadedFlag = EFalse;
       
  1815 			break;
       
  1816 
       
  1817 			case EGetImap4EmailAttachments:
       
  1818 				toBeCompletelyDownloadedFlag = ETrue;
       
  1819 			break;
       
  1820 			
       
  1821 			case EGetImap4EmailBodyTextAndAttachments:
       
  1822 				toBeCompletelyDownloadedFlag = ETrue;
       
  1823 			break;
       
  1824 			
       
  1825 			case EGetImap4EmailBodyAlternativeText:
       
  1826 				// Check is done against filename because Mime_type field isn't filled out
       
  1827 				if ( aAttachmentName.CompareF(_L("calendar.ics")) == 0 )
       
  1828 					{
       
  1829 					toBeCompletelyDownloadedFlag = ETrue;
       
  1830 					}
       
  1831 			break;
       
  1832 			}
       
  1833 		}
       
  1834 	return 	toBeCompletelyDownloadedFlag;
       
  1835 	}
       
  1836 
       
  1837 
       
  1838 /**
       
  1839   CheckIfAttachmentTobeDownloadedWithPartialDownloadSet
       
  1840   Checks if the attachment download when Partial download options is set.
       
  1841   @internalTechnology
       
  1842   @param  aAttachmentSize  Size of the attachment
       
  1843   @return TBool  ETrue if attachment is to be downloaded, EFalse otherwise
       
  1844   @pre    None
       
  1845   @post   None
       
  1846 */
       
  1847 TBool CMtfTestActionCompareEmailMessages::
       
  1848 			CheckIfAttachmentTobeDownloadedWithPartialDownloadSet
       
  1849 										  (const TDesC& aAttachmentName, TInt32 aAttachmentSize)
       
  1850 	{
       
  1851 	// [WorkAround for Attachments Ref1] Begin
       
  1852 	TInt32 recvAttachmentSize = (TInt32)(aAttachmentSize * ATTACHMENT_SIZE_CORRECTION);
       
  1853 	// [WorkAround for Attachments Ref1] End
       
  1854 
       
  1855 	TBool toBePartialyDownloadedFlag = EFalse;
       
  1856 
       
  1857 	if(iDownloadType == EPartialDownload)
       
  1858 		{		
       
  1859 		switch(iImapPartialDownloadLimits.iPartialMailOptions)
       
  1860 			{
       
  1861 			case ENoSizeLimits:
       
  1862 				toBePartialyDownloadedFlag = ETrue;
       
  1863 			break;
       
  1864 			
       
  1865 			case EBodyTextOnly:
       
  1866 				toBePartialyDownloadedFlag = EFalse;
       
  1867 			break;
       
  1868 			
       
  1869 			case EAttachmentsOnly:
       
  1870 				if( recvAttachmentSize <= iImapPartialDownloadLimits.iAttachmentSizeLimit)
       
  1871 					{
       
  1872 					toBePartialyDownloadedFlag = ETrue;
       
  1873 					}
       
  1874 			break;
       
  1875 			
       
  1876 			case EBodyTextAndAttachments:
       
  1877 				if( recvAttachmentSize <= iImapPartialDownloadLimits.iAttachmentSizeLimit)
       
  1878 					{
       
  1879 					toBePartialyDownloadedFlag = ETrue;
       
  1880 					}
       
  1881 			break;
       
  1882 
       
  1883 			case ECumulative:
       
  1884 				if( recvAttachmentSize <= iCumulativeSize)
       
  1885 					{
       
  1886 					toBePartialyDownloadedFlag = ETrue;
       
  1887 					iCumulativeSize = iCumulativeSize - recvAttachmentSize;
       
  1888 					}
       
  1889 			break;
       
  1890 
       
  1891 			case EBodyAlternativeText:
       
  1892 				// Check is done against filename because Mime_type field isn't filled out
       
  1893 				if( recvAttachmentSize <= iImapPartialDownloadLimits.iAttachmentSizeLimit &&
       
  1894 					 aAttachmentName.CompareF(_L("calendar.ics")) == 0 )
       
  1895 					{
       
  1896 					toBePartialyDownloadedFlag = ETrue;
       
  1897 					}
       
  1898 			break;
       
  1899 			} 
       
  1900 		}
       
  1901 	return toBePartialyDownloadedFlag;
       
  1902 	}