messagingfw/msgtestfw/TestActions/SendAs/src/CMtfTestActionVerifyRecipients.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 // VerifyRecipients
       
    17 // [Action Parameters]
       
    18 // CMsvEntry	paramMsgEntry	   <input>: Reference to the message entry object
       
    19 // CMsvStore	paramMsgStore	   <input>: Reference to the message's store object
       
    20 // TFieldList	paramRecipientType <input>: Enumeration specifying the message field type
       
    21 // (One of the enumeration values: ETo, ECc EBcc.
       
    22 // Other enumerations are currently not supported) 
       
    23 // HBufC		Address1	 <input>: String containing Recipient Address
       
    24 // HBufC		Address2	 <input>: String containing Recipient Address
       
    25 // HBufC		addressN	 <input>: String containing Recipient Address
       
    26 // [Action Description]
       
    27 // VerifyRecipients Test Action is intended verify the recipient address set for
       
    28 // the message using SendAs API, by comparing it with the recipient addresses provided
       
    29 // as input to the Test Action.
       
    30 // [APIs Used]
       
    31 // CImHeader::RestoreL ()
       
    32 // CImHeader::ToRecipients ()
       
    33 // CImHeader::CcRecipients ()
       
    34 // CImHeader::BccRecipients ()
       
    35 // CSmsHeader::RestoreL ()
       
    36 // CSmsHeader::Recipients()
       
    37 // CSmsNumber::Address()
       
    38 // CIrHeader::RestoreL ()
       
    39 // CBtHeader::RestoreL()
       
    40 // CObexMtmHeader::Addr ()
       
    41 // __ACTION_INFO_END__
       
    42 // 
       
    43 //
       
    44 
       
    45 /**
       
    46  @file 
       
    47  @internalTechnology 
       
    48 */
       
    49 
       
    50 
       
    51 // User include
       
    52 #include "CMtfTestActionVerifyRecipients.h"
       
    53 #include "CMtfTestCase.h"
       
    54 #include "CMtfTestActionParameters.h"
       
    55 #include "CMtfTestActionUtilsMessage.h"
       
    56 
       
    57 #include "btmsgtypeuid.h"
       
    58 #include "irmsgtypeuid.h"
       
    59 
       
    60 //Granularity for CArrayFixFlat arrays
       
    61 const TInt KArrayGranularity = 16;
       
    62 
       
    63 /**
       
    64   NewL()
       
    65   Constructs a CMtfTestActionVerifyRecipients object.
       
    66   Uses two phase construction and leaves nothing on the CleanupStack.   
       
    67   @internalTechnology
       
    68   @param  aTestCase         Test Case to which this Test Action belongs
       
    69   @param  aActionParameters Action parameters, must not be NULL
       
    70   @return Created object of type CMtfTestActionVerifyRecipients
       
    71   @pre    None
       
    72   @post   CMtfTestActionVerifyRecipients object is created
       
    73 */
       
    74 CMtfTestAction* CMtfTestActionVerifyRecipients::
       
    75 		NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    76 	{
       
    77 	CMtfTestActionVerifyRecipients* self = 
       
    78 							new (ELeave) CMtfTestActionVerifyRecipients(aTestCase);
       
    79 
       
    80 	CleanupStack::PushL(self);
       
    81 	self->ConstructL(aActionParameters);
       
    82 	CleanupStack::Pop(self);
       
    83 	return self;
       
    84 	}
       
    85 	
       
    86 
       
    87 /**
       
    88   CMtfTestActionVerifyRecipients constructor
       
    89   Calls the base class' constructor
       
    90   @internalTechnology  
       
    91   @param  aTestCase  Test Case to which this Test Action belongs
       
    92   @pre    None
       
    93   @post   None
       
    94 */ 
       
    95 CMtfTestActionVerifyRecipients::CMtfTestActionVerifyRecipients(CMtfTestCase& aTestCase)
       
    96 	: CMtfSynchronousTestAction(aTestCase)
       
    97 	{
       
    98 	}
       
    99 
       
   100 /**
       
   101   Function : ~CMtfTestActionVerifyRecipients
       
   102   Description : Destructor
       
   103   @internalTechnology
       
   104   @param :
       
   105   @return : 
       
   106   @pre 
       
   107   @post 
       
   108 */
       
   109 CMtfTestActionVerifyRecipients::~CMtfTestActionVerifyRecipients()
       
   110 	{
       
   111 	}
       
   112 
       
   113 /**
       
   114   ExecuteActionL
       
   115   Verifies whther the recipient address of a specified type	(ETo, ECc EBcc)
       
   116   is set by comparing the set value(s) with the expected recipient address string(s)
       
   117   @internalTechnology 
       
   118   @pre    None
       
   119   @post   None
       
   120   @leave  System wide errors
       
   121 */
       
   122 void CMtfTestActionVerifyRecipients::ExecuteActionL()
       
   123 	{
       
   124 	if((TestCase().TestStepResult()) == EPass)
       
   125 		{
       
   126 		TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionVerifyRecipients);
       
   127 			
       
   128 		// Get Test Action input parameters
       
   129 		CMsvEntry*	paramMsgEntry = ObtainParameterReferenceL<CMsvEntry>(TestCase(),
       
   130 										ActionParameters().Parameter(0));
       
   131 										
       
   132 		TImHeaderEncodingInfo::TFieldList paramRecipientType = 
       
   133 								   ObtainValueParameterL<TImHeaderEncodingInfo::TFieldList>(TestCase(), ActionParameters().Parameter(1));
       
   134 
       
   135 		if (paramMsgEntry == NULL)
       
   136 			{
       
   137 			TestCase().ERR_PRINTF1(_L("Invalid parameter: Message Entry value is NULL"));
       
   138 			TestCase().SetTestStepResult(EFail);
       
   139 			}
       
   140 			
       
   141 		if((TestCase().TestStepResult()) == EPass)	
       
   142 			{
       
   143 			CMsvStore * msvStore = NULL;
       
   144 			
       
   145 			if(paramMsgEntry->HasStoreL())
       
   146 				{
       
   147 				msvStore = paramMsgEntry->ReadStoreL();
       
   148 				CleanupStack::PushL(msvStore);
       
   149 				}
       
   150 			
       
   151 			CDesC16ArrayFlat* recipientArray = new (ELeave) CDesC16ArrayFlat(KArrayGranularity);
       
   152 			CleanupStack::PushL(recipientArray);
       
   153 		
       
   154 			// Read the recipient address and alias names from the ini file
       
   155 			TRAPD(result, ObtainRecipientsL(paramMsgEntry , *recipientArray));
       
   156 			
       
   157 			if (result != KErrNone)
       
   158 				{
       
   159 				TestCase().ERR_PRINTF2(_L("Failure while reading the recipients from ini file: %d"), result);
       
   160 				TestCase().SetTestStepResult(EFail);
       
   161 				}
       
   162 			else
       
   163 				{
       
   164 				// Call function to verify the recipient address for the message
       
   165 			 	result = VerifyRecipientsL(*paramMsgEntry, *msvStore, paramRecipientType, *recipientArray);
       
   166 			 	if (result == KErrNone)
       
   167 					{
       
   168 					TestCase().INFO_PRINTF2(_L("Verification of recipient address was successful: %d"), result);
       
   169 					}
       
   170 				else if (result == KErrNotFound)
       
   171 					{
       
   172 					TestCase().ERR_PRINTF1(_L("Recipient address was not found in the message"));
       
   173 					TestCase().SetTestStepResult(EFail);			
       
   174 					}
       
   175 				else
       
   176 					{
       
   177 					TestCase().ERR_PRINTF2(_L("Verification of Recipient address failed with error: %d"), result);
       
   178 					TestCase().SetTestStepResult(EFail);			
       
   179 					}
       
   180 				}
       
   181 			CleanupStack::PopAndDestroy(recipientArray);
       
   182 			CleanupStack::PopAndDestroy(msvStore);
       
   183 			}
       
   184 		}
       
   185 			
       
   186 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionVerifyRecipients);
       
   187 	TestCase().ActionCompletedL(*this);
       
   188 	}
       
   189 	
       
   190 	
       
   191 /** 
       
   192  Reads the recipient address and the alias names from the ini file and formats the 
       
   193  recipient address if the alias type is specified
       
   194 */ 
       
   195 void CMtfTestActionVerifyRecipients::ObtainRecipientsL(CMsvEntry* aMsvEntry, CDesC16ArrayFlat&  aRecipientArray)
       
   196 	{
       
   197 	TInt numberOfParameters = ActionParameters().Count();
       
   198 
       
   199 	for(TInt index = 2; index < numberOfParameters ; index+=2)
       
   200 		{
       
   201 		HBufC* recipientAddr = ObtainParameterReferenceL<HBufC>(TestCase(),
       
   202 									ActionParameters().Parameter(index));
       
   203 		
       
   204 		HBufC* aliasBuf = ObtainParameterReferenceL<HBufC>(TestCase(),
       
   205 									ActionParameters().Parameter(index+1),NULL);
       
   206 									
       
   207 		// If alias is not provided, then copy the address into the array
       
   208 		// For IR, BT and SMS, ignore the alias type set in the ini file							
       
   209 		if((aliasBuf == NULL) || (aMsvEntry->Entry().iMtm != (KUidMsgTypeSMTP)))
       
   210 			{
       
   211 			TPtrC ptr16 = recipientAddr->Des();
       
   212 			aRecipientArray.AppendL(ptr16);	
       
   213 			}
       
   214 		else
       
   215 			{
       
   216 			// For SMTP message, format the recipient address with the alias
       
   217 			if((aMsvEntry->Entry().iMtm) == (KUidMsgTypeSMTP))
       
   218 				{
       
   219 				// To be done: String formating to include both alias and address
       
   220 				TPtrC ptr16 = recipientAddr->Des();
       
   221 				_LIT(KFormat,"\"%S\" <%S>");
       
   222 				TBuf<256> x;
       
   223 				x.Format(KFormat,aliasBuf,recipientAddr);
       
   224 				aRecipientArray.AppendL(x);
       
   225 				}
       
   226 			}		
       
   227 		}
       
   228 	}
       
   229 
       
   230 
       
   231 /**
       
   232  Based on the type of the message, calls the corresponding utility function
       
   233  to verify the specified type of recipient address
       
   234 */
       
   235 TInt CMtfTestActionVerifyRecipients::VerifyRecipientsL (CMsvEntry& aMsgEntry,
       
   236 								CMsvStore & aMsgStore,
       
   237 								TImHeaderEncodingInfo::TFieldList recipientType,
       
   238 								CDesC16Array&  aRecipientArray)
       
   239 	{
       
   240 	TInt returnValue = KErrNone;
       
   241 	TUid msgMtmType = aMsgEntry.Entry().iMtm;
       
   242 
       
   243 	if( (msgMtmType == KUidMsgTypeIMAP4) || (msgMtmType == KUidMsgTypePOP3) || (msgMtmType == KUidMsgTypeSMTP) )
       
   244 		{
       
   245 		returnValue = CMtfTestActionUtilsMessage::VerifyEmailRecipientsL(aMsgStore, aRecipientArray,recipientType);
       
   246 		}
       
   247 	else if((msgMtmType == KUidMsgTypeBt) || (msgMtmType == KUidMsgTypeIrUID))
       
   248 		{
       
   249 		returnValue = CMtfTestActionUtilsMessage::VerifyObexRecipientL(aMsgEntry, aMsgStore, aRecipientArray);	
       
   250 		}
       
   251 	else if (msgMtmType == KUidMsgTypeSMS)
       
   252 		{
       
   253 		returnValue = CMtfTestActionUtilsMessage::VerifySmsRecipientsL(aMsgStore,aRecipientArray);	
       
   254 		}
       
   255 	else
       
   256 		{
       
   257 		returnValue = KErrUnknown;
       
   258 		}
       
   259 		
       
   260 	return returnValue;
       
   261 	}
       
   262 	
       
   263