|
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 // GetAttachmentIndexFromId |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // MsgId <input>: Value of the message Id. |
|
20 // AttachmentId <input>: Value of the attachment id. |
|
21 // Index <output>: The index of the attachment. |
|
22 // [Action Description] |
|
23 // Get the index position of the attachment specified by its id for the |
|
24 // specified message entry. |
|
25 // [APIs Used] |
|
26 // CMsvSession::GetEntryL |
|
27 // CMsvStore::ReadStoreL |
|
28 // CMsvStore::AttachmentManagerL |
|
29 // TODO |
|
30 // __ACTION_INFO_END__ |
|
31 // |
|
32 // |
|
33 |
|
34 |
|
35 #include "CMtfTestActionGetAttachmentIndexFromId.h" |
|
36 #include "CMtfTestCase.h" |
|
37 #include "CMtfTestActionParameters.h" |
|
38 #include "MtfTestActionUtilsUser.h" |
|
39 |
|
40 #include <miutset.h> |
|
41 #include <mmsvattachmentmanager.h> |
|
42 #include <cmsvattachment.h> |
|
43 |
|
44 CMtfTestAction* CMtfTestActionGetAttachmentIndexFromId::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
45 { |
|
46 CMtfTestActionGetAttachmentIndexFromId* self = new(ELeave) CMtfTestActionGetAttachmentIndexFromId(aTestCase); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(aActionParameters); |
|
49 CleanupStack::Pop(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 CMtfTestActionGetAttachmentIndexFromId::CMtfTestActionGetAttachmentIndexFromId(CMtfTestCase& aTestCase) |
|
55 : CMtfSynchronousTestAction(aTestCase) |
|
56 { |
|
57 } |
|
58 |
|
59 |
|
60 CMtfTestActionGetAttachmentIndexFromId::~CMtfTestActionGetAttachmentIndexFromId() |
|
61 { |
|
62 } |
|
63 |
|
64 |
|
65 void CMtfTestActionGetAttachmentIndexFromId::ExecuteActionL() |
|
66 { |
|
67 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionGetAttachmentIndexFromId); |
|
68 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
69 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
70 TMsvAttachmentId attachmentId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2)); |
|
71 |
|
72 CMsvEntry* entry = paramSession->GetEntryL(messageEntry); |
|
73 CleanupStack::PushL(entry); |
|
74 |
|
75 CMsvStore* store = entry->ReadStoreL(); |
|
76 CleanupStack::PushL(store); |
|
77 |
|
78 MMsvAttachmentManager& manager = store->AttachmentManagerL(); |
|
79 |
|
80 TInt attachmentCount = manager.AttachmentCount(); |
|
81 TBool found = EFalse; |
|
82 |
|
83 TInt attachmentIndex; |
|
84 |
|
85 for(attachmentIndex=0; attachmentIndex<attachmentCount; ++attachmentIndex) |
|
86 { |
|
87 CMsvAttachment* attachment = manager.GetAttachmentInfoL(attachmentIndex); |
|
88 |
|
89 if( attachment->Id() == attachmentId ) |
|
90 { |
|
91 // found the attachment |
|
92 found = ETrue; |
|
93 delete attachment; |
|
94 break; |
|
95 } |
|
96 |
|
97 delete attachment; |
|
98 } |
|
99 |
|
100 CleanupStack::PopAndDestroy(2, entry); // store, entry |
|
101 |
|
102 if( !found ) |
|
103 { |
|
104 // can't find the attachment |
|
105 User::Leave(KErrNotFound); |
|
106 } |
|
107 |
|
108 StoreParameterL<TInt>(TestCase(),attachmentIndex,ActionParameters().Parameter(3)); |
|
109 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionGetAttachmentIndexFromId); |
|
110 TestCase().ActionCompletedL(*this); |
|
111 } |
|
112 |