messagingfw/msgtestfw/TestActions/SendAs/src/CMtfTestActionSendAsAddRecipient.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 // SendAsAddRecipient
       
    17 // [Action Parameters]
       
    18 // RSendAsMessage			sendAsMessage	<input>			: Reference of  the RSendAsMessage object
       
    19 // TDesC					recipientAddress<input>			: Recipient address
       
    20 // TDesC					alias			<input>			: Alias of recipient addresses. Default value implies no Alias information is provided
       
    21 // TSendAsRecipientType		recipientType	<input>			: Type of recipient (ESendAsRecipientTo or ESendAsRecipientCc or  ESendAsRecipientBcc)
       
    22 // TMsvId 					paramServiceId	<input>			: Value of the SMTP service id. Recipient address determined using this ID for SMTP message. 
       
    23 // [Action Description]
       
    24 // SendAsAddRecipient Test Action is intended to add a recipient of type 
       
    25 // 'To' or 'Cc' or 'Bcc' address to the created message.  The type ('To' or 'Cc' or 'Bcc')
       
    26 // is specified as an input to the Test Action.  If the alias information is provided,
       
    27 // the alias information will be set along 
       
    28 // with the recipient address, otherwise, only the recipient address will be set.
       
    29 // [APIs Used]
       
    30 // 1.	RSendAsMessage::AddRecipient(const TDesC& aAddress, TSendAsRecipientType aRecipientType)
       
    31 // 2.	RSendAsMessage::AddRecipient(const TDesC& aAddress, const TDesC& aAlias, 
       
    32 // TSendAsRecipientType aRecipientType); 
       
    33 // __ACTION_INFO_END__
       
    34 // 
       
    35 //
       
    36 
       
    37 /**
       
    38  @file 
       
    39  @internalTechnology 
       
    40 */
       
    41 
       
    42 // User include
       
    43 #include "CMtfTestActionSendAsAddRecipient.h"
       
    44 #include "CMtfTestCase.h"
       
    45 #include "CMtfTestActionParameters.h"
       
    46 #include "TestFrameworkActionsUtils.h"
       
    47 #include "CMtfTestActionUtilsMessage.h"
       
    48 #include "CMtfTestActionUtilsConfigFileMachineName.h"
       
    49 
       
    50 #include <btmsgtypeuid.h>
       
    51 #include <cemailaccounts.h>
       
    52 /**
       
    53   NewL()
       
    54   Constructs a CMtfTestActionSendAsAddRecipient object.
       
    55   Uses two phase construction and leaves nothing on the CleanupStack.   
       
    56   @internalTechnology
       
    57   @param  aTestCase         Test Case to which this Test Action belongs
       
    58   @param  aActionParameters Action parameters, must not be NULL
       
    59   @return Created object of type CMtfTestActionSendAsAddRecipient
       
    60   @pre    None
       
    61   @post   CMtfTestActionSendAsAddRecipient object is created
       
    62 */
       
    63 CMtfTestAction* CMtfTestActionSendAsAddRecipient::
       
    64 		NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    65 	{
       
    66 	CMtfTestActionSendAsAddRecipient* self = 
       
    67 							new (ELeave) CMtfTestActionSendAsAddRecipient(aTestCase);
       
    68 
       
    69 	CleanupStack::PushL(self);
       
    70 	self->ConstructL(aActionParameters);
       
    71 	CleanupStack::Pop(self);
       
    72 	return self;
       
    73 	}
       
    74 	
       
    75 
       
    76 /**
       
    77   CMtfTestActionSendAsAddRecipient constructor
       
    78   Calls the base class' constructor
       
    79   @internalTechnology  
       
    80   @param  aTestCase  Test Case to which this Test Action belongs
       
    81   @pre    None
       
    82   @post   None
       
    83 */ 
       
    84 CMtfTestActionSendAsAddRecipient::CMtfTestActionSendAsAddRecipient(CMtfTestCase& aTestCase)
       
    85 	: CMtfSynchronousTestAction(aTestCase)
       
    86 	{
       
    87 	}
       
    88 
       
    89 /**
       
    90   Function : ~CMtfTestActionSendAsCloseAndDeleteMessage
       
    91   Description : Destructor
       
    92   @internalTechnology
       
    93   @param :
       
    94   @return : 
       
    95   @pre 
       
    96   @post 
       
    97 */
       
    98 CMtfTestActionSendAsAddRecipient::~CMtfTestActionSendAsAddRecipient()
       
    99 	{
       
   100 	}
       
   101 
       
   102 
       
   103 /**
       
   104   ExecuteActionL
       
   105 	Obtain the input parameters
       
   106 	1.	sendAsMessage
       
   107 	2.	recipientAddress
       
   108 	3.	alias  (Default value implies empty string)
       
   109 	4.	recipientType 
       
   110 	IF alias for recipient address is provided as input 
       
   111 	Call RSendAsMessage::AddRecipient (const TDesC& aAddress, const TDesC& aAlias, 
       
   112 	TSendAsRecipientType aRecipientType) passing recipientAddress, alias and
       
   113 	recipientType as input parameters
       
   114     ELSE 
       
   115 	Call RSendAsMessage::AddRecipient (const TDesC& aAddress, TSendAsRecipientType aRecipientType) passing recipientAddress and recipientType as input parameters
       
   116 
       
   117   @internalTechnology 
       
   118   @pre    None
       
   119   @post   None
       
   120   @leave  System wide errors
       
   121 */
       
   122 void CMtfTestActionSendAsAddRecipient::ExecuteActionL()
       
   123 	{
       
   124 	if((TestCase().TestStepResult()) == EPass)
       
   125 		{
       
   126 		TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendAsAddRecipient);
       
   127 	
       
   128 		// Get test action input parameters
       
   129 		RSendAsMessage sendAsMessage = ObtainValueParameterL<RSendAsMessage>(TestCase(),
       
   130 											ActionParameters().Parameter(0));
       
   131 
       
   132 		HBufC*  recipientAddress	 = ObtainParameterReferenceL<HBufC>(TestCase(),
       
   133 											ActionParameters().Parameter(1), NULL);
       
   134 
       
   135 		
       
   136 		HBufC* alias				 = ObtainParameterReferenceL<HBufC>(TestCase(),
       
   137 											ActionParameters().Parameter(2), NULL);
       
   138 
       
   139 		RSendAsMessage::TSendAsRecipientType recipientType	
       
   140 									 = ObtainValueParameterL<RSendAsMessage::TSendAsRecipientType>(TestCase(),
       
   141 											ActionParameters().Parameter(3));
       
   142 
       
   143 		TUid msgTypeId				 =  ObtainValueParameterL<TUid>(TestCase(),
       
   144 											ActionParameters().Parameter(4));
       
   145 											
       
   146 		TInt expectedErr			 =  ObtainValueParameterL<TInt>(TestCase(),
       
   147 											ActionParameters().Parameter(5));
       
   148 		
       
   149 		TInt err = KErrNone;
       
   150 		TBuf16<3> btAddress;
       
   151 
       
   152 		if(recipientAddress == NULL)
       
   153 			{
       
   154 			if( msgTypeId.operator == (KUidMsgTypeSMTP))
       
   155 				{
       
   156 				TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(), ActionParameters().Parameter(6), 0);
       
   157 				CImSmtpSettings* settings = new(ELeave) CImSmtpSettings();
       
   158 				CleanupStack::PushL(settings);
       
   159 		 		
       
   160 		 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   161 		 		TSmtpAccount smtpAccount;
       
   162 		 		accounts->GetSmtpAccountL(paramServiceId, smtpAccount);
       
   163 				accounts->LoadSmtpSettingsL(smtpAccount, *settings);
       
   164 				CleanupStack::PopAndDestroy(accounts);
       
   165 				
       
   166 				recipientAddress=settings->EmailAddress().AllocL();
       
   167 				CleanupStack::PopAndDestroy(settings);
       
   168 				}
       
   169 			else
       
   170 				{
       
   171 				TestCase().ERR_PRINTF1(_L("Recipient address is not provided"));
       
   172 				TestCase().SetTestStepResult(EFail);
       
   173 				}
       
   174 			}
       
   175 		else
       
   176 			{
       
   177 			if( msgTypeId.operator == (KUidMsgTypeBt))
       
   178 				{
       
   179 				CMtfTestActionUtilsMessage::FormatBtRecipientAddress(*recipientAddress, btAddress);
       
   180 				}
       
   181 				
       
   182 			}
       
   183 		if((TestCase().TestStepResult()) == EPass)
       
   184 			{
       
   185 			if(alias == NULL )
       
   186 				{
       
   187 				if( msgTypeId.operator == (KUidMsgTypeBt))
       
   188 					{
       
   189 					TRAP(err,sendAsMessage.AddRecipientL(btAddress, recipientType));
       
   190 					}
       
   191 				else
       
   192 					{
       
   193 					TRAP(err,sendAsMessage.AddRecipientL(*recipientAddress, recipientType));
       
   194 					}
       
   195 				if(err == expectedErr)
       
   196 					{
       
   197 					TestCase().INFO_PRINTF1(_L("Recipient address added successfully"));	
       
   198 					}
       
   199 				else
       
   200 					{
       
   201 					TestCase().ERR_PRINTF2(_L("Add Recipient address failed with error %d"), err);
       
   202 					}
       
   203 				}
       
   204 			else
       
   205 				{
       
   206 				if( msgTypeId.operator == (KUidMsgTypeBt))
       
   207 					{
       
   208 					TRAP(err,sendAsMessage.AddRecipientL(btAddress, alias->Des(), recipientType));
       
   209 					}
       
   210 				else
       
   211 					{
       
   212 					TRAP(err, sendAsMessage.AddRecipientL(recipientAddress->Des(), alias->Des(), recipientType));
       
   213 					}
       
   214 
       
   215 				if (err == expectedErr)
       
   216 					{
       
   217 					if(err == KErrNone)
       
   218 						{
       
   219 						TestCase().INFO_PRINTF1(_L("Recipient address with alias added successfully"));						
       
   220 						}
       
   221 					else
       
   222 						{
       
   223 						TestCase().INFO_PRINTF1(_L("Recipient address with alias failed with expected error"));
       
   224 						}
       
   225 					}
       
   226 				else
       
   227 					{
       
   228 					TestCase().ERR_PRINTF2(_L("Add Recipient address with alias failed with error %d"), err);
       
   229 					}
       
   230 				}
       
   231 			}
       
   232 		StoreParameterL<HBufC>(TestCase(),*recipientAddress,ActionParameters().Parameter(7));						
       
   233 		TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsAddRecipient);
       
   234 		}
       
   235 	TestCase().ActionCompletedL(*this);
       
   236 	}
       
   237