messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionAddFileAttachmentByPath.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 // AddFileAttachmentByPath
       
    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 // CMsvStore::EditStoreL
       
    30 // CMsvStore::AttachmentManagerL
       
    31 // CMsvAttachment::NewL
       
    32 // CMsvAttachment::SetMimeType
       
    33 // MMsvAttachmentManager::AddAttachmentL
       
    34 // __ACTION_INFO_END__
       
    35 // 
       
    36 //
       
    37 
       
    38 
       
    39 #include "CMtfTestActionAddFileAttachmentByPath.h"
       
    40 #include "CMtfTestCase.h"
       
    41 #include "CMtfTestActionParameters.h"
       
    42 #include "MtfTestActionUtilsUser.h"
       
    43 
       
    44 #include <miutset.h>
       
    45 #include <mmsvattachmentmanager.h>
       
    46 
       
    47 CMtfTestAction* CMtfTestActionAddFileAttachmentByPath::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    48 	{
       
    49 	CMtfTestActionAddFileAttachmentByPath* self = new(ELeave) CMtfTestActionAddFileAttachmentByPath(aTestCase);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL(aActionParameters);
       
    52 	CleanupStack::Pop();
       
    53 	return self;
       
    54 	}
       
    55 	
       
    56 
       
    57 CMtfTestActionAddFileAttachmentByPath::CMtfTestActionAddFileAttachmentByPath(CMtfTestCase& aTestCase)
       
    58 	: CMtfTestAction(aTestCase)
       
    59 	{
       
    60 	}
       
    61 
       
    62 
       
    63 CMtfTestActionAddFileAttachmentByPath::~CMtfTestActionAddFileAttachmentByPath()
       
    64 	{
       
    65 	Cancel();
       
    66 	delete iAttachment;
       
    67 	delete iStore;
       
    68 	delete iEntry;
       
    69 	}
       
    70 
       
    71 void CMtfTestActionAddFileAttachmentByPath::ExecuteActionL()
       
    72 	{
       
    73 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddFileAttachmentByPath);
       
    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 iStore;
       
    84 		iStore = NULL;
       
    85 		delete iEntry;
       
    86 		iEntry = NULL;
       
    87 		TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionAddFileAttachmentByPath);
       
    88 		TestCase().ActionCompletedL(*this);
       
    89 		}
       
    90 	}
       
    91 
       
    92 void CMtfTestActionAddFileAttachmentByPath::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 	iStore = iEntry->EditStoreL();
       
   101 	iAttachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
   102 	
       
   103 	iAttachment->SetMimeTypeL(*paramMimeType);
       
   104 	TEntry fileEntry;
       
   105 	User::LeaveIfError(paramSession->FileSession().Entry(*paramFilePath, fileEntry));
       
   106 	iAttachment->SetSize(fileEntry.iSize);
       
   107 	
       
   108 	TParse fileNameParser;
       
   109 	User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL));
       
   110 	iAttachment->SetAttachmentNameL(fileNameParser.NameAndExt());
       
   111 	
       
   112 	MMsvAttachmentManager& manager = iStore->AttachmentManagerL();
       
   113 	
       
   114 	CActiveScheduler::Add(this);
       
   115 	manager.AddAttachmentL(*paramFilePath, iAttachment, iStatus);
       
   116 	SetActive();
       
   117 	iAttachmentId = iAttachment->Id();
       
   118 	iAttachment = NULL; // ownership passed to manager
       
   119 	}
       
   120 
       
   121 void CMtfTestActionAddFileAttachmentByPath::RunL()
       
   122 	{
       
   123 	User::LeaveIfError(iStatus.Int());
       
   124 	iStore->CommitL();
       
   125 	
       
   126 	delete iStore;
       
   127 	iStore = NULL;
       
   128 	delete iEntry;
       
   129 	iEntry = NULL;
       
   130 	
       
   131 	StoreParameterL<TMsvAttachmentId>(TestCase(),iAttachmentId,ActionParameters().Parameter(4));
       
   132 	if( ActionParameters().Count() == 6 )
       
   133 		{
       
   134 		TInt err = KErrNone;
       
   135 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5));
       
   136 		}
       
   137 
       
   138 	TestCase().ActionCompletedL(*this);
       
   139 	}
       
   140 
       
   141 void CMtfTestActionAddFileAttachmentByPath::DoCancel()
       
   142 	{
       
   143 	iStore->AttachmentManagerL().CancelRequest();
       
   144 	}
       
   145 
       
   146 TInt CMtfTestActionAddFileAttachmentByPath::RunError(TInt aError)
       
   147 	{
       
   148 	if(ActionParameters().Count() == 6)
       
   149 		{
       
   150 		StoreParameterL<TInt>(TestCase(),aError,ActionParameters().Parameter(5));
       
   151 		}
       
   152 	delete iStore;
       
   153 	iStore = NULL;
       
   154 	delete iEntry;
       
   155 	iEntry = NULL;
       
   156 	TRAPD(err, TestCase().ActionCompletedL(*this));
       
   157 	return err;
       
   158 	}
       
   159