|
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 // CMTFTESTACTIOSMTPNGETATTACHMENTFILEFROMINDEX.CPP |
|
15 // __ACTION_INFO_BEGIN__ |
|
16 // [Action Name] |
|
17 // SmtpGetAttachmentFileFromIndex |
|
18 // [Action Parameters] |
|
19 // Session <input>: Reference to the session. |
|
20 // MsgId <input>: Value of the message Id. |
|
21 // Index <input>: Index value of attachment to retrieve. |
|
22 // DataFilePath <input>: (optional) File path of data to compare attachment to. |
|
23 // ExpectedError <input>: (optional) Expected error code to compare against. |
|
24 // [Action Description] |
|
25 // Gets the attachment file from the specified index |
|
26 // [APIs Used] |
|
27 // CMsvSession::GetEntryL |
|
28 // CImEmailMessage::AttachmentManagerL |
|
29 // __ACTION_INFO_END__ |
|
30 // |
|
31 // |
|
32 |
|
33 |
|
34 #include "CMtfTestActionSmtpGetAttachmentFileFromIndex.h" |
|
35 #include "CMtfTestCase.h" |
|
36 #include "CMtfTestActionParameters.h" |
|
37 #include "MtfTestActionUtilsUser.h" |
|
38 |
|
39 #include <miutset.h> |
|
40 #include <mmsvattachmentmanager.h> |
|
41 #include <miutmsg.h> |
|
42 |
|
43 CMtfTestAction* CMtfTestActionSmtpGetAttachmentFileFromIndex::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
44 { |
|
45 CMtfTestActionSmtpGetAttachmentFileFromIndex* self = new(ELeave) CMtfTestActionSmtpGetAttachmentFileFromIndex(aTestCase); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aActionParameters); |
|
48 CleanupStack::Pop(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 CMtfTestActionSmtpGetAttachmentFileFromIndex::CMtfTestActionSmtpGetAttachmentFileFromIndex(CMtfTestCase& aTestCase) |
|
54 : CMtfSynchronousTestAction(aTestCase) |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 CMtfTestActionSmtpGetAttachmentFileFromIndex::~CMtfTestActionSmtpGetAttachmentFileFromIndex() |
|
60 { |
|
61 } |
|
62 |
|
63 void CMtfTestActionSmtpGetAttachmentFileFromIndex::ExecuteActionL() |
|
64 { |
|
65 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpGetAttachmentFileFromIndex); |
|
66 TInt expectedError = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(4), KErrNone); |
|
67 |
|
68 if( expectedError != KErrNone ) |
|
69 { |
|
70 // error checking is requested |
|
71 TRAPD(err, RunTestActionL()); |
|
72 if( expectedError != err ) |
|
73 { |
|
74 // not the expected error code |
|
75 User::Leave(KErrGeneral); |
|
76 } |
|
77 } |
|
78 else |
|
79 { |
|
80 // no error expected |
|
81 RunTestActionL(); |
|
82 } |
|
83 |
|
84 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpGetAttachmentFileFromIndex); |
|
85 TestCase().ActionCompletedL(*this); |
|
86 } |
|
87 |
|
88 void CMtfTestActionSmtpGetAttachmentFileFromIndex::RunTestActionL() |
|
89 { |
|
90 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
91 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
92 TInt attachIndex = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2)); |
|
93 HBufC* dataFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(3), NULL); |
|
94 |
|
95 CMsvEntry* entry = paramSession->GetEntryL(messageEntry); |
|
96 CleanupStack::PushL(entry); |
|
97 |
|
98 CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry); |
|
99 CleanupStack::PushL(emailMsg); |
|
100 |
|
101 MMsvAttachmentManager& manager = emailMsg->AttachmentManager(); |
|
102 |
|
103 TInt attachmentCount = manager.AttachmentCount(); |
|
104 |
|
105 RFile fileAttachment = manager.GetAttachmentFileL(attachIndex); |
|
106 CleanupClosePushL(fileAttachment); |
|
107 |
|
108 if( dataFilePath != NULL ) |
|
109 { |
|
110 // check of contents of attachment file is requested |
|
111 CompareFileL(fileAttachment, *dataFilePath); |
|
112 } |
|
113 |
|
114 CleanupStack::PopAndDestroy(3, entry); // fileAttachment, emailMsg, entry |
|
115 } |
|
116 |
|
117 void CMtfTestActionSmtpGetAttachmentFileFromIndex::CompareFileL(RFile& aAttachment, const TDesC& aDataFilePath) |
|
118 { |
|
119 RFs fs; |
|
120 User::LeaveIfError(fs.Connect()); |
|
121 CleanupClosePushL(fs); |
|
122 |
|
123 RFile dataFile; |
|
124 User::LeaveIfError(dataFile.Open(fs, aDataFilePath, EFileRead|EFileShareReadersOnly)); |
|
125 CleanupClosePushL(fs); |
|
126 |
|
127 TInt fileSize = 0; |
|
128 |
|
129 User::LeaveIfError(dataFile.Size(fileSize)); |
|
130 HBufC8* dataBuffer = HBufC8::NewLC(fileSize); |
|
131 TPtr8 bufferPtr(dataBuffer->Des()); |
|
132 |
|
133 User::LeaveIfError(aAttachment.Size(fileSize)); |
|
134 HBufC8* attachmentData = HBufC8::NewLC(fileSize); |
|
135 TPtr8 attachmentPtr(attachmentData->Des()); |
|
136 |
|
137 TInt compare = attachmentPtr.Compare(bufferPtr); |
|
138 if( compare != 0 ) |
|
139 User::Leave(KErrCorrupt); |
|
140 |
|
141 CleanupStack::PopAndDestroy(4, &fs); // attachmentData, dataBuffer, dataFile, fs |
|
142 } |
|
143 |