messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionRemoveFileAttachmentById.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 // RemoveFileAttachmentById
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // AttachmentId	  <input>: Attachment Id of attachment to remove.
       
    21 // ErrorCode	  <output>: (Optional) Returned error code, if not requested then code will
       
    22 // leave if not KErrNone
       
    23 // [Action Description]
       
    24 // Removes the specified file attachment by its attachment Id. The attachment
       
    25 // is first checked to to ensure that it is a file attachment and then
       
    26 // removes it.
       
    27 // [APIs Used]
       
    28 // CMsvSession::GetEntryL
       
    29 // CMsvStore::ReadStoreL
       
    30 // CMsvStore::AttachmentManagerL
       
    31 // TODO
       
    32 // __ACTION_INFO_END__
       
    33 // 
       
    34 //
       
    35 
       
    36 
       
    37 #include "CMtfTestActionRemoveFileAttachmentById.h"
       
    38 #include "CMtfAsyncWaiter.h"
       
    39 #include "CMtfTestCase.h"
       
    40 #include "CMtfTestActionParameters.h"
       
    41 #include "MtfTestActionUtilsUser.h"
       
    42 
       
    43 #include <miutset.h>
       
    44 #include <mmsvattachmentmanager.h>
       
    45 #include <cmsvattachment.h>
       
    46 
       
    47 CMtfTestAction* CMtfTestActionRemoveFileAttachmentById::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    48 	{
       
    49 	CMtfTestActionRemoveFileAttachmentById* self = new(ELeave) CMtfTestActionRemoveFileAttachmentById(aTestCase);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL(aActionParameters);
       
    52 	CleanupStack::Pop();
       
    53 	return self;
       
    54 	}
       
    55 	
       
    56 
       
    57 CMtfTestActionRemoveFileAttachmentById::CMtfTestActionRemoveFileAttachmentById(CMtfTestCase& aTestCase)
       
    58 	: CMtfSynchronousTestAction(aTestCase)
       
    59 	{
       
    60 	}
       
    61 
       
    62 
       
    63 CMtfTestActionRemoveFileAttachmentById::~CMtfTestActionRemoveFileAttachmentById()
       
    64 	{
       
    65 	}
       
    66 
       
    67 void CMtfTestActionRemoveFileAttachmentById::ExecuteActionL()
       
    68 	{
       
    69 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionRemoveFileAttachmentById);
       
    70 	TRAPD(err, RunTestL());
       
    71 	
       
    72 	if( ActionParameters().Count() < 4 )
       
    73 		{
       
    74 		User::LeaveIfError(err);
       
    75 		}
       
    76 	else
       
    77 		{
       
    78 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(3));
       
    79 		}
       
    80 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionRemoveFileAttachmentById);	
       
    81 	TestCase().ActionCompletedL(*this); 
       
    82 	}
       
    83 
       
    84 void CMtfTestActionRemoveFileAttachmentById::RunTestL()
       
    85 	{
       
    86 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    87 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    88 	TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2));
       
    89 
       
    90 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    91 	CleanupStack::PushL(entry);
       
    92 	
       
    93 	CMsvStore* store = entry->EditStoreL();
       
    94 	CleanupStack::PushL(store);
       
    95 	
       
    96 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
    97 	
       
    98 	CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId);
       
    99 	CleanupStack::PushL(attachInfo);
       
   100 	
       
   101 	// First ensure that the attachment is a file attachment
       
   102 	if( attachInfo->Type() != CMsvAttachment::EMsvFile )
       
   103 		{
       
   104 		User::Leave(KErrGeneral);
       
   105 		}
       
   106 	
       
   107 	CleanupStack::PopAndDestroy(attachInfo);
       
   108 	
       
   109 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
   110 	CleanupStack::PushL(waiter);
       
   111 	manager.RemoveAttachmentL(attachId, waiter->iStatus);	
       
   112 	waiter->StartAndWait();
       
   113 	User::LeaveIfError(waiter->Result());
       
   114 	CleanupStack::PopAndDestroy(waiter);
       
   115 	
       
   116 	store->CommitL();
       
   117 	
       
   118 	CleanupStack::PopAndDestroy(2, entry); // store, entry
       
   119 	}
       
   120 
       
   121 
       
   122