|
1 // Copyright (c) 2008-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 // RenameFileAttachmentById |
|
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 "CMtfTestActionRenameFileAttachmentById.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* CMtfTestActionRenameFileAttachmentById::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
48 { |
|
49 CMtfTestActionRenameFileAttachmentById* self = new(ELeave) CMtfTestActionRenameFileAttachmentById(aTestCase); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aActionParameters); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 CMtfTestActionRenameFileAttachmentById::CMtfTestActionRenameFileAttachmentById(CMtfTestCase& aTestCase) |
|
58 : CMtfSynchronousTestAction(aTestCase) |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 CMtfTestActionRenameFileAttachmentById::~CMtfTestActionRenameFileAttachmentById() |
|
64 { |
|
65 } |
|
66 |
|
67 void CMtfTestActionRenameFileAttachmentById::ExecuteActionL() |
|
68 { |
|
69 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionRenameFileAttachmentById); |
|
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."), &KTestActionRenameFileAttachmentById); |
|
81 TestCase().ActionCompletedL(*this); |
|
82 } |
|
83 |
|
84 void CMtfTestActionRenameFileAttachmentById::RunTestL() |
|
85 { |
|
86 _LIT(KTxtFileName, "C:\\Private\\1000484b\\Mail2\\00001001_S\\0\\00100002_F\\sample1.jpg"); |
|
87 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
88 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
89 TMsvAttachmentId originalAttachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2)); |
|
90 TMsvAttachmentId renameAttachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(3)); |
|
91 |
|
92 //Obtains the entry details. |
|
93 CMsvEntry* entry = paramSession->GetEntryL(messageEntry); |
|
94 CleanupStack::PushL(entry); |
|
95 |
|
96 //Read the entry details from the store. |
|
97 CMsvStore* store = entry->EditStoreL(); |
|
98 CleanupStack::PushL(store); |
|
99 |
|
100 //Refer to the attachment info from the store. |
|
101 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
102 |
|
103 //Obtains the attachment info |
|
104 CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(renameAttachId); |
|
105 CleanupStack::PushL(attachInfo); |
|
106 |
|
107 // First ensure that the attachment is a file attachment |
|
108 if( attachInfo->Type() != CMsvAttachment::EMsvFile ) |
|
109 { |
|
110 User::Leave(KErrGeneral); |
|
111 } |
|
112 |
|
113 CleanupStack::PopAndDestroy(attachInfo); |
|
114 |
|
115 CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); |
|
116 CleanupStack::PushL(waiter); |
|
117 manager.RenameAttachmentL(originalAttachId,KTxtFileName,waiter->iStatus); |
|
118 waiter->StartAndWait(); |
|
119 User::LeaveIfError(waiter->Result()); |
|
120 TMsvAttachmentId newattachmentId = attachInfo->Id(); |
|
121 TestCase().TEST(newattachmentId == renameAttachId); |
|
122 CleanupStack::PopAndDestroy(waiter); |
|
123 |
|
124 store->CommitL(); |
|
125 CleanupStack::PopAndDestroy(2, entry); // store, entry |
|
126 } |
|
127 |
|
128 |
|
129 |