1 // Copyright (c) 2006-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 // This file contains utility functions used by the SMS test steps. The actual SMS test steps are |
|
15 // declared in Te_SMSTestSteps.h and are defined in their own file with appropriate name. |
|
16 // These utilities proved quite extensive functionality. If a SMS test step you need is not |
|
17 // available, before creating a new one, check through these functions; You might find something |
|
18 // you can simply plug into your new test step. |
|
19 // |
|
20 // |
|
21 |
|
22 /** |
|
23 @file |
|
24 */ |
|
25 |
|
26 #include "Te_SmsTestSteps.h" |
|
27 #include "TE_smsprtbase.h" |
|
28 #include <sacls.h> |
|
29 #include <smspver.h> |
|
30 |
|
31 |
|
32 #if defined (__WINS__) |
|
33 #define PDD_NAME _L("ECDRV") |
|
34 #define PDD_NAME2 _L("ECDRV") |
|
35 #define LDD_NAME _L("ECOMM") |
|
36 #else |
|
37 #define PDD_NAME _L("EUART1") |
|
38 #define LDD_NAME _L("ECOMM") |
|
39 #endif |
|
40 |
|
41 // Here are the section names |
|
42 _LIT8(KSetupTelNumbers, "Defaults"); |
|
43 |
|
44 // Here are the item names |
|
45 _LIT8(KServiceCenter, "ServiceCenter"); |
|
46 _LIT8(KTelefoneNumber, "TelephoneNumber"); |
|
47 |
|
48 // Location of directory for reserving disk space |
|
49 _LIT(KTempDiskSpaceDirName, "C:\\sms\\temp\\"); |
|
50 |
|
51 // Location and name of the RSC file. |
|
52 _LIT(KSMSUResourceDir, "C:\\private\\101f7989\\sms\\"); |
|
53 _LIT(KSMSUResourceFile, "C:\\private\\101f7989\\sms\\smsu.rsc"); |
|
54 |
|
55 |
|
56 |
|
57 CSMSTestSteps::~CSMSTestSteps() |
|
58 { |
|
59 iFs.Close(); |
|
60 } |
|
61 |
|
62 |
|
63 /** |
|
64 Creates the file server session and marks the heap |
|
65 */ |
|
66 TVerdict CSMSTestSteps::doTestStepPreambleL() |
|
67 { |
|
68 RDebug::Print(_L("%S"), &TestStepName()); |
|
69 |
|
70 User::LeaveIfError(iFs.Connect()); |
|
71 |
|
72 __UHEAP_MARK; |
|
73 |
|
74 return TestStepResult(); |
|
75 } |
|
76 |
|
77 /** |
|
78 Closes file server session and unmarks the heap |
|
79 */ |
|
80 TVerdict CSMSTestSteps::doTestStepPostambleL() |
|
81 { |
|
82 |
|
83 __UHEAP_MARKEND; |
|
84 |
|
85 iFs.Close(); |
|
86 |
|
87 return TestStepResult(); |
|
88 } |
|
89 |
|
90 void CSMSTestSteps::ParseSettingsFromFileL() |
|
91 { |
|
92 CTestConfig* configFile = CTestConfig::NewLC(iFs,KGmsSmsConfigFileDir,KGmsSmsConfigFileName); |
|
93 const CTestConfigSection* cfgFile = configFile->Section(KSetupTelNumbers); |
|
94 if (cfgFile == NULL) |
|
95 { |
|
96 User::Leave(KErrNotFound); |
|
97 } |
|
98 |
|
99 const CTestConfigItem* item = cfgFile->Item(KServiceCenter,0); |
|
100 if (item == NULL) |
|
101 { |
|
102 User::Leave(KErrNotFound); |
|
103 } |
|
104 |
|
105 iServiceCenterNumber.Copy(item->Value()); |
|
106 |
|
107 item = cfgFile->Item(KTelefoneNumber,0); |
|
108 if (item == NULL) |
|
109 { |
|
110 User::Leave(KErrNotFound); |
|
111 } |
|
112 |
|
113 iTelephoneNumber.Copy(item->Value()); |
|
114 |
|
115 // beginning of the destruction |
|
116 CleanupStack::PopAndDestroy(configFile);//configFile |
|
117 } |
|
118 |
|
119 void CSMSTestSteps::SetSimTSYTestNumberL(TInt aTestNumber) |
|
120 /** |
|
121 Set the SIM TSY Test number |
|
122 @param aTestNumber is the test number in SIM TSY config file |
|
123 */ |
|
124 { |
|
125 INFO_PRINTF2(_L("Setting SIMTSY test number to %d"), aTestNumber); |
|
126 |
|
127 // |
|
128 // Set the property... |
|
129 // |
|
130 User::LeaveIfError(RProperty::Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,aTestNumber)); |
|
131 |
|
132 // |
|
133 // Check the property is set... |
|
134 // |
|
135 TInt testNumberCheck; |
|
136 |
|
137 User::LeaveIfError(RProperty::Get(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNumberCheck)); |
|
138 if (aTestNumber != testNumberCheck) |
|
139 { |
|
140 INFO_PRINTF3(_L("Test number property set to %d, but value returned is %d"),aTestNumber,testNumberCheck); |
|
141 User::Leave(KErrNotFound); |
|
142 } |
|
143 } |
|
144 //----------------------------------------------------------------------------- |
|
145 void CSMSTestSteps::WaitForInitializeL() |
|
146 /** |
|
147 * Initialize the phone for the tsy. IF this is not called, message sends will complete with KErrNotReady |
|
148 */ |
|
149 { |
|
150 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
151 CMDBSession* db = CMDBSession::NewL(KCDVersion1_2); |
|
152 #else |
|
153 CMDBSession* db = CMDBSession::NewL(KCDVersion1_1); |
|
154 #endif |
|
155 CleanupStack::PushL(db); |
|
156 |
|
157 TName tsy; |
|
158 TUint32 modemId = 0; |
|
159 |
|
160 CMDBField<TUint32>* globalSettingsField = new(ELeave) CMDBField<TUint32>(KCDTIdModemPhoneServicesSMS); |
|
161 CleanupStack::PushL(globalSettingsField); |
|
162 globalSettingsField->SetRecordId(1); |
|
163 globalSettingsField->LoadL(*db); |
|
164 modemId = *globalSettingsField; |
|
165 CleanupStack::PopAndDestroy(globalSettingsField); |
|
166 |
|
167 CMDBField<TDesC>* tsyField = new(ELeave) CMDBField<TDesC>(KCDTIdTsyName); |
|
168 CleanupStack::PushL(tsyField); |
|
169 tsyField->SetRecordId(modemId); |
|
170 tsyField->SetMaxLengthL(KMaxTextLength); |
|
171 tsyField->LoadL(*db); |
|
172 tsy = *tsyField; |
|
173 CleanupStack::PopAndDestroy(tsyField); |
|
174 |
|
175 CleanupStack::PopAndDestroy(db); |
|
176 |
|
177 INFO_PRINTF2(_L("Using TSY \"%S\"Loading RTelServer..."), &tsy); |
|
178 |
|
179 RTelServer server; |
|
180 User::LeaveIfError(server.Connect()); |
|
181 CleanupClosePushL(server); |
|
182 User::LeaveIfError(server.LoadPhoneModule(tsy)); |
|
183 |
|
184 // Find the phone corresponding to this TSY and open a number of handles on it |
|
185 TInt numPhones; |
|
186 User::LeaveIfError(server.EnumeratePhones(numPhones)); |
|
187 RPhone phone; |
|
188 TBool found=EFalse; |
|
189 |
|
190 while (numPhones--) |
|
191 { |
|
192 TName phoneTsy; |
|
193 User::LeaveIfError(server.GetTsyName(numPhones,phoneTsy)); |
|
194 if (phoneTsy.CompareF(tsy)==KErrNone) |
|
195 { |
|
196 INFO_PRINTF1(_L("Found RPhone...")); |
|
197 found = ETrue; |
|
198 RTelServer::TPhoneInfo info; |
|
199 User::LeaveIfError(server.GetPhoneInfo(numPhones,info)); |
|
200 User::LeaveIfError(phone.Open(server,info.iName)); |
|
201 CleanupClosePushL(phone); |
|
202 INFO_PRINTF1(_L("Initializing...")); |
|
203 const TInt err = phone.Initialise(); |
|
204 TTimeIntervalMicroSeconds32 InitPause=9000000; //Required Pause to Allow SMSStack to Complete its Async Init |
|
205 User::After(InitPause); //call to the TSY and finish its StartUp. |
|
206 INFO_PRINTF2(_L("Completed Initialize [err=%d]"), err); |
|
207 User::LeaveIfError(err); |
|
208 CleanupStack::PopAndDestroy(&phone); |
|
209 break; |
|
210 } |
|
211 } |
|
212 |
|
213 TEST(found); |
|
214 CleanupStack::PopAndDestroy(&server); |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 void CSMSTestSteps::PrepareRegTestLC(RSocketServ& aSocketServer, TInt aTestNumber) |
|
220 /** |
|
221 * Run a specified test. |
|
222 * The test number is passed via property KUidPSSimTsyCategory. This will notify the SIM tsy |
|
223 * SIM tsy uses test number to parse correct script from config.txt |
|
224 * @param aTestNumber The test number corresponding the test case |
|
225 */ |
|
226 { |
|
227 // |
|
228 // Set the SIM.TSY test number... |
|
229 // |
|
230 RProperty testNumberProperty; |
|
231 User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber)); |
|
232 CleanupClosePushL(testNumberProperty); |
|
233 |
|
234 TRequestStatus status; |
|
235 testNumberProperty.Subscribe(status); |
|
236 INFO_PRINTF2(_L("Setting Sim.Tsy test number to %d"), aTestNumber); |
|
237 User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,aTestNumber)); |
|
238 User::WaitForRequest(status); |
|
239 TEST(status.Int() == KErrNone); |
|
240 |
|
241 TInt testNumberCheck; |
|
242 User::LeaveIfError(testNumberProperty.Get(testNumberCheck)); |
|
243 if (aTestNumber != testNumberCheck) |
|
244 { |
|
245 INFO_PRINTF3(_L("Test number property set to [%d], but value returned is [%d]"),aTestNumber,testNumberCheck); |
|
246 User::Leave(KErrNotFound); |
|
247 } |
|
248 |
|
249 CleanupStack::PopAndDestroy(&testNumberProperty); |
|
250 |
|
251 // |
|
252 // Connect to the Socket Server... |
|
253 // |
|
254 TInt ret = aSocketServer.Connect(KSocketMessageSlots); |
|
255 TESTL(ret == KErrNone); |
|
256 CleanupClosePushL(aSocketServer); |
|
257 |
|
258 // |
|
259 // Delete segmentation and reassembly store files before the test... |
|
260 // |
|
261 _LIT(KReassemblyStoreName,"C:\\Private\\101F7989\\sms\\smsreast.dat"); |
|
262 _LIT(KSegmentationStoreName,"C:\\Private\\101F7989\\sms\\smssegst.dat"); |
|
263 _LIT(KWapReassemblyStoreName,"C:\\Private\\101F7989\\sms\\wapreast.dat"); |
|
264 |
|
265 iFs.Delete(KWapReassemblyStoreName); |
|
266 iFs.Delete(KReassemblyStoreName); |
|
267 iFs.Delete(KSegmentationStoreName); |
|
268 |
|
269 } |
|
270 |
|
271 CSmsMessage* CSMSTestSteps::CreateSmsMessageL(const TDesC& aDes, TSmsDataCodingScheme::TSmsAlphabet aAlphabet, CSmsPDU::TSmsPDUType aType) |
|
272 /** |
|
273 * Create a uninitialised SMS message |
|
274 * @param aDes contains text that will be inserted to the pdu |
|
275 * @param aAlphabet describes the alphabet of the pdu |
|
276 * @return CSmsMessage* :Pointer to the created CSmsMessage object. |
|
277 */ |
|
278 { |
|
279 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
280 CSmsMessage* smsMessage=CSmsMessage::NewL(iFs, aType, buffer); |
|
281 CleanupStack::PushL(smsMessage); |
|
282 |
|
283 TSmsUserDataSettings smsSettings; |
|
284 smsSettings.SetAlphabet(aAlphabet); |
|
285 smsSettings.SetTextCompressed(EFalse); |
|
286 smsMessage->SetUserDataSettingsL(smsSettings); |
|
287 |
|
288 smsMessage->SetToFromAddressL(iTelephoneNumber); |
|
289 smsMessage->SmsPDU().SetServiceCenterAddressL(iServiceCenterNumber); |
|
290 buffer->InsertL(0,aDes); |
|
291 CleanupStack::Pop(smsMessage); |
|
292 return smsMessage; |
|
293 } |
|
294 |
|
295 CSmsMessage* CSMSTestSteps::CreateSmsWithStatusReportReqL(const TDesC& aDes, TSmsDataCodingScheme::TSmsAlphabet aAlphabet) |
|
296 /** |
|
297 * Create a uninitialised SMS message with Status Report request |
|
298 * @param aDes contains text that will be inserted to the pdu |
|
299 * @param aAlphabet describes the alphabet of the pdu |
|
300 * @return CSmsMessage* :Pointer to the created CSmsMessage object. |
|
301 */ |
|
302 { |
|
303 CSmsMessage* smsMessage=CreateSmsMessageL(aDes, aAlphabet); |
|
304 |
|
305 CleanupStack::PushL(smsMessage); |
|
306 |
|
307 //Set Status report request |
|
308 CSmsSubmit& submitPdu=(CSmsSubmit&)smsMessage->SmsPDU(); |
|
309 submitPdu.SetStatusReportRequest(ETrue); |
|
310 |
|
311 CleanupStack::Pop(smsMessage); |
|
312 return smsMessage; |
|
313 } |
|
314 |
|
315 CSmsMessage* CSMSTestSteps::RecvSmsL(RSocket& aSocket, TInt aIoctl) |
|
316 /** |
|
317 * Receive an Sms |
|
318 * @param aSocket is used to stream the sms message from the socket server |
|
319 * @return CSmsMessage* :Sms message from Sms stack |
|
320 * @leave Leaves if streaming the message from the socket server doesn't succeed |
|
321 */ |
|
322 { |
|
323 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
324 CSmsMessage* smsMessage=CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit,buffer); |
|
325 CleanupStack::PushL(smsMessage); |
|
326 |
|
327 RSmsSocketReadStream readstream(aSocket); |
|
328 TRAPD(ret,readstream >> *smsMessage); |
|
329 |
|
330 INFO_PRINTF2(_L("Return from streaming message over socket %d"),ret ); |
|
331 |
|
332 TPckgBuf<TUint> sbuf; |
|
333 TRequestStatus status; |
|
334 |
|
335 if(ret==KErrNone) |
|
336 { |
|
337 aSocket.Ioctl(aIoctl, status, &sbuf, KSolSmsProv); |
|
338 User::WaitForRequest(status); |
|
339 CleanupStack::Pop(smsMessage); |
|
340 } |
|
341 //An error has occured, No message has been received, so return a NULL |
|
342 else |
|
343 { |
|
344 aSocket.Ioctl(KIoctlReadMessageFailed, status, &sbuf, KSolSmsProv); |
|
345 User::WaitForRequest(status); |
|
346 TEST(status.Int() == KErrNone); |
|
347 User::Leave(ret); |
|
348 } |
|
349 return smsMessage; |
|
350 } |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 CSmsMessage* CSMSTestSteps::RecvSmsFailedL(RSocket& aSocket) |
|
356 /** |
|
357 * Receive an Sms, first nack the receive several times before succeeding |
|
358 * @param aSocket is used to stream the sms message from the socket server |
|
359 * @return CSmsMessage* :Sms message from Sms stack |
|
360 * @leave Leaves if streaming the message from the socket server doesn't succeed |
|
361 * @leave Leaves if nack of receiving is completed with error code |
|
362 * @leave Leaves if ack of receiving is completed with error code |
|
363 */ |
|
364 { |
|
365 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
366 CSmsMessage* smsMessage=CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit,buffer); |
|
367 CleanupStack::PushL(smsMessage); |
|
368 RSmsSocketReadStream readstream(aSocket); |
|
369 |
|
370 TPckgBuf<TUint> sbuf; |
|
371 TRequestStatus status; |
|
372 |
|
373 for(TInt i=0; i<10; i++) |
|
374 { |
|
375 TRAPD(ret,readstream >> *smsMessage); |
|
376 TEST(ret == KErrNone); |
|
377 aSocket.Ioctl(KIoctlReadMessageFailed, status, &sbuf, KSolSmsProv); |
|
378 User::WaitForRequest(status); |
|
379 TEST(status.Int() == KErrNone); |
|
380 } |
|
381 |
|
382 TRAPD(ret,readstream >> *smsMessage); |
|
383 TEST(ret == KErrNone); |
|
384 aSocket.Ioctl(KIoctlReadMessageSucceeded, status, NULL, KSolSmsProv); |
|
385 User::WaitForRequest(status); |
|
386 TEST(status.Int() == KErrNone); |
|
387 |
|
388 CleanupStack::Pop(smsMessage); |
|
389 return smsMessage; |
|
390 } |
|
391 |
|
392 void CSMSTestSteps::SendSmsL(const CSmsMessage* aSms, RSocket& aSocket) |
|
393 /** |
|
394 * Stream aSms out to the socket server |
|
395 * @param aSms contains the sms tpdu that will be streamed to the sms stack |
|
396 * @param aSocket is used to stream the aSms to the sms stack |
|
397 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
398 * @leave Leaves if sending is completed with error code |
|
399 */ |
|
400 { |
|
401 TBool tryAgain = ETrue; |
|
402 TInt sendTry (0); |
|
403 TRequestStatus status = KErrNone; |
|
404 |
|
405 while (tryAgain && sendTry < 3) |
|
406 { |
|
407 RSmsSocketWriteStream writestream(aSocket); |
|
408 TRAPD(ret,writestream << *aSms); |
|
409 |
|
410 TRAP(ret,writestream.CommitL()); |
|
411 |
|
412 TPckgBuf<TUint> sbuf; |
|
413 aSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf, KSolSmsProv); |
|
414 User::WaitForRequest(status); |
|
415 INFO_PRINTF2(_L("SendSmsL - sendSmsMessage returned %d"), status.Int()); |
|
416 if (status.Int() != KErrNone) |
|
417 { |
|
418 tryAgain = ETrue; |
|
419 INFO_PRINTF1(_L("Try again... ")); |
|
420 sendTry++; |
|
421 } |
|
422 else tryAgain = EFalse; |
|
423 } |
|
424 |
|
425 TEST(status.Int() == KErrNone); |
|
426 PrintMessageL(aSms); |
|
427 if (status.Int() != KErrNone) |
|
428 { |
|
429 User::Leave(status.Int()); |
|
430 } |
|
431 } |
|
432 |
|
433 void CSMSTestSteps::SendSmsCancelL(CSmsMessage* aSms, RSocket& aSocket1, RSocket& aSocket2) |
|
434 /** |
|
435 * Stream Sms out to the socket server by two RSmsSocketWriteStream object. |
|
436 * The first request is canceled and then the second request is completed with error code. |
|
437 * @param aSms contains the sms tpdu that will be streamed to the sms stack |
|
438 * @param aSocket1 The socket used with message that will be canceled |
|
439 * @param aSocket2 The socket used with message that will be completed with error code |
|
440 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
441 * @leave Leaves if sending is completed with KErrNone |
|
442 */ |
|
443 { |
|
444 RSmsSocketWriteStream writestream(aSocket1); |
|
445 TRAPD(ret,writestream << *aSms); |
|
446 TEST(ret == KErrNone); |
|
447 TRAP(ret,writestream.CommitL()); |
|
448 TEST(ret == KErrNone); |
|
449 |
|
450 TPckgBuf<TUint> sbuf; |
|
451 TRequestStatus status1,status2; |
|
452 |
|
453 //stream to socket2 |
|
454 RSmsSocketWriteStream writestream2(aSocket2); |
|
455 TRAP(ret,writestream2 << *aSms); |
|
456 TEST(ret == KErrNone); |
|
457 TRAP(ret,writestream2.CommitL()); |
|
458 TEST(ret == KErrNone); |
|
459 |
|
460 aSocket1.Ioctl(KIoctlSendSmsMessage,status1,&sbuf, KSolSmsProv); |
|
461 aSocket2.Ioctl(KIoctlSendSmsMessage,status2,&sbuf, KSolSmsProv); |
|
462 |
|
463 User::After(2000000); |
|
464 |
|
465 // Test cancel first |
|
466 aSocket1.CancelIoctl(); |
|
467 User::WaitForRequest(status1); |
|
468 TEST(status1.Int()==KErrCancel); |
|
469 |
|
470 User::After(50000); |
|
471 |
|
472 |
|
473 User::WaitForRequest(status2); |
|
474 |
|
475 INFO_PRINTF2(_L("SendSmsL - sendSmsMessage returned %d"),status2.Int()); |
|
476 PrintMessageL(aSms); |
|
477 |
|
478 //Ensure the request is completed with error code ;) |
|
479 TEST(status2.Int() != KErrNone); |
|
480 INFO_PRINTF2(_L("Sending failed! %d"), status2.Int()); |
|
481 } |
|
482 |
|
483 TInt CSMSTestSteps::SendSmsErrorL(CSmsMessage* aSms, RSocket& aSocket) |
|
484 /** |
|
485 * Stream aSms out to the socket server. Sending is completed with error code. |
|
486 * @param aSms contains the sms tpdu that will be streamed to the sms stack |
|
487 * @param aSocket is used to stream the aSms to the sms stack |
|
488 * @return error code |
|
489 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
490 * @leave Leaves if sending is completed with KErrNone |
|
491 */ |
|
492 { |
|
493 RSmsSocketWriteStream writestream(aSocket); |
|
494 TRAPD(ret,writestream << *aSms); |
|
495 TEST(ret == KErrNone); |
|
496 TRAP(ret,writestream.CommitL()); |
|
497 TEST(ret == KErrNone); |
|
498 |
|
499 TPckgBuf<TUint> sbuf; |
|
500 TRequestStatus status; |
|
501 |
|
502 User::After(50000); |
|
503 // test cancel first |
|
504 aSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf, KSolSmsProv); |
|
505 aSocket.CancelIoctl(); |
|
506 User::WaitForRequest(status); |
|
507 TEST(status.Int()==KErrCancel); |
|
508 |
|
509 //Now send again, completed with error |
|
510 TRAP(ret,writestream << *aSms); |
|
511 TEST(ret == KErrNone); |
|
512 TRAP(ret,writestream.CommitL()); |
|
513 TEST(ret == KErrNone); |
|
514 |
|
515 aSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf, KSolSmsProv); |
|
516 User::WaitForRequest(status); |
|
517 INFO_PRINTF2(_L("SendSmsL - sendSmsMessage returned %d"), status.Int()); |
|
518 PrintMessageL(aSms); |
|
519 INFO_PRINTF2(_L("Sending failed! %d"), status.Int()); |
|
520 TEST(status.Int() != KErrNone); |
|
521 return status.Int(); |
|
522 } |
|
523 |
|
524 void CSMSTestSteps::SendCommandSmsL(CSmsMessage* aSms, RSocket& aSocket) |
|
525 /** |
|
526 * Stream command message out to the socket server and wait for the return status |
|
527 * @param aSms contains the sms tpdu that will be streamed to the sms stack |
|
528 * @param aSocket is used to stream the aSms to the sms stack |
|
529 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
530 * @leave Leaves if sending is completed with error code |
|
531 */ |
|
532 { |
|
533 RSmsSocketWriteStream writestream(aSocket); |
|
534 TRAPD(ret,writestream << *aSms); |
|
535 TEST(ret == KErrNone); |
|
536 TRAP(ret,writestream.CommitL()); |
|
537 TEST(ret == KErrNone); |
|
538 |
|
539 TRequestStatus status; |
|
540 TPckgBuf<TUint> sbuf; |
|
541 aSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf,KSolSmsProv); |
|
542 |
|
543 User::WaitForRequest(status); |
|
544 |
|
545 INFO_PRINTF2(_L("SendCommandSmsL, sendSms returned %d"), status.Int()); |
|
546 User::After(1000000); |
|
547 TEST(status.Int() == KErrNone); |
|
548 |
|
549 } |
|
550 |
|
551 void CSMSTestSteps::SendAndRecvTestMessageL(const TTestCase& aTestCase, RSocket& aSocket) |
|
552 /** |
|
553 * Send a test message. This method is used to send and receive different DCS type messages |
|
554 * @param aTestCase has information about the used test message, e.g. message data and DCS |
|
555 * @leave Leaves if any of the leaving functions used at this function leaves |
|
556 */ |
|
557 { |
|
558 SendTestMessageL(aTestCase, aSocket); |
|
559 |
|
560 WaitForRecvL(aSocket); |
|
561 CSmsMessage* smsMessage = RecvSmsL(aSocket); |
|
562 CleanupStack::PushL(smsMessage); |
|
563 TestMessageContentsL(smsMessage,aTestCase); |
|
564 CleanupStack::PopAndDestroy(smsMessage); |
|
565 } |
|
566 |
|
567 void CSMSTestSteps::SendTestMessageL(const TTestCase& aTestCase, RSocket& aSocket) |
|
568 /** |
|
569 * Send a test message |
|
570 * Assumes recv is already done. |
|
571 * @param aTestCase has information about the used test message, e.g. message data and DCS |
|
572 * @leave Leaves if any of the leaving functions used at this function leaves |
|
573 */ |
|
574 { |
|
575 CSmsMessage* smsMessage = CreateSmsMessageL(aTestCase.iMsg, TSmsDataCodingScheme::ESmsAlphabet7Bit); |
|
576 CleanupStack::PushL(smsMessage); |
|
577 |
|
578 CSmsPDU& pdu = smsMessage->SmsPDU(); |
|
579 CSmsUserData& userData = pdu.UserData(); |
|
580 |
|
581 if (aTestCase.iMatchType == ESmsAddrMatchIEI) |
|
582 userData.AddInformationElementL(aTestCase.iIdentifierMatch,_L8("98")); |
|
583 |
|
584 if (aTestCase.iTestSmsClass) |
|
585 { |
|
586 pdu.SetBits7To4(TSmsDataCodingScheme::ESmsDCSTextUncompressedWithClassInfo); |
|
587 pdu.SetClass(ETrue,aTestCase.iSmsClass); |
|
588 } |
|
589 |
|
590 if (aTestCase.iTestValidityPeriod && pdu.Type()==CSmsPDU::ESmsSubmit) |
|
591 { |
|
592 CSmsSubmit* submitPdu = static_cast<CSmsSubmit*>(&pdu); |
|
593 submitPdu->SetValidityPeriod(aTestCase.iValidityPeriod); |
|
594 } |
|
595 |
|
596 if (aTestCase.iTestIndicators && pdu.Type()==CSmsPDU::ESmsSubmit) |
|
597 { |
|
598 SetIndicatorL(aTestCase, smsMessage); |
|
599 } |
|
600 |
|
601 SendSmsL(smsMessage, aSocket); |
|
602 CleanupStack::PopAndDestroy(smsMessage); |
|
603 } |
|
604 |
|
605 void CSMSTestSteps::SendSmsDontCheckReturnValueL(CSmsMessage* aSms, RSocket& aSocket) |
|
606 /** |
|
607 * Stream aSms out to the socket server and don't check return value. |
|
608 * @param aSms contains the sms tpdu that will be streamed to the sms stack |
|
609 * @param aSocket is used to stream the aSms to the sms stack |
|
610 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
611 * @leave Leaves if sending is completed with KErrNone |
|
612 */ |
|
613 { |
|
614 RSmsSocketWriteStream writestream(aSocket); |
|
615 writestream << *aSms; |
|
616 writestream.CommitL(); |
|
617 |
|
618 TPckgBuf<TUint> sbuf; |
|
619 TRequestStatus status; |
|
620 aSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf, KSolSmsProv); |
|
621 User::WaitForRequest(status); |
|
622 INFO_PRINTF2(_L("Send SMS message returned %d"), status.Int()); |
|
623 if(status.Int() != KErrNone) |
|
624 { |
|
625 User::Leave(status.Int()); |
|
626 } |
|
627 } |
|
628 |
|
629 void CSMSTestSteps::SendAndRecvSms7BitL(const TDesC& aDes, RSocket& aSocket) |
|
630 /** |
|
631 * Send and receive one 7bit sms |
|
632 * @param aDes contains the text to be send |
|
633 * @leave Leaves if DoSendAndRecvSmsL leaves |
|
634 */ |
|
635 { |
|
636 DoSendAndRecvSmsL(aDes,TSmsDataCodingScheme::ESmsAlphabet7Bit, aSocket); |
|
637 } |
|
638 |
|
639 void CSMSTestSteps::DoSendAndRecvSmsL(const TDesC& aDes, TSmsDataCodingScheme::TSmsAlphabet aAlphabet, RSocket& aSocket) |
|
640 /** |
|
641 * Send and recv one sms, |
|
642 * then check that the sent message corresponds with the received message |
|
643 * @param aDes contains the text that will be inserted to the pdu at CreateSmsMessageL |
|
644 * @param aAlphabet describes the alphabet of the pdu that will be created at CreateSmsMessageL |
|
645 * @leave Leaves if any of the leaving functions used at this function leaves |
|
646 */ |
|
647 { |
|
648 CSmsMessage* smsMessage=CreateSmsMessageL(aDes, aAlphabet); |
|
649 CleanupStack::PushL(smsMessage); |
|
650 SendSmsL(smsMessage, aSocket); |
|
651 CleanupStack::PopAndDestroy(smsMessage); //destroyed because created again in RecvSmsL |
|
652 |
|
653 INFO_PRINTF1(_L("waiting for incoming SMS...") ); |
|
654 WaitForRecvL( aSocket); |
|
655 smsMessage = RecvSmsL( aSocket); |
|
656 |
|
657 INFO_PRINTF1(_L("incoming SMS") ); |
|
658 |
|
659 CleanupStack::PushL(smsMessage); |
|
660 TestSmsContentsL(smsMessage,aDes); |
|
661 |
|
662 User::After(1000000); |
|
663 |
|
664 CleanupStack::PopAndDestroy(smsMessage); |
|
665 } |
|
666 |
|
667 void CSMSTestSteps::PrintMessageL(const CSmsMessage* aSms) |
|
668 /** |
|
669 * Print the content of SMS to the console |
|
670 */ |
|
671 { |
|
672 CSmsBuffer& smsbuffer = (CSmsBuffer&)aSms->Buffer(); |
|
673 const TInt len = smsbuffer.Length(); |
|
674 HBufC* hbuf = HBufC::NewL(len); |
|
675 TPtr ptr = hbuf->Des(); |
|
676 smsbuffer.Extract(ptr,0,len); |
|
677 |
|
678 INFO_PRINTF1(_L("SMS contains...")); |
|
679 |
|
680 for (TInt j = 0; j < len; j++) |
|
681 { |
|
682 if (ptr[j] < 0x20 || ptr[j] > 0xFF) |
|
683 { |
|
684 ptr[j] = 0x007F; |
|
685 } |
|
686 } |
|
687 INFO_PRINTF2(_L("%S"), &ptr); |
|
688 |
|
689 delete hbuf; |
|
690 } |
|
691 |
|
692 void CSMSTestSteps::PrintSmsMessage(const CSmsMessage& aMessage) |
|
693 { |
|
694 TBuf<255> buf; |
|
695 aMessage.Buffer().Extract(buf, 0, Min(aMessage.Buffer().Length(), 255)); |
|
696 INFO_PRINTF2(_L("%S"), &buf); |
|
697 } |
|
698 |
|
699 TSmsStatus::TSmsStatusValue CSMSTestSteps::RecvStatusReportL(TSmsServiceCenterAddress& aRecipientNumber, RSocket& aSocket) |
|
700 /** |
|
701 * Receive a Status report |
|
702 * @param aRecipientNumber The supposed recipient number |
|
703 * @param aSocket is used to stream the sms message from the socket server |
|
704 */ |
|
705 { |
|
706 //Receive SMS |
|
707 INFO_PRINTF1(_L("waiting for incoming status report...") ); |
|
708 WaitForRecvL(aSocket); |
|
709 CSmsMessage* smsMessage = RecvSmsL(aSocket); |
|
710 |
|
711 INFO_PRINTF1(_L("incoming SMS") ); |
|
712 |
|
713 //Check the status report |
|
714 CleanupStack::PushL(smsMessage); |
|
715 TBool isSR = (smsMessage->Type()==CSmsPDU::ESmsStatusReport); |
|
716 |
|
717 if (isSR) |
|
718 { |
|
719 INFO_PRINTF1(_L("Received status report")); |
|
720 TSmsServiceCenterAddress telephoneNumber=smsMessage->ToFromAddress(); |
|
721 TEST(telephoneNumber==aRecipientNumber); |
|
722 INFO_PRINTF2(_L("Message delivered to %S"), &telephoneNumber); |
|
723 } |
|
724 else |
|
725 { |
|
726 INFO_PRINTF1(_L("Received SMS is NOT a Status report!")); |
|
727 } |
|
728 |
|
729 TEST(isSR==1); |
|
730 |
|
731 //Get the status report |
|
732 CSmsStatusReport& statusReport = static_cast<CSmsStatusReport&>(smsMessage->SmsPDU()); |
|
733 TSmsStatus::TSmsStatusValue status = statusReport.Status(); |
|
734 |
|
735 CleanupStack::PopAndDestroy(smsMessage); |
|
736 |
|
737 return status; |
|
738 } |
|
739 |
|
740 void CSMSTestSteps::WaitForRecvL(RSocket& aSocket) |
|
741 /** |
|
742 * Wait for an Sms to be received |
|
743 * @param aSocket The status is return to this socket |
|
744 * @leave Leaves if receiving is completed with error code |
|
745 */ |
|
746 { |
|
747 TPckgBuf<TUint> sbuf; |
|
748 sbuf()=KSockSelectRead; |
|
749 TRequestStatus status; |
|
750 aSocket.Ioctl(KIOctlSelect,status,&sbuf,KSOLSocket); |
|
751 User::WaitForRequest(status); |
|
752 TEST(status.Int() == KErrNone); |
|
753 } |
|
754 |
|
755 void CSMSTestSteps::TestSmsContentsL(CSmsMessage* aSms, const TDesC& aDes, TBool aIgnorePrintOutput) |
|
756 /** |
|
757 * Check that aSms contains text that matches to aDes |
|
758 * @param aSms SMS message that has been come from SMS stack |
|
759 * @param aDes SMS message's text that is defined at client side |
|
760 * @leave Leaves if aSms doesn't match to aDes |
|
761 */ |
|
762 { |
|
763 CSmsBufferBase& smsBuffer=aSms->Buffer(); |
|
764 TInt bufLen=smsBuffer.Length(); |
|
765 |
|
766 INFO_PRINTF2(_L("Length of buffer is : %d"),bufLen); |
|
767 |
|
768 HBufC* textBuf=HBufC::NewL(bufLen); |
|
769 CleanupStack::PushL(textBuf); |
|
770 TPtr textPtr(textBuf->Des()); |
|
771 smsBuffer.Extract(textPtr,0,bufLen); |
|
772 |
|
773 INFO_PRINTF1(_L("Comparing messages...")); |
|
774 TInt compareResult = textPtr.Compare(aDes); |
|
775 |
|
776 if (!aIgnorePrintOutput) |
|
777 { |
|
778 TInt bufLen2 = aDes.Length(); |
|
779 HBufC* textBuf2 = HBufC::NewL(aDes.Length()); |
|
780 CleanupStack::PushL(textBuf2); |
|
781 TPtr textPtr2(textBuf2->Des()); |
|
782 TInt index; |
|
783 |
|
784 for (index = 0; index < bufLen; index++) |
|
785 { |
|
786 if (textPtr[index] < 0x20 || textPtr[index] > 0xff) |
|
787 { |
|
788 textPtr[index] = 0x007f; |
|
789 } |
|
790 } |
|
791 INFO_PRINTF2(_L("%S"), &textPtr); |
|
792 |
|
793 INFO_PRINTF1(_L("with expected")); |
|
794 |
|
795 textPtr2.Copy(aDes); |
|
796 for (index = 0; index < bufLen2; index++) |
|
797 { |
|
798 if (textPtr2[index] < 0x20 || textPtr2[index] > 0xff) |
|
799 { |
|
800 textPtr2[index] = 0x007f; |
|
801 } |
|
802 } |
|
803 INFO_PRINTF2(_L("%S"), &textPtr2); |
|
804 |
|
805 CleanupStack::PopAndDestroy(textBuf2); |
|
806 } |
|
807 |
|
808 TEST(compareResult == 0); |
|
809 if (compareResult != 0) |
|
810 { |
|
811 INFO_PRINTF1(_L("No Match!")); |
|
812 } |
|
813 else |
|
814 { |
|
815 INFO_PRINTF1(_L("Incoming matches outgoing!")); |
|
816 } |
|
817 |
|
818 CleanupStack::PopAndDestroy(textBuf); |
|
819 } |
|
820 |
|
821 void CSMSTestSteps::TestMessageContentsL(CSmsMessage* aSms, const TTestCase& aTestCase) |
|
822 /** |
|
823 * Check the sms matches the expected test result |
|
824 * @param aSms has the message to be tested with aTestCase.iMsg |
|
825 * @param aTestCase has information about the used test message, e.g. message data and DCS |
|
826 * @leave Leaves if TSmsClass isn't defined at the pdu |
|
827 * @leave Leaves if class of pdu doesn't match to supposed class (aTestCase.iSmsClass) |
|
828 */ |
|
829 { |
|
830 TestSmsContentsL(aSms,aTestCase.iMsg); |
|
831 CSmsPDU& pdu = aSms->SmsPDU(); |
|
832 |
|
833 if (aTestCase.iTestSmsClass) |
|
834 { |
|
835 TSmsDataCodingScheme::TSmsClass smsClass; |
|
836 TBool isDefined = pdu.Class(smsClass); |
|
837 TEST(isDefined); |
|
838 TEST(smsClass == aTestCase.iSmsClass); |
|
839 } |
|
840 if (aTestCase.iTestIndicators) |
|
841 { |
|
842 TEST(pdu.Bits7To4() == aTestCase.iBits7To4); |
|
843 TEST(pdu.IndicationType() == aTestCase.iIndicationType); |
|
844 TEST(pdu.IndicationState() == aTestCase.iIndicationState); |
|
845 } |
|
846 |
|
847 } |
|
848 |
|
849 void CSMSTestSteps::WriteSmsToSimL(CSmsMessage& aSms, RSocket& aSocket) |
|
850 /** |
|
851 * This method stores SMS messages to the SMS storage. |
|
852 * @param aSms SMS message that will be stored |
|
853 * @param aSocket Used to stream SMS message to the sms stack |
|
854 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
855 * @leave Leaves if store request is completed with error code |
|
856 */ |
|
857 { |
|
858 INFO_PRINTF1(_L("Write message")); |
|
859 |
|
860 TRequestStatus status; |
|
861 |
|
862 RSmsSocketWriteStream writestream(aSocket); |
|
863 TRAPD(ret,writestream << aSms); |
|
864 TEST(ret == KErrNone); |
|
865 TRAP(ret,writestream.CommitL()); |
|
866 TEST(ret == KErrNone); |
|
867 |
|
868 aSocket.Ioctl(KIoctlWriteSmsMessage,status,NULL,KSolSmsProv); |
|
869 User::WaitForRequest(status); |
|
870 INFO_PRINTF2(_L("WriteSmsToSimL - returned %d"), status.Int()); |
|
871 } |
|
872 |
|
873 void CSMSTestSteps::WriteSmsLeaveIfErrorL(const CSmsMessage& aSms, RSocket& aSocket) |
|
874 /** |
|
875 * This method stores SMS messages to the SMS storage. |
|
876 * @param aSms SMS message that will be stored |
|
877 * @param aSocket Used to stream SMS message to the sms stack |
|
878 */ |
|
879 { |
|
880 TRequestStatus status; |
|
881 RSmsSocketWriteStream writestream(aSocket); |
|
882 writestream << aSms; |
|
883 writestream.CommitL(); |
|
884 aSocket.Ioctl(KIoctlWriteSmsMessage,status,NULL, KSolSmsProv); |
|
885 User::WaitForRequest(status); |
|
886 INFO_PRINTF2(_L("Write SMS message returned %d"), status.Int()); |
|
887 if(status.Int() != KErrNone) |
|
888 { |
|
889 User::Leave(status.Int()); |
|
890 } |
|
891 } |
|
892 |
|
893 void CSMSTestSteps::ReadSmsStoreL(RSocket& aSocket, RPointerArray<CSmsMessage>& aMessages) |
|
894 /** |
|
895 * This method retrieves SMS messages from SMS storage and print them out. |
|
896 * @param aSocket Used to stream SMS messages from the socket server |
|
897 * @param aMessages Sms messages will be streamed to this array |
|
898 * @leave Leaves if first request is NOT completed with KErrCancel |
|
899 * @leave Leaves if second request is completed with error code |
|
900 * @leave Leaves if streaming the message from the socket server doesn't succeed |
|
901 * @leave Leaves if nack of reading is completed with error code |
|
902 * @leave Leaves if ack of reading is completed with error code |
|
903 */ |
|
904 { |
|
905 TRequestStatus status; |
|
906 ReadSmsStoreL(aSocket, aMessages, status); |
|
907 } |
|
908 |
|
909 void CSMSTestSteps::ReadSmsStoreL(RSocket& aSocket, RPointerArray<CSmsMessage>& aMessages, TRequestStatus& aStatus) |
|
910 /** |
|
911 * This method retrieves SMS messages from SMS storage and print them out. |
|
912 * @param aSocket Used to stream SMS messages from the socket server |
|
913 * @param aMessages Sms messages will be streamed to this array |
|
914 * @param aStatus Status of request to enumerate messages from store |
|
915 * @leave Leaves if first request is NOT completed with KErrCancel |
|
916 * @leave Leaves if second request is completed with error code |
|
917 * @leave Leaves if streaming the message from the socket server doesn't succeed |
|
918 * @leave Leaves if nack of reading is completed with error code |
|
919 * @leave Leaves if ack of reading is completed with error code |
|
920 */ |
|
921 { |
|
922 INFO_PRINTF1(_L("Enumerating messages")); |
|
923 |
|
924 TPckgBuf<TUint> sbuf; |
|
925 sbuf()=0; |
|
926 |
|
927 // test cancel first - due to Lubbock problems canceled out |
|
928 aSocket.Ioctl(KIoctlEnumerateSmsMessages,aStatus,&sbuf, KSolSmsProv); |
|
929 aSocket.CancelIoctl(); |
|
930 User::WaitForRequest(aStatus); |
|
931 TEST(aStatus.Int()==KErrCancel); |
|
932 |
|
933 User::After(2000000); |
|
934 //Now enumerate messages from store |
|
935 aSocket.Ioctl(KIoctlEnumerateSmsMessages,aStatus,&sbuf, KSolSmsProv); |
|
936 User::WaitForRequest(aStatus); |
|
937 TEST(aStatus.Int() == KErrNone); |
|
938 User::After(2000000); |
|
939 |
|
940 //sbuf() includes the count of messages on Store |
|
941 TInt count = sbuf(); |
|
942 INFO_PRINTF2(_L("%d enumerated messages"), count); |
|
943 |
|
944 RSmsSocketReadStream readstream(aSocket); |
|
945 |
|
946 //Read each message from the stream |
|
947 for(TInt i=0; i< count; i++) |
|
948 { |
|
949 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
950 CSmsMessage* smsmessage=CSmsMessage::NewL(iFs, CSmsPDU::ESmsDeliver,buffer); |
|
951 CleanupStack::PushL(smsmessage); |
|
952 |
|
953 TRAPD(ret,readstream >> *smsmessage); |
|
954 TEST(ret == KErrNone); |
|
955 aSocket.Ioctl(KIoctlReadMessageFailed, aStatus, NULL, KSolSmsProv); |
|
956 User::WaitForRequest(aStatus); |
|
957 TEST(aStatus.Int() == KErrNone); |
|
958 |
|
959 TRAP(ret,readstream >> *smsmessage); |
|
960 TEST(ret == KErrNone); |
|
961 aSocket.Ioctl(KIoctlReadMessageSucceeded, aStatus, NULL, KSolSmsProv); |
|
962 User::WaitForRequest(aStatus); |
|
963 TEST(aStatus.Int() == KErrNone); |
|
964 |
|
965 Logger().Write(smsmessage->ToFromAddress()); |
|
966 INFO_PRINTF1(_L(" ")); |
|
967 Logger().Write(smsmessage->ServiceCenterAddress()); |
|
968 INFO_PRINTF1(_L("")); |
|
969 |
|
970 if(smsmessage->Storage() == CSmsMessage::ESmsSIMStorage) |
|
971 { |
|
972 INFO_PRINTF1(_L("Store: SIM")); |
|
973 } |
|
974 else if (smsmessage->Storage() == CSmsMessage::ESmsPhoneStorage) |
|
975 { |
|
976 INFO_PRINTF1(_L("Store: Phone")); |
|
977 } |
|
978 else if (smsmessage->Storage() == CSmsMessage::ESmsCombinedStorage) |
|
979 { |
|
980 INFO_PRINTF1(_L("Store: Combined")); |
|
981 } |
|
982 else |
|
983 { |
|
984 INFO_PRINTF1(_L("Store: Unknown")); |
|
985 } |
|
986 |
|
987 switch (smsmessage->Status()) |
|
988 { |
|
989 case RMobileSmsStore::EStoredMessageUnread: |
|
990 INFO_PRINTF1(_L("Status: Unread")); |
|
991 break; |
|
992 |
|
993 case RMobileSmsStore::EStoredMessageRead: |
|
994 INFO_PRINTF1(_L("Status: Read")); |
|
995 break; |
|
996 |
|
997 case RMobileSmsStore::EStoredMessageUnsent: |
|
998 INFO_PRINTF1(_L("Status: Unsent")); |
|
999 break; |
|
1000 |
|
1001 case RMobileSmsStore::EStoredMessageSent: |
|
1002 INFO_PRINTF1(_L("Status: Sent")); |
|
1003 break; |
|
1004 |
|
1005 case RMobileSmsStore::EStoredMessageDelivered: |
|
1006 INFO_PRINTF1(_L("Status: Delivered")); |
|
1007 break; |
|
1008 |
|
1009 case RMobileSmsStore::EStoredMessageUnknownStatus: |
|
1010 default: |
|
1011 INFO_PRINTF1(_L("Status: Unknown")); |
|
1012 break; |
|
1013 } |
|
1014 |
|
1015 PrintMessageL(smsmessage); |
|
1016 User::LeaveIfError(aMessages.Append(smsmessage)); |
|
1017 CleanupStack::Pop(smsmessage); |
|
1018 } |
|
1019 |
|
1020 } |
|
1021 |
|
1022 |
|
1023 TInt CSMSTestSteps::DeleteSmsL(const CSmsMessage& aSms, RSocket& aSocket) |
|
1024 /** |
|
1025 * This method deletes SMS message from the SMS storage. |
|
1026 * @param aSms SMS message that will be deleted |
|
1027 * @param aSocket Used to stream SMS message to the sms stack |
|
1028 * @leave Leaves if delete request is completed with error code (except KErrNotFound) |
|
1029 * @return TInt :error code |
|
1030 */ |
|
1031 { |
|
1032 INFO_PRINTF1(_L("Delete message")); |
|
1033 |
|
1034 TRequestStatus status; |
|
1035 |
|
1036 RSmsSocketWriteStream writestream(aSocket); |
|
1037 TRAPD(ret,writestream << aSms); |
|
1038 TEST(ret == KErrNone); |
|
1039 TRAP(ret,writestream.CommitL()); |
|
1040 TEST(ret == KErrNone); |
|
1041 |
|
1042 aSocket.Ioctl(KIoctlDeleteSmsMessage, status, NULL, KSolSmsProv); |
|
1043 User::WaitForRequest(status); |
|
1044 INFO_PRINTF2(_L("DeleteSmsL - returned %d"), status.Int()); |
|
1045 |
|
1046 if (status.Int()!=KErrArgument) |
|
1047 { |
|
1048 TEST(status.Int() == KErrNone); |
|
1049 } |
|
1050 |
|
1051 return status.Int(); |
|
1052 } |
|
1053 |
|
1054 void CSMSTestSteps::DeleteSmsLeaveIfErrorL(const CSmsMessage& aSms, RSocket& aSocket) |
|
1055 /** |
|
1056 * This method deletes SMS message from the SMS storage. |
|
1057 * @param aSms SMS message that will be deleted |
|
1058 * @param aSocket Used to stream SMS message to the sms stack |
|
1059 */ |
|
1060 { |
|
1061 TRequestStatus status; |
|
1062 RSmsSocketWriteStream writestream(aSocket); |
|
1063 writestream << aSms; |
|
1064 writestream.CommitL(); |
|
1065 aSocket.Ioctl(KIoctlDeleteSmsMessage, status, NULL, KSolSmsProv); |
|
1066 User::WaitForRequest(status); |
|
1067 INFO_PRINTF2(_L("Delete SMS returned %d"), status.Int()); |
|
1068 if(status.Int() != KErrNone) |
|
1069 { |
|
1070 User::Leave(status.Int()); |
|
1071 } |
|
1072 } |
|
1073 |
|
1074 void CSMSTestSteps::SetIndicatorL(const TTestCase& aTestCase, CSmsMessage* aSms) |
|
1075 /** |
|
1076 * |
|
1077 */ |
|
1078 { |
|
1079 TSmsDataCodingScheme::TSmsAlphabet alphabet; |
|
1080 if (aTestCase.iBits7To4 == TSmsDataCodingScheme::ESmsDCSMessageWaitingIndicationUCS2) |
|
1081 alphabet = TSmsDataCodingScheme::ESmsAlphabetUCS2; |
|
1082 else |
|
1083 alphabet = TSmsDataCodingScheme::ESmsAlphabet7Bit; |
|
1084 |
|
1085 TSmsUserDataSettings smsSettings; |
|
1086 smsSettings.SetAlphabet(alphabet); |
|
1087 smsSettings.SetTextCompressed(EFalse); |
|
1088 aSms->SetUserDataSettingsL(smsSettings); |
|
1089 |
|
1090 CSmsPDU& pdu = aSms->SmsPDU(); |
|
1091 pdu.SetBits7To4(aTestCase.iBits7To4); |
|
1092 pdu.SetIndicationType(aTestCase.iIndicationType); |
|
1093 pdu.SetIndicationState(aTestCase.iIndicationState); |
|
1094 |
|
1095 } |
|
1096 |
|
1097 void CSMSTestSteps::FillDes(TDes& aDes,TInt aLength) |
|
1098 /** |
|
1099 * Fill aDes with randomly generated 7bit data |
|
1100 * @param aDes will be filled with random data |
|
1101 * @param aLength has the length to be set to aDes |
|
1102 */ |
|
1103 { |
|
1104 TText baseChar='A'; |
|
1105 |
|
1106 aDes.SetLength(aLength); |
|
1107 for (TInt i=0; i<aLength; i++) |
|
1108 { |
|
1109 aDes[i]=TText(baseChar + i%26); |
|
1110 } |
|
1111 } |
|
1112 |
|
1113 TInt CSMSTestSteps::MakeReadSmsStoreRequestL(RSocket& aSocket) |
|
1114 /** |
|
1115 * This method retrieves SMS messages from SMS storage. |
|
1116 * Main purpose is to test out of memory conditions. |
|
1117 * @param aSocket Used to stream SMS messages from the sms stack |
|
1118 * @param aMessages reference to CSmsMessage pointer array. |
|
1119 */ |
|
1120 { |
|
1121 TRequestStatus status; |
|
1122 TPckgBuf<TUint> sbuf; |
|
1123 sbuf()=0; |
|
1124 |
|
1125 //Now enumerate messages from SIM |
|
1126 aSocket.Ioctl(KIoctlEnumerateSmsMessages,status,&sbuf, KSolSmsProv); |
|
1127 User::WaitForRequest(status); |
|
1128 INFO_PRINTF2(_L("Read SMS returned %d"), status.Int()); |
|
1129 if(status.Int() != KErrNone) |
|
1130 { |
|
1131 User::Leave(status.Int()); |
|
1132 } |
|
1133 |
|
1134 //sbuf() includes the count of messages on SIM |
|
1135 return sbuf(); |
|
1136 } |
|
1137 |
|
1138 TBool CSMSTestSteps::TimedWaitForRecvL(RSocket& aSocket, TUint aDelay) |
|
1139 /** |
|
1140 * Wait for up to the delay for an Sms to be received |
|
1141 * @param aSocket The status is return to this socket |
|
1142 * @param aDelay Maximum time to wait for receipt |
|
1143 * @return ETrue if data received |
|
1144 * @leave Leaves if receiving is completed with error code |
|
1145 */ |
|
1146 { |
|
1147 TRequestStatus timerStatus; |
|
1148 RTimer timer; |
|
1149 timer.CreateLocal(); |
|
1150 timer.After(timerStatus, TTimeIntervalMicroSeconds32(aDelay)); |
|
1151 |
|
1152 TPckgBuf<TUint> sbuf; |
|
1153 sbuf()=KSockSelectRead; |
|
1154 TRequestStatus ioctlStatus; |
|
1155 aSocket.Ioctl(KIOctlSelect, ioctlStatus, &sbuf, KSOLSocket); |
|
1156 User::WaitForRequest(timerStatus, ioctlStatus); |
|
1157 TBool retval = EFalse; |
|
1158 if(ioctlStatus == KRequestPending) |
|
1159 { |
|
1160 // if timer elapsed but ESock request is still pending |
|
1161 aSocket.CancelIoctl(); |
|
1162 User::WaitForRequest(ioctlStatus); |
|
1163 } |
|
1164 else |
|
1165 { |
|
1166 // ESock request is done. Cancel timer |
|
1167 timer.Cancel(); |
|
1168 User::WaitForRequest(timerStatus); |
|
1169 // check ESock error status |
|
1170 if(ioctlStatus.Int() == KErrNone) |
|
1171 { |
|
1172 retval=ETrue; |
|
1173 } |
|
1174 } |
|
1175 timer.Close(); |
|
1176 return retval; |
|
1177 } |
|
1178 |
|
1179 TInt CSMSTestSteps::CancelWriteSmsToSimL(CSmsMessage& aSms, RSocket& aSocket, TInt aDelay) |
|
1180 /** |
|
1181 * This method stores SMS messages to the SMS storage. |
|
1182 * @param aSms SMS message that will be stored |
|
1183 * @param aSocket Used to stream SMS message to the sms stack |
|
1184 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
1185 * @leave Leaves if store request is completed with error code |
|
1186 */ |
|
1187 { |
|
1188 INFO_PRINTF1(_L("Write message")); |
|
1189 |
|
1190 TRequestStatus status; |
|
1191 |
|
1192 RSmsSocketWriteStream writestream(aSocket); |
|
1193 TRAPD(ret,writestream << aSms); |
|
1194 TEST(ret == KErrNone); |
|
1195 TRAP(ret,writestream.CommitL()); |
|
1196 TEST(ret == KErrNone); |
|
1197 |
|
1198 aSocket.Ioctl(KIoctlWriteSmsMessage,status,NULL, KSolSmsProv); |
|
1199 INFO_PRINTF1(_L("Cancel")); |
|
1200 User::After(aDelay); |
|
1201 aSocket.CancelIoctl(); |
|
1202 User::WaitForRequest(status); |
|
1203 INFO_PRINTF2(_L("WriteSmsToSimL - returned %d"), status.Int()); |
|
1204 |
|
1205 return status.Int(); |
|
1206 } |
|
1207 |
|
1208 TBool CSMSTestSteps::DoSingleTestCaseL( const TDesC8& aSection, TInt aCount ) |
|
1209 { |
|
1210 CTestConfig* configFile = CTestConfig::NewLC(iFs, KGmsSmsConfigFileDir, KConfigFilename); |
|
1211 |
|
1212 TBuf8<64> sectionName(aSection); |
|
1213 sectionName.AppendNum(aCount); |
|
1214 const CTestConfigSection* section = NULL; |
|
1215 TBool found( ETrue ); |
|
1216 |
|
1217 if ( ( section = configFile->Section( sectionName ) ) != NULL ) |
|
1218 { |
|
1219 if ( aSection == KTestSendAndRecvMsgsWithDifferentTON ) |
|
1220 { |
|
1221 TInt num( 1 ); |
|
1222 CArrayFixFlat<TInt>* alphabetArray = new ( ELeave ) CArrayFixFlat<TInt>( 1 ); |
|
1223 CleanupStack::PushL(alphabetArray); |
|
1224 CArrayFixFlat<TInt>* typeOfNumberArray = new ( ELeave ) CArrayFixFlat<TInt>( 1 ); |
|
1225 CleanupStack::PushL(typeOfNumberArray); |
|
1226 |
|
1227 TBuf8<32> itemName( KAlphabet ); |
|
1228 itemName.AppendNum( num ); |
|
1229 |
|
1230 TInt param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1231 while ( param != KErrNotFound ) |
|
1232 { |
|
1233 alphabetArray->AppendL(param); |
|
1234 itemName = KAlphabet; |
|
1235 itemName.AppendNum( ++num ); |
|
1236 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1237 } |
|
1238 num = 1; |
|
1239 itemName = KTypeOfNumber; |
|
1240 itemName.AppendNum( num ); |
|
1241 |
|
1242 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1243 while ( param != KErrNotFound ) |
|
1244 { |
|
1245 typeOfNumberArray->AppendL(param); |
|
1246 itemName = KTypeOfNumber; |
|
1247 itemName.AppendNum( ++num ); |
|
1248 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1249 } |
|
1250 |
|
1251 RPointerArray<CSmsPduDbMessage> array; |
|
1252 CleanupResetAndDestroyPushL(array); |
|
1253 ReadPduL( sectionName, array ); |
|
1254 TestSendAndRecvMsgsWithDifferentTONL( array, alphabetArray, typeOfNumberArray ); |
|
1255 CleanupStack::PopAndDestroy(&array); |
|
1256 CleanupStack::PopAndDestroy(typeOfNumberArray); |
|
1257 CleanupStack::PopAndDestroy(alphabetArray); |
|
1258 } |
|
1259 else if ( aSection == KTestSendAndReceiveIndicatorMsgs ) |
|
1260 { |
|
1261 TInt num( 1 ); |
|
1262 CArrayFixFlat<TInt>* indicationTypeArray = new ( ELeave ) CArrayFixFlat<TInt>( 1 ); |
|
1263 CleanupStack::PushL(indicationTypeArray); |
|
1264 CArrayFixFlat<TInt>* dcsBits7To4Array = new ( ELeave ) CArrayFixFlat<TInt>( 1 ); |
|
1265 CleanupStack::PushL(dcsBits7To4Array); |
|
1266 CArrayFixFlat<TInt>* indicationStateArray = new ( ELeave ) CArrayFixFlat<TInt>( 1 ); |
|
1267 CleanupStack::PushL(indicationStateArray); |
|
1268 |
|
1269 TBuf8<32> itemName( KIndicationType ); |
|
1270 itemName.AppendNum( num ); |
|
1271 |
|
1272 TInt param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1273 while ( param != KErrNotFound ) |
|
1274 { |
|
1275 indicationTypeArray->AppendL(param); |
|
1276 itemName = KIndicationType; |
|
1277 itemName.AppendNum( ++num ); |
|
1278 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1279 } |
|
1280 num = 1; |
|
1281 itemName = KDCSBits7To4; |
|
1282 itemName.AppendNum( num ); |
|
1283 |
|
1284 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1285 while ( param != KErrNotFound ) |
|
1286 { |
|
1287 dcsBits7To4Array->AppendL(param); |
|
1288 itemName = KDCSBits7To4; |
|
1289 itemName.AppendNum( ++num ); |
|
1290 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1291 } |
|
1292 num = 1; |
|
1293 itemName = KIndicationState; |
|
1294 itemName.AppendNum( num ); |
|
1295 |
|
1296 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1297 while ( param != KErrNotFound ) |
|
1298 { |
|
1299 indicationStateArray->AppendL(param); |
|
1300 itemName = KIndicationState; |
|
1301 itemName.AppendNum( ++num ); |
|
1302 param = section->ItemValue( (TPtrC8)itemName, KErrNotFound ); |
|
1303 } |
|
1304 |
|
1305 RPointerArray<CSmsPduDbMessage> array; |
|
1306 CleanupResetAndDestroyPushL(array); |
|
1307 ReadPduL( sectionName, array ); |
|
1308 TestSendAndReceiveIndicatorMsgsL( array, indicationStateArray, dcsBits7To4Array, indicationTypeArray ); |
|
1309 CleanupStack::PopAndDestroy(&array); |
|
1310 CleanupStack::PopAndDestroy(indicationStateArray); |
|
1311 CleanupStack::PopAndDestroy(dcsBits7To4Array); |
|
1312 CleanupStack::PopAndDestroy(indicationTypeArray); |
|
1313 } |
|
1314 else |
|
1315 found = EFalse; |
|
1316 } |
|
1317 else |
|
1318 found = EFalse; |
|
1319 |
|
1320 CleanupStack::PopAndDestroy(configFile);//configFile |
|
1321 return found; |
|
1322 } |
|
1323 |
|
1324 void CSMSTestSteps::TestSendAndRecvMsgsWithDifferentTONL( const RPointerArray<CSmsPduDbMessage>& aArray, |
|
1325 const CArrayFixFlat<TInt>* aAlphabetArray, |
|
1326 const CArrayFixFlat<TInt>* aTypeOfNumberArray ) |
|
1327 { |
|
1328 INFO_PRINTF1(_L("Send and receive messages with different type of number")); |
|
1329 |
|
1330 RSocketServ socketServer; |
|
1331 PrepareRegTestLC(socketServer, 39); |
|
1332 |
|
1333 RSocket socket; |
|
1334 iSmsStackTestUtils->OpenSmsSocketLC(socketServer,socket,ESmsAddrRecvAny); |
|
1335 |
|
1336 TSmsDataCodingScheme::TSmsAlphabet alphabet = ( TSmsDataCodingScheme::TSmsAlphabet )aAlphabetArray->At(0); |
|
1337 |
|
1338 TInt bufLen=aArray[0]->iSmsMessage->Buffer().Length(); |
|
1339 HBufC* textBuf=HBufC::NewL(bufLen); |
|
1340 CleanupStack::PushL(textBuf); |
|
1341 TPtr testText(textBuf->Des()); |
|
1342 aArray[0]->iSmsMessage->Buffer().Extract(testText,0,bufLen); |
|
1343 |
|
1344 CSmsMessage* sendMessage=CreateSmsMessageL(testText,alphabet); |
|
1345 CleanupStack::PushL(sendMessage); |
|
1346 CSmsSubmit& submitPdu=(CSmsSubmit&)sendMessage->SmsPDU(); |
|
1347 TGsmSmsTelNumber gsmSmsTelNumber; |
|
1348 gsmSmsTelNumber.iTelNumber.Append(iTelephoneNumber); |
|
1349 if(gsmSmsTelNumber.iTelNumber.Length() > 0 && gsmSmsTelNumber.iTelNumber[0] == '+') |
|
1350 { |
|
1351 // Remove "+" sign from telephony number |
|
1352 gsmSmsTelNumber.iTelNumber.Delete(0,1); |
|
1353 gsmSmsTelNumber.iTelNumber.Trim(); |
|
1354 } |
|
1355 |
|
1356 for ( TInt i = 0; i < aTypeOfNumberArray->Count(); i++ ) |
|
1357 { |
|
1358 |
|
1359 gsmSmsTelNumber.iTypeOfAddress.SetTON( ( TGsmSmsTypeOfNumber )aTypeOfNumberArray->At(i) ); |
|
1360 sendMessage->SetParsedToFromAddressL(gsmSmsTelNumber); |
|
1361 |
|
1362 if ( ( TGsmSmsTypeOfNumber )aTypeOfNumberArray->At(i) == EGsmSmsTONSubscriberNumber ) |
|
1363 { |
|
1364 submitPdu.SetPIDType(TSmsProtocolIdentifier::ESmsPIDShortMessageType); |
|
1365 submitPdu.SetShortMessageType(TSmsProtocolIdentifier::ESmsReturnCallMesage); |
|
1366 } |
|
1367 INFO_PRINTF2(_L("Send SMS message. Type of number is %d"), aTypeOfNumberArray->At(i) ); |
|
1368 SendSmsL(sendMessage,socket); |
|
1369 |
|
1370 INFO_PRINTF1(_L("Waiting for incoming SMS...") ); |
|
1371 WaitForRecvL(socket); |
|
1372 CSmsMessage* recvMessage = RecvSmsL(socket); |
|
1373 delete recvMessage; |
|
1374 |
|
1375 } |
|
1376 |
|
1377 CleanupStack::PopAndDestroy(sendMessage); |
|
1378 CleanupStack::PopAndDestroy(textBuf); |
|
1379 CleanupStack::PopAndDestroy(&socket); |
|
1380 CleanupStack::PopAndDestroy(&socketServer); |
|
1381 |
|
1382 |
|
1383 } |
|
1384 |
|
1385 void CSMSTestSteps::TestSendAndReceiveIndicatorMsgsL( const RPointerArray<CSmsPduDbMessage>& aArray, |
|
1386 const CArrayFixFlat<TInt>* aIndicationStateArray, |
|
1387 const CArrayFixFlat<TInt>* aDcsBits7To4Array, |
|
1388 const CArrayFixFlat<TInt>* aIndicationTypeArray ) |
|
1389 /** |
|
1390 * @test Send and receive different indicator messages |
|
1391 * TODO ESmsDCSMessageWaitingIndicationDiscardMessage test doesn't work with Nokia 6210 because phone |
|
1392 * doesn't route incoming message to the MM TSY. |
|
1393 */ |
|
1394 { |
|
1395 |
|
1396 INFO_PRINTF1(_L("Send and receive different indicator messages")); |
|
1397 |
|
1398 RSocketServ socketServer; |
|
1399 PrepareRegTestLC(socketServer, 40); |
|
1400 |
|
1401 RSocket socket; |
|
1402 iSmsStackTestUtils->OpenSmsSocketLC(socketServer,socket,ESmsAddrRecvAny); |
|
1403 |
|
1404 for ( TInt i = 0; i < aArray.Count(); i++ ) |
|
1405 { |
|
1406 |
|
1407 TSmsDataCodingScheme::TSmsIndicationState indicationState = |
|
1408 ( TSmsDataCodingScheme::TSmsIndicationState )aIndicationStateArray->At(i); |
|
1409 TSmsDataCodingScheme::TSmsDCSBits7To4 dcsBits7To4Array = |
|
1410 ( TSmsDataCodingScheme::TSmsDCSBits7To4 )aDcsBits7To4Array->At(i); |
|
1411 TSmsDataCodingScheme::TSmsIndicationType indicationType = |
|
1412 ( TSmsDataCodingScheme::TSmsIndicationType )aIndicationTypeArray->At(i); |
|
1413 |
|
1414 TInt bufLen=aArray[i]->iSmsMessage->Buffer().Length(); |
|
1415 HBufC* textBuf=HBufC::NewL(bufLen); |
|
1416 CleanupStack::PushL(textBuf); |
|
1417 TPtr testText(textBuf->Des()); |
|
1418 aArray[i]->iSmsMessage->Buffer().Extract(testText,0,bufLen); |
|
1419 |
|
1420 TTestCase msg(testText, indicationType, dcsBits7To4Array, indicationState ); |
|
1421 |
|
1422 SendAndRecvTestMessageL(msg,socket); |
|
1423 |
|
1424 CleanupStack::PopAndDestroy(textBuf); |
|
1425 } |
|
1426 |
|
1427 CleanupStack::PopAndDestroy(&socket); |
|
1428 CleanupStack::PopAndDestroy(&socketServer); |
|
1429 |
|
1430 } |
|
1431 |
|
1432 void CSMSTestSteps::ReadPduL( TBuf8<64> aSectionName, RPointerArray<CSmsPduDbMessage>& aArray ) |
|
1433 { |
|
1434 CSmsPduDatabase* db = CSmsPduDatabase::NewL(iFs, aSectionName, KConfigFilename, KConfigFileDir); |
|
1435 CleanupStack::PushL(db); |
|
1436 |
|
1437 db->GetMessageL(aArray, CSmsPDU::ESmsSubmit); |
|
1438 |
|
1439 CleanupStack::PopAndDestroy(db); |
|
1440 } |
|
1441 |
|
1442 |
|
1443 CSmsMessage* CSMSTestSteps::CreateSmsMessageLC(CSmsPDU::TSmsPDUType aType, CSmsBuffer* aBuffer, const TDesC& aAddress) |
|
1444 { |
|
1445 CSmsMessage* msg = CSmsMessage::NewL(iFs, aType, aBuffer); |
|
1446 CleanupStack::PushL(msg); |
|
1447 |
|
1448 if (aAddress.Length() != 0) |
|
1449 { |
|
1450 msg->SetToFromAddressL(aAddress); |
|
1451 } |
|
1452 |
|
1453 return msg; |
|
1454 } |
|
1455 |
|
1456 |
|
1457 void CSMSTestSteps::WriteToSIML(RSocket& aSocket, const CSmsMessage& aMsg) |
|
1458 { |
|
1459 TRequestStatus status; |
|
1460 |
|
1461 RSmsSocketWriteStream writestream(aSocket); |
|
1462 writestream << aMsg; |
|
1463 writestream.CommitL(); |
|
1464 |
|
1465 aSocket.Ioctl(KIoctlWriteSmsMessage,status,NULL, KSolSmsProv); |
|
1466 User::WaitForRequest(status); |
|
1467 INFO_PRINTF2(_L("Write Sms - returned %d"), status.Int()); |
|
1468 if (status.Int() != KErrNone) |
|
1469 { |
|
1470 INFO_PRINTF1(_L("Test has not written message to SIM successfully")); |
|
1471 } |
|
1472 TEST(status.Int() == KErrNone); |
|
1473 } |
|
1474 |
|
1475 |
|
1476 /* |
|
1477 These functions were grabbed from SMSStackTestUtils.dll |
|
1478 */ |
|
1479 void CSMSTestSteps::OpenSmsSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TSmsAddrFamily aFamily) |
|
1480 /** |
|
1481 * Initialise an RSocket for SMS, aSocket is NOT pushed to CleanupStack. |
|
1482 * @param aSocketServer reference to the socket server object |
|
1483 * @param aSocket The socket that will be opened |
|
1484 * @param aFamily The sms address family |
|
1485 */ |
|
1486 { |
|
1487 TSmsAddr smsaddr; |
|
1488 smsaddr.SetSmsAddrFamily(aFamily); |
|
1489 OpenSmsSocketL(aSocketServer, aSocket, smsaddr); |
|
1490 } |
|
1491 |
|
1492 void CSMSTestSteps::OpenSmsSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TSmsAddr& aSmsAddr) |
|
1493 /* |
|
1494 * Initialise an RSocket for SMS, aSocket is NOT pushed to CleanupStack. |
|
1495 * @param aSocketServer reference to the socket server object |
|
1496 * @param aSocket The socket that will be opened |
|
1497 * @param aSmsAddr The sms address to bind to |
|
1498 */ |
|
1499 { |
|
1500 TInt ret=aSocket.Open(aSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); |
|
1501 TEST(ret==KErrNone); |
|
1502 CleanupClosePushL(aSocket); |
|
1503 ret=aSocket.Bind(aSmsAddr); |
|
1504 TEST(ret==KErrNone); |
|
1505 CleanupStack::Pop(&aSocket); |
|
1506 } |
|
1507 |
|
1508 /* |
|
1509 Utility for creating a SMS message from test data (ini) file |
|
1510 */ |
|
1511 CSmsMessage* CSMSTestSteps::CreateSMSL() |
|
1512 { |
|
1513 INFO_PRINTF1(_L("Creating SMS...") ); |
|
1514 |
|
1515 TInt codingScheme; |
|
1516 GetIntFromConfig(ConfigSection(), _L("messageCoding"), codingScheme); |
|
1517 |
|
1518 TCodingScheme dataCodingScheme = (TCodingScheme)codingScheme; |
|
1519 |
|
1520 TSmsDataCodingScheme::TSmsAlphabet alphabet; |
|
1521 if (dataCodingScheme == ESevenBit) |
|
1522 { |
|
1523 //8 bit coding scheme |
|
1524 alphabet = TSmsDataCodingScheme::ESmsAlphabet7Bit; |
|
1525 } |
|
1526 |
|
1527 else |
|
1528 { |
|
1529 alphabet = TSmsDataCodingScheme::ESmsAlphabet8Bit; |
|
1530 } |
|
1531 |
|
1532 TPtrC messageText; |
|
1533 GetStringFromConfig(ConfigSection(), _L("message"), messageText); |
|
1534 CSmsMessage *iSms = CreateSmsMessageL(messageText,alphabet); |
|
1535 |
|
1536 INFO_PRINTF1(_L("SMS created") ); |
|
1537 PrintMessageL(iSms); |
|
1538 |
|
1539 return iSms; |
|
1540 |
|
1541 } |
|
1542 |
|
1543 /** |
|
1544 * Sets high and low limits in .RSC file and then reserves disk space to match requested levels. |
|
1545 * |
|
1546 * Checks the current free space and then sets the high and low marks |
|
1547 * to be aHighDrop MB and aLowDrop MB below the current free space |
|
1548 * level. |
|
1549 * |
|
1550 * Then diskspace is reserved to aFreeDrop MB below the current free |
|
1551 * space level. |
|
1552 * |
|
1553 * If the current free space level is greater then aMax then the |
|
1554 * current free space level is set to aMax |
|
1555 * |
|
1556 * If the current free space level is less than aLowDrop MB then this |
|
1557 * method leaves with KErrArgument. |
|
1558 * |
|
1559 * @param aHighDrop The number of MB below the current free space level for the high level mark (in the .RSC file) |
|
1560 * @param aLowDrop The number of MB below the current free space level for the low level mark (in the .RSC file) |
|
1561 * @param aFreeDrop The number of MB below the current free space level to set the free space to ; |
|
1562 * if aFreeDrop == 0, then SetFreeDiskSpaceL() is not called |
|
1563 * @param aMax The maximum level for the high limit allowed |
|
1564 * |
|
1565 * @return The max current free space level used. |
|
1566 * |
|
1567 * @leave KErrArgument if the current free diskspace level is less than aLowDrop MB |
|
1568 * @leave KErrArgument if aMax is not greater than aLowDrop MB |
|
1569 * @leave KErrArgument if aHighDrop >= aLowDrop |
|
1570 */ |
|
1571 TUint64 CSMSTestSteps::SetHighLowLimitsAndDiskSpaceLevelL(TUint aHighDrop, TUint aLowDrop, TUint aFreeDrop, TUint64 aMax/*=0x7fffffff*/) |
|
1572 { |
|
1573 INFO_PRINTF5(_L("Setting High-Low limits and Diskspace levels [aHighDrop=%u, aLowDrop=%u, aFreeDrop=%u, aMax=%ld]"), |
|
1574 aHighDrop, aLowDrop, aFreeDrop, aMax); |
|
1575 |
|
1576 __ASSERT_ALWAYS( (aMax > (aLowDrop*1024*1024)), User::Leave(KErrArgument)); |
|
1577 __ASSERT_ALWAYS( (aLowDrop > aHighDrop), User::Leave(KErrArgument)); |
|
1578 |
|
1579 ReleaseDiskSpaceL(); |
|
1580 |
|
1581 TVolumeInfo volumeInfo; |
|
1582 User::LeaveIfError(iFs.Volume(volumeInfo, EDriveC)); |
|
1583 INFO_PRINTF2(_L(" Drive C currently has %ld bytes free."), volumeInfo.iFree); |
|
1584 |
|
1585 TUint64 current = volumeInfo.iFree; |
|
1586 if( current < (aLowDrop*1024*1024) ) |
|
1587 { |
|
1588 INFO_PRINTF1(_L(" Drive C already has too little free space!")); |
|
1589 User::Leave(KErrArgument); |
|
1590 } |
|
1591 if( current > aMax ) |
|
1592 { |
|
1593 current = aMax; |
|
1594 } |
|
1595 TUint64 high = current - (aHighDrop*1024*1024); |
|
1596 TUint64 low = current - (aLowDrop*1024*1024); |
|
1597 |
|
1598 SetLowHighLimitsInSmsuRscL(low, high); |
|
1599 |
|
1600 if( aFreeDrop > 0 ) |
|
1601 { |
|
1602 TUint64 free = current - (aFreeDrop*1024*1024); |
|
1603 SetFreeDiskSpaceL(free); |
|
1604 } |
|
1605 |
|
1606 return current; |
|
1607 } |
|
1608 |
|
1609 void CSMSTestSteps::SetFreeDiskSpaceFromDropLevelL(TUint aFreeDrop) |
|
1610 { |
|
1611 if( aFreeDrop == 0) |
|
1612 { |
|
1613 return; |
|
1614 } |
|
1615 |
|
1616 TVolumeInfo volumeInfo; |
|
1617 User::LeaveIfError(iFs.Volume(volumeInfo, EDriveC)); |
|
1618 TUint64 current = volumeInfo.iFree; |
|
1619 if( current > 0x7fffffff ) |
|
1620 { |
|
1621 current = 0x7fffffff; |
|
1622 } |
|
1623 TUint64 free = current - (aFreeDrop*1024*1024); |
|
1624 SetFreeDiskSpaceL(free); |
|
1625 } |
|
1626 |
|
1627 /** |
|
1628 * Reserves disk space so that a specified amount of free disk space is |
|
1629 * available. |
|
1630 * |
|
1631 * @param aNewFreeValue Amount of free space required. |
|
1632 */ |
|
1633 void CSMSTestSteps::SetFreeDiskSpaceL(TInt64 aNewFreeValue) |
|
1634 { |
|
1635 |
|
1636 #ifndef _DEBUG |
|
1637 ERR_PRINTF1(_L("Unexpected call: CSMSTestSteps::SetFreeDiskSpaceL() is expected to be called only in DEBUG mode.")); |
|
1638 User::Leave(KErrNotSupported); |
|
1639 #else |
|
1640 |
|
1641 INFO_PRINTF2(_L("Setting Drive C free disk space to %ld bytes."), aNewFreeValue); |
|
1642 |
|
1643 __ASSERT_DEBUG( (aNewFreeValue <= 0x7fffffff), User::Leave(KErrArgument)); |
|
1644 |
|
1645 TInt err = RProperty::Set(KUidPSSMSStackCategory, KUidPSSMSStackFreeDiskSpaceKey, (TInt)aNewFreeValue); |
|
1646 if (err != KErrNone) |
|
1647 { |
|
1648 ERR_PRINTF2(_L("RProperty::Set() failure [err=%d]"), err); |
|
1649 User::Leave(err); |
|
1650 } |
|
1651 #endif |
|
1652 } // CSMSTestSteps::SetFreeDiskSpaceL |
|
1653 |
|
1654 /** |
|
1655 * Release all reserved disk space. |
|
1656 */ |
|
1657 void CSMSTestSteps::ReleaseDiskSpaceL() |
|
1658 { |
|
1659 |
|
1660 #ifndef _DEBUG |
|
1661 ERR_PRINTF1(_L("Unexpected call: CSMSTestSteps::ReleaseDiskSpaceL() is expected to be called only in DEBUG mode.")); |
|
1662 User::Leave(KErrNotSupported); |
|
1663 #else |
|
1664 |
|
1665 INFO_PRINTF1(_L("CSMSTestSteps::ReleaseDiskSpaceL()")); |
|
1666 |
|
1667 TVolumeInfo volumeInfo; |
|
1668 User::LeaveIfError(iFs.Volume(volumeInfo, EDriveC)); |
|
1669 TUint64 current = volumeInfo.iFree; |
|
1670 if( current > 0x7fffffff ) |
|
1671 { |
|
1672 current = 0x7fffffff; |
|
1673 } |
|
1674 |
|
1675 SetFreeDiskSpaceL(current); |
|
1676 #endif |
|
1677 } // CSMSTestSteps::ReleaseDiskSpaceL |
|
1678 |
|
1679 |
|
1680 /** |
|
1681 * Set high and low limits in .RSC file. When the SMS Stack starts the limits |
|
1682 * will be loaded as if set by the licensee. |
|
1683 * |
|
1684 * @param aLowLimit Low limit value. |
|
1685 * @param aHighLimit High limit value. |
|
1686 * |
|
1687 * @note Only works in debug mode for security reasons. |
|
1688 */ |
|
1689 void CSMSTestSteps::SetLowHighLimitsInSmsuRscL(TInt64 aLowLimit, TInt64 aHighLimit) |
|
1690 { |
|
1691 INFO_PRINTF3(_L("Setting high and low .RSC limits to %ld and %ld."), |
|
1692 aHighLimit, aLowLimit); |
|
1693 |
|
1694 __ASSERT_ALWAYS(aLowLimit < 0x7fffffff, User::Leave(KErrArgument)); |
|
1695 __ASSERT_ALWAYS(aHighLimit < 0x7fffffff, User::Leave(KErrArgument)); |
|
1696 __ASSERT_ALWAYS(aLowLimit < aHighLimit, User::Leave(KErrArgument)); |
|
1697 |
|
1698 // |
|
1699 // Data for the SMSU resource file. The low limit is written at position |
|
1700 // 20 and the high limit at position 24. |
|
1701 // |
|
1702 const TInt smsuRscSize = 34; |
|
1703 TChar smsuRscData[smsuRscSize] = |
|
1704 {0x6b, 0x4a, 0x1f, 0x10, 0x00, 0x00, 0x00, 0x00, |
|
1705 0x00, 0x00, 0x00, 0x00, 0x19, 0xfd, 0x48, 0xe8, |
|
1706 0x01, 0x04, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12, |
|
1707 0x87, 0x65, 0x43, 0x21, 0x14, 0x00, 0x18, 0x00, |
|
1708 0x1c, 0x00}; |
|
1709 |
|
1710 smsuRscData[20] = (aLowLimit >> 0) & 0xff; |
|
1711 smsuRscData[21] = (aLowLimit >> 8) & 0xff; |
|
1712 smsuRscData[22] = (aLowLimit >> 16) & 0xff; |
|
1713 smsuRscData[23] = (aLowLimit >> 24) & 0xff; |
|
1714 smsuRscData[24] = (aHighLimit >> 0) & 0xff; |
|
1715 smsuRscData[25] = (aHighLimit >> 8) & 0xff; |
|
1716 smsuRscData[26] = (aHighLimit >> 16) & 0xff; |
|
1717 smsuRscData[27] = (aHighLimit >> 24) & 0xff; |
|
1718 |
|
1719 TBuf8<smsuRscSize> smsuRscBuffer; |
|
1720 |
|
1721 for (TInt index = 0; index < smsuRscSize; index++) |
|
1722 { |
|
1723 smsuRscBuffer.Append(smsuRscData[index]); |
|
1724 } |
|
1725 |
|
1726 // |
|
1727 // Ensure the target directory exists... |
|
1728 // |
|
1729 TInt ret; |
|
1730 |
|
1731 ret = iFs.MkDir(KSMSUResourceDir); |
|
1732 if (ret != KErrNone && ret != KErrAlreadyExists) |
|
1733 { |
|
1734 User::Leave(ret); |
|
1735 } |
|
1736 |
|
1737 // |
|
1738 // Write the RSC file to the private C:\ directory... |
|
1739 // |
|
1740 RFile file; |
|
1741 |
|
1742 User::LeaveIfError(file.Replace(iFs, KSMSUResourceFile, EFileWrite)); |
|
1743 CleanupClosePushL(file); |
|
1744 User::LeaveIfError(file.Write(smsuRscSize, smsuRscBuffer)); |
|
1745 CleanupStack::PopAndDestroy(&file); |
|
1746 } // CSMSTestSteps::SetLowHighLimitsInSmsuRscL |
|
1747 |
|
1748 |
|
1749 /** |
|
1750 * Removes the low and high limits and returns the SMSU.RSC to defauls. |
|
1751 */ |
|
1752 void CSMSTestSteps::RemoveLowHighLimitsFromSmsuRscL() |
|
1753 { |
|
1754 INFO_PRINTF1(_L("Removing .RSC limits.")); |
|
1755 |
|
1756 // |
|
1757 // Remove the RSC file... |
|
1758 // |
|
1759 TInt ret; |
|
1760 |
|
1761 ret = iFs.Delete(KSMSUResourceFile); |
|
1762 if (ret != KErrNone && ret != KErrNotFound) |
|
1763 { |
|
1764 User::Leave(ret); |
|
1765 } |
|
1766 } // CSMSTestSteps::RemoveLowHighLimitsFromSmsuRscL |
|