|
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 // AddLinkedAttachment |
|
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 add as linked. |
|
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 // Adds the specified file as a linked attachment to the specified message |
|
27 // entry. |
|
28 // [APIs Used] |
|
29 // CMsvSession::GetEntryL |
|
30 // CMsvStore::EditStoreL |
|
31 // CMsvStore::AttachmentManagerL |
|
32 // CMsvAttachment::NewL |
|
33 // CMsvAttachment::SetMimeType |
|
34 // MMsvAttachmentManager::AddLinkedAttachmentL |
|
35 // __ACTION_INFO_END__ |
|
36 // |
|
37 // |
|
38 |
|
39 |
|
40 #include "CMtfTestActionAddLinkedAttachment.h" |
|
41 #include "CMtfAsyncWaiter.h" |
|
42 #include "CMtfTestCase.h" |
|
43 #include "CMtfTestActionParameters.h" |
|
44 #include "MtfTestActionUtilsUser.h" |
|
45 |
|
46 #include <miutset.h> |
|
47 #include <cmsvattachment.h> |
|
48 #include <mmsvattachmentmanager.h> |
|
49 |
|
50 CMtfTestAction* CMtfTestActionAddLinkedAttachment::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
51 { |
|
52 CMtfTestActionAddLinkedAttachment* self = new(ELeave) CMtfTestActionAddLinkedAttachment(aTestCase); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(aActionParameters); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 CMtfTestActionAddLinkedAttachment::CMtfTestActionAddLinkedAttachment(CMtfTestCase& aTestCase) |
|
61 : CMtfSynchronousTestAction(aTestCase) |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 CMtfTestActionAddLinkedAttachment::~CMtfTestActionAddLinkedAttachment() |
|
67 { |
|
68 } |
|
69 |
|
70 void CMtfTestActionAddLinkedAttachment::ExecuteActionL() |
|
71 { |
|
72 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddLinkedAttachment); |
|
73 TRAPD(err, RunTestL()); |
|
74 |
|
75 if( ActionParameters().Count() < 6 ) |
|
76 { |
|
77 User::LeaveIfError(err); |
|
78 } |
|
79 else |
|
80 { |
|
81 StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5)); |
|
82 } |
|
83 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionAddLinkedAttachment); |
|
84 TestCase().ActionCompletedL(*this); |
|
85 } |
|
86 |
|
87 void CMtfTestActionAddLinkedAttachment::RunTestL() |
|
88 { |
|
89 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
90 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
91 HBufC* paramFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2)); |
|
92 HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(3)); |
|
93 |
|
94 CMsvEntry* entry = paramSession->GetEntryL(messageEntry); |
|
95 CleanupStack::PushL(entry); |
|
96 |
|
97 CMsvStore* store = entry->EditStoreL(); |
|
98 CleanupStack::PushL(store); |
|
99 |
|
100 CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); |
|
101 CleanupStack::PushL(waiter); |
|
102 |
|
103 CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvLinkedFile); |
|
104 CleanupStack::PushL(attachment); |
|
105 |
|
106 attachment->SetMimeTypeL(*paramMimeType); |
|
107 TParse fileNameParser; |
|
108 User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL)); |
|
109 attachment->SetAttachmentNameL(fileNameParser.NameAndExt()); |
|
110 TEntry fileEntry; |
|
111 User::LeaveIfError(paramSession->FileSession().Entry( fileNameParser.FullName(), fileEntry) ); |
|
112 attachment->SetSize(fileEntry.iSize); |
|
113 |
|
114 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
115 |
|
116 manager.AddLinkedAttachmentL(*paramFilePath, attachment, waiter->iStatus); |
|
117 CleanupStack::Pop(attachment); // ownership passed to manager |
|
118 waiter->StartAndWait(); |
|
119 User::LeaveIfError(waiter->Result()); |
|
120 CleanupStack::PopAndDestroy(waiter); |
|
121 |
|
122 TMsvAttachmentId attachmentId = attachment->Id(); |
|
123 |
|
124 store->CommitL(); |
|
125 |
|
126 CleanupStack::PopAndDestroy(2, entry); // store, entry |
|
127 |
|
128 StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(4)); |
|
129 } |
|
130 |
|
131 |
|
132 |