|
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 // AddAttachmentAsLink |
|
17 // [Action Parameters] |
|
18 // Store <input>: Reference to the store. |
|
19 // FilePath <input>: File path of the linked attachment file. |
|
20 // MimeType <input>: Mime-type of the attachment. |
|
21 // AttachmentId <output>: Value of the created attachment id. |
|
22 // ErrorCode <output>: (Optional) Returned error code, if not requested then code will |
|
23 // leave if not KErrNone |
|
24 // [Action Description] |
|
25 // Adds the specified file as a linked attachment to the specified message |
|
26 // entry. |
|
27 // [APIs Used] |
|
28 // CMsvStore::AttachmentManagerL |
|
29 // CMsvAttachment::NewL |
|
30 // CMsvAttachment::SetMimeType |
|
31 // MMsvAttachmentManager::AddLinkedAttachmentL |
|
32 // __ACTION_INFO_END__ |
|
33 // |
|
34 // |
|
35 |
|
36 |
|
37 #include "CMtfTestActionAddAttachmentAsLink.h" |
|
38 #include "CMtfAsyncWaiter.h" |
|
39 #include "CMtfTestCase.h" |
|
40 #include "CMtfTestActionParameters.h" |
|
41 #include "MtfTestActionUtilsUser.h" |
|
42 |
|
43 #include <miutset.h> |
|
44 #include <cmsvattachment.h> |
|
45 #include <mmsvattachmentmanager.h> |
|
46 |
|
47 CMtfTestAction* CMtfTestActionAddAttachmentAsLink::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
48 { |
|
49 CMtfTestActionAddAttachmentAsLink* self = new(ELeave) CMtfTestActionAddAttachmentAsLink(aTestCase); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(aActionParameters); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 CMtfTestActionAddAttachmentAsLink::CMtfTestActionAddAttachmentAsLink(CMtfTestCase& aTestCase) |
|
58 : CMtfSynchronousTestAction(aTestCase) |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 CMtfTestActionAddAttachmentAsLink::~CMtfTestActionAddAttachmentAsLink() |
|
64 { |
|
65 } |
|
66 |
|
67 void CMtfTestActionAddAttachmentAsLink::ExecuteActionL() |
|
68 { |
|
69 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddAttachmentAsLink); |
|
70 TRAPD(err, RunTestL()); |
|
71 |
|
72 if( ActionParameters().Count() < 5 ) |
|
73 { |
|
74 User::LeaveIfError(err); |
|
75 } |
|
76 else |
|
77 { |
|
78 StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(4)); |
|
79 } |
|
80 |
|
81 TestCase().INFO_PRINTF1(_L("CMtfTestActionAddAttachmentAsLink completed.....")); |
|
82 |
|
83 TestCase().ActionCompletedL(*this); |
|
84 } |
|
85 |
|
86 void CMtfTestActionAddAttachmentAsLink::RunTestL() |
|
87 { |
|
88 CMsvStore* paramStore = ObtainParameterReferenceL<CMsvStore>(TestCase(),ActionParameters().Parameter(0)); |
|
89 HBufC* paramFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(1)); |
|
90 HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(2)); |
|
91 |
|
92 |
|
93 CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); |
|
94 CleanupStack::PushL(waiter); |
|
95 |
|
96 CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvLinkedFile); |
|
97 CleanupStack::PushL(attachment); |
|
98 |
|
99 attachment->SetMimeTypeL(*paramMimeType); |
|
100 |
|
101 TParse fileNameParser; |
|
102 User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL)); |
|
103 attachment->SetAttachmentNameL(fileNameParser.NameAndExt()); |
|
104 |
|
105 MMsvAttachmentManager& manager = paramStore->AttachmentManagerL(); |
|
106 |
|
107 manager.AddLinkedAttachmentL(*paramFilePath, attachment, waiter->iStatus); |
|
108 CleanupStack::Pop(attachment); // ownership passed to manager |
|
109 |
|
110 waiter->StartAndWait(); |
|
111 User::LeaveIfError(waiter->Result()); |
|
112 CleanupStack::PopAndDestroy(waiter); |
|
113 |
|
114 TMsvAttachmentId attachmentId = attachment->Id(); |
|
115 |
|
116 paramStore->CommitL(); |
|
117 |
|
118 StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(3)); |
|
119 } |