|
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 // AddFileAttachmentByHandle |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // MsgId <input>: Value of the message Id. |
|
20 // FilePath <input>: File path of the attachment file to open as a handle. |
|
21 // MimeType <input>: Mime-type of the attachment. |
|
22 // AttachmentId <output>: Value of the created attachment id. |
|
23 // ErrorCode <output>: (Optional) Returned error code, if not requested then code will |
|
24 // leave if not KErrNone |
|
25 // [Action Description] |
|
26 // Opens the specified file and adds the file to the message entry by the open |
|
27 // file handle. |
|
28 // [APIs Used] |
|
29 // CMsvSession::GetEntryL |
|
30 // CMsvStore::EditStoreL |
|
31 // CMsvStore::AttachmentManagerL |
|
32 // CMsvAttachment::NewL |
|
33 // CMsvAttachment::SetMimeType |
|
34 // MMsvAttachmentManager::AddAttachmentL |
|
35 // __ACTION_INFO_END__ |
|
36 // |
|
37 // |
|
38 |
|
39 |
|
40 #include "CMtfTestActionAddFileAttachmentByHandle.h" |
|
41 #include "CMtfTestCase.h" |
|
42 #include "CMtfTestActionParameters.h" |
|
43 #include "MtfTestActionUtilsUser.h" |
|
44 |
|
45 #include <miutset.h> |
|
46 #include <mmsvattachmentmanager.h> |
|
47 |
|
48 CMtfTestAction* CMtfTestActionAddFileAttachmentByHandle::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
49 { |
|
50 CMtfTestActionAddFileAttachmentByHandle* self = new(ELeave) CMtfTestActionAddFileAttachmentByHandle(aTestCase); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aActionParameters); |
|
53 CleanupStack::Pop(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 CMtfTestActionAddFileAttachmentByHandle::CMtfTestActionAddFileAttachmentByHandle(CMtfTestCase& aTestCase) |
|
59 : CMtfTestAction(aTestCase) |
|
60 { |
|
61 } |
|
62 |
|
63 |
|
64 CMtfTestActionAddFileAttachmentByHandle::~CMtfTestActionAddFileAttachmentByHandle() |
|
65 { |
|
66 Cancel(); |
|
67 delete iAttachment; |
|
68 delete iStore; |
|
69 delete iEntry; |
|
70 } |
|
71 |
|
72 void CMtfTestActionAddFileAttachmentByHandle::ExecuteActionL() |
|
73 { |
|
74 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddFileAttachmentByHandle); |
|
75 TRAPD(err, RunTestL()); |
|
76 |
|
77 if( ActionParameters().Count() < 6 ) |
|
78 { |
|
79 User::LeaveIfError(err); |
|
80 } |
|
81 else if( err!=KErrNone ) |
|
82 { |
|
83 StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5)); |
|
84 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionAddFileAttachmentByHandle); |
|
85 TestCase().ActionCompletedL(*this); |
|
86 } |
|
87 } |
|
88 |
|
89 void CMtfTestActionAddFileAttachmentByHandle::RunTestL() |
|
90 { |
|
91 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
92 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
93 HBufC* paramFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2)); |
|
94 HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(3)); |
|
95 |
|
96 iEntry = paramSession->GetEntryL(messageEntry); |
|
97 iStore = iEntry->EditStoreL(); |
|
98 iAttachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); |
|
99 iAttachment->SetMimeTypeL(*paramMimeType); |
|
100 |
|
101 RFile fileHandle = OpenFileL(paramSession->FileSession(), *paramFilePath); |
|
102 CleanupClosePushL(fileHandle); |
|
103 TFileName fileName; |
|
104 User::LeaveIfError(fileHandle.Name(fileName)); |
|
105 iAttachment->SetAttachmentNameL(fileName); |
|
106 TInt fileSize = 0; |
|
107 User::LeaveIfError(fileHandle.Size(fileSize)); |
|
108 iAttachment->SetSize(fileSize); |
|
109 |
|
110 MMsvAttachmentManager& manager = iStore->AttachmentManagerL(); |
|
111 CActiveScheduler::Add(this); |
|
112 SetActive(); |
|
113 manager.AddAttachmentL(fileHandle, iAttachment, iStatus); |
|
114 iAttachmentId = iAttachment->Id(); |
|
115 iAttachment = NULL; // ownership passed to manager |
|
116 |
|
117 CleanupStack::Pop(&fileHandle); |
|
118 } |
|
119 |
|
120 void CMtfTestActionAddFileAttachmentByHandle::RunL() |
|
121 { |
|
122 User::LeaveIfError(iStatus.Int()); |
|
123 iStore->CommitL(); |
|
124 |
|
125 delete iStore; |
|
126 iStore = NULL; |
|
127 delete iEntry; |
|
128 iEntry = NULL; |
|
129 |
|
130 StoreParameterL<TMsvAttachmentId>(TestCase(),iAttachmentId,ActionParameters().Parameter(4)); |
|
131 if(ActionParameters().Count() == 6) |
|
132 { |
|
133 TInt err = KErrNone; |
|
134 StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5)); |
|
135 } |
|
136 |
|
137 TestCase().ActionCompletedL(*this); |
|
138 } |
|
139 |
|
140 void CMtfTestActionAddFileAttachmentByHandle::DoCancel() |
|
141 { |
|
142 iStore->AttachmentManagerL().CancelRequest(); |
|
143 } |
|
144 |
|
145 TInt CMtfTestActionAddFileAttachmentByHandle::RunError(TInt aError) |
|
146 { |
|
147 StoreParameterL<TInt>(TestCase(),aError,ActionParameters().Parameter(5)); |
|
148 TRAPD(err, TestCase().ActionCompletedL(*this)); |
|
149 return err; |
|
150 } |
|
151 |
|
152 RFile CMtfTestActionAddFileAttachmentByHandle::OpenFileL(RFs& aFs, const TDesC& aFilePath) |
|
153 { |
|
154 RFile fileHandle; |
|
155 User::LeaveIfError(fileHandle.Open(aFs, aFilePath, EFileRead)); |
|
156 return fileHandle; |
|
157 } |
|
158 |