messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionRemoveLinkedAttachmentById.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 // RemoveLinkedAttachmentById
       
    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 linked file attachment by its attachment Id. The
       
    25 // attachment is first checked to to ensure that it is a linked attachment and 
       
    26 // then removes it. An additional check is done to access the file to ensure
       
    27 // that the linked file has not been deleted.
       
    28 // [APIs Used]
       
    29 // CMsvSession::GetEntryL
       
    30 // CMsvStore::ReadStoreL
       
    31 // CMsvStore::AttachmentManagerL
       
    32 // TODO
       
    33 // __ACTION_INFO_END__
       
    34 // 
       
    35 //
       
    36 
       
    37 
       
    38 #include "CMtfTestActionRemoveLinkedAttachmentById.h"
       
    39 #include "CMtfAsyncWaiter.h"
       
    40 #include "CMtfTestCase.h"
       
    41 #include "CMtfTestActionParameters.h"
       
    42 #include "MtfTestActionUtilsUser.h"
       
    43 
       
    44 #include <miutset.h>
       
    45 #include <mmsvattachmentmanager.h>
       
    46 #include <cmsvattachment.h>
       
    47 
       
    48 CMtfTestAction* CMtfTestActionRemoveLinkedAttachmentById::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    49 	{
       
    50 	CMtfTestActionRemoveLinkedAttachmentById* self = new(ELeave) CMtfTestActionRemoveLinkedAttachmentById(aTestCase);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aActionParameters);
       
    53 	CleanupStack::Pop();
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 
       
    58 CMtfTestActionRemoveLinkedAttachmentById::CMtfTestActionRemoveLinkedAttachmentById(CMtfTestCase& aTestCase)
       
    59 	: CMtfSynchronousTestAction(aTestCase)
       
    60 	{
       
    61 	}
       
    62 
       
    63 
       
    64 CMtfTestActionRemoveLinkedAttachmentById::~CMtfTestActionRemoveLinkedAttachmentById()
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CMtfTestActionRemoveLinkedAttachmentById::ExecuteActionL()
       
    69 	{
       
    70 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionRemoveLinkedAttachmentById);
       
    71 	TRAPD(err, RunTestL());
       
    72 	
       
    73 	if( ActionParameters().Count() < 4 )
       
    74 		{
       
    75 		User::LeaveIfError(err);
       
    76 		}
       
    77 	else
       
    78 		{
       
    79 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(3));
       
    80 		}
       
    81 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionRemoveLinkedAttachmentById);	
       
    82 	TestCase().ActionCompletedL(*this);
       
    83 	}
       
    84 	
       
    85 void CMtfTestActionRemoveLinkedAttachmentById::RunTestL()
       
    86 	{
       
    87 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    88 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    89 	TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2));
       
    90 
       
    91 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    92 	CleanupStack::PushL(entry);
       
    93 	
       
    94 	CMsvStore* store = entry->EditStoreL();
       
    95 	CleanupStack::PushL(store);
       
    96 	
       
    97 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
    98 	
       
    99 	CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId);
       
   100 	CleanupStack::PushL(attachInfo);
       
   101 	
       
   102 	// First ensure that the attachment is a file attachment
       
   103 	if( attachInfo->Type() != CMsvAttachment::EMsvLinkedFile )
       
   104 		{
       
   105 		User::Leave(KErrGeneral);
       
   106 		}
       
   107 		
       
   108 	// Get the linked file
       
   109 	RFile file = manager.GetAttachmentFileL(attachId);
       
   110 	CleanupClosePushL(file);
       
   111 	
       
   112 	// Remove the attachment
       
   113 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
   114 	CleanupStack::PushL(waiter);
       
   115 	manager.RemoveAttachmentL(attachId, waiter->iStatus);
       
   116 	waiter->StartAndWait();
       
   117 	User::LeaveIfError(waiter->Result());
       
   118 	CleanupStack::PopAndDestroy(waiter);
       
   119 	
       
   120 	store->CommitL();
       
   121 	
       
   122 	// Ensure that the file still there
       
   123 	TInt fileSize;
       
   124 	User::LeaveIfError(file.Size(fileSize));
       
   125 	if( !(fileSize > 0) )
       
   126 		{
       
   127 		// no contents in the file
       
   128 		User::Leave(KErrGeneral);
       
   129 		}
       
   130 	
       
   131 	CleanupStack::PopAndDestroy(4, entry); // attachInfo, file, store, entry
       
   132 	}
       
   133 
       
   134 
       
   135