|
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 // |
|
15 |
|
16 |
|
17 #include "ObexParsers.h" |
|
18 // System includes |
|
19 #include <obexheaders.h> |
|
20 // User includes |
|
21 #include "harness.h" // CMainTestHarness |
|
22 #include "ObexHarness.h" // CObexClientTest |
|
23 #include "ObexTestUtils.h" // CObexTestUtils |
|
24 #include "testframeutils.h" // CTestScript |
|
25 #include "SelectObexMtmTypeState.h" // CSelectObexMtmTypeState |
|
26 #include "SetObexMessageRecipientStates.h" // CSetObexMessageRecipientState & BT Version |
|
27 #include "CreateServiceEntryState.h" // CCreateServiceEntryState |
|
28 #include "CreateObexMessageState.h" // CCreateObexMessageState |
|
29 #include "SendMessageState.h" // CSendMessageState |
|
30 #include "AddObexAttachmentState.h" // CAddObexAttachmentState |
|
31 #include "ObexFileDebugReceiveState.h" // CObexFileDebugReceiveState |
|
32 #include "ObexIgnoreSendErrorsState.h" // CObexIgnoreSendErrorsState |
|
33 #include "sendasstates.h" // CObexSendAsCreateState, CObexSendAsAddRecipientState, |
|
34 // CObexSendAsSetSubjectState, CObexSendAsAddAttachmentState, |
|
35 // CObexSendAsAbandonState, CObexSendAsSaveState, CObexSendAsValidateState |
|
36 #include "obexsetpasswordstate.h" // CObexSetPasswordState |
|
37 #include "obexresetpasswordstate.h" // CObexResetPasswordState |
|
38 #include "obexgetpasswordstate.h" // CObexGetPasswordState |
|
39 |
|
40 #include "RegisterObexMtmTypeState.h" // CRegisterObexMtmTypeState |
|
41 #include "UnRegisterObexMtmTypeState.h" // CRegisterObexMtmTypeState |
|
42 |
|
43 #include "AddHeadersState.h" // CAddHeadersState |
|
44 |
|
45 |
|
46 // |
|
47 // SCRIPT TOKENS // |
|
48 // |
|
49 |
|
50 // Test tokens |
|
51 _LIT(KCommandObexClientTest, "obex_client_test"); |
|
52 _LIT(KCommandObexSelectMtm, "obex_select_mtm"); |
|
53 _LIT(KCommandObexCreateMessage, "create_message"); |
|
54 _LIT(KCommandObexSetMessageAddressee, "set_recipient"); |
|
55 _LIT(KCommandObexSetBTMessageAddressee, "set_bt_recipient"); |
|
56 _LIT(KCommandObexSendMessage, "send_message"); |
|
57 _LIT(KCommandObexSendMessageAndCancel, "send_message_and_cancel"); |
|
58 _LIT(KCommandObexCreateService, "create_service"); |
|
59 _LIT(KCommandObexAddAttachmentAsEntry, "add_attachment_as_entry"); |
|
60 _LIT(KCommandObexAddAttachmentByName, "add_attachment_by_name"); |
|
61 _LIT(KCommandObexSimulateObjectReceipt, "simulate_object_receipt"); |
|
62 _LIT(KCommandObexIgnoreSendErrors, "ignore_send_errors"); |
|
63 |
|
64 |
|
65 // Send As Commands |
|
66 _LIT(KCommandObexCreateSendAs, "sendas_create"); // 0 parameters, creates a SendAs object and message |
|
67 _LIT(KCommandObexAddSendAsRecipient, "sendas_add_recipient"); // 1 parameter, adds the specified recipient to the SendAs message |
|
68 _LIT(KCommandObexAddSendAsBTRecipient, "sendas_add_bt_recipient"); // 1 parameter, adds the specified recipient to the SendAs message |
|
69 _LIT(KCommandObexSetSendAsSubject, "sendas_set_subject"); // 1 parameter, sets the subject of a SendAs Message |
|
70 _LIT(KCommandObexAddSendAsAttachment, "sendas_add_attachment"); // 1 parameter, adds the specified attachment to a SendAs Message |
|
71 _LIT(KCommandObexAbandonSendAsMessage, "sendas_abandon_message"); // 0 parameters, abandons the creation of a SendAs message |
|
72 _LIT(KCommandObexSaveSendAsMessage, "sendas_save_message"); // 0 parameters, saves the current SendAs message to the outbox |
|
73 _LIT(KCommandObexValidateSendAsMessage, "sendas_validate_message"); // 0 parameters, validates the current SendAs message |
|
74 |
|
75 //password commands |
|
76 |
|
77 //register/unregistering commands |
|
78 _LIT(KCommandObexRegisterMtm, "register_mtm"); // 1 paramter, registers either an IR or BT Mtm |
|
79 _LIT(KCommandObexUnRegisterMtm, "unregister_mtm"); // 1 paramter, unregister either an IR or BT Mtm |
|
80 |
|
81 // commands for obex header support |
|
82 _LIT(KCommandObexAddHeader, "add_header"); |
|
83 _LIT(KCommandObexAddAttachmentByNameWithHeaders, "add_attachment_by_name_with_headers"); |
|
84 |
|
85 |
|
86 // |
|
87 // CObexMainSectionParser |
|
88 // |
|
89 CObexMainSectionParser* CObexMainSectionParser::NewL(CMainTestHarness& aMainTest, CTestScript& aScript) |
|
90 { |
|
91 CObexMainSectionParser* self = new (ELeave) CObexMainSectionParser(aMainTest, aScript); |
|
92 CleanupStack::PushL(self); |
|
93 self->ConstructL(); |
|
94 CleanupStack::Pop(); // self |
|
95 return self; |
|
96 } |
|
97 |
|
98 void CObexMainSectionParser::ConstructL() |
|
99 { |
|
100 CMainSectionParser::ConstructL(); |
|
101 iCommandParsers->AppendL(CNewObexTestCommandParser::NewL(iScript, iMainTest)); |
|
102 } |
|
103 |
|
104 CObexMainSectionParser::CObexMainSectionParser(CMainTestHarness& aMainTest, CTestScript& aScript) |
|
105 : CMainSectionParser(aMainTest, aScript), |
|
106 iMainTest(aMainTest) |
|
107 { |
|
108 } |
|
109 |
|
110 |
|
111 // |
|
112 // CNewObexTestCommandParser |
|
113 // |
|
114 CNewObexTestCommandParser* CNewObexTestCommandParser::NewL(CTestScript& aScript, CMainTestHarness& aMainTest) |
|
115 { |
|
116 CNewObexTestCommandParser* self = new (ELeave) CNewObexTestCommandParser(aScript, aMainTest); |
|
117 CleanupStack::PushL(self); |
|
118 self->ConstructL(); |
|
119 CleanupStack::Pop(); // self |
|
120 return self; |
|
121 } |
|
122 |
|
123 void CNewObexTestCommandParser::ConstructL() |
|
124 { |
|
125 CBaseCommandParser::ConstructL(); |
|
126 AddCommandL(KCommandObexClientTest); |
|
127 } |
|
128 |
|
129 CNewObexTestCommandParser::CNewObexTestCommandParser(CTestScript& aScript, CMainTestHarness& aMainTest) |
|
130 : iMainTest(aMainTest), |
|
131 iScript(aScript) |
|
132 { |
|
133 } |
|
134 |
|
135 void CNewObexTestCommandParser::ProcessL() |
|
136 { |
|
137 // Create an obex test utilities |
|
138 CObexTestUtils* obexTestUtils = CObexTestUtils::NewL(iMainTest.TestConsole()); |
|
139 CleanupStack::PushL(obexTestUtils); // PUSH |
|
140 |
|
141 // Create an obex test, give it the test utilities |
|
142 CObexClientTest* obexTest = CObexClientTest::NewL(obexTestUtils, iMainTest.TestConsole()); // obexTest takes ownership of obexTestUtils |
|
143 CleanupStack::Pop(); // obexTestUtils // POP(1) |
|
144 CleanupStack::PushL(obexTest); // PUSH |
|
145 |
|
146 // Attach the obex test to the main test |
|
147 iMainTest.AddStateL(obexTest, iDebugInfo); // iMainTest takes ownership of obexTest |
|
148 CleanupStack::Pop(); // obexTest // POP(1) |
|
149 |
|
150 // Check that there is one argument, the obex test section name |
|
151 CheckNumberOfArgumentsL(1); |
|
152 |
|
153 // Create an obex client section parser |
|
154 CObexClientSectionParser* sectionParser = CObexClientSectionParser::NewL(*obexTest, iScript, (*iArgumentList)[0]); |
|
155 CleanupStack::PushL(sectionParser); // PUSH |
|
156 sectionParser->ParseL(); |
|
157 CleanupStack::PopAndDestroy(); // sectionParser // POP(1) |
|
158 } |
|
159 |
|
160 |
|
161 |
|
162 // |
|
163 // CObexClientSectionParser |
|
164 // |
|
165 CObexClientSectionParser* CObexClientSectionParser::NewL(CObexClientTest& aObexClientTest, CTestScript& aScript, const TDesC& aNewSectionName) |
|
166 { |
|
167 CObexClientSectionParser* self = new (ELeave) CObexClientSectionParser(aObexClientTest, aScript); |
|
168 CleanupStack::PushL(self); |
|
169 self->ConstructL(aNewSectionName); |
|
170 CleanupStack::Pop(self); |
|
171 return self; |
|
172 } |
|
173 |
|
174 void CObexClientSectionParser::ConstructL(const TDesC& aNewSectionName) |
|
175 { |
|
176 CBaseSectionParser::ConstructL(aNewSectionName); |
|
177 |
|
178 TTestDebugInfo debugInfo = iObexTest.GetDebugInfo(); |
|
179 debugInfo.SetTestHarnessName(iSection->SectionPosition()); |
|
180 iObexTest.SetDebugInfo(debugInfo); |
|
181 |
|
182 iCommandParsers->AppendL(CMsvSelectParser::NewL(iObexTest)); |
|
183 iCommandParsers->AppendL(CMsvUtilitiesParser::NewL(iObexTest)); |
|
184 iCommandParsers->AppendL(CMsvOperationParser::NewL(iObexTest)); |
|
185 iCommandParsers->AppendL(CObexClientTestCommandParser::NewL(iScript, iObexTest)); |
|
186 } |
|
187 |
|
188 CObexClientSectionParser::CObexClientSectionParser(CObexClientTest& aObexTest, CTestScript& aScript) |
|
189 : CBaseSectionParser(aScript), |
|
190 iObexTest(aObexTest), |
|
191 iScript(aScript) |
|
192 { |
|
193 } |
|
194 |
|
195 |
|
196 void CObexClientSectionParser::LogCommentL(const TDesC& aComment) |
|
197 { |
|
198 iObexTest.ObexTestUtils().WriteComment(aComment); |
|
199 } |
|
200 |
|
201 // |
|
202 // CObexClientTestCommandParser |
|
203 // |
|
204 void CObexClientTestCommandParser::ProcessL() |
|
205 { |
|
206 if ((*iCurrentCommand) == KCommandObexSelectMtm) |
|
207 { |
|
208 CheckNumberOfArgumentsL(1); //"BT" or "IR" |
|
209 iObexTest.AddStateL(new (ELeave)CSelectObexMtmTypeState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
210 } |
|
211 else if ((*iCurrentCommand) == KCommandObexCreateService) |
|
212 { |
|
213 CheckNumberOfArgumentsL(0); |
|
214 iObexTest.AddStateL(new (ELeave)CCreateServiceEntryState(iObexTest), iDebugInfo); |
|
215 } |
|
216 else if ((*iCurrentCommand) == KCommandObexCreateMessage) |
|
217 { |
|
218 CheckNumberOfArgumentsL(0); |
|
219 iObexTest.AddStateL(new (ELeave)CCreateObexMessageState(iObexTest), iDebugInfo); |
|
220 } |
|
221 else if ((*iCurrentCommand) == KCommandObexSendMessage) |
|
222 { |
|
223 if (iArgumentList->Count() == 0) |
|
224 iObexTest.AddStateL(new (ELeave)CSendMessageState(_L("succeed"), iObexTest), iDebugInfo); |
|
225 else |
|
226 iObexTest.AddStateL(new (ELeave)CSendMessageState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
227 } |
|
228 else if ((*iCurrentCommand) == KCommandObexSendMessageAndCancel) |
|
229 { |
|
230 iObexTest.SetCancelGranularity(1000); |
|
231 iObexTest.AddStateL(new (ELeave)CSendMessageState(_L("succeed"), iObexTest), iDebugInfo); |
|
232 } |
|
233 else if ((*iCurrentCommand) == KCommandObexSetMessageAddressee) |
|
234 { |
|
235 CheckNumberOfArgumentsL(1); |
|
236 iObexTest.AddStateL(new (ELeave)CSetObexMessageRecipientState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
237 } |
|
238 else if ((*iCurrentCommand) == KCommandObexSetBTMessageAddressee) |
|
239 { |
|
240 CheckNumberOfArgumentsL(1); |
|
241 iObexTest.AddStateL(new (ELeave)CSetObexMessageBTRecipientState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
242 } |
|
243 else if ((*iCurrentCommand) == KCommandObexAddAttachmentByName) |
|
244 { |
|
245 CheckNumberOfArgumentsL(1); |
|
246 iObexTest.AddStateL(new (ELeave)CAddObexAttachmentByNameState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
247 } |
|
248 else if ((*iCurrentCommand) == KCommandObexAddAttachmentAsEntry) |
|
249 { |
|
250 CheckNumberOfArgumentsL(1); |
|
251 iObexTest.AddStateL(new (ELeave)CAddObexAttachmentAsEntryState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
252 } |
|
253 else if((*iCurrentCommand) == KCommandObexSimulateObjectReceipt) |
|
254 { |
|
255 CheckNumberOfArgumentsL(2); |
|
256 iObexTest.AddStateL(new (ELeave)CObexFileDebugReceiveState((*iArgumentList)[0], (*iArgumentList)[1], iObexTest), iDebugInfo); |
|
257 } |
|
258 //sendas |
|
259 else if((*iCurrentCommand) == KCommandObexCreateSendAs) |
|
260 { |
|
261 CheckNumberOfArgumentsL(0); |
|
262 iObexTest.AddStateL(new (ELeave) CObexSendAsCreateState(iObexTest), iDebugInfo); |
|
263 } |
|
264 else if((*iCurrentCommand) == KCommandObexAddSendAsRecipient) |
|
265 { |
|
266 CheckNumberOfArgumentsL(1); |
|
267 iObexTest.AddStateL(new (ELeave) CObexSendAsAddRecipientState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
268 } |
|
269 else if((*iCurrentCommand) == KCommandObexAddSendAsBTRecipient) |
|
270 { |
|
271 CheckNumberOfArgumentsL(1); |
|
272 iObexTest.AddStateL(new (ELeave) CObexSendAsAddBTRecipientState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
273 } |
|
274 else if((*iCurrentCommand) == KCommandObexSetSendAsSubject) |
|
275 { |
|
276 CheckNumberOfArgumentsL(1); |
|
277 iObexTest.AddStateL(new (ELeave) CObexSendAsSetSubjectState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
278 } |
|
279 else if((*iCurrentCommand) == KCommandObexAddSendAsAttachment) |
|
280 { |
|
281 CheckNumberOfArgumentsL(1); |
|
282 iObexTest.AddStateL(new (ELeave) CObexSendAsAddAttachmentState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
283 } |
|
284 else if((*iCurrentCommand) == KCommandObexAbandonSendAsMessage) |
|
285 { |
|
286 CheckNumberOfArgumentsL(0); |
|
287 iObexTest.AddStateL(new (ELeave) CObexSendAsAbandonState(iObexTest), iDebugInfo); |
|
288 } |
|
289 else if((*iCurrentCommand) == KCommandObexSaveSendAsMessage) |
|
290 { |
|
291 CheckNumberOfArgumentsL(0); |
|
292 iObexTest.AddStateL(new (ELeave) CObexSendAsSaveState(iObexTest), iDebugInfo); |
|
293 } |
|
294 else if((*iCurrentCommand) == KCommandObexValidateSendAsMessage) |
|
295 { |
|
296 CheckNumberOfArgumentsL(0); |
|
297 iObexTest.AddStateL(new (ELeave) CObexSendAsValidateState(iObexTest), iDebugInfo); |
|
298 } |
|
299 else if((*iCurrentCommand) == KCommandObexIgnoreSendErrors) |
|
300 { |
|
301 CheckNumberOfArgumentsL(0); |
|
302 iObexTest.AddStateL(new (ELeave) CObexIgnoreSendErrorsState(iObexTest), iDebugInfo); |
|
303 } |
|
304 //registering mtms |
|
305 else if ((*iCurrentCommand) == KCommandObexRegisterMtm) |
|
306 { |
|
307 CheckNumberOfArgumentsL(1); |
|
308 iObexTest.AddStateL(new (ELeave) CRegisterObexMtmTypeState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
309 } |
|
310 else if ((*iCurrentCommand) == KCommandObexUnRegisterMtm) |
|
311 { |
|
312 CheckNumberOfArgumentsL(1); |
|
313 iObexTest.AddStateL(new (ELeave) CUnRegisterObexMtmTypeState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
314 } |
|
315 // obex header |
|
316 else if ((*iCurrentCommand) == KCommandObexAddHeader) |
|
317 { |
|
318 CheckNumberOfArgumentsL(2); |
|
319 |
|
320 // Determine the obex header HI value. |
|
321 TUint8 headerHI = 0; |
|
322 TLex lex((*iArgumentList)[0]); |
|
323 |
|
324 lex.Inc(2); // Jump '0x'. |
|
325 User::LeaveIfError(lex.Val(headerHI, EHex)); |
|
326 |
|
327 // Determine the obex header type from the HI value. |
|
328 CObexHeader::THeaderType headerType; |
|
329 |
|
330 // Mask the top 2 bits, and shift the result down. |
|
331 headerType = (CObexHeader::THeaderType)((0xC0 & headerHI) >> 6); |
|
332 |
|
333 iObexTest.AddStateL(new (ELeave) CAddHeadersState(headerType, headerHI, (*iArgumentList)[1], iObexTest), iDebugInfo); |
|
334 } |
|
335 |
|
336 else if ((*iCurrentCommand) == KCommandObexAddAttachmentByNameWithHeaders) |
|
337 { |
|
338 CheckNumberOfArgumentsL(1); |
|
339 iObexTest.AddStateL(new (ELeave) CAddObexAttachmentByNameWithHeadersState((*iArgumentList)[0], iObexTest), iDebugInfo); |
|
340 } |
|
341 |
|
342 else |
|
343 User::Leave(KErrNotSupported); |
|
344 } |
|
345 |
|
346 CObexClientTestCommandParser* CObexClientTestCommandParser::NewL(CTestScript& aScript, CObexClientTest& aObexTest) |
|
347 { |
|
348 CObexClientTestCommandParser* self = new (ELeave) CObexClientTestCommandParser(aScript, aObexTest); |
|
349 CleanupStack::PushL(self); |
|
350 self->ConstructL(); |
|
351 CleanupStack::Pop(); |
|
352 return self; |
|
353 } |
|
354 |
|
355 void CObexClientTestCommandParser::ConstructL() |
|
356 { |
|
357 CBaseCommandParser::ConstructL(); |
|
358 AddCommandL(KCommandObexSelectMtm); |
|
359 AddCommandL(KCommandObexCreateMessage); |
|
360 AddCommandL(KCommandObexSendMessage); |
|
361 AddCommandL(KCommandObexSendMessageAndCancel); |
|
362 AddCommandL(KCommandObexSetMessageAddressee); |
|
363 AddCommandL(KCommandObexSetBTMessageAddressee); |
|
364 AddCommandL(KCommandObexCreateService); |
|
365 AddCommandL(KCommandObexAddAttachmentByName); |
|
366 AddCommandL(KCommandObexAddAttachmentAsEntry); |
|
367 AddCommandL(KCommandObexSimulateObjectReceipt); |
|
368 AddCommandL(KCommandObexIgnoreSendErrors); |
|
369 |
|
370 //sendas |
|
371 AddCommandL(KCommandObexCreateSendAs); |
|
372 AddCommandL(KCommandObexAddSendAsRecipient); |
|
373 AddCommandL(KCommandObexAddSendAsBTRecipient); |
|
374 AddCommandL(KCommandObexSetSendAsSubject); |
|
375 AddCommandL(KCommandObexAddSendAsAttachment); |
|
376 AddCommandL(KCommandObexAbandonSendAsMessage); |
|
377 AddCommandL(KCommandObexSaveSendAsMessage); |
|
378 AddCommandL(KCommandObexValidateSendAsMessage); |
|
379 |
|
380 #ifdef __SUPPORT_MESSAGING_API_V2__ |
|
381 //password |
|
382 AddCommandL(KCommandObexSetPassword); |
|
383 AddCommandL(KCommandObexResetPassword); |
|
384 AddCommandL(KCommandObexGetPassword); |
|
385 #endif //__SUPPORT_MESSAGING_API_V2__ |
|
386 |
|
387 //registering mtm types |
|
388 AddCommandL(KCommandObexRegisterMtm); |
|
389 AddCommandL(KCommandObexUnRegisterMtm); |
|
390 |
|
391 // obex header |
|
392 AddCommandL(KCommandObexAddHeader); |
|
393 AddCommandL(KCommandObexAddAttachmentByNameWithHeaders); |
|
394 } |
|
395 |
|
396 CObexClientTestCommandParser::CObexClientTestCommandParser(CTestScript& aScript, CObexClientTest& aObexTest) |
|
397 : iScript(aScript), |
|
398 iObexTest(aObexTest) |
|
399 { |
|
400 |
|
401 } |
|
402 |
|
403 |