|
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 // SendAsCreateAttachment |
|
17 // [Action Parameters] |
|
18 // RSendAsMessage sendAsMessage <input> : Reference of the RSendAsMessage object |
|
19 // HBufC attachmentFile <input> : The file to be attached as a linked attachment |
|
20 // HBufC mimeType <input> : MIME type.Default value implies that no MIME type is specified |
|
21 // [Action Description] |
|
22 // SendAsCreateAttachment Test Action is intended to create an attachment to the message. |
|
23 // If the MIME type is provided as an input to the Test Action, the MIME type will be set. |
|
24 // [APIs Used] |
|
25 // RSendAsMessage::CreateAttachmentL(RFs& aFs, RFile& aAttachmentFile, const TDesC& aMimeType) |
|
26 // RSendAsMessage::CreateAttachmentL(RFs& aFs, RFile& aAttachmentFile) |
|
27 // __ACTION_INFO_END__ |
|
28 // |
|
29 // |
|
30 |
|
31 /** |
|
32 @file |
|
33 @internalTechnology |
|
34 */ |
|
35 |
|
36 |
|
37 // User include |
|
38 #include "sendas2.h" |
|
39 #include "CMtfTestActionSendAsCreateAttachment.h" |
|
40 #include "CMtfTestCase.h" |
|
41 #include "CMtfTestActionParameters.h" |
|
42 |
|
43 |
|
44 /** |
|
45 NewL() |
|
46 Constructs a CMtfTestActionSendAsCreateAttachment object. |
|
47 Uses two phase construction and leaves nothing on the CleanupStack. |
|
48 @internalTechnology |
|
49 @param aTestCase Test Case to which this Test Action belongs |
|
50 @param aActionParameters Action parameters, must not be NULL |
|
51 @return Created object of type CMtfTestActionSendAsCreateAttachment |
|
52 @pre None |
|
53 @post CMtfTestActionSendAsCreateAttachment object is created |
|
54 */ |
|
55 CMtfTestAction* CMtfTestActionSendAsCreateAttachment:: |
|
56 NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
57 { |
|
58 CMtfTestActionSendAsCreateAttachment* self = |
|
59 new (ELeave) CMtfTestActionSendAsCreateAttachment(aTestCase); |
|
60 |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(aActionParameters); |
|
63 CleanupStack::Pop(self); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 /** |
|
69 CMtfTestActionSendAsCreateAttachment constructor |
|
70 Calls the base class' constructor |
|
71 @internalTechnology |
|
72 @param aTestCase Test Case to which this Test Action belongs |
|
73 @pre None |
|
74 @post None |
|
75 */ |
|
76 CMtfTestActionSendAsCreateAttachment::CMtfTestActionSendAsCreateAttachment(CMtfTestCase& aTestCase) |
|
77 : CMtfSynchronousTestAction(aTestCase) |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 /** |
|
83 Function : ~CMtfTestActionSendAsCreateAttachment |
|
84 Description : Destructor |
|
85 @internalTechnology |
|
86 @param : |
|
87 @return : |
|
88 @pre |
|
89 @post |
|
90 */ |
|
91 CMtfTestActionSendAsCreateAttachment::~CMtfTestActionSendAsCreateAttachment() |
|
92 { |
|
93 } |
|
94 |
|
95 /** |
|
96 ExecuteActionL |
|
97 Obtain the input parameters |
|
98 1. sendAsMessage |
|
99 2. attachmentFile |
|
100 3. mimeType (Default value implies empty string) |
|
101 Create a File Server session and create a RFile for the attachment File |
|
102 IF MIME type is specified |
|
103 Call RSendAsMessage::CreateAttachmentL (RFs& aFs, RFile& aAttachmentFile, const TDesC& aMimeType) providing file session, RFile and the mimeType as input parameters |
|
104 ELSE |
|
105 Call RSendAsMessage::CreateAttachmentL (RFs& aFs, RFile& aAttachmentFile) providing file session, RFile as input parameter |
|
106 END IF |
|
107 Open the attachmentFile in Read-Only mode |
|
108 Read the contents of the attachmentFile and write it to the attachment |
|
109 file using the File handle provided by RSendAsMessage::CreateAttachmentL() function |
|
110 Close the file handles |
|
111 Close session with the file server |
|
112 |
|
113 @internalTechnology |
|
114 @pre None |
|
115 @post None |
|
116 @leave System wide errors |
|
117 */ |
|
118 void CMtfTestActionSendAsCreateAttachment::ExecuteActionL() |
|
119 { |
|
120 if((TestCase().TestStepResult()) == EPass) |
|
121 { |
|
122 RSendAsMessage sendAsMessage = ObtainValueParameterL<RSendAsMessage>(TestCase(), |
|
123 ActionParameters().Parameter(0)); |
|
124 HBufC* attachmentFileName = ObtainParameterReferenceL<HBufC>(TestCase(), |
|
125 ActionParameters().Parameter(1)); |
|
126 HBufC* attachmentFile = ObtainParameterReferenceL<HBufC>(TestCase(), |
|
127 ActionParameters().Parameter(2)); |
|
128 HBufC8* mimeType = ObtainParameterReferenceL<HBufC8>(TestCase(), |
|
129 ActionParameters().Parameter(3), NULL); |
|
130 |
|
131 RFs fs; |
|
132 TInt err = KErrNone; |
|
133 if(fs.Connect() == KErrNone) |
|
134 { |
|
135 CleanupClosePushL(fs); |
|
136 |
|
137 RFile createdAttachment; |
|
138 if(mimeType == NULL) |
|
139 { |
|
140 TRAP(err,sendAsMessage.CreateAttachmentL(*attachmentFileName, createdAttachment)); |
|
141 } |
|
142 else |
|
143 { |
|
144 TRAP(err,sendAsMessage.CreateAttachmentL(*attachmentFileName, createdAttachment, *mimeType)); |
|
145 } |
|
146 CleanupClosePushL(createdAttachment); |
|
147 |
|
148 RFile attachFile; |
|
149 |
|
150 User::LeaveIfError(attachFile.Open(fs,*attachmentFile,EFileShareReadersOnly)); |
|
151 CleanupClosePushL(attachFile); |
|
152 |
|
153 |
|
154 TInt fileSize = 0; |
|
155 User::LeaveIfError(attachFile.Size(fileSize)); |
|
156 HBufC8* fileContents = HBufC8::NewLC(fileSize); |
|
157 TPtr8 fileContentsptr = fileContents->Des(); |
|
158 |
|
159 User::LeaveIfError(attachFile.Read(fileContentsptr)); |
|
160 |
|
161 createdAttachment.Write(0, fileContentsptr); |
|
162 |
|
163 TInt fileSize1 = 0; |
|
164 User::LeaveIfError(createdAttachment.Size(fileSize1)); |
|
165 CleanupStack::PopAndDestroy(4); // fileContents, attachFile, createdAttachment,fs |
|
166 } |
|
167 else |
|
168 { |
|
169 TestCase().ERR_PRINTF1(_L("Failed to Connect to the File Server")); |
|
170 } |
|
171 |
|
172 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsCreateAttachment); |
|
173 } |
|
174 TestCase().ActionCompletedL(*this); |
|
175 } |