messagingfw/msgtestfw/TestActions/SendAs/src/CMtfTestActionSendAsAddAttachment.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 // SendAsAddAttachment
       
    17 // [Action Parameters]
       
    18 // RSendAsMessage			sendAsMessage	<input>		: Reference of  the RSendAsMessage object
       
    19 // HBufC						attachmentFile	<input>		: The file to be attached
       
    20 // HBufC						mimeType		<input>		: MIME type.Default value implies that no MIME type is specified
       
    21 // [Action Description]
       
    22 // SendAsAddAttachment Test Action is intended to add non-linked attachment 
       
    23 // to the created message.  If the
       
    24 // MIME type is provided as an input, the MIME type for the attachment is set.
       
    25 // [APIs Used]
       
    26 // RSendAsMessage::AddAttachment(RFs& aFs, RFile& aAttachmentFile, const TDesC& aMimeType)
       
    27 // RSendAsMessage::AddAttachment(RFs& aFs, RFile& aAttachmentFile)
       
    28 // __ACTION_INFO_END__
       
    29 // 
       
    30 //
       
    31 
       
    32 /**
       
    33  @file 
       
    34  @internalTechnology 
       
    35 */
       
    36 
       
    37 
       
    38 // User include
       
    39 #include "sendas2.h"
       
    40 #include "CMtfTestActionSendAsAddAttachment.h"
       
    41 #include "CMtfTestCase.h"
       
    42 #include "CMtfTestActionParameters.h"
       
    43 
       
    44 #include "MtfTestActionUtilsUser.h"
       
    45 
       
    46 /**
       
    47   NewL()
       
    48   Constructs a CMtfTestActionSendAsAddAttachment object.
       
    49   Uses two phase construction and leaves nothing on the CleanupStack.   
       
    50   @internalTechnology
       
    51   @param  aTestCase         Test Case to which this Test Action belongs
       
    52   @param  aActionParameters Action parameters, must not be NULL
       
    53   @return Created object of type CMtfTestActionSendAsAddAttachment
       
    54   @pre    None
       
    55   @post   CMtfTestActionSendAsAddAttachment object is created
       
    56 */
       
    57 CMtfTestAction* CMtfTestActionSendAsAddAttachment::
       
    58 		NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    59 	{
       
    60 	CMtfTestActionSendAsAddAttachment* self = 
       
    61 							new (ELeave) CMtfTestActionSendAsAddAttachment(aTestCase);
       
    62 
       
    63 	CleanupStack::PushL(self);
       
    64 	self->ConstructL(aActionParameters);
       
    65 	CleanupStack::Pop(self);
       
    66 	return self;
       
    67 	}
       
    68 	
       
    69 
       
    70 /**
       
    71   CMtfTestActionSendAsAddAttachment constructor
       
    72   Calls the base class' constructor
       
    73   @internalTechnology  
       
    74   @param  aTestCase  Test Case to which this Test Action belongs
       
    75   @pre    None
       
    76   @post   None
       
    77 */ 
       
    78 CMtfTestActionSendAsAddAttachment::CMtfTestActionSendAsAddAttachment(CMtfTestCase& aTestCase)
       
    79 	: CMtfTestAction(aTestCase)
       
    80 	{
       
    81 	}
       
    82 
       
    83 /**
       
    84   Function : ~CMtfTestActionSendAsAddAttachment
       
    85   Description : Destructor
       
    86   @internalTechnology
       
    87   @param :
       
    88   @return : 
       
    89   @pre 
       
    90   @post 
       
    91 */
       
    92 CMtfTestActionSendAsAddAttachment::~CMtfTestActionSendAsAddAttachment()
       
    93 	{
       
    94 	}
       
    95 	
       
    96 
       
    97 /**
       
    98   ExecuteActionL
       
    99   	Obtain the input parameters
       
   100 	1.	sendAsMessage 
       
   101 	2.	attachmentFile
       
   102 	3.	mimeType (Default value implies empty string)
       
   103 	Open a File Server session and create a RFile for the attachment File
       
   104 	IF MIME type is specified 
       
   105 	RSendAsMessage::AddAttachment (RFs& aFs, RFile& aAttachmentFile, const TDesC& aMimeType) by passing parameters of RFs for file server session, RFile type for attachment file and MIME type
       
   106     Else 
       
   107 	Call RSendAsMessage::AddAttachment (RFs& aFs, RFile& aAttachmentFile) by passing parameters of RFs type for file server session, RFile type for attachment file
       
   108 
       
   109 	Close session with the file server
       
   110 
       
   111   @internalTechnology 
       
   112   @pre    None
       
   113   @post   None
       
   114   @leave  System wide errors
       
   115 */
       
   116 void CMtfTestActionSendAsAddAttachment::ExecuteActionL()
       
   117 	{
       
   118 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendAsAddAttachment);
       
   119 	if((TestCase().TestStepResult()) == EPass)
       
   120 		{
       
   121 		iSendAsMessage = ObtainValueParameterL<RSendAsMessage>(TestCase(),
       
   122 											ActionParameters().Parameter(0));
       
   123 		HBufC* attachmentFile = ObtainParameterReferenceL<HBufC>(TestCase(),
       
   124 											ActionParameters().Parameter(1)); 
       
   125 		HBufC8* mimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(2), NULL);	
       
   126 		
       
   127 		
       
   128 		if(mimeType != NULL)
       
   129 			{
       
   130 			iSendAsMessage.AddAttachment(*attachmentFile, *mimeType, iStatus);
       
   131 			}
       
   132 		else
       
   133 			{
       
   134 			iSendAsMessage.AddAttachment(*attachmentFile, iStatus);
       
   135 			}
       
   136 		
       
   137 		CActiveScheduler::Add(this);		
       
   138 		SetActive();
       
   139 		}
       
   140 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsAddAttachment);
       
   141 	}
       
   142 
       
   143 void CMtfTestActionSendAsAddAttachment::DoCancel()
       
   144 	{
       
   145 	iSendAsMessage.Cancel();
       
   146 	}
       
   147 
       
   148 
       
   149 void CMtfTestActionSendAsAddAttachment::RunL()
       
   150 	{
       
   151 	TSendAsProgress		sendAsProgress;
       
   152 	TInt	errorCode = KErrNone;
       
   153 		
       
   154 	if (iStatus == KErrNone)
       
   155 		{
       
   156 		iSendAsMessage.ProgressL(sendAsProgress);
       
   157 		errorCode = sendAsProgress.iError;
       
   158 		}
       
   159 	else
       
   160 		{
       
   161 		errorCode = iStatus.Int();
       
   162 		}
       
   163 
       
   164 	if(ActionParameters().Count() == 4)
       
   165 		{
       
   166 		StoreParameterL<TInt>(TestCase(),errorCode,ActionParameters().Parameter(3));
       
   167 		}
       
   168 	else
       
   169 		{
       
   170 		User::LeaveIfError(errorCode);
       
   171 		}
       
   172 
       
   173 	
       
   174 	TestCase().INFO_PRINTF2(_L("Add Attchment completed with Error code: %d"),errorCode );
       
   175 	
       
   176 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsAddAttachment);
       
   177 	TestCase().ActionCompletedL(*this);
       
   178 	}
       
   179