messagingfw/msgtestfw/TestActions/Email/Smtp/src/CMtfTestActionSmtpAddFileAttachmentByPath.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 // SmtpAddFileAttachmentByPath
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // FilePath       <input>: File path of the attachment file.
       
    21 // MimeType		  <input>: Mime-type of the attachment.
       
    22 // AttachmentId   <output>: Value of the created attachment id.
       
    23 // ErrorCode	  <output>: (Optional) Returned error code, if not requested then code will
       
    24 // leave if not KErrNone
       
    25 // [Action Description]
       
    26 // Creates a file attachment on the specified message entry located using a specified file.
       
    27 // [APIs Used]
       
    28 // CMsvSession::GetEntryL
       
    29 // CImEmailMessage::AttachmentManagerL
       
    30 // CMsvAttachment::NewL
       
    31 // CMsvAttachment::SetMimeType
       
    32 // MMsvAttachmentManager::AddAttachmentL
       
    33 // __ACTION_INFO_END__
       
    34 // 
       
    35 //
       
    36 
       
    37 
       
    38 #include "CMtfTestActionSmtpAddFileAttachmentByPath.h"
       
    39 #include "CMtfTestCase.h"
       
    40 #include "CMtfTestActionParameters.h"
       
    41 #include "MtfTestActionUtilsUser.h"
       
    42 
       
    43 #include <miutset.h>
       
    44 #include <mmsvattachmentmanager.h>
       
    45 #include <miutmsg.h>
       
    46 
       
    47 CMtfTestAction* CMtfTestActionSmtpAddFileAttachmentByPath::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    48 	{
       
    49 	CMtfTestActionSmtpAddFileAttachmentByPath* self = new(ELeave) CMtfTestActionSmtpAddFileAttachmentByPath(aTestCase);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL(aActionParameters);
       
    52 	CleanupStack::Pop();
       
    53 	return self;
       
    54 	}
       
    55 	
       
    56 
       
    57 CMtfTestActionSmtpAddFileAttachmentByPath::CMtfTestActionSmtpAddFileAttachmentByPath(CMtfTestCase& aTestCase)
       
    58 	: CMtfTestAction(aTestCase)
       
    59 	{
       
    60 	}
       
    61 
       
    62 
       
    63 CMtfTestActionSmtpAddFileAttachmentByPath::~CMtfTestActionSmtpAddFileAttachmentByPath()
       
    64 	{
       
    65 	Cancel();	
       
    66 	delete iAttachment;
       
    67 	delete imEmailMsg;
       
    68 	delete iEntry;
       
    69 	}
       
    70 
       
    71 void CMtfTestActionSmtpAddFileAttachmentByPath::ExecuteActionL()
       
    72 	{
       
    73 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpAddFileAttachmentByPath);
       
    74 	TRAPD(err, RunTestL());
       
    75 	
       
    76 	if( ActionParameters().Count() < 6 )
       
    77 		{
       
    78 		User::LeaveIfError(err);
       
    79 		}
       
    80 	else if( err!=KErrNone )
       
    81 		{
       
    82 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5));		
       
    83 		delete imEmailMsg;
       
    84 		imEmailMsg = NULL;
       
    85 		delete iEntry;
       
    86 		iEntry = NULL;		
       
    87 		TestCase().ActionCompletedL(*this);
       
    88 		}
       
    89 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpAddFileAttachmentByPath);
       
    90 	}
       
    91 
       
    92 void CMtfTestActionSmtpAddFileAttachmentByPath::RunTestL()
       
    93 	{
       
    94 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    95 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    96 	HBufC* paramFilePath   = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2));
       
    97 	HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(3));
       
    98 
       
    99 	iEntry = paramSession->GetEntryL(messageEntry);
       
   100 	imEmailMsg = CImEmailMessage::NewL(*iEntry);	
       
   101 	
       
   102 	iAttachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
   103 
       
   104 	iAttachment->SetMimeTypeL(*paramMimeType);
       
   105 	
       
   106 	TEntry fileEntry;
       
   107 	User::LeaveIfError(paramSession->FileSession().Entry(*paramFilePath, fileEntry));
       
   108 	iAttachment->SetSize(fileEntry.iSize);
       
   109 
       
   110 	TParse fileNameParser;
       
   111 	User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL));
       
   112 	iAttachment->SetAttachmentNameL(fileNameParser.NameAndExt());
       
   113 	
       
   114 	MMsvAttachmentManager& manager = imEmailMsg->AttachmentManager();
       
   115 	
       
   116 	CActiveScheduler::Add(this);	
       
   117 	manager.AddAttachmentL(*paramFilePath, iAttachment, iStatus);
       
   118 	SetActive();
       
   119 	
       
   120 	iAttachment = NULL; // ownership passed to manager
       
   121 	
       
   122 	}
       
   123 
       
   124 void CMtfTestActionSmtpAddFileAttachmentByPath::RunL()
       
   125 	{
       
   126 	User::LeaveIfError(iStatus.Int());
       
   127 	
       
   128 	MMsvAttachmentManager& manager = imEmailMsg->AttachmentManager();
       
   129 	
       
   130 	TInt attachmentCount = manager.AttachmentCount();
       
   131 	CMsvAttachment* attachmentInfo = manager.GetAttachmentInfoL(attachmentCount - 1);
       
   132 	CleanupStack::PushL(attachmentInfo);
       
   133 	
       
   134 	iAttachmentId = attachmentInfo->Id();
       
   135 	CleanupStack::PopAndDestroy(attachmentInfo);
       
   136 	
       
   137 	delete imEmailMsg;
       
   138 	imEmailMsg = NULL;
       
   139 	delete iEntry;
       
   140 	iEntry = NULL;
       
   141 	
       
   142 	StoreParameterL<TMsvAttachmentId>(TestCase(),iAttachmentId,ActionParameters().Parameter(4));
       
   143 	if( ActionParameters().Count() == 6 )
       
   144 		{
       
   145 		TInt err = KErrNone;
       
   146 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5));
       
   147 		}
       
   148 
       
   149 	TestCase().ActionCompletedL(*this);
       
   150 	}
       
   151 
       
   152 void CMtfTestActionSmtpAddFileAttachmentByPath::DoCancel()
       
   153 	{
       
   154 	imEmailMsg->AttachmentManager().CancelRequest();
       
   155 	}
       
   156 
       
   157 TInt CMtfTestActionSmtpAddFileAttachmentByPath::RunError(TInt aError)
       
   158 	{
       
   159 	if(ActionParameters().Count() == 6)
       
   160 		{
       
   161 		StoreParameterL<TInt>(TestCase(),aError,ActionParameters().Parameter(5));
       
   162 		}
       
   163 	
       
   164 	delete imEmailMsg;
       
   165 	imEmailMsg = NULL;
       
   166 	delete iEntry;
       
   167 	iEntry = NULL;
       
   168 	
       
   169 	TRAPD(r,TestCase().ActionCompletedL(*this));
       
   170 		
       
   171 	return r;
       
   172 	}
       
   173