|
1 // Copyright (c) 2002-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 // $Workfile: SendAsStates.cpp $ |
|
15 // $Author: Stevep $ |
|
16 // $Revision: 2 $ |
|
17 // $Date: 27/03/02 10:44 $ |
|
18 // |
|
19 // |
|
20 |
|
21 #include "sendasstates.h" |
|
22 |
|
23 // System includes |
|
24 #include <sendas.h> // CSendAs |
|
25 #include <mtmdef.h> // Message part constant bitmasks for a TMsvPartList value. |
|
26 |
|
27 |
|
28 // User includes |
|
29 #include "obexharness.h" // CObexClientTest |
|
30 #include "obextestutils.h" // CObexTestUtils |
|
31 |
|
32 _LIT(KObexSendAsPanicLiteral, "Obex SendAs States"); // literal for panic |
|
33 |
|
34 // |
|
35 // CObexSendAsCreateState |
|
36 // |
|
37 |
|
38 CObexSendAsCreateState::CObexSendAsCreateState(CObexClientTest& aClientTest) : |
|
39 iClientTest(aClientTest) |
|
40 { |
|
41 } |
|
42 |
|
43 void CObexSendAsCreateState::StartL(TRequestStatus& aStatus) |
|
44 { |
|
45 if(!iClientTest.SendAs()) |
|
46 iClientTest.CreateSendAsL(); |
|
47 |
|
48 TRequestStatus* status = &aStatus; |
|
49 User::RequestComplete(status, KErrNone); |
|
50 } |
|
51 |
|
52 |
|
53 // |
|
54 // CObexSendAsAddRecipientState |
|
55 // |
|
56 |
|
57 CObexSendAsAddRecipientState::CObexSendAsAddRecipientState(const TDesC& aRecipient, CObexClientTest& aClientTest) : |
|
58 iClientTest(aClientTest), |
|
59 iRecipient(aRecipient) |
|
60 { |
|
61 } |
|
62 |
|
63 void CObexSendAsAddRecipientState::StartL(TRequestStatus& aStatus) |
|
64 { |
|
65 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
66 |
|
67 iClientTest.SendAs()->AddRecipientL(iRecipient); |
|
68 |
|
69 TRequestStatus* status = &aStatus; |
|
70 User::RequestComplete(status, KErrNone); |
|
71 } |
|
72 |
|
73 // |
|
74 // CObexSendAsAddBTRecipientState |
|
75 // |
|
76 |
|
77 TUint8 CObexSendAsAddBTRecipientState::GetByteFromUnicodeHexTextChar(const TUint16 *input) |
|
78 { |
|
79 TUint8 result = (TUint8)*input; |
|
80 |
|
81 if(result >='0' && result <='9') |
|
82 result = (TUint8)(result - '0'); |
|
83 else if(result >='a' && result <='f') |
|
84 result = (TUint8)(result - 'a' + 10); |
|
85 else if(result >='A' && result <='F') |
|
86 result = (TUint8)(result - 'A' + 10); |
|
87 else |
|
88 result = 0; |
|
89 |
|
90 return result; |
|
91 } |
|
92 |
|
93 CObexSendAsAddBTRecipientState::CObexSendAsAddBTRecipientState(const TDesC& aRecipient, CObexClientTest& aClientTest) : |
|
94 iClientTest(aClientTest) |
|
95 { |
|
96 // convert the incoming string from 12 unicode chars to 3 by |
|
97 // converting 4 chars into 1 thus: |
|
98 |
|
99 // first 4 input chars: '0' '0' '0' '2' |
|
100 // output char 0x0002 |
|
101 |
|
102 // Convert first addresse from 16bit descriptor to 8bit descriptor containing 48bit BT device address |
|
103 TPtrC16 ptr16 = aRecipient; |
|
104 int ii; |
|
105 |
|
106 for(ii=0;ii<12;ii+=4) |
|
107 { |
|
108 // do 4 characters to get one out. We're going to force the compiler to do the character endianness. |
|
109 TUint8 byte1 = GetByteFromUnicodeHexTextChar(&ptr16[ii]); |
|
110 TUint8 byte2 = GetByteFromUnicodeHexTextChar(&ptr16[ii+1]); |
|
111 TUint8 byte3 = GetByteFromUnicodeHexTextChar(&ptr16[ii+2]); |
|
112 TUint8 byte4 = GetByteFromUnicodeHexTextChar(&ptr16[ii+3]); |
|
113 |
|
114 byte1 = (TUint8) ( ((byte1 & 0x0F) << 4) | (byte2 & 0x0f) ); |
|
115 byte3 = (TUint8) ( ((byte3 & 0x0F) << 4) | (byte4 & 0x0f) ); |
|
116 |
|
117 // make sure this is put together in network endianness |
|
118 TUint16 result = (TUint16)( (TUint16)(byte3 << 8) | byte1 ); |
|
119 |
|
120 iRecipient.Append( result ); |
|
121 } |
|
122 |
|
123 } |
|
124 |
|
125 void CObexSendAsAddBTRecipientState::StartL(TRequestStatus& aStatus) |
|
126 { |
|
127 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
128 |
|
129 iClientTest.SendAs()->AddRecipientL(iRecipient); |
|
130 |
|
131 TRequestStatus* status = &aStatus; |
|
132 User::RequestComplete(status, KErrNone); |
|
133 } |
|
134 |
|
135 // |
|
136 // CObexSendAsSetSubjectState |
|
137 // |
|
138 |
|
139 CObexSendAsSetSubjectState::CObexSendAsSetSubjectState(const TDesC& aSubject, CObexClientTest& aClientTest) : |
|
140 iClientTest(aClientTest), |
|
141 iSubject(aSubject) |
|
142 { |
|
143 } |
|
144 |
|
145 void CObexSendAsSetSubjectState::StartL(TRequestStatus& aStatus) |
|
146 { |
|
147 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
148 |
|
149 iClientTest.SendAs()->SetSubjectL(iSubject); |
|
150 |
|
151 TRequestStatus* status = &aStatus; |
|
152 User::RequestComplete(status, KErrNone); |
|
153 } |
|
154 |
|
155 |
|
156 // |
|
157 // CObexSendAsAddAttachmentState |
|
158 // |
|
159 |
|
160 CObexSendAsAddAttachmentState::CObexSendAsAddAttachmentState(const TDesC& aFileName, CObexClientTest& aClientTest) : |
|
161 iClientTest(aClientTest), |
|
162 iFileName(aFileName) |
|
163 { |
|
164 } |
|
165 |
|
166 void CObexSendAsAddAttachmentState::StartL(TRequestStatus& aStatus) |
|
167 { |
|
168 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
169 |
|
170 TMsvId id; |
|
171 TFileName filename; |
|
172 |
|
173 iClientTest.SendAs()->CreateAttachmentL(id, filename); |
|
174 |
|
175 CFileMan* fileMan = CFileMan::NewL(iClientTest.ObexTestUtils().iMsvSession->FileSession()); |
|
176 CleanupStack::PushL(fileMan); // PUSH |
|
177 User::LeaveIfError(fileMan->Copy(iFileName, filename)); |
|
178 CleanupStack::PopAndDestroy(); // fileMan // POP(1) |
|
179 |
|
180 TRequestStatus* status = &aStatus; |
|
181 User::RequestComplete(status, KErrNone); |
|
182 } |
|
183 |
|
184 |
|
185 // |
|
186 // CObexSendAsAbandonState |
|
187 // |
|
188 |
|
189 CObexSendAsAbandonState::CObexSendAsAbandonState(CObexClientTest& aClientTest) : |
|
190 iClientTest(aClientTest) |
|
191 { |
|
192 } |
|
193 |
|
194 void CObexSendAsAbandonState::StartL(TRequestStatus& aStatus) |
|
195 { |
|
196 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
197 |
|
198 iClientTest.SendAs()->AbandonMessage(); |
|
199 |
|
200 TRequestStatus* status = &aStatus; |
|
201 User::RequestComplete(status, KErrNone); |
|
202 } |
|
203 |
|
204 |
|
205 // |
|
206 // CObexSendAsSaveState |
|
207 // |
|
208 |
|
209 CObexSendAsSaveState::CObexSendAsSaveState(CObexClientTest& aClientTest) : |
|
210 iClientTest(aClientTest) |
|
211 { |
|
212 } |
|
213 |
|
214 void CObexSendAsSaveState::StartL(TRequestStatus& aStatus) |
|
215 { |
|
216 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
217 |
|
218 iClientTest.SendAs()->SaveMessageL(); //no real benefit in using the async version of this function |
|
219 |
|
220 TRequestStatus* status = &aStatus; |
|
221 User::RequestComplete(status, KErrNone); |
|
222 } |
|
223 |
|
224 |
|
225 // |
|
226 // CObexSendAsValidateState |
|
227 // |
|
228 |
|
229 CObexSendAsValidateState::CObexSendAsValidateState(CObexClientTest& aClientTest) : |
|
230 iClientTest(aClientTest) |
|
231 { |
|
232 } |
|
233 |
|
234 void CObexSendAsValidateState::StartL(TRequestStatus& aStatus) |
|
235 { |
|
236 //CBaseMtm::ValidateMessage currently only validates the recipient part of the message but, hey, that may change. |
|
237 __ASSERT_ALWAYS( iClientTest.SendAs(), User::Panic(KObexSendAsPanicLiteral, KErrNotReady)); |
|
238 |
|
239 TMsvPartList partlist = iClientTest.SendAs()->ValidateMessage(); |
|
240 |
|
241 if(partlist != 0) |
|
242 { |
|
243 _LIT(KOpeningMessage, "\nThe following parts of the SendAs message are invalid:"); |
|
244 iClientTest.LogCommentL(KOpeningMessage); |
|
245 |
|
246 if(partlist & KMsvMessagePartAttachments) |
|
247 { |
|
248 _LIT(KAttachments, "KMsvMessagePartAttachments."); |
|
249 iClientTest.LogCommentL(KAttachments); |
|
250 } |
|
251 |
|
252 if(partlist & KMsvMessagePartBody) |
|
253 { |
|
254 _LIT(KBody, "KMsvMessagePartBody."); |
|
255 iClientTest.LogCommentL(KBody); |
|
256 } |
|
257 |
|
258 if(partlist & KMsvMessagePartDate) |
|
259 { |
|
260 _LIT(KDate, "KMsvMessagePartDate."); |
|
261 iClientTest.LogCommentL(KDate); |
|
262 } |
|
263 |
|
264 if(partlist & KMsvMessagePartDescription) |
|
265 { |
|
266 _LIT(KDescription, "KMsvMessagePartDescription."); |
|
267 iClientTest.LogCommentL(KDescription); |
|
268 } |
|
269 |
|
270 if(partlist & KMsvMessagePartOriginator) |
|
271 { |
|
272 _LIT(KOriginator, "KMsvMessagePartOriginator."); |
|
273 iClientTest.LogCommentL(KOriginator); |
|
274 } |
|
275 |
|
276 if(partlist & KMsvMessagePartRecipient) |
|
277 { |
|
278 _LIT(KRecipient, "KMsvMessagePartRecipient."); |
|
279 iClientTest.LogCommentL(KRecipient); |
|
280 } |
|
281 |
|
282 } |
|
283 else |
|
284 { |
|
285 _LIT(KMessageValid, "\nThe SendAs message is valid."); |
|
286 iClientTest.LogCommentL(KMessageValid); |
|
287 } |
|
288 |
|
289 TRequestStatus* status = &aStatus; |
|
290 User::RequestComplete(status, KErrNone); |
|
291 } |
|
292 |