messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionAddFileAttachmentByPathSync.cpp
changeset 0 8e480a14352b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionAddFileAttachmentByPathSync.cpp	Mon Jan 18 20:36:02 2010 +0200
@@ -0,0 +1,132 @@
+// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+// __ACTION_INFO_BEGIN__ 
+// [Action Name]
+// AddFileAttachmentByPathSync
+// [Action Parameters]
+// Session        <input>: Reference to the session.
+// MsgId		  <input>: Value of the message Id.
+// FilePath       <input>: File path of the attachment file.
+// MimeType		  <input>: Mime-type of the attachment.
+// AttachmentId   <output>: Value of the created attachment id.
+// ErrorCode	  <output>: (Optional) Returned error code, if not requested then code will
+// leave if not KErrNone
+// [Action Description]
+// Synchrounously creates a file attachment on the specified message entry located
+// using a specified file.
+// [APIs Used]
+// CMsvSession::GetEntryL
+// CMsvStore::EditStoreL
+// CMsvStore::AttachmentManagerL
+// CMsvAttachment::NewL
+// CMsvAttachment::SetMimeType
+// MMsvAttachmentManager::AddAttachmentL
+// __ACTION_INFO_END__
+// 
+//
+
+
+#include "CMtfTestActionAddFileAttachmentByPathSync.h"
+#include "CMtfAsyncWaiter.h"
+#include "CMtfTestCase.h"
+#include "CMtfTestActionParameters.h"
+#include "MtfTestActionUtilsUser.h"
+
+#include <miutset.h>
+#include <cmsvattachment.h>
+#include <mmsvattachmentmanager.h>
+
+CMtfTestAction* CMtfTestActionAddFileAttachmentByPathSync::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
+	{
+	CMtfTestActionAddFileAttachmentByPathSync* self = new(ELeave) CMtfTestActionAddFileAttachmentByPathSync(aTestCase);
+	CleanupStack::PushL(self);
+	self->ConstructL(aActionParameters);
+	CleanupStack::Pop();
+	return self;
+	}
+	
+
+CMtfTestActionAddFileAttachmentByPathSync::CMtfTestActionAddFileAttachmentByPathSync(CMtfTestCase& aTestCase)
+	: CMtfSynchronousTestAction(aTestCase)
+	{
+	}
+
+
+CMtfTestActionAddFileAttachmentByPathSync::~CMtfTestActionAddFileAttachmentByPathSync()
+	{
+	}
+
+void CMtfTestActionAddFileAttachmentByPathSync::ExecuteActionL()
+	{
+	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddFileAttachmentByPathSync);
+	TRAPD(err, RunTestL())
+	
+	if( ActionParameters().Count() < 6 )
+		{
+		User::LeaveIfError(err);
+		}
+	else
+		{
+		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5));
+		}
+	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionAddFileAttachmentByPathSync);	
+	TestCase().ActionCompletedL(*this);
+	}
+	
+void CMtfTestActionAddFileAttachmentByPathSync::RunTestL()
+	{
+	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
+	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
+	HBufC* paramFilePath   = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2));
+	HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(3));
+
+	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
+	CleanupStack::PushL(entry);
+	
+	CMsvStore* store = entry->EditStoreL();
+	CleanupStack::PushL(store);
+	
+	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
+	CleanupStack::PushL(waiter);
+	
+	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
+	CleanupStack::PushL(attachment);
+
+	attachment->SetMimeTypeL(*paramMimeType);
+	TEntry fileEntry;
+	User::LeaveIfError(paramSession->FileSession().Entry(*paramFilePath, fileEntry));
+	attachment->SetSize(fileEntry.iSize);
+	
+	TParse fileNameParser;
+	User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL));
+	attachment->SetAttachmentNameL(fileNameParser.NameAndExt());
+
+	MMsvAttachmentManager& manager = store->AttachmentManagerL();
+	
+	manager.AddAttachmentL(*paramFilePath, attachment, waiter->iStatus);
+	CleanupStack::Pop(attachment); // ownership passed to manager
+	waiter->StartAndWait();
+	User::LeaveIfError(waiter->Result());
+	CleanupStack::PopAndDestroy(waiter);
+	
+	TMsvAttachmentId attachmentId = attachment->Id();
+	
+	store->CommitL();
+	
+	CleanupStack::PopAndDestroy(2, entry); // store, entry
+	StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(4));	
+	}
+
+
+