|
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 // SmtpRemoveFileAttachmentByIndex |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // MsgId <input>: Value of the message Id. |
|
20 // Index <input>: Index value 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 index value. 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 // CImEmailMessage::AttachmentManagerL |
|
30 // MMsvAttachmentManager::GetAttachmentInfoL |
|
31 // MMsvAttachmentManager::RemoveAttachmentL |
|
32 // __ACTION_INFO_END__ |
|
33 // |
|
34 // |
|
35 |
|
36 |
|
37 #include "CMtfTestActionSmtpRemoveFileAttachmentByIndex.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 #include <miutmsg.h> |
|
47 |
|
48 CMtfTestAction* CMtfTestActionSmtpRemoveFileAttachmentByIndex::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
49 { |
|
50 CMtfTestActionSmtpRemoveFileAttachmentByIndex* self = new(ELeave) CMtfTestActionSmtpRemoveFileAttachmentByIndex(aTestCase); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aActionParameters); |
|
53 CleanupStack::Pop(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 CMtfTestActionSmtpRemoveFileAttachmentByIndex::CMtfTestActionSmtpRemoveFileAttachmentByIndex(CMtfTestCase& aTestCase) |
|
59 : CMtfSynchronousTestAction(aTestCase) |
|
60 { |
|
61 } |
|
62 |
|
63 |
|
64 CMtfTestActionSmtpRemoveFileAttachmentByIndex::~CMtfTestActionSmtpRemoveFileAttachmentByIndex() |
|
65 { |
|
66 } |
|
67 |
|
68 void CMtfTestActionSmtpRemoveFileAttachmentByIndex::ExecuteActionL() |
|
69 { |
|
70 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpRemoveFileAttachmentByIndex); |
|
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 |
|
82 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpRemoveFileAttachmentByIndex); |
|
83 TestCase().ActionCompletedL(*this); |
|
84 } |
|
85 |
|
86 void CMtfTestActionSmtpRemoveFileAttachmentByIndex::RunTestL() |
|
87 { |
|
88 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
89 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
90 TInt attachIndex = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2)); |
|
91 |
|
92 CMsvEntry* entry = paramSession->GetEntryL(messageEntry); |
|
93 CleanupStack::PushL(entry); |
|
94 |
|
95 CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry); |
|
96 CleanupStack::PushL(emailMsg); |
|
97 |
|
98 MMsvAttachmentManager& manager = emailMsg->AttachmentManager(); |
|
99 |
|
100 CMsvAttachment* attachmentInfo = manager.GetAttachmentInfoL(attachIndex); |
|
101 CleanupStack::PushL(attachmentInfo); |
|
102 |
|
103 // First ensure that the attachment is a file attachment |
|
104 if( attachmentInfo->Type() != CMsvAttachment::EMsvFile ) |
|
105 { |
|
106 User::Leave(KErrGeneral); |
|
107 } |
|
108 |
|
109 CleanupStack::PopAndDestroy(attachmentInfo); |
|
110 |
|
111 CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); |
|
112 CleanupStack::PushL(waiter); |
|
113 |
|
114 manager.RemoveAttachmentL(attachIndex, waiter->iStatus); |
|
115 |
|
116 waiter->StartAndWait(); |
|
117 User::LeaveIfError(waiter->Result()); |
|
118 CleanupStack::PopAndDestroy(waiter); |
|
119 |
|
120 CleanupStack::PopAndDestroy(2, entry); // emailMsg, entry |
|
121 } |
|
122 |
|
123 |
|
124 |