|
1 // Copyright (c) 2003-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 // Utility functions for Sms Stack test harnesses |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include <commsdattypesv1_1.h> |
|
23 #include <logcli.h> |
|
24 |
|
25 #include "smsstacktestutilities.h" |
|
26 #include <e32math.h> |
|
27 #include "smsustrm.h" |
|
28 #include "Gsmumsg.h" |
|
29 #include "smsuaddr.H" |
|
30 #include "gsmubuf.h" |
|
31 |
|
32 #include "smspdudb.h" |
|
33 #include <e32test.h> |
|
34 #include <f32file.h> |
|
35 #include "SmsuTimer.h" |
|
36 #include "smsstacklog.h" |
|
37 #include <logwraplimits.h> |
|
38 |
|
39 using namespace CommsDat; |
|
40 |
|
41 |
|
42 // Check a boolean is true |
|
43 #define LOCAL_CHECKPOINT(a) iTestStep->testBooleanTrue((a), (TText8*)__FILE__, __LINE__) |
|
44 |
|
45 // Check a boolean is true if not return error code b |
|
46 #define LOCAL_CHECKPOINT_CODE(a, b) iTestStep->testBooleanTrueWithErrorCode((a), (b), (TText8*)__FILE__, __LINE__) |
|
47 #define LOCAL_CHECKPOINT_COMPAREL(p1, p2, p3) iTestStep->TestCheckPointCompareL((p1), (p2), (p3), (TText8*)__FILE__, __LINE__) |
|
48 |
|
49 // TestExecute style Printf |
|
50 #define PRINTF1(p1) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) |
|
51 #define PRINTF2(p1, p2) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) |
|
52 #define PRINTF3(p1, p2, p3) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3)) |
|
53 #define PRINTF4(p1, p2, p3, p4) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4)) |
|
54 #define PRINTF5(p1, p2, p3, p4, p5) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5)) |
|
55 #define PRINTF6(p1, p2, p3, p4, p5, p6) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6)) |
|
56 #define PRINTF7(p1, p2, p3, p4, p5, p6, p7) iTestStep->Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) |
|
57 |
|
58 |
|
59 class CTSmsRegTstActive : public CActive |
|
60 { |
|
61 public: |
|
62 CTSmsRegTstActive(); |
|
63 ~CTSmsRegTstActive(); |
|
64 void StartL(); |
|
65 protected: |
|
66 void DoCancel(); |
|
67 void RunL(); |
|
68 }; |
|
69 |
|
70 CTSmsRegTstActive::CTSmsRegTstActive(): |
|
71 CActive(0) |
|
72 { |
|
73 CActiveScheduler::Add(this); |
|
74 } |
|
75 |
|
76 CTSmsRegTstActive::~CTSmsRegTstActive() |
|
77 { |
|
78 Cancel(); |
|
79 } |
|
80 |
|
81 void CTSmsRegTstActive::DoCancel() |
|
82 { |
|
83 TRequestStatus* s=&iStatus; |
|
84 User::RequestComplete(s, KErrNone); |
|
85 } |
|
86 |
|
87 void CTSmsRegTstActive::StartL() |
|
88 { |
|
89 SetActive(); |
|
90 } |
|
91 |
|
92 void CTSmsRegTstActive::RunL() |
|
93 { |
|
94 CActiveScheduler::Stop(); |
|
95 } |
|
96 |
|
97 |
|
98 EXPORT_C CSmsStackTestUtils* CSmsStackTestUtils::NewL(CTestStep* aTestStep, RFs& aFs) |
|
99 { |
|
100 CSmsStackTestUtils* self = new (ELeave) CSmsStackTestUtils(aTestStep, aFs); |
|
101 CleanupStack::PushL(self); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop(self); |
|
104 return self; |
|
105 } |
|
106 |
|
107 void CSmsStackTestUtils::ConstructL() |
|
108 { |
|
109 iCharConv = CCnvCharacterSetConverter::NewL(); |
|
110 } |
|
111 |
|
112 EXPORT_C CSmsStackTestUtils::~CSmsStackTestUtils() |
|
113 { |
|
114 delete iCharConv; |
|
115 } |
|
116 |
|
117 CSmsStackTestUtils::CSmsStackTestUtils(CTestStep* aTestStep, RFs& aFs) |
|
118 : iTestStep(aTestStep), iFs(aFs) |
|
119 { |
|
120 } |
|
121 |
|
122 EXPORT_C void CSmsStackTestUtils::WaitForInitializeL() |
|
123 /** |
|
124 * Initialize the phone for the tsy. This will prevent message sends from completing with KErrNotReady |
|
125 */ |
|
126 { |
|
127 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
128 CMDBSession* db = CMDBSession::NewL(KCDVersion1_2); |
|
129 #else |
|
130 CMDBSession* db = CMDBSession::NewL(KCDVersion1_1); |
|
131 #endif |
|
132 |
|
133 CleanupStack::PushL(db); |
|
134 |
|
135 TName tsy; |
|
136 TUint32 modemId = 0; |
|
137 |
|
138 CMDBField<TUint32>* globalSettingsField = new(ELeave) CMDBField<TUint32>(KCDTIdModemPhoneServicesSMS); |
|
139 CleanupStack::PushL(globalSettingsField); |
|
140 globalSettingsField->SetRecordId(1); |
|
141 globalSettingsField->LoadL(*db); |
|
142 modemId = *globalSettingsField; |
|
143 CleanupStack::PopAndDestroy(globalSettingsField); |
|
144 |
|
145 CMDBField<TDesC>* tsyField = new(ELeave) CMDBField<TDesC>(KCDTIdTsyName); |
|
146 CleanupStack::PushL(tsyField); |
|
147 tsyField->SetRecordId(modemId); |
|
148 tsyField->SetMaxLengthL(KMaxTextLength); |
|
149 tsyField->LoadL(*db); |
|
150 tsy = *tsyField; |
|
151 CleanupStack::PopAndDestroy(tsyField); |
|
152 |
|
153 CleanupStack::PopAndDestroy(db); |
|
154 |
|
155 PRINTF2(_L("Loading TSY \"%S\"..."), &tsy); |
|
156 |
|
157 RTelServer server; |
|
158 User::LeaveIfError(server.Connect()); |
|
159 CleanupClosePushL(server); |
|
160 User::LeaveIfError(server.LoadPhoneModule(tsy)); |
|
161 |
|
162 // Find the phone corresponding to this TSY and open a number of handles on it |
|
163 TInt numPhones; |
|
164 User::LeaveIfError(server.EnumeratePhones(numPhones)); |
|
165 RPhone phone; |
|
166 TBool found=EFalse; |
|
167 |
|
168 while (numPhones--) |
|
169 { |
|
170 TName phoneTsy; |
|
171 User::LeaveIfError(server.GetTsyName(numPhones,phoneTsy)); |
|
172 if (phoneTsy.CompareF(tsy)==KErrNone) |
|
173 { |
|
174 PRINTF1(_L("Found RPhone...")); |
|
175 found = ETrue; |
|
176 RTelServer::TPhoneInfo info; |
|
177 User::LeaveIfError(server.GetPhoneInfo(numPhones,info)); |
|
178 User::LeaveIfError(phone.Open(server,info.iName)); |
|
179 CleanupClosePushL(phone); |
|
180 PRINTF1(_L("Initializing...")); |
|
181 const TInt err = phone.Initialise(); |
|
182 TTimeIntervalMicroSeconds32 InitPause=9000000; //Required Pause to Allow SMSStack to Complete its Async Init |
|
183 User::After(InitPause); //call to the TSY and finish its StartUp. |
|
184 PRINTF2(_L("Completed Initialize [err=%d]"), err); |
|
185 User::LeaveIfError(err); |
|
186 CleanupStack::PopAndDestroy(&phone); |
|
187 break; |
|
188 } |
|
189 } |
|
190 |
|
191 LOCAL_CHECKPOINT(found); |
|
192 CleanupStack::PopAndDestroy(&server); |
|
193 } |
|
194 |
|
195 EXPORT_C void CSmsStackTestUtils::OpenSmsSocketLC(RSocketServ& aSocketServer, RSocket& aSocket, TSmsAddrFamily aFamily) |
|
196 /** |
|
197 * Initialise an RSocket for SMS |
|
198 * @note aSocket is pushed to CleanupStack. |
|
199 * @param aSocketServer reference to the socket server object |
|
200 * @param aSocket The socket that will be opened |
|
201 * @param aFamily The sms address family |
|
202 */ |
|
203 { |
|
204 OpenSmsSocketL(aSocketServer, aSocket, aFamily); |
|
205 CleanupClosePushL(aSocket); |
|
206 } |
|
207 |
|
208 EXPORT_C void CSmsStackTestUtils::OpenSmsSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TSmsAddrFamily aFamily) |
|
209 /** |
|
210 * Initialise an RSocket for SMS, aSocket is NOT pushed to CleanupStack. |
|
211 * @param aSocketServer reference to the socket server object |
|
212 * @param aSocket The socket that will be opened |
|
213 * @param aFamily The sms address family |
|
214 */ |
|
215 { |
|
216 TSmsAddr smsaddr; |
|
217 smsaddr.SetSmsAddrFamily(aFamily); |
|
218 OpenSmsSocketL(aSocketServer, aSocket, smsaddr); |
|
219 } |
|
220 |
|
221 EXPORT_C void CSmsStackTestUtils::OpenSmsSocketLC(RSocketServ& aSocketServer, RSocket& aSocket, TSmsAddr& aSmsAddr) |
|
222 /** |
|
223 * Initialise an RSocket for SMS. |
|
224 * @note aSocket is pushed to CleanupStack |
|
225 * @param aSocketServer reference to the socket server object |
|
226 * @param aSocket The socket that will be opened |
|
227 * @param aSmsAddr The sms address to bind to |
|
228 */ |
|
229 { |
|
230 OpenSmsSocketL(aSocketServer, aSocket, aSmsAddr); |
|
231 CleanupClosePushL(aSocket); |
|
232 } |
|
233 |
|
234 |
|
235 EXPORT_C void CSmsStackTestUtils::OpenSmsSocketL(RSocketServ& aSocketServer, RSocket& aSocket, TSmsAddr& aSmsAddr) |
|
236 /** |
|
237 * Initialise an RSocket for SMS, aSocket is NOT pushed to CleanupStack. |
|
238 * @param aSocketServer reference to the socket server object |
|
239 * @param aSocket The socket that will be opened |
|
240 * @param aSmsAddr The sms address to bind to |
|
241 */ |
|
242 { |
|
243 TInt ret=aSocket.Open(aSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); |
|
244 PRINTF2(_L("Socket Open Return Value : %d"),ret); |
|
245 LOCAL_CHECKPOINT(ret == KErrNone); |
|
246 CleanupClosePushL(aSocket); |
|
247 ret=aSocket.Bind(aSmsAddr); |
|
248 PRINTF2(_L("Socket Bind Return Value : %d"),ret); |
|
249 LOCAL_CHECKPOINT(ret == KErrNone); |
|
250 WaitForInitializeL(); |
|
251 CleanupStack::Pop(&aSocket); |
|
252 } |
|
253 |
|
254 EXPORT_C void CSmsStackTestUtils::SendSmsAndChangeBearerL(CSmsMessage* aSms, RSocket& aSocket, RMobileSmsMessaging::TMobileSmsBearer aBearer) |
|
255 /** |
|
256 * Stream aSms out to the socket server. The idea is to change bearer midway through |
|
257 * sending the PDUs making up the complete message. |
|
258 * @param aSms contains the sms tpdu that will be streamed to the sms stack |
|
259 * @param aSocket is used to stream the aSms to the sms stack |
|
260 * @param aBearer Bearer setting that is changed to CommDb |
|
261 * @leave Leaves if streaming the message to the socket server doesn't succeed |
|
262 * @leave Leaves if sending is completed with error code |
|
263 */ |
|
264 { |
|
265 RSmsSocketWriteStream writestream(aSocket); |
|
266 TRAPD(ret,writestream << *aSms); |
|
267 LOCAL_CHECKPOINT(ret == KErrNone); |
|
268 TRAP(ret,writestream.CommitL()); |
|
269 LOCAL_CHECKPOINT(ret == KErrNone); |
|
270 |
|
271 // Create comms database object |
|
272 CMDBSession* db = CMDBSession::NewL(KCDVersion1_1); |
|
273 CleanupStack::PushL(db); |
|
274 |
|
275 //Send message and change bearer |
|
276 TPckgBuf<TUint> sbuf; |
|
277 TRequestStatus status; |
|
278 aSocket.Ioctl(KIoctlSendSmsMessage,status,&sbuf, KSolSmsProv); |
|
279 |
|
280 //Wait couple of seconds to ensure first pdus of message have been sent |
|
281 User::After(2500000); |
|
282 |
|
283 // Change bearer |
|
284 CMDBField<TUint32>* smsBearerField = new(ELeave) CMDBField<TUint32>(KCDTIdSMSBearer); |
|
285 CleanupStack::PushL(smsBearerField); |
|
286 smsBearerField->SetRecordId(1); //it's GlobalSettingsRecord |
|
287 *smsBearerField = aBearer; |
|
288 smsBearerField->ModifyL(*db); |
|
289 CleanupStack::PopAndDestroy(smsBearerField); |
|
290 CleanupStack::PopAndDestroy(db); |
|
291 |
|
292 User::WaitForRequest(status); |
|
293 PRINTF2(_L("SendSmsL - sendSmsMessage returned %d"), status.Int()); |
|
294 LOCAL_CHECKPOINT(status.Int() == KErrNone); |
|
295 |
|
296 CSmsBuffer& smsbuffer = (CSmsBuffer&)aSms->Buffer(); |
|
297 TInt len = smsbuffer.Length(); |
|
298 HBufC* hbuf = HBufC::NewL(len); |
|
299 TPtr ptr = hbuf->Des(); |
|
300 smsbuffer.Extract(ptr,0,len); |
|
301 PRINTF2(_L("SMS contains %d characters"),len); |
|
302 delete hbuf; |
|
303 } |
|
304 |
|
305 EXPORT_C void CSmsStackTestUtils::ChangeBearerL(RMobileSmsMessaging::TMobileSmsBearer aBearer) |
|
306 /** |
|
307 Change the bearer in CommDB global settings. |
|
308 |
|
309 @param aBearer The new bearer setting. |
|
310 @return none |
|
311 */ |
|
312 { |
|
313 // Start a CommDB session |
|
314 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
315 CMDBSession* db = CMDBSession::NewL(KCDVersion1_2); |
|
316 #else |
|
317 CMDBSession* db = CMDBSession::NewL(KCDVersion1_1); |
|
318 #endif |
|
319 CleanupStack::PushL(db); |
|
320 |
|
321 // Change bearer in global settings |
|
322 CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord); |
|
323 TRAPD(err, globalSettingsRecord.LoadL(*db)); |
|
324 if (err != KErrNone) |
|
325 { |
|
326 PRINTF2(_L("Could not load global settings. Error = %d\n"), err); |
|
327 User::Leave(err); |
|
328 } |
|
329 ((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iSMSBearer = aBearer; |
|
330 globalSettingsRecord.ModifyL(*db); |
|
331 |
|
332 PRINTF2(_L("Setting bearer in global settings to %d\n"), aBearer); |
|
333 |
|
334 CleanupStack::PopAndDestroy(db); |
|
335 } |
|
336 |
|
337 EXPORT_C void CSmsStackTestUtils::GetBearerL(RMobileSmsMessaging::TMobileSmsBearer& aBearer) |
|
338 /** |
|
339 Get the bearer from CommDB global settings. |
|
340 |
|
341 @param aBearer The bearer setting retrieved from global settings. |
|
342 @return none |
|
343 */ |
|
344 { |
|
345 // Start a CommDB session |
|
346 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
347 CMDBSession* db = CMDBSession::NewL(KCDVersion1_2); |
|
348 #else |
|
349 CMDBSession* db = CMDBSession::NewL(KCDVersion1_1); |
|
350 #endif |
|
351 CleanupStack::PushL(db); |
|
352 |
|
353 // Load global settings |
|
354 CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord); |
|
355 TRAPD(err, globalSettingsRecord.LoadL(*db)); |
|
356 if (err != KErrNone) |
|
357 { |
|
358 PRINTF2(_L("Could not load global settings. Error = %d\n"), err); |
|
359 User::Leave(err); |
|
360 } |
|
361 TInt tempBearer = ((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iSMSBearer; |
|
362 aBearer = static_cast<RMobileSmsMessaging::TMobileSmsBearer>(tempBearer); |
|
363 PRINTF2(_L("Got bearer from CommDB. Bearer = %d\n"), aBearer); |
|
364 |
|
365 CleanupStack::PopAndDestroy(db); |
|
366 } |
|
367 |
|
368 EXPORT_C void CSmsStackTestUtils::DisableLogging() |
|
369 { |
|
370 CTSmsRegTstActive* testActive = new(ELeave)CTSmsRegTstActive(); |
|
371 CleanupStack::PushL(testActive); |
|
372 testActive->StartL(); |
|
373 |
|
374 CLogWrapper* logWrapper=CLogWrapper::NewL(iFs); |
|
375 CleanupStack::PushL(logWrapper); |
|
376 CLogClient& logClient = static_cast<CLogClient&>(logWrapper->Log()); |
|
377 TLogConfig config; |
|
378 logClient.GetConfig(config, testActive->iStatus); |
|
379 CActiveScheduler::Start(); |
|
380 LOCAL_CHECKPOINT(testActive->iStatus.Int() == KErrNone); |
|
381 |
|
382 // Disable logging |
|
383 config.iMaxEventAge = 0; |
|
384 config.iMaxLogSize = 0; |
|
385 config.iMaxRecentLogSize = 0; |
|
386 |
|
387 testActive->StartL(); |
|
388 logClient.ChangeConfig(config, testActive->iStatus); |
|
389 CActiveScheduler::Start(); |
|
390 LOCAL_CHECKPOINT(testActive->iStatus.Int() == KErrNone); |
|
391 |
|
392 CleanupStack::PopAndDestroy(logWrapper); |
|
393 CleanupStack::PopAndDestroy(testActive); |
|
394 } |
|
395 |
|
396 EXPORT_C void CSmsStackTestUtils::EnableLogging() |
|
397 { |
|
398 CTSmsRegTstActive* testActive = new(ELeave)CTSmsRegTstActive(); |
|
399 CleanupStack::PushL(testActive); |
|
400 testActive->StartL(); |
|
401 |
|
402 CLogWrapper* logWrapper=CLogWrapper::NewL(iFs); |
|
403 CleanupStack::PushL(logWrapper); |
|
404 CLogClient& logClient = static_cast<CLogClient&> (logWrapper->Log()); |
|
405 TLogConfig config; |
|
406 logClient.GetConfig(config, testActive->iStatus); |
|
407 CActiveScheduler::Start(); |
|
408 LOCAL_CHECKPOINT(testActive->iStatus.Int() == KErrNone); |
|
409 |
|
410 // Enable logging |
|
411 config.iMaxEventAge = 10000; |
|
412 config.iMaxLogSize = 10000; |
|
413 config.iMaxRecentLogSize = 127; |
|
414 |
|
415 testActive->StartL(); |
|
416 logClient.ChangeConfig(config, testActive->iStatus); |
|
417 CActiveScheduler::Start(); |
|
418 LOCAL_CHECKPOINT(testActive->iStatus.Int() == KErrNone); |
|
419 |
|
420 CleanupStack::PopAndDestroy(logWrapper); |
|
421 CleanupStack::PopAndDestroy(testActive); |
|
422 } |
|
423 |
|
424 |
|
425 EXPORT_C void CSmsStackTestUtils::GetLogEventL(CLogEvent& aLogEvent, TInt aLogServerId) |
|
426 /** |
|
427 * Get SMS log event from event logger. |
|
428 * @param aLogEvent reference to the CLogEvent object |
|
429 * @param aLogServerId number of log event |
|
430 */ |
|
431 { |
|
432 CTSmsRegTstActive* testActive = new(ELeave)CTSmsRegTstActive(); |
|
433 CleanupStack::PushL(testActive); |
|
434 |
|
435 CLogWrapper* logWrapper=CLogWrapper::NewL(iFs); |
|
436 CleanupStack::PushL(logWrapper); |
|
437 |
|
438 aLogEvent.SetId(aLogServerId); |
|
439 testActive->StartL(); |
|
440 logWrapper->Log().GetEvent(aLogEvent,testActive->iStatus); |
|
441 CActiveScheduler::Start(); |
|
442 LOCAL_CHECKPOINT(testActive->iStatus.Int() == KErrNone); |
|
443 CleanupStack::PopAndDestroy(2); // testActive, logWrapper |
|
444 } |
|
445 |
|
446 EXPORT_C TLogId CSmsStackTestUtils::AddLogEventL(CSmsMessage& aSmsMessage,TLogSmsPduData& aSmsPDUData) |
|
447 /** |
|
448 * Add SMS log event to the event logger. |
|
449 * @param aSmsMessage SM mesage |
|
450 * @param aLogSmsPduData initialised structure with data relevant to logging |
|
451 */ |
|
452 { |
|
453 CTSmsRegTstActive* testActive = new(ELeave)CTSmsRegTstActive(); |
|
454 CleanupStack::PushL(testActive); |
|
455 |
|
456 CLogWrapper* logWrapper=CLogWrapper::NewL(iFs); |
|
457 CleanupStack::PushL(logWrapper); |
|
458 |
|
459 TLogId id=NULL; |
|
460 |
|
461 if(logWrapper->ClientAvailable()) |
|
462 { |
|
463 testActive->StartL(); |
|
464 |
|
465 |
|
466 CLogEvent* logevent=CLogEvent::NewL(); |
|
467 CleanupStack::PushL(logevent); |
|
468 |
|
469 TBuf<KLogMaxDirectionLength> direction; |
|
470 User::LeaveIfError(logWrapper->Log().GetString(direction,R_LOG_DIR_OUT)); |
|
471 |
|
472 |
|
473 logevent->SetDirection(direction); |
|
474 logevent->SetEventType(KLogShortMessageEventTypeUid); |
|
475 logevent->SetNumber(aSmsMessage.ToFromAddress()); |
|
476 |
|
477 logevent->SetSubject(_L("test")); |
|
478 logevent->SetStatus(_L("status")); |
|
479 TPckg<TLogSmsPduData> packeddata(aSmsPDUData); |
|
480 logevent->SetDataL(packeddata); |
|
481 |
|
482 logWrapper->Log().AddEvent(*logevent,testActive->iStatus); |
|
483 CActiveScheduler::Start(); |
|
484 LOCAL_CHECKPOINT(testActive->iStatus.Int() == KErrNone); |
|
485 id=logevent->Id(); |
|
486 CleanupStack::PopAndDestroy(logevent); |
|
487 } |
|
488 |
|
489 CleanupStack::PopAndDestroy(2); // testActive, logWrapper |
|
490 return id; |
|
491 } |
|
492 |
|
493 |
|
494 EXPORT_C void CSmsStackTestUtils::CopyConfigFileL(const TDesC& aFromSmsConfigFile, CSmsPduDatabase* aPduDb) |
|
495 { |
|
496 PRINTF3(_L("Copying %S to %S..."), &aFromSmsConfigFile, &KSimTsyConfigFileName); |
|
497 TBool createdDb = EFalse; |
|
498 |
|
499 if (aPduDb == NULL) |
|
500 { |
|
501 aPduDb = CSmsPduDatabase::NewL(iFs); |
|
502 CleanupStack::PushL(aPduDb); |
|
503 createdDb = ETrue; |
|
504 } |
|
505 |
|
506 aPduDb->RewriteFileL(aFromSmsConfigFile, KGmsSmsConfigFileDir, KSimTsyConfigFileName); |
|
507 PRINTF1(_L("done")); |
|
508 |
|
509 if (createdDb) |
|
510 CleanupStack::PopAndDestroy(aPduDb); |
|
511 } |
|
512 |
|
513 |
|
514 EXPORT_C CSmsMessage* CSmsStackTestUtils::CreateSmsMessageLC(CSmsPDU::TSmsPDUType aType, const TDesC& aDestination, const TDesC& aMessage) |
|
515 { |
|
516 CSmsBuffer* buffer = CSmsBuffer::NewL(); |
|
517 buffer->InsertL(0, aMessage); |
|
518 |
|
519 CSmsMessage* message = CSmsMessage::NewL(iFs, aType, buffer); |
|
520 CleanupStack::PushL(message); |
|
521 |
|
522 message->SetToFromAddressL(aDestination); |
|
523 |
|
524 return message; |
|
525 } |
|
526 |
|
527 EXPORT_C void CSmsStackTestUtils::AddSmsRxL(CTestConfig& aConfigFile, TInt aTestNumber, CSmsMessage& aMessage, const TDesC& aServiceCenter) const |
|
528 { |
|
529 _LIT8(KSmspTestUtilsSmsRx, "SmsRx"); |
|
530 _LIT8(KSmspTestUtilsSmsRxFormat, "%S, %S"); |
|
531 |
|
532 CTestConfigSection& section = GetSectionL(aConfigFile, aTestNumber); |
|
533 |
|
534 CArrayFixFlat<TGsmSms>* pdus = EncodeMessageLC(aMessage); |
|
535 |
|
536 const TInt pduCount = pdus->Count(); |
|
537 |
|
538 for (TInt i = 0; i < pduCount; i++) |
|
539 { |
|
540 const TGsmSms& pdu = (*pdus)[i]; |
|
541 |
|
542 HBufC8* pduBuf = ConvertToHexLC(pdu.Pdu()); |
|
543 |
|
544 HBufC8* sc = HBufC8::NewLC(aServiceCenter.Length()); |
|
545 sc->Des().Copy(aServiceCenter); |
|
546 |
|
547 const TInt maxLen = KSmspTestUtilsSmsRxFormat().Length() + pduBuf->Length() + sc->Length(); |
|
548 HBufC8* smsRx = HBufC8::NewLC(maxLen); |
|
549 |
|
550 smsRx->Des().AppendFormat(KSmspTestUtilsSmsRxFormat, pduBuf, sc); |
|
551 |
|
552 CTestConfigItem* item = CTestConfigItem::NewLC(section, KSmspTestUtilsSmsRx, *smsRx); |
|
553 |
|
554 User::LeaveIfError(section.Items().Append(item)); |
|
555 |
|
556 CleanupStack::Pop(item); |
|
557 CleanupStack::PopAndDestroy(smsRx); |
|
558 CleanupStack::PopAndDestroy(sc); |
|
559 CleanupStack::PopAndDestroy(pduBuf); |
|
560 } |
|
561 |
|
562 CleanupStack::PopAndDestroy(pdus); |
|
563 } |
|
564 |
|
565 EXPORT_C CTestConfigSection& CSmsStackTestUtils::GetSectionL(CTestConfig& aConfigFile, TInt aTestNumber) const |
|
566 { |
|
567 _LIT8(KSmspTestUtilsTest, "test%d"); |
|
568 |
|
569 TBuf8<16> test; |
|
570 test.AppendFormat(KSmspTestUtilsTest, aTestNumber); |
|
571 CTestConfigSection* section = aConfigFile.Section(test); |
|
572 |
|
573 if (section == NULL) |
|
574 { |
|
575 User::Leave(KErrNotFound); |
|
576 } |
|
577 |
|
578 return *section; |
|
579 } |
|
580 |
|
581 EXPORT_C void CSmsStackTestUtils::AddSmsTxL(CTestConfig& aConfigFile, TInt aTestNumber, CSmsMessage& aMessage, const TDesC& aServiceCenter, TInt aMsgRef, CSmsMessage* aSubmitReport, TInt aExpectedError) const |
|
582 { |
|
583 _LIT8(KSmspTestUtilsSmsTx, "SmsTx"); |
|
584 _LIT8(KSmspTestUtilsSmsTxFormat, "%S, %S, %d, %S, %d"); |
|
585 |
|
586 CTestConfigSection& section = GetSectionL(aConfigFile, aTestNumber); |
|
587 CArrayFixFlat<TGsmSms>* pdus = EncodeMessageLC(aMessage); |
|
588 |
|
589 HBufC8* submitReport = NULL; |
|
590 |
|
591 if (aSubmitReport == NULL) |
|
592 { |
|
593 submitReport = KNullDesC8().AllocLC(); |
|
594 } |
|
595 else |
|
596 { |
|
597 CArrayFixFlat<TGsmSms>* srPdus = EncodeMessageLC(*aSubmitReport); |
|
598 const TGsmSms& pdu = (*srPdus)[0]; |
|
599 submitReport = ConvertToHexLC(pdu.Pdu()); |
|
600 CleanupStack::Pop(submitReport); |
|
601 CleanupStack::PopAndDestroy(srPdus); |
|
602 CleanupStack::PushL(submitReport); |
|
603 } |
|
604 |
|
605 const TInt pduCount = pdus->Count(); |
|
606 |
|
607 for (TInt i = 0; i < pduCount; i++) |
|
608 { |
|
609 const TGsmSms& pdu = (*pdus)[i]; |
|
610 HBufC8* pduBuf = ConvertToHexLC(pdu.Pdu()); |
|
611 |
|
612 HBufC8* sc = HBufC8::NewLC(aServiceCenter.Length()); |
|
613 sc->Des().Copy(aServiceCenter); |
|
614 |
|
615 const TInt maxLen = KSmspTestUtilsSmsTxFormat().Length() + pduBuf->Length() + sc->Length() + submitReport->Length(); |
|
616 HBufC8* smsTx = HBufC8::NewLC(maxLen); |
|
617 |
|
618 smsTx->Des().AppendFormat(KSmspTestUtilsSmsTxFormat, pduBuf, sc, aMsgRef, submitReport, aExpectedError); |
|
619 |
|
620 CTestConfigItem* item = CTestConfigItem::NewLC(section, KSmspTestUtilsSmsTx, *smsTx); |
|
621 |
|
622 User::LeaveIfError(section.Items().Append(item)); |
|
623 |
|
624 CleanupStack::Pop(item); |
|
625 CleanupStack::PopAndDestroy(smsTx); |
|
626 CleanupStack::PopAndDestroy(sc); |
|
627 CleanupStack::PopAndDestroy(pduBuf); |
|
628 } |
|
629 |
|
630 CleanupStack::PopAndDestroy(submitReport); |
|
631 CleanupStack::PopAndDestroy(pdus); |
|
632 } |
|
633 |
|
634 EXPORT_C HBufC8* CSmsStackTestUtils::ConvertToHexLC(const TDesC8& aDes) const |
|
635 { |
|
636 const TInt len = aDes.Length(); |
|
637 |
|
638 HBufC8* hBuf = HBufC8::NewLC(len*2); |
|
639 TPtr8 value(hBuf->Des()); |
|
640 |
|
641 for (TInt i = 0; i < len; i++) |
|
642 { |
|
643 value.AppendFormat(_L8("%02X"), aDes[i]); |
|
644 } |
|
645 |
|
646 return hBuf; |
|
647 } |
|
648 |
|
649 CArrayFixFlat<TGsmSms>* CSmsStackTestUtils::EncodeMessageLC(CSmsMessage& aMessage) const |
|
650 { |
|
651 CArrayFixFlat<TGsmSms>* array = new (ELeave) CArrayFixFlat<TGsmSms>(1); |
|
652 CleanupStack::PushL(array); |
|
653 aMessage.EncodeMessagePDUsL(*array); |
|
654 return array; |
|
655 } |
|
656 |
|
657 EXPORT_C TSmsFirstOctet CSmsStackTestUtils::FirstDeliverOctet(TBool aMMS, TBool aRP, TBool aUDHI, TBool aSRI) |
|
658 { |
|
659 TSmsFirstOctet firstOctet(0); |
|
660 |
|
661 if (!aMMS) |
|
662 firstOctet = firstOctet | TSmsFirstOctet::ESmsNoMoreMessagesToSend; |
|
663 |
|
664 if (aRP) |
|
665 firstOctet = firstOctet | TSmsFirstOctet::ESmsReplyPathExists; |
|
666 |
|
667 if (aUDHI) |
|
668 firstOctet = firstOctet | TSmsFirstOctet::ESmsUDHIHeaderPresent; |
|
669 |
|
670 if (aSRI) |
|
671 firstOctet = firstOctet | TSmsFirstOctet::ESmsStatusReportRequested; |
|
672 |
|
673 return firstOctet; |
|
674 } |
|
675 |
|
676 EXPORT_C void CSmsStackTestUtils::DeliverWithoutUserDataL(TGsmSms& aPdu, TSmsFirstOctet aFO, const TGsmSmsTelNumber& aOA, TSmsProtocolIdentifier aPID, TSmsDataCodingScheme aDCS, const TTime& aSCTS, TInt aUTCOffset) |
|
677 { |
|
678 RMobileSmsMessaging::TMobileSmsGsmTpdu pdu; |
|
679 pdu.SetLength(pdu.MaxLength()); |
|
680 TUint8* ptr0 = &pdu[0]; |
|
681 TUint8* ptr1 = ptr0; |
|
682 |
|
683 //Prepare the OA |
|
684 CSmsAddress* addr = CSmsAddress::NewL(*iCharConv, iFs); |
|
685 CleanupStack::PushL(addr); |
|
686 addr->SetParsedAddressL(aOA); |
|
687 |
|
688 //Prepare the service center time stamp |
|
689 TSmsServiceCenterTimeStamp time; |
|
690 time.SetTime(aSCTS); |
|
691 time.SetTimeOffset(aUTCOffset); |
|
692 |
|
693 //Encode the PDU. Unfortunately this relies on GSMU. |
|
694 ptr1 = aFO.EncodeL(ptr1); |
|
695 ptr1 = addr->EncodeL(ptr1); |
|
696 ptr1 = aPID.EncodeL(ptr1); |
|
697 ptr1 = aDCS.EncodeL(ptr1); |
|
698 ptr1 = time.EncodeL(ptr1); |
|
699 pdu.SetLength(ptr1 - ptr0); |
|
700 aPdu.SetPdu(pdu); |
|
701 |
|
702 CleanupStack::PopAndDestroy(addr); |
|
703 } |
|
704 |
|
705 |
|
706 /** |
|
707 * This is a unit test for class TSmsServiceCenterTimeStamp. It is added to this utility |
|
708 * class because it has access to TSmsServiceCenterTimeStamp. TSmsServiceCenterTimeStamp is not exported |
|
709 * out of the gsmsu.dll. This is why this project compiles with gsmsuelem.cpp. |
|
710 */ |
|
711 EXPORT_C void CSmsStackTestUtils::CreateTSmsServiceCenterTimeStampL() |
|
712 { |
|
713 //Prepare the service center time stamp |
|
714 TSmsServiceCenterTimeStamp serviceCenterTime; |
|
715 TTime utcTime; |
|
716 TInt offset=0; |
|
717 utcTime.UniversalTime(); |
|
718 |
|
719 // Set and Get |
|
720 serviceCenterTime.SetTime(utcTime); |
|
721 serviceCenterTime.SetTimeOffset(offset); |
|
722 |
|
723 TTime testTimeValue=serviceCenterTime.Time(); |
|
724 TInt testOffsetValue=serviceCenterTime.TimeOffset(); |
|
725 |
|
726 LOCAL_CHECKPOINT(testTimeValue==utcTime); |
|
727 LOCAL_CHECKPOINT(testOffsetValue==offset); |
|
728 |
|
729 //boundary value checks |
|
730 //Offset is stored in number of quarter hours. |
|
731 //Max/Min value = +/- 79 |
|
732 //This is the maximum value specified in the spec 3GPP TS23.040 |
|
733 //The biggest value allowed by the production code is KSmsMaxTimeZoneNumQuarterHours=79 |
|
734 //This is the maximum value that can be stored in the PDU when encoded. Actual max byte |
|
735 //storage space available. The test will check that this maximum will be allowable. |
|
736 //Values beyond 79 will cause the thread to panic |
|
737 TInt positiveValue=79; |
|
738 TInt negativeValue=-79; |
|
739 |
|
740 serviceCenterTime.SetTimeOffset(positiveValue); |
|
741 testOffsetValue=serviceCenterTime.TimeOffset(); |
|
742 LOCAL_CHECKPOINT(testOffsetValue==positiveValue); |
|
743 |
|
744 serviceCenterTime.SetTimeOffset(negativeValue); |
|
745 testOffsetValue=serviceCenterTime.TimeOffset(); |
|
746 LOCAL_CHECKPOINT(testOffsetValue==negativeValue); |
|
747 |
|
748 //Try past the end. This panics the test case. It has been done as a check to test |
|
749 // a panic will be raised. |
|
750 /* TInt overFlowValue=80; |
|
751 serviceCenterTime.SetTimeOffset(overFlowValue); |
|
752 |
|
753 TInt underFlowValue=-99; |
|
754 serviceCenterTime.SetTimeOffset(underFlowValue); |
|
755 */ |
|
756 } |
|
757 |
|
758 EXPORT_C void CSmsStackTestUtils::DecodeTSmsServiceCenterTimeStampL() |
|
759 { |
|
760 //Decode timestamp |
|
761 TTimeIntervalSeconds oneSecond(1); |
|
762 const TInt KTimeStampSize=7; |
|
763 TInt ret=0; |
|
764 TBuf8<KTimeStampSize> encodedPdu; |
|
765 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
766 |
|
767 //--------------------------------------------------- |
|
768 //Decode a valid service center time stamp |
|
769 //Expected UTC = 29/02/2004, 15h30m0s, offset=3hrs |
|
770 //Local Time = 29/02/2004, 18h30m0s |
|
771 TDateTime utcDateTime(2004,EFebruary,28,15,30,0,0); |
|
772 TTime expectedDecodedTime(utcDateTime); |
|
773 |
|
774 encodedPdu[0]=0x40; //year=2004 |
|
775 encodedPdu[1]=0x20; //month=Feb |
|
776 encodedPdu[2]=0x92; //day=29th |
|
777 encodedPdu[3]=0x81; //hour=18h |
|
778 encodedPdu[4]=0x03; //minute=30min |
|
779 encodedPdu[5]=0x00; //second=0 |
|
780 encodedPdu[6]=0x21; //timeZone=12x15min=3hrs |
|
781 |
|
782 //Decode the service center time stamp. This must equal the expected |
|
783 TGsmuLex8 pduTime(encodedPdu); |
|
784 TSmsServiceCenterTimeStamp serviceCenterTimeStamp; |
|
785 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
786 LOCAL_CHECKPOINT(ret==KErrNone); |
|
787 |
|
788 //Compare the times |
|
789 TTime time=serviceCenterTimeStamp.Time(); |
|
790 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
791 |
|
792 //Check the offset |
|
793 TInt offset=serviceCenterTimeStamp.TimeOffset(); |
|
794 LOCAL_CHECKPOINT(offset==12); |
|
795 |
|
796 //--------------------------------------------------- |
|
797 //Decode a negative offset |
|
798 //Expected UTC = 29/02/2004, 15h30m0s, offset=-5hrs |
|
799 //Local Time = 29/02/2004, 10h30m0s |
|
800 |
|
801 encodedPdu[0]=0x40; //year=2004 |
|
802 encodedPdu[1]=0x20; //month=Feb |
|
803 encodedPdu[2]=0x92; //day=29 |
|
804 encodedPdu[3]=0x01; //hour=10 |
|
805 encodedPdu[4]=0x03; //minute=30 |
|
806 encodedPdu[5]=0x00; //second |
|
807 encodedPdu[6]=0x0A; //timeZone=-5hrs=15minx20, 4th bit is 1 for negative |
|
808 |
|
809 |
|
810 //Decode the service center time stamp. This must equal the expected |
|
811 pduTime=TGsmuLex8(encodedPdu); |
|
812 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
813 LOCAL_CHECKPOINT(ret==KErrNone); |
|
814 |
|
815 //Compare the times |
|
816 time=serviceCenterTimeStamp.Time(); |
|
817 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
818 |
|
819 //Check the offset |
|
820 offset=serviceCenterTimeStamp.TimeOffset(); |
|
821 LOCAL_CHECKPOINT(offset==-20); |
|
822 |
|
823 //--------------------------------------------------- |
|
824 //Decode time stamp over new year |
|
825 // |
|
826 //Expected UTC = 01/01/2005, 00h15m0s, offset=-1h15m |
|
827 //Local Time = 31/12/2004, 23h00m0s |
|
828 utcDateTime=TDateTime(2005,EJanuary,0,0,15,0,0); |
|
829 expectedDecodedTime=TTime(utcDateTime); |
|
830 |
|
831 encodedPdu[0]=0x40; //year=2004 |
|
832 encodedPdu[1]=0x21; //month=December=12 |
|
833 encodedPdu[2]=0x13; //day=31 |
|
834 encodedPdu[3]=0x32; //hour=23hrs |
|
835 encodedPdu[4]=0x00; //minute=0 |
|
836 encodedPdu[5]=0x00; //second=0 |
|
837 encodedPdu[6]=0x58; //timeZone is -5. |
|
838 // -5x15min=-1hr15min |
|
839 |
|
840 //Decode the service center time stamp. This must equal the expected |
|
841 pduTime=TGsmuLex8(encodedPdu); |
|
842 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
843 LOCAL_CHECKPOINT(ret==KErrNone); |
|
844 |
|
845 //Compare the times |
|
846 time=serviceCenterTimeStamp.Time(); |
|
847 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
848 |
|
849 //Check the offset |
|
850 offset=serviceCenterTimeStamp.TimeOffset(); |
|
851 LOCAL_CHECKPOINT(offset==-5); |
|
852 |
|
853 //--------------------------------------------------- |
|
854 //Decode over leap year |
|
855 |
|
856 //Expected UTC = 29/02/2004, 21h00m0s, offset=+5h 30min 0s |
|
857 //Local Time = 01/03/2004, 02h30m0s |
|
858 utcDateTime=TDateTime(2004,EFebruary,28,21,0,0,0); |
|
859 expectedDecodedTime=TTime(utcDateTime); |
|
860 |
|
861 // local time is 01/03/2004 2hrs 30 |
|
862 encodedPdu[0]=0x40; //year=2004 |
|
863 encodedPdu[1]=0x30; //month=March |
|
864 encodedPdu[2]=0x10; //day=1st |
|
865 encodedPdu[3]=0x20; //hour=2hrs |
|
866 encodedPdu[4]=0x03; //minute=30min |
|
867 encodedPdu[5]=0x00; //second=0 |
|
868 encodedPdu[6]=0x22; //timeZone is 5hrs30min. |
|
869 // 22x15min=5hr30min |
|
870 |
|
871 pduTime=TGsmuLex8(encodedPdu); |
|
872 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
873 LOCAL_CHECKPOINT(ret==KErrNone); |
|
874 |
|
875 //Compare the times |
|
876 time=serviceCenterTimeStamp.Time(); |
|
877 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
878 |
|
879 //Check the offset |
|
880 offset=serviceCenterTimeStamp.TimeOffset(); |
|
881 LOCAL_CHECKPOINT(offset==22); |
|
882 |
|
883 //--------------------------------------------------- |
|
884 //DecodeL a corrupt time stamp |
|
885 encodedPdu[0]=0x40; //year |
|
886 encodedPdu[1]=0x02; //month = 20 |
|
887 encodedPdu[2]=0x96; //day = 69 |
|
888 encodedPdu[3]=0x51; //hour |
|
889 encodedPdu[4]=0x03; //minute |
|
890 encodedPdu[5]=0; //second |
|
891 encodedPdu[6]=0x20; //timezone=12 |
|
892 |
|
893 //Decode should fail trying to recreate the time. |
|
894 pduTime=TGsmuLex8(encodedPdu); |
|
895 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
896 LOCAL_CHECKPOINT(ret==KErrGeneral); |
|
897 |
|
898 //--------------------------------------------------- |
|
899 //DecodeL a zero offset |
|
900 |
|
901 //Expected UTC = 15/06/2004, 14h20, offset = 0 |
|
902 //Local Time = 15/06/2004, 14h20 |
|
903 utcDateTime=TDateTime(2004,EJune,14,14,20,0,0); |
|
904 expectedDecodedTime=TTime(utcDateTime); |
|
905 |
|
906 encodedPdu[0]=0x40; //year=2004 |
|
907 encodedPdu[1]=0x60; //month=06 |
|
908 encodedPdu[2]=0x51; //day=15 |
|
909 encodedPdu[3]=0x41; //hour=14 |
|
910 encodedPdu[4]=0x02; //minute=20 |
|
911 encodedPdu[5]=0x00; //second=0 |
|
912 encodedPdu[6]=0x00; //timezone=0 |
|
913 |
|
914 //Decode should bring back the same date. ie. local time==utc time |
|
915 pduTime=TGsmuLex8(encodedPdu); |
|
916 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
917 LOCAL_CHECKPOINT(ret==KErrNone); |
|
918 |
|
919 //Compare the times |
|
920 time=serviceCenterTimeStamp.Time(); |
|
921 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
922 |
|
923 //Check the offset |
|
924 offset=serviceCenterTimeStamp.TimeOffset(); |
|
925 LOCAL_CHECKPOINT(offset==0); |
|
926 |
|
927 //--------------------------------------------------- |
|
928 //DecodeL a maximum possitive offset |
|
929 |
|
930 //Expected UTC = 15/06/2004, 01h20, offset = 19h45min |
|
931 //Local Time = 15/06/2004, 21h05 |
|
932 utcDateTime=TDateTime(2004,EJune,14,01,20,0,0); |
|
933 expectedDecodedTime=TTime(utcDateTime); |
|
934 |
|
935 encodedPdu[0]=0x40; //year=2004 |
|
936 encodedPdu[1]=0x60; //month=06 |
|
937 encodedPdu[2]=0x51; //day=15 |
|
938 encodedPdu[3]=0x12; //hour=21 |
|
939 encodedPdu[4]=0x50; //minute=05 |
|
940 encodedPdu[5]=0x00; //second=0 |
|
941 encodedPdu[6]=0x97; //timezone=79x15min=19h45 |
|
942 //offset = 1185 minutes = 19h45min |
|
943 |
|
944 //Decode should bring back the same date. ie. local time==utc time |
|
945 pduTime=TGsmuLex8(encodedPdu); |
|
946 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
947 LOCAL_CHECKPOINT(ret==KErrNone); |
|
948 |
|
949 //Compare the times |
|
950 time=serviceCenterTimeStamp.Time(); |
|
951 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
952 |
|
953 //Check the offset |
|
954 offset=serviceCenterTimeStamp.TimeOffset(); |
|
955 LOCAL_CHECKPOINT(offset==79); |
|
956 |
|
957 //--------------------------------------------------- |
|
958 //DecodeL a maximum negative offset |
|
959 |
|
960 //Expected UTC = 15/06/2004, 23h45, offset = -19h45min |
|
961 //Local Time = 15/06/2004, 04h00 |
|
962 utcDateTime=TDateTime(2004,EJune,14,23,45,0,0); |
|
963 expectedDecodedTime=TTime(utcDateTime); |
|
964 |
|
965 encodedPdu[0]=0x40; //year=2004 |
|
966 encodedPdu[1]=0x60; //month=06 |
|
967 encodedPdu[2]=0x51; //day=15 |
|
968 encodedPdu[3]=0x40; //hour=4 |
|
969 encodedPdu[4]=0x00; //minute=0 |
|
970 encodedPdu[5]=0x00; //second=0 |
|
971 encodedPdu[6]=0x9F; //timezone=-79x15min=-19h45 |
|
972 //offset = -1185 minutes = 19h45min |
|
973 |
|
974 //Decode should bring back the same date. ie. local time==utc time |
|
975 pduTime=TGsmuLex8(encodedPdu); |
|
976 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
977 LOCAL_CHECKPOINT(ret==KErrNone); |
|
978 |
|
979 //Compare the times |
|
980 time=serviceCenterTimeStamp.Time(); |
|
981 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
982 |
|
983 //Check the offset |
|
984 offset=serviceCenterTimeStamp.TimeOffset(); |
|
985 LOCAL_CHECKPOINT(offset==-79); |
|
986 |
|
987 //--------------------------------------------------- |
|
988 //DecodeL a timestamp with an invalid offset 0xFF. |
|
989 |
|
990 //Expected UTC = 15/06/2004, 14h20, offset = 0 |
|
991 //Local Time = 15/06/2004, 14h20 |
|
992 utcDateTime=TDateTime(2004,EJune,14,14,20,0,0); |
|
993 expectedDecodedTime=TTime(utcDateTime); |
|
994 |
|
995 encodedPdu[0]=0x40; //year=2004 |
|
996 encodedPdu[1]=0x60; //month=06 |
|
997 encodedPdu[2]=0x51; //day=15 |
|
998 encodedPdu[3]=0x41; //hour=14 |
|
999 encodedPdu[4]=0x02; //minute=20 |
|
1000 encodedPdu[5]=0x00; //second=0 |
|
1001 encodedPdu[6]=0xFF; //timezone off set is invalid, so set to zero |
|
1002 |
|
1003 //Decode should bring back the same date. ie. local time==utc time |
|
1004 pduTime=TGsmuLex8(encodedPdu); |
|
1005 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
1006 LOCAL_CHECKPOINT(ret==KErrNone); |
|
1007 |
|
1008 //Compare the times |
|
1009 time=serviceCenterTimeStamp.Time(); |
|
1010 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
1011 |
|
1012 //Check the offset |
|
1013 offset=serviceCenterTimeStamp.TimeOffset(); |
|
1014 LOCAL_CHECKPOINT(offset==0); |
|
1015 |
|
1016 //--------------------------------------------------- |
|
1017 //DecodeL a timestamp with an invalid offset 0xAF |
|
1018 |
|
1019 //Expected UTC = 15/06/2004, 14h20, offset = 0 |
|
1020 //Local Time = 15/06/2004, 14h20 |
|
1021 utcDateTime=TDateTime(2004,EJune,14,14,20,0,0); |
|
1022 expectedDecodedTime=TTime(utcDateTime); |
|
1023 |
|
1024 encodedPdu[0]=0x40; //year=2004 |
|
1025 encodedPdu[1]=0x60; //month=06 |
|
1026 encodedPdu[2]=0x51; //day=15 |
|
1027 encodedPdu[3]=0x41; //hour=14 |
|
1028 encodedPdu[4]=0x02; //minute=20 |
|
1029 encodedPdu[5]=0x00; //second=0 |
|
1030 encodedPdu[6]=0xAF; //timezone off set is invalid, so set to zero |
|
1031 |
|
1032 //Decode should bring back the same date. ie. local time==utc time |
|
1033 pduTime=TGsmuLex8(encodedPdu); |
|
1034 serviceCenterTimeStamp.DecodeL(pduTime,ret); |
|
1035 LOCAL_CHECKPOINT(ret==KErrNone); |
|
1036 |
|
1037 //Compare the times |
|
1038 time=serviceCenterTimeStamp.Time(); |
|
1039 LOCAL_CHECKPOINT(time==expectedDecodedTime); |
|
1040 |
|
1041 //Check the offset |
|
1042 offset=serviceCenterTimeStamp.TimeOffset(); |
|
1043 LOCAL_CHECKPOINT(offset==0); |
|
1044 } |
|
1045 |
|
1046 |
|
1047 EXPORT_C void CSmsStackTestUtils::EncodeTSmsServiceCenterTimeStampL() |
|
1048 { |
|
1049 //Encode timestamp |
|
1050 const TInt KServiceCenterBuffSizeInPDU=7; //Buffer is a 14 semi-octet buffer, 7 byte |
|
1051 TBuf8<KServiceCenterBuffSizeInPDU> encodedPdu; |
|
1052 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
1053 TUint8* ptr = &encodedPdu[0]; |
|
1054 |
|
1055 //--------------------------------------------------- |
|
1056 //Expected UTC = 03/03/2005, 12h00, offset = 3hrs |
|
1057 //Local Time = 03/03/2005, 15h00 |
|
1058 TMonth month=EMarch; |
|
1059 TDateTime utcDateTime(2005,month,2,12,0,0,0); |
|
1060 TTime expectedDecodedTime(utcDateTime); |
|
1061 |
|
1062 //Prepare the service center time stamp |
|
1063 TSmsServiceCenterTimeStamp time; |
|
1064 time.SetTime(expectedDecodedTime); |
|
1065 |
|
1066 //Set offset=+12, +3hrs |
|
1067 time.SetTimeOffset(12); |
|
1068 |
|
1069 //Encode the PDU. |
|
1070 time.EncodeL(ptr); |
|
1071 |
|
1072 // This is the expected structure in bytes for the time above |
|
1073 TUint8 semioctet = encodedPdu[0]; //2005 |
|
1074 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1075 semioctet = encodedPdu[1]; //March |
|
1076 LOCAL_CHECKPOINT(semioctet==0x30); |
|
1077 semioctet = encodedPdu[2]; //3rd |
|
1078 LOCAL_CHECKPOINT(semioctet==0x30); |
|
1079 semioctet = encodedPdu[3]; //15h |
|
1080 LOCAL_CHECKPOINT(semioctet==0x51); |
|
1081 semioctet = encodedPdu[4]; //min |
|
1082 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1083 semioctet = encodedPdu[5]; //sec |
|
1084 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1085 semioctet = encodedPdu[6]; //offset |
|
1086 LOCAL_CHECKPOINT(semioctet==0x21); |
|
1087 |
|
1088 |
|
1089 //--------------------------------------------------- |
|
1090 //Expected UTC = 01/03/2005, 01h00, offset = -3hrs |
|
1091 //Local Time = 28/02/2005, 22h00 |
|
1092 encodedPdu.Delete(0,encodedPdu.MaxLength()); |
|
1093 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
1094 ptr = &encodedPdu[0]; |
|
1095 |
|
1096 utcDateTime=TDateTime(2005,month,0,1,0,0,0); |
|
1097 expectedDecodedTime=TTime(utcDateTime); |
|
1098 |
|
1099 //Prepare the service center time stamp |
|
1100 time.SetTime(expectedDecodedTime); |
|
1101 |
|
1102 //Set offset=-12, -3hrs |
|
1103 time.SetTimeOffset(-12); |
|
1104 |
|
1105 //Encode the PDU. |
|
1106 time.EncodeL(ptr); |
|
1107 |
|
1108 // This is the expected structure in bytes for the time above |
|
1109 semioctet = encodedPdu[0]; //2005 |
|
1110 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1111 semioctet = encodedPdu[1]; //Feb |
|
1112 LOCAL_CHECKPOINT(semioctet==0x20); |
|
1113 semioctet = encodedPdu[2]; //28th |
|
1114 LOCAL_CHECKPOINT(semioctet==0x82); |
|
1115 semioctet = encodedPdu[3]; //22h |
|
1116 LOCAL_CHECKPOINT(semioctet==0x22); |
|
1117 semioctet = encodedPdu[4]; //min |
|
1118 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1119 semioctet = encodedPdu[5]; //sec |
|
1120 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1121 semioctet = encodedPdu[6]; //offset |
|
1122 LOCAL_CHECKPOINT(semioctet==0x29); |
|
1123 |
|
1124 |
|
1125 //--------------------------------------------------- |
|
1126 //Expected UTC = 31/12/2005, 23h45min55s, offset = +3h15min |
|
1127 //Local Time = 01/01/2006, 03h00min55s |
|
1128 encodedPdu.Delete(0,encodedPdu.MaxLength()); |
|
1129 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
1130 ptr = &encodedPdu[0]; |
|
1131 month=EDecember; |
|
1132 utcDateTime=TDateTime(2005,month,30,23,45,55,0); |
|
1133 expectedDecodedTime=TTime(utcDateTime); |
|
1134 |
|
1135 //Prepare the service center time stamp |
|
1136 time.SetTime(expectedDecodedTime); |
|
1137 |
|
1138 //Set offset=13, 3hrs15min |
|
1139 time.SetTimeOffset(13); |
|
1140 |
|
1141 //Encode the PDU. |
|
1142 time.EncodeL(ptr); |
|
1143 |
|
1144 // This is the expected structure in bytes for the time above |
|
1145 semioctet = encodedPdu[0]; //2006 |
|
1146 LOCAL_CHECKPOINT(semioctet==0x60); |
|
1147 semioctet = encodedPdu[1]; //Jan |
|
1148 LOCAL_CHECKPOINT(semioctet==0x10); |
|
1149 semioctet = encodedPdu[2]; //1st |
|
1150 LOCAL_CHECKPOINT(semioctet==0x10); |
|
1151 semioctet = encodedPdu[3]; //3h |
|
1152 LOCAL_CHECKPOINT(semioctet==0x30); |
|
1153 semioctet = encodedPdu[4]; //00min |
|
1154 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1155 semioctet = encodedPdu[5]; //55sec |
|
1156 LOCAL_CHECKPOINT(semioctet==0x55); |
|
1157 semioctet = encodedPdu[6]; //offset = 13 x 15min bocks |
|
1158 LOCAL_CHECKPOINT(semioctet==0x31); |
|
1159 |
|
1160 //--------------------------------------------------- |
|
1161 //Check zero offset |
|
1162 |
|
1163 //Expected UTC = 12/07/2005, 01h00, offset = 0hrs |
|
1164 //Local Time = 12/07/2005, 01h00 |
|
1165 encodedPdu.Delete(0,encodedPdu.MaxLength()); |
|
1166 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
1167 ptr = &encodedPdu[0]; |
|
1168 |
|
1169 month=EJuly; |
|
1170 utcDateTime=TDateTime(2005,month,11,1,0,0,0); |
|
1171 expectedDecodedTime=TTime(utcDateTime); |
|
1172 |
|
1173 //Prepare the service center time stamp |
|
1174 time.SetTime(expectedDecodedTime); |
|
1175 |
|
1176 //Set offset=0 |
|
1177 time.SetTimeOffset(0); |
|
1178 |
|
1179 //Encode the PDU. |
|
1180 time.EncodeL(ptr); |
|
1181 |
|
1182 // This is the expected structure in bytes for the time above |
|
1183 semioctet = encodedPdu[0]; //2005 |
|
1184 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1185 semioctet = encodedPdu[1]; //July |
|
1186 LOCAL_CHECKPOINT(semioctet==0x70); |
|
1187 semioctet = encodedPdu[2]; //12th |
|
1188 LOCAL_CHECKPOINT(semioctet==0x21); |
|
1189 semioctet = encodedPdu[3]; //01h |
|
1190 LOCAL_CHECKPOINT(semioctet==0x10); |
|
1191 semioctet = encodedPdu[4]; //min |
|
1192 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1193 semioctet = encodedPdu[5]; //sec |
|
1194 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1195 semioctet = encodedPdu[6]; //offset |
|
1196 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1197 |
|
1198 //--------------------------------------------------- |
|
1199 //Check boundary value, maximum positive |
|
1200 |
|
1201 //Expected UTC = 12/07/2005, 01h00, offset = 19h45min |
|
1202 //Local Time = 12/07/2005, 20h45 |
|
1203 encodedPdu.Delete(0,encodedPdu.MaxLength()); |
|
1204 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
1205 ptr = &encodedPdu[0]; |
|
1206 |
|
1207 month=EJuly; |
|
1208 utcDateTime=TDateTime(2005,month,11,1,0,0,0); |
|
1209 expectedDecodedTime=TTime(utcDateTime); |
|
1210 |
|
1211 //Prepare the service center time stamp |
|
1212 time.SetTime(expectedDecodedTime); |
|
1213 |
|
1214 //Set offset=0 |
|
1215 time.SetTimeOffset(79); |
|
1216 |
|
1217 //Encode the PDU. |
|
1218 time.EncodeL(ptr); |
|
1219 |
|
1220 // This is the expected structure in bytes for the time above |
|
1221 semioctet = encodedPdu[0]; //2005 |
|
1222 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1223 semioctet = encodedPdu[1]; //July |
|
1224 LOCAL_CHECKPOINT(semioctet==0x70); |
|
1225 semioctet = encodedPdu[2]; //12th |
|
1226 LOCAL_CHECKPOINT(semioctet==0x21); |
|
1227 semioctet = encodedPdu[3]; //20h |
|
1228 LOCAL_CHECKPOINT(semioctet==0x02); |
|
1229 semioctet = encodedPdu[4]; //45min |
|
1230 LOCAL_CHECKPOINT(semioctet==0x54); |
|
1231 semioctet = encodedPdu[5]; //sec |
|
1232 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1233 semioctet = encodedPdu[6]; //offset |
|
1234 LOCAL_CHECKPOINT(semioctet==0x97); |
|
1235 |
|
1236 |
|
1237 //--------------------------------------------------- |
|
1238 //Check boundary value, maximum positive |
|
1239 |
|
1240 //Expected UTC = 12/07/2005, 01h00, offset = -19h45min |
|
1241 //Local Time = 11/07/2005, 05h15 |
|
1242 encodedPdu.Delete(0,encodedPdu.MaxLength()); |
|
1243 encodedPdu.SetLength(encodedPdu.MaxLength()); |
|
1244 ptr = &encodedPdu[0]; |
|
1245 |
|
1246 month=EJuly; |
|
1247 utcDateTime=TDateTime(2005,month,11,1,0,0,0); |
|
1248 expectedDecodedTime=TTime(utcDateTime); |
|
1249 |
|
1250 //Prepare the service center time stamp |
|
1251 time.SetTime(expectedDecodedTime); |
|
1252 |
|
1253 //Set offset=0 |
|
1254 time.SetTimeOffset(-79); |
|
1255 |
|
1256 //Encode the PDU. |
|
1257 time.EncodeL(ptr); |
|
1258 |
|
1259 // This is the expected structure in bytes for the time above |
|
1260 semioctet = encodedPdu[0]; //2005 |
|
1261 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1262 semioctet = encodedPdu[1]; //July |
|
1263 LOCAL_CHECKPOINT(semioctet==0x70); |
|
1264 semioctet = encodedPdu[2]; //11th |
|
1265 LOCAL_CHECKPOINT(semioctet==0x11); |
|
1266 semioctet = encodedPdu[3]; //05h |
|
1267 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1268 semioctet = encodedPdu[4]; //15min |
|
1269 LOCAL_CHECKPOINT(semioctet==0x51); |
|
1270 semioctet = encodedPdu[5]; //sec |
|
1271 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1272 semioctet = encodedPdu[6]; //offset |
|
1273 LOCAL_CHECKPOINT(semioctet==0x9F); |
|
1274 } |
|
1275 |
|
1276 /** |
|
1277 * This is a unit test for class TSmsValidityPeriod. |
|
1278 * TSmsValidityPeriod is not exported out of the gsmsu.dll. |
|
1279 * We build gsmuelem.cpp to get access. |
|
1280 */ |
|
1281 EXPORT_C void CSmsStackTestUtils::CreateTSmsValidityPeriodL() |
|
1282 { |
|
1283 //Get the current UTC offset |
|
1284 TTime currUTCTime; |
|
1285 currUTCTime.UniversalTime(); |
|
1286 TTimeIntervalSeconds currUTCOffset=User::UTCOffset(); |
|
1287 |
|
1288 //--------------------------------------------------- |
|
1289 //Time() |
|
1290 //setup expected time for this validity period |
|
1291 //UTC = 2005/03/31 10hr45min55sec, offset=135sec |
|
1292 //Validity period = 3days |
|
1293 TMonth month=EMarch; |
|
1294 TDateTime utcDateTime(2005,month,30,10,45,55,0); |
|
1295 TTime utcTime(utcDateTime); |
|
1296 TInt offset=135; // 135 seconds |
|
1297 TTimeIntervalSeconds utcOffset(offset); |
|
1298 User::SetUTCTimeAndOffset(utcTime,utcOffset); |
|
1299 |
|
1300 //--------------------------------------------------- |
|
1301 //Create |
|
1302 //Format is set to an absolute format |
|
1303 TSmsFirstOctet validityPeriodFormat=TSmsFirstOctet::ESmsVPFSemiOctet; |
|
1304 TSmsValidityPeriod validityPeriod(validityPeriodFormat); |
|
1305 |
|
1306 //--------------------------------------------------- |
|
1307 //Set the validity period |
|
1308 TInt expectedIntervalPeriod(3*24*60+15); // 3days15min=4320 minutes |
|
1309 TTimeIntervalMinutes validityTimeInterval(expectedIntervalPeriod); |
|
1310 validityPeriod.SetTimeIntervalMinutes(validityTimeInterval); |
|
1311 TTimeIntervalMinutes actualInterval=validityPeriod.TimeIntervalMinutes(); |
|
1312 LOCAL_CHECKPOINT(expectedIntervalPeriod==actualInterval.Int()); |
|
1313 |
|
1314 //update utc, validity period is unchanged. |
|
1315 TDateTime nextDateTime(2005,month,30,12,45,55,0); |
|
1316 TTime nextTime(nextDateTime); |
|
1317 User::SetUTCTime(nextTime); |
|
1318 |
|
1319 TTime actualValidityTime=validityPeriod.Time(); |
|
1320 LOCAL_CHECKPOINT(actualValidityTime!=nextTime); |
|
1321 |
|
1322 User::SetUTCTimeAndOffset(currUTCTime,currUTCOffset); |
|
1323 } |
|
1324 |
|
1325 /** |
|
1326 * Test ability to encode a TSmsValidityPeriod inside a validity period inside a pdu |
|
1327 */ |
|
1328 EXPORT_C void CSmsStackTestUtils::EncodeTSmsValidityPeriodL() |
|
1329 { |
|
1330 //Get the current UTC offset |
|
1331 TTime currUTCTime; |
|
1332 currUTCTime.UniversalTime(); |
|
1333 TTimeIntervalSeconds currUTCOffset=User::UTCOffset(); |
|
1334 |
|
1335 //Encode |
|
1336 const TInt KServiceCenterBuffSizeInPDU=7; //Buffer is a 14 semi-octet buffer, 7 byte |
|
1337 TBuf8<KServiceCenterBuffSizeInPDU> serviceCenterBuffer; |
|
1338 serviceCenterBuffer.SetLength(serviceCenterBuffer.MaxLength()); |
|
1339 TUint8* ptr = &serviceCenterBuffer[0]; |
|
1340 |
|
1341 //--------------------------------------------------- |
|
1342 //Set the UTC time |
|
1343 //UTC = 03/03/2005, 12h00min30sec, offset = +3hrs = 10800 seconds |
|
1344 //Validity = 2hrs |
|
1345 //Expected local time = 03/03/2005, 17h00min30sec |
|
1346 TTimeIntervalSeconds utcOffset(10800); |
|
1347 TMonth month=EMarch; |
|
1348 TDateTime utcDateTime(2005,month,2,12,0,30,0); |
|
1349 TTime utcTime(utcDateTime); |
|
1350 User::SetUTCTimeAndOffset(utcTime,utcOffset); |
|
1351 |
|
1352 //Create the validity period |
|
1353 TSmsFirstOctet validityPeriodFormat=TSmsFirstOctet::ESmsVPFSemiOctet; |
|
1354 TSmsValidityPeriod validityPeriod(validityPeriodFormat); |
|
1355 |
|
1356 //Set the validity period to 2hrs, = 120 minutes |
|
1357 TInt expectedIntervalPeriod=120; |
|
1358 TTimeIntervalMinutes validityTimeInterval(expectedIntervalPeriod); |
|
1359 validityPeriod.SetTimeIntervalMinutes(validityTimeInterval); |
|
1360 |
|
1361 //Encode the PDU. |
|
1362 validityPeriod.EncodeL(ptr); |
|
1363 |
|
1364 // This is the expected structure in bytes for the time above |
|
1365 TUint8 semioctet = serviceCenterBuffer[0]; //2005 |
|
1366 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1367 semioctet = serviceCenterBuffer[1]; //March |
|
1368 LOCAL_CHECKPOINT(semioctet==0x30); |
|
1369 semioctet = serviceCenterBuffer[2]; //3rd |
|
1370 LOCAL_CHECKPOINT(semioctet==0x30); |
|
1371 semioctet = serviceCenterBuffer[3]; //17h |
|
1372 LOCAL_CHECKPOINT(semioctet==0x71); |
|
1373 semioctet = serviceCenterBuffer[4]; //0min |
|
1374 LOCAL_CHECKPOINT(semioctet==0x00); |
|
1375 semioctet = serviceCenterBuffer[5]; //30sec |
|
1376 LOCAL_CHECKPOINT(semioctet>=2 && semioctet<=4); // 1 second window each side of 3 |
|
1377 semioctet = serviceCenterBuffer[6]; //offset |
|
1378 LOCAL_CHECKPOINT(semioctet==0x21); //3hrs=15minx12 |
|
1379 |
|
1380 //Try a negative offset |
|
1381 //UTC = 03/03/2005, 12h00min30sec, offset = -6hrs = -21600 seconds |
|
1382 //Validity = 5days |
|
1383 //Expected local time = 08/03/2005, 06h00min30sec |
|
1384 |
|
1385 utcOffset=TTimeIntervalSeconds(-21600); // -6hrs validity |
|
1386 month=EMarch; |
|
1387 utcDateTime=TDateTime(2005,month,2,12,0,30,0); |
|
1388 utcTime=TTime(utcDateTime); |
|
1389 User::SetUTCTimeAndOffset(utcTime,utcOffset); |
|
1390 |
|
1391 //Create the validity period |
|
1392 //validityPeriodFormat=TSmsFirstOctet::ESmsVPFSemiOctet; |
|
1393 //validityPeriod=TSmsValidityPeriod(validityPeriodFormat); |
|
1394 |
|
1395 //Set the validity period to 5days, = 5*24*60=7200 minutes |
|
1396 expectedIntervalPeriod=7200; |
|
1397 validityTimeInterval=TTimeIntervalMinutes(expectedIntervalPeriod); |
|
1398 validityPeriod.SetTimeIntervalMinutes(validityTimeInterval); |
|
1399 |
|
1400 //Encode the PDU |
|
1401 validityPeriod.EncodeL(ptr); |
|
1402 |
|
1403 // This is the expected structure in bytes for the time above |
|
1404 semioctet = serviceCenterBuffer[0]; //2005 |
|
1405 LOCAL_CHECKPOINT(semioctet==0x50); |
|
1406 semioctet = serviceCenterBuffer[1]; //March |
|
1407 LOCAL_CHECKPOINT(semioctet==0x30); |
|
1408 semioctet = serviceCenterBuffer[2]; //3rd |
|
1409 LOCAL_CHECKPOINT(semioctet==0x80); |
|
1410 semioctet = serviceCenterBuffer[3]; //6h |
|
1411 LOCAL_CHECKPOINT(semioctet==0x60); |
|
1412 semioctet = serviceCenterBuffer[4]; //0min |
|
1413 LOCAL_CHECKPOINT(semioctet==0); |
|
1414 semioctet = serviceCenterBuffer[5]; //30sec |
|
1415 LOCAL_CHECKPOINT(semioctet>=2 && semioctet<=4); // 1 second window each side of 3 |
|
1416 semioctet = serviceCenterBuffer[6]; //offset |
|
1417 LOCAL_CHECKPOINT(semioctet==0x4A); //-6hrs = -6*60=360 minutes 15x24 minutes |
|
1418 |
|
1419 User::SetUTCTimeAndOffset(currUTCTime,currUTCOffset); |
|
1420 } |
|
1421 |
|
1422 /** |
|
1423 * Test ability to decode a validity period inside a pdu into a TSmsValidityPeriod. |
|
1424 */ |
|
1425 EXPORT_C void CSmsStackTestUtils::DecodeTSmsValidityPeriodL() |
|
1426 { |
|
1427 //Get the current UTC offset |
|
1428 TTime currUTCTime; |
|
1429 currUTCTime.UniversalTime(); |
|
1430 TTimeIntervalSeconds currUTCOffset=User::UTCOffset(); |
|
1431 |
|
1432 //Decode timestamp |
|
1433 const TInt KTimeStampSize=7; |
|
1434 //TInt ret=0; |
|
1435 TBuf8<KTimeStampSize> timeStamp; |
|
1436 timeStamp.SetLength(timeStamp.MaxLength()); |
|
1437 |
|
1438 //--------------------------------------------------- |
|
1439 // In integer values - local time |
|
1440 timeStamp[0]=64; //year=2004 |
|
1441 timeStamp[1]=32; //month=Feb |
|
1442 timeStamp[2]=146; //day=29th |
|
1443 timeStamp[3]=81; //hour=15h |
|
1444 timeStamp[4]=3; //minute=30min |
|
1445 timeStamp[5]=0; //second=0 |
|
1446 timeStamp[6]=33; //timeZone=12x15min=3hrs |
|
1447 |
|
1448 //UTC time is 29 January 2004, 12.30 |
|
1449 //This should give a TTimeIntervalMinutes of 31 Days = 44640 minutes |
|
1450 TMonth month=EJanuary; |
|
1451 TDateTime utcDateTime(2004,month,28,12,30,0,0); |
|
1452 //Setup UTC time and offset |
|
1453 TTime utcTime(utcDateTime); |
|
1454 //+3hrs offset = 10800 seconds |
|
1455 TTimeIntervalSeconds utcOffset(10800); |
|
1456 User::SetUTCTimeAndOffset(utcTime,utcOffset); |
|
1457 |
|
1458 //Create buffer |
|
1459 TGsmuLex8 timeStampPosOffsetBuffer(timeStamp); |
|
1460 //Create validity period |
|
1461 TSmsFirstOctet validityPeriodFormat=TSmsFirstOctet::ESmsVPFSemiOctet; |
|
1462 TSmsValidityPeriod validityPeriod(validityPeriodFormat); |
|
1463 |
|
1464 //Decode |
|
1465 validityPeriod.DecodeL(timeStampPosOffsetBuffer); |
|
1466 |
|
1467 //Now I have a TValidityPeriod |
|
1468 //Check validity period format |
|
1469 //ValidityPeriodFormat |
|
1470 LOCAL_CHECKPOINT(validityPeriod.ValidityPeriodFormat()==TSmsFirstOctet::ESmsVPFSemiOctet); |
|
1471 |
|
1472 //Check the expected Interval |
|
1473 TTimeIntervalMinutes expectedInterval(44640); |
|
1474 //Give or take a minute |
|
1475 TTimeIntervalMinutes actualInterval=validityPeriod.TimeIntervalMinutes(); |
|
1476 LOCAL_CHECKPOINT(actualInterval.Int()==expectedInterval.Int()+1||actualInterval.Int()==expectedInterval.Int()-1||actualInterval.Int()==expectedInterval.Int()); |
|
1477 User::SetUTCTimeAndOffset(currUTCTime,currUTCOffset); |
|
1478 } |
|
1479 |
|
1480 |
|
1481 EXPORT_C void CSmsStackTestUtils::AppendUserDataL(TGsmSms& aPdu, const CSmsUserData& aUD, TInt aUDL /* = KErrNotFound */) |
|
1482 /** |
|
1483 * Appends an encoded CSmsUserData to the PDU |
|
1484 * |
|
1485 * @pre aPdu contains an appropriate Data Coding Scheme |
|
1486 * @param aPdu Partially constructed TGsmSms, lacking the user data |
|
1487 * @param aUD The User Data to append to aPdu |
|
1488 * @param aUDL OPTIONAL Value to set the TP-UDL in the PDU. Only used if >= 0 |
|
1489 */ |
|
1490 { |
|
1491 RMobileSmsMessaging::TMobileSmsGsmTpdu pdu(aPdu.Pdu()); |
|
1492 const TInt origLen = pdu.Length(); |
|
1493 pdu.SetLength(pdu.MaxLength()); |
|
1494 TUint8* ptr0 = &pdu[origLen]; |
|
1495 TUint8* ptr1 = ptr0; |
|
1496 |
|
1497 ptr1 = aUD.EncodeL(ptr1); |
|
1498 |
|
1499 if (aUDL >= 0 && aUDL <= 0x99) |
|
1500 { |
|
1501 *ptr0 = static_cast<TInt8>(aUDL); |
|
1502 } |
|
1503 |
|
1504 pdu.SetLength((ptr1 - ptr0) + origLen); |
|
1505 aPdu.SetPdu(pdu); |
|
1506 } |
|
1507 |
|
1508 EXPORT_C void CSmsStackTestUtils::CompareDCSL(const CSmsPDU& aPdu, TSmsDataCodingScheme aDCS) |
|
1509 /** |
|
1510 * TODO |
|
1511 */ |
|
1512 { |
|
1513 LOCAL_CHECKPOINT(aPdu.DataCodingSchemePresent()); |
|
1514 LOCAL_CHECKPOINT(aPdu.Alphabet() == aDCS.Alphabet()); |
|
1515 LOCAL_CHECKPOINT(aPdu.Bits7To4() == aDCS.Bits7To4()); |
|
1516 |
|
1517 TSmsDataCodingScheme::TSmsClass class1, class2; |
|
1518 const TBool hasClass1 = aPdu.Class(class1); |
|
1519 const TBool hasClass2 = aPdu.Class(class2); |
|
1520 |
|
1521 LOCAL_CHECKPOINT((hasClass1 && hasClass2) || (!hasClass1 && !hasClass2)); |
|
1522 |
|
1523 if (hasClass1) |
|
1524 { |
|
1525 LOCAL_CHECKPOINT(class1 == class2); |
|
1526 } |
|
1527 } |
|
1528 |
|
1529 EXPORT_C void CSmsStackTestUtils::ComparePIDL(const CSmsPDU& aPDU, TSmsProtocolIdentifier aPID) |
|
1530 /** |
|
1531 * TODO |
|
1532 */ |
|
1533 { |
|
1534 LOCAL_CHECKPOINT(aPDU.ProtocolIdentifierPresent()); |
|
1535 LOCAL_CHECKPOINT(aPDU.PIDType() == aPID.PIDType()); |
|
1536 LOCAL_CHECKPOINT(aPDU.TelematicDeviceIndicator() == aPID.TelematicDeviceIndicator()); |
|
1537 |
|
1538 if (aPDU.TelematicDeviceIndicator()==TSmsProtocolIdentifier::ESmsTelematicDevice) |
|
1539 { |
|
1540 LOCAL_CHECKPOINT(aPDU.TelematicDeviceType() == aPID.TelematicDeviceType()); |
|
1541 } |
|
1542 } |
|
1543 |
|
1544 EXPORT_C void CSmsStackTestUtils::CompareUDL(const CSmsPDU& aPDU, const CSmsUserData& aUD) |
|
1545 /** |
|
1546 * TODO |
|
1547 */ |
|
1548 { |
|
1549 LOCAL_CHECKPOINT(aPDU.UserDataPresent()); |
|
1550 const CSmsUserData& pduUD = aPDU.UserData(); |
|
1551 |
|
1552 TInt count = pduUD.NumInformationElements(); |
|
1553 |
|
1554 LOCAL_CHECKPOINT(count == aUD.NumInformationElements()); |
|
1555 |
|
1556 while (count--) |
|
1557 { |
|
1558 const CSmsInformationElement& ie1 = pduUD.InformationElement(count); |
|
1559 const CSmsInformationElement& ie2 = aUD.InformationElement(count); |
|
1560 LOCAL_CHECKPOINT(ie1.Identifier() == ie2.Identifier()); |
|
1561 LOCAL_CHECKPOINT(ie1.Data() == ie2.Data()); |
|
1562 } |
|
1563 |
|
1564 LOCAL_CHECKPOINT(pduUD.Body() == aUD.Body()); |
|
1565 } |
|
1566 |
|
1567 EXPORT_C void CSmsStackTestUtils::PrintAndTestDecodeL(const TGsmSms& aPdu, TSmsDataCodingScheme aExpectedDCS, TSmsProtocolIdentifier aExpectedPID, const CSmsUserData& aExpectedUD, TBool aIsMobileTerminated, TInt aExpectedError) |
|
1568 /** |
|
1569 * TODO |
|
1570 */ |
|
1571 { |
|
1572 LOGSMSIFPDU(_L8("TestPduDbToolsL PDU: "), aPdu.Pdu(), EFalse); |
|
1573 LOGSMSIFTIMESTAMP(); |
|
1574 |
|
1575 CSmsPDU* pdu = NULL; |
|
1576 TRAPD(err, pdu = CSmsPDU::NewL(aPdu, *iCharConv, iFs, aIsMobileTerminated)); |
|
1577 |
|
1578 if (err == KErrNone) |
|
1579 CleanupStack::PushL(pdu); |
|
1580 |
|
1581 LOCAL_CHECKPOINT(err == aExpectedError); |
|
1582 |
|
1583 if (err == KErrNone) |
|
1584 { |
|
1585 CompareDCSL(*pdu, aExpectedDCS); |
|
1586 ComparePIDL(*pdu, aExpectedPID); |
|
1587 CompareUDL(*pdu, aExpectedUD); |
|
1588 } |
|
1589 |
|
1590 if (err == KErrNone) |
|
1591 CleanupStack::PopAndDestroy(pdu); |
|
1592 } |
|
1593 |
|
1594 EXPORT_C TInt CSmsStackTestUtils::StoreParamsL(CMobilePhoneSmspList& aSmspList, RSocket& aSocket, TBool aCancelAfterRequest) |
|
1595 /** |
|
1596 * Stream Sms parameters out to the socket server |
|
1597 * @param aSmspList has Sms parameters list that is streamed to the socket server |
|
1598 * @param aSocket is used to stream the aSmspList to the socket server |
|
1599 * @param aCancelAfterRequest Boolean parameter tells if the request is wanted to be canceled |
|
1600 * @return TInt : The completing status of the request |
|
1601 */ |
|
1602 { |
|
1603 // Write parameters |
|
1604 RSmsSocketWriteStream writestream(aSocket); |
|
1605 TRAPD(ret,writestream << aSmspList); |
|
1606 LOCAL_CHECKPOINT(ret == KErrNone); |
|
1607 TRAP(ret,writestream.CommitL()); |
|
1608 LOCAL_CHECKPOINT(ret == KErrNone); |
|
1609 |
|
1610 TRequestStatus status; |
|
1611 aSocket.Ioctl(KIoctlWriteSmsParams,status,NULL, KSolSmsProv); |
|
1612 if(aCancelAfterRequest) |
|
1613 aSocket.CancelIoctl(); |
|
1614 User::WaitForRequest(status); |
|
1615 |
|
1616 PRINTF2(_L("StoreParamsL - storeSmsParams returned %d"), status.Int()); |
|
1617 return status.Int(); |
|
1618 } |
|
1619 |
|
1620 EXPORT_C TInt CSmsStackTestUtils::RetrieveParamsL(CMobilePhoneSmspList& aSmspList, RSocket& aSocket, TBool aCancelAfterRequest) |
|
1621 /** |
|
1622 * Retrieve Sms parameters |
|
1623 * @param aSmspList pointer to the Sms parameters list to be read into |
|
1624 * @param aSocket is used to stream the aSmspList from the socket server |
|
1625 * @param aCancelAfterRequest Boolean parameter tells if the request is wanted to be canceled |
|
1626 * @return TInt : The completing status of the request |
|
1627 */ |
|
1628 { |
|
1629 TInt ret; |
|
1630 TRequestStatus status; |
|
1631 |
|
1632 // |
|
1633 // Retrieve Sms parameters from Phone |
|
1634 // |
|
1635 aSocket.Ioctl(KIoctlReadSmsParams,status,NULL, KSolSmsProv); |
|
1636 if(aCancelAfterRequest) |
|
1637 aSocket.CancelIoctl(); |
|
1638 User::WaitForRequest(status); |
|
1639 |
|
1640 if(status.Int() == KErrNone && !aCancelAfterRequest) |
|
1641 { |
|
1642 RSmsSocketReadStream readstream(aSocket); |
|
1643 TRAP(ret,readstream >> aSmspList); |
|
1644 LOCAL_CHECKPOINT(ret == KErrNone); |
|
1645 } |
|
1646 |
|
1647 return status.Int(); |
|
1648 } |
|
1649 |
|
1650 EXPORT_C void CSmsStackTestUtils::MakeParametersReadRequestL(RSocket& aSocket) |
|
1651 /** |
|
1652 * Make SMS parameters read request to the SMS Stack. |
|
1653 * @param aSocket that is used to make request to the stack. |
|
1654 */ |
|
1655 { |
|
1656 TRequestStatus status; |
|
1657 |
|
1658 // Make read SMS params request to the SMS Stack |
|
1659 aSocket.Ioctl(KIoctlReadSmsParams,status,NULL, KSolSmsProv); |
|
1660 User::WaitForRequest(status); |
|
1661 PRINTF2(_L("Retrieve SMS parameters returned %d"), status.Int()); |
|
1662 if(status.Int() != KErrNone) |
|
1663 { |
|
1664 User::Leave(status.Int()); |
|
1665 } |
|
1666 } |
|
1667 |
|
1668 EXPORT_C void CSmsStackTestUtils::StoreParamsLeaveIfErrorL(CMobilePhoneSmspList& aSmspList,RSocket& aSocket) |
|
1669 /** |
|
1670 * Stream Sms parameters out to the socket server and make request. |
|
1671 * @param aSmspList has Sms parameters list that is streamed to the socket server |
|
1672 * @param aSocket is used to stream the aSmspList to the socket server |
|
1673 */ |
|
1674 { |
|
1675 // Write parameters |
|
1676 RSmsSocketWriteStream writestream(aSocket); |
|
1677 writestream << aSmspList; |
|
1678 writestream.CommitL(); |
|
1679 |
|
1680 TRequestStatus status; |
|
1681 aSocket.Ioctl(KIoctlWriteSmsParams,status,NULL, KSolSmsProv); |
|
1682 User::WaitForRequest(status); |
|
1683 PRINTF2(_L("Store SMS parameters returned %d"), status.Int()); |
|
1684 if(status.Int() != KErrNone) |
|
1685 { |
|
1686 User::Leave(status.Int()); |
|
1687 } |
|
1688 } |
|
1689 |
|
1690 EXPORT_C TInt CSmsStackTestUtils::TestParameters(CMobilePhoneSmspList& aLeft,CMobilePhoneSmspList& aRight) |
|
1691 /** |
|
1692 * Compare sms parameters taken from chunk to parameters retrieved from SIM |
|
1693 * @param aLeft sms parameters taken from the Dummychunk |
|
1694 * @param aRight sms parameters retrieved from the SIM |
|
1695 * @return TInt : The error code |
|
1696 */ |
|
1697 { |
|
1698 TInt ret(KErrNone); |
|
1699 |
|
1700 if(aLeft.Enumerate() == aRight.Enumerate()) |
|
1701 { |
|
1702 for(TInt storeIndex=0; storeIndex<aLeft.Enumerate(); storeIndex++) |
|
1703 { |
|
1704 const RMobileSmsMessaging::TMobileSmspEntryV1* leftEntry(NULL); |
|
1705 TBool found=EFalse; |
|
1706 |
|
1707 TRAPD(myLeftErr, leftEntry = &aLeft.GetEntryL(storeIndex)); |
|
1708 if (myLeftErr != KErrNone) |
|
1709 { |
|
1710 return myLeftErr; |
|
1711 } |
|
1712 if (leftEntry == NULL) |
|
1713 { |
|
1714 return KErrArgument; |
|
1715 } |
|
1716 |
|
1717 for(TInt writeIndex=0; writeIndex<aRight.Enumerate(); writeIndex++) |
|
1718 { |
|
1719 const RMobileSmsMessaging::TMobileSmspEntryV1* rightEntry(NULL); |
|
1720 |
|
1721 TRAPD(myRightErr, rightEntry = &aRight.GetEntryL(writeIndex)); |
|
1722 if (myRightErr != KErrNone) |
|
1723 { |
|
1724 return myRightErr; |
|
1725 } |
|
1726 if (rightEntry == NULL) |
|
1727 { |
|
1728 return KErrArgument; |
|
1729 } |
|
1730 |
|
1731 if(leftEntry->iIndex == rightEntry->iIndex) |
|
1732 { |
|
1733 found=ETrue; |
|
1734 if((leftEntry->iValidParams != rightEntry->iValidParams) || |
|
1735 (leftEntry->iText != rightEntry->iText)) |
|
1736 { |
|
1737 ret = KErrCorrupt; |
|
1738 break; |
|
1739 } |
|
1740 if(leftEntry->iValidParams & RMobileSmsMessaging::KDestinationIncluded) |
|
1741 { |
|
1742 ret = TestPhoneNumbers(leftEntry->iDestination,rightEntry->iDestination); |
|
1743 if(ret) |
|
1744 break; |
|
1745 } |
|
1746 if(leftEntry->iValidParams & RMobileSmsMessaging::KSCAIncluded) |
|
1747 { |
|
1748 ret = TestPhoneNumbers(leftEntry->iServiceCentre,rightEntry->iServiceCentre); |
|
1749 if(ret) |
|
1750 break; |
|
1751 } |
|
1752 if((leftEntry->iValidParams & RMobileSmsMessaging::KProtocolIdIncluded) && |
|
1753 (leftEntry->iProtocolId != rightEntry->iProtocolId)) |
|
1754 ret = KErrCorrupt; |
|
1755 if((leftEntry->iValidParams & RMobileSmsMessaging::KValidityPeriodIncluded) && |
|
1756 (leftEntry->iValidityPeriod != rightEntry->iValidityPeriod)) |
|
1757 ret = KErrCorrupt; |
|
1758 if((leftEntry->iValidParams & RMobileSmsMessaging::KDcsIncluded) && |
|
1759 (leftEntry->iDcs != rightEntry->iDcs)) |
|
1760 ret = KErrCorrupt; |
|
1761 break; |
|
1762 } |
|
1763 } |
|
1764 |
|
1765 if(!found || ret != KErrNone) |
|
1766 { |
|
1767 ret = KErrCorrupt; |
|
1768 break; |
|
1769 } |
|
1770 } |
|
1771 } |
|
1772 else |
|
1773 ret = KErrCorrupt; |
|
1774 |
|
1775 if(ret == KErrNone) |
|
1776 PRINTF1(_L("SMS Parameters Ok!") ); |
|
1777 else |
|
1778 PRINTF2(_L("ERROR: SMSP lists doesn't match: %d"), ret ); |
|
1779 |
|
1780 return ret; |
|
1781 } |
|
1782 |
|
1783 EXPORT_C TInt CSmsStackTestUtils::TestPhoneNumbers(const RMobilePhone::TMobileAddress& aLeftNumber,const RMobilePhone::TMobileAddress& aRightNumber) |
|
1784 /** |
|
1785 * Compare phone numbers |
|
1786 * @param aLeftNumber reference to TMobileAddress object |
|
1787 * @param aRightNumber reference to TMobileAddress object |
|
1788 */ |
|
1789 { |
|
1790 TInt ret(KErrNone); |
|
1791 TBuf<TGsmSmsTelNumberMaxLen> leftNumber; |
|
1792 TBuf<TGsmSmsTelNumberMaxLen> rightNumber; |
|
1793 |
|
1794 //Take '+' sign away first |
|
1795 leftNumber.Copy(aLeftNumber.iTelNumber); |
|
1796 if(leftNumber.Length() > 0 && leftNumber[0] == '+') |
|
1797 { |
|
1798 // Remove "+" sign from telephony number |
|
1799 leftNumber.Delete(0,1); |
|
1800 leftNumber.Trim(); |
|
1801 } |
|
1802 //Take '+' sign away first |
|
1803 rightNumber.Copy(aRightNumber.iTelNumber); |
|
1804 if(rightNumber.Length() > 0 && rightNumber[0] == '+') |
|
1805 { |
|
1806 // Remove "+" sign from telephony number |
|
1807 rightNumber.Delete(0,1); |
|
1808 rightNumber.Trim(); |
|
1809 } |
|
1810 if((leftNumber.Compare(rightNumber) != 0) || |
|
1811 (aLeftNumber.iTypeOfNumber != aRightNumber.iTypeOfNumber) || |
|
1812 (aLeftNumber.iNumberPlan != aRightNumber.iNumberPlan)) |
|
1813 { |
|
1814 ret = KErrCorrupt; |
|
1815 } |
|
1816 return(ret); |
|
1817 } |
|
1818 |
|
1819 EXPORT_C void CSmsStackTestUtils::PrintSmspEntry(RMobileSmsMessaging::TMobileSmspEntryV1& aEntryToTsy) |
|
1820 /** |
|
1821 * Print a single SMS parameter entry, induvidual content depends on valid flags |
|
1822 * @param aEntryToTsy reference to TMobileSmspEntryV1 object |
|
1823 */ |
|
1824 { |
|
1825 PRINTF2( _L("Index %d"), aEntryToTsy.iIndex); |
|
1826 PRINTF2( _L("Text %S"), &aEntryToTsy.iText); |
|
1827 PRINTF2( _L("Validity Flags %d"), aEntryToTsy.iValidParams); |
|
1828 |
|
1829 // Protocol ID |
|
1830 if (aEntryToTsy.iValidParams & RMobileSmsMessaging::KProtocolIdIncluded) |
|
1831 { |
|
1832 PRINTF2( _L("Protocol ID is %d"), |
|
1833 aEntryToTsy.iProtocolId); |
|
1834 } |
|
1835 |
|
1836 //DCS |
|
1837 if (aEntryToTsy.iValidParams & RMobileSmsMessaging::KDcsIncluded) |
|
1838 { |
|
1839 PRINTF2( _L("Default Ccding Scheme is %d"), |
|
1840 aEntryToTsy.iDcs); |
|
1841 } |
|
1842 |
|
1843 //validity |
|
1844 if (aEntryToTsy.iValidParams & RMobileSmsMessaging::KValidityPeriodIncluded) |
|
1845 { |
|
1846 PRINTF2( _L("Validity Period is %d"), |
|
1847 aEntryToTsy.iValidityPeriod); |
|
1848 } |
|
1849 |
|
1850 // destination number |
|
1851 if (aEntryToTsy.iValidParams & RMobileSmsMessaging::KDestinationIncluded) |
|
1852 { |
|
1853 PRINTF2( _L("Destination Type Number is %d"), |
|
1854 aEntryToTsy.iDestination.iTypeOfNumber); |
|
1855 PRINTF2( _L("Destination Number Plan is %d"), |
|
1856 aEntryToTsy.iDestination.iNumberPlan); |
|
1857 PRINTF2( _L("Destination Number is %S"), |
|
1858 &aEntryToTsy.iDestination.iTelNumber); |
|
1859 } |
|
1860 // service center number |
|
1861 if (aEntryToTsy.iValidParams & RMobileSmsMessaging::KSCAIncluded) |
|
1862 { |
|
1863 PRINTF2( _L("Service Center Type Number is %d"), |
|
1864 aEntryToTsy.iServiceCentre.iTypeOfNumber); |
|
1865 PRINTF2( _L("Service Center Number Plan is %d"), |
|
1866 aEntryToTsy.iServiceCentre.iNumberPlan); |
|
1867 PRINTF2( _L("Service Center Number is %S"), |
|
1868 &aEntryToTsy.iServiceCentre.iTelNumber); |
|
1869 } |
|
1870 } |
|
1871 |
|
1872 EXPORT_C void CSmsStackTestUtils::PrintSmspList(CMobilePhoneSmspList& aSmspList) |
|
1873 /** |
|
1874 * Print a SMS parameter list |
|
1875 * @param aSmspList reference to CMobilePhoneSmspList object |
|
1876 */ |
|
1877 { |
|
1878 TInt entries; |
|
1879 entries = aSmspList.Enumerate(); |
|
1880 |
|
1881 if (entries != 1) |
|
1882 { |
|
1883 PRINTF2(_L("The Sms Parameter List has %d parameter entries "), entries ); |
|
1884 } |
|
1885 else |
|
1886 { |
|
1887 PRINTF2(_L("The Sms Parameter List has %d parameter entry "), entries ); |
|
1888 } |
|
1889 |
|
1890 RMobileSmsMessaging::TMobileSmspEntryV1 entryToTsy; |
|
1891 |
|
1892 for (TInt i = 0; i < entries; i++) |
|
1893 { |
|
1894 PRINTF1(_L("")); |
|
1895 TRAPD(err, entryToTsy = aSmspList.GetEntryL(i)); |
|
1896 |
|
1897 if (err == KErrNone) |
|
1898 { |
|
1899 PrintSmspEntry(entryToTsy); |
|
1900 } |
|
1901 else |
|
1902 { |
|
1903 //if leave occurs print to the console |
|
1904 PRINTF2(_L("SmspList.GetEntryL() left: possible cause memory allocation %d"), err); |
|
1905 break; |
|
1906 } |
|
1907 } |
|
1908 } |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 // |
|
1914 // CTestGetSmsList |
|
1915 // |
|
1916 |
|
1917 EXPORT_C CTestGetSmsList* CTestGetSmsList::NewL(TInt aPriority, RSocketServ& aSocketServer, CSmsStackTestUtils& aTestUtils) |
|
1918 { |
|
1919 CTestGetSmsList* smsListGetter = new(ELeave) CTestGetSmsList(aPriority, aSocketServer, aTestUtils); |
|
1920 CleanupStack::PushL(smsListGetter); |
|
1921 smsListGetter->ConstructL(); |
|
1922 CleanupStack::Pop(smsListGetter); |
|
1923 return smsListGetter; |
|
1924 } |
|
1925 |
|
1926 CTestGetSmsList::CTestGetSmsList(TInt aPriority, RSocketServ& aSocketServer, CSmsStackTestUtils& aTestUtils) |
|
1927 /** |
|
1928 * Constructor |
|
1929 * |
|
1930 * * |
|
1931 */ |
|
1932 : CSmsuActiveBase(aPriority), //parent construction |
|
1933 iSocketServer(aSocketServer), |
|
1934 iTestUtils(aTestUtils) |
|
1935 { |
|
1936 } |
|
1937 |
|
1938 |
|
1939 void CTestGetSmsList::ConstructL() |
|
1940 { |
|
1941 iTestUtils.OpenSmsSocketLC(iSocketServer,iSocket,ESmsAddrLocalOperation); |
|
1942 CleanupStack::Pop(&iSocket); |
|
1943 } |
|
1944 |
|
1945 EXPORT_C void CTestGetSmsList::GetSmsList(TRequestStatus& aStatus) |
|
1946 /** |
|
1947 * Starts the active object: Puts a Ioctl request on a socket to enumerate the number |
|
1948 * of messsages in the store |
|
1949 * @param aStatus, copied to iStatus of this active object |
|
1950 * |
|
1951 * * |
|
1952 */ |
|
1953 { |
|
1954 Queue(aStatus); |
|
1955 iMessageCount()=0; |
|
1956 iSocket.Ioctl(KIoctlEnumerateSmsMessages, iStatus,&iMessageCount, KSolSmsProv); |
|
1957 SetActive(); |
|
1958 iState = EEnuming; |
|
1959 } |
|
1960 |
|
1961 void CTestGetSmsList::DoRunL() |
|
1962 /** |
|
1963 * Active object completion function |
|
1964 * Active while there are still messages to read from the socket |
|
1965 */ |
|
1966 { |
|
1967 iTestUtils.PRINTF1(_L("Messages enumerated")); |
|
1968 User::LeaveIfError(iStatus.Int()); |
|
1969 |
|
1970 switch (iState) |
|
1971 { |
|
1972 case EEnuming: |
|
1973 { |
|
1974 iRemainingMessages = iMessageCount(); |
|
1975 iTestUtils.PRINTF2(_L("%d messages in the store"), iRemainingMessages); |
|
1976 } |
|
1977 |
|
1978 case EReading: |
|
1979 { |
|
1980 if (iRemainingMessages > 0) |
|
1981 { |
|
1982 iRemainingMessages--; |
|
1983 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
1984 CSmsMessage* smsMessage=CSmsMessage::NewL(iTestUtils.iFs, CSmsPDU::ESmsDeliver,buffer); |
|
1985 CleanupStack::PushL(smsMessage); |
|
1986 |
|
1987 RSmsSocketReadStream readstream(iSocket); |
|
1988 readstream >> *smsMessage; |
|
1989 CleanupStack::PopAndDestroy(smsMessage);//operation was done only to clear the socket, we are not interested in the message content |
|
1990 |
|
1991 iSocket.Ioctl(KIoctlReadMessageSucceeded, iStatus, NULL, KSolSmsProv); |
|
1992 SetActive(); |
|
1993 iState = EReading; |
|
1994 } |
|
1995 } |
|
1996 } |
|
1997 } |
|
1998 |
|
1999 void CTestGetSmsList::DoCancel() |
|
2000 { |
|
2001 iSocket.CancelIoctl(); |
|
2002 Complete(KErrCancel); |
|
2003 } |
|
2004 |
|
2005 |
|
2006 // |
|
2007 // SmsReceiver AO |
|
2008 // |
|
2009 |
|
2010 EXPORT_C CTestReceiveMessages* CTestReceiveMessages::NewL(TInt aPriority, RSocketServ& aSocketServer, CSmsStackTestUtils& aTestUtils) |
|
2011 { |
|
2012 CTestReceiveMessages* smsReceiver = new(ELeave) CTestReceiveMessages(aPriority, aSocketServer, aTestUtils); |
|
2013 CleanupStack::PushL(smsReceiver); |
|
2014 smsReceiver->ConstructL(); |
|
2015 CleanupStack::Pop(smsReceiver); |
|
2016 return smsReceiver; |
|
2017 } |
|
2018 |
|
2019 CTestReceiveMessages::CTestReceiveMessages(TInt aPriority, RSocketServ& aSocketServer, CSmsStackTestUtils& aTestUtils) |
|
2020 /** |
|
2021 * Constructor |
|
2022 */ |
|
2023 : CSmsuActiveBase(aPriority), //parent construction |
|
2024 iSocketServer(aSocketServer), |
|
2025 iTestUtils(aTestUtils) |
|
2026 { |
|
2027 } |
|
2028 |
|
2029 |
|
2030 void CTestReceiveMessages::ConstructL() |
|
2031 { |
|
2032 iTestUtils.OpenSmsSocketLC(iSocketServer,iSocket,ESmsAddrRecvAny); |
|
2033 CleanupStack::Pop(&iSocket); |
|
2034 } |
|
2035 |
|
2036 EXPORT_C void CTestReceiveMessages::Receive(TRequestStatus& aStatus, TInt aNumberOfMessages) |
|
2037 /** |
|
2038 * Starts the AO by putting a request on the socket receive sms messages |
|
2039 * This function will normally be used when we start using the active object |
|
2040 * Active while the number of received messages is > aNumberOfmessages |
|
2041 * @param aNumberOfMessages the number of messages to be received |
|
2042 */ |
|
2043 { |
|
2044 Queue(aStatus); |
|
2045 if (iNumberOfReceivedMessages >= aNumberOfMessages) |
|
2046 Complete(KErrNone); |
|
2047 else |
|
2048 { |
|
2049 iNumberOfMessagesToReceive=aNumberOfMessages; |
|
2050 if (!IsActive()) |
|
2051 Receive(); |
|
2052 } |
|
2053 } |
|
2054 |
|
2055 EXPORT_C void CTestReceiveMessages::Receive() |
|
2056 /** |
|
2057 * Reposts the receive request -note Receive(aStatus, aNunmberOfMessages) has to be called prior to this one |
|
2058 * |
|
2059 */ |
|
2060 { |
|
2061 iMessageBuf()=KSockSelectRead; |
|
2062 iSocket.Ioctl(KIOctlSelect,iStatus,&iMessageBuf,KSOLSocket); |
|
2063 iState = EReceiving; |
|
2064 SetActive(); |
|
2065 } |
|
2066 |
|
2067 |
|
2068 void CTestReceiveMessages::DoRunL() |
|
2069 /** |
|
2070 * Active object completion function.completes once in each state for each message received |
|
2071 * |
|
2072 */ |
|
2073 { |
|
2074 User::LeaveIfError(iStatus.Int()); |
|
2075 |
|
2076 switch(iState) |
|
2077 { |
|
2078 case (EReceiving): |
|
2079 { |
|
2080 iTestUtils.PRINTF1(_L(" Message received")); |
|
2081 |
|
2082 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
2083 CSmsMessage* smsMessage=CSmsMessage::NewL(iTestUtils.iFs, CSmsPDU::ESmsSubmit,buffer); |
|
2084 CleanupStack::PushL(smsMessage); |
|
2085 RSmsSocketReadStream readstream(iSocket); |
|
2086 readstream >> *smsMessage; |
|
2087 CleanupStack::PopAndDestroy(smsMessage);//operation was done only to clear the socket, we are not interested in the message content |
|
2088 iSocket.Ioctl(KIoctlReadMessageSucceeded, iStatus, NULL, KSolSmsProv); |
|
2089 SetActive(); |
|
2090 iState = EReceived; |
|
2091 break; |
|
2092 } |
|
2093 case (EReceived): |
|
2094 { |
|
2095 iNumberOfReceivedMessages++; |
|
2096 iTestUtils.PRINTF2(_L("%d Messages received"), iNumberOfReceivedMessages); |
|
2097 iState=EReceiving; |
|
2098 |
|
2099 if (iNumberOfMessagesToReceive!=iNumberOfReceivedMessages || iReport == NULL) |
|
2100 Receive(); |
|
2101 |
|
2102 break; |
|
2103 } |
|
2104 } |
|
2105 } |
|
2106 |
|
2107 void CTestReceiveMessages::DoCancel() |
|
2108 { |
|
2109 iSocket.CancelIoctl(); |
|
2110 Complete(KErrCancel); |
|
2111 } |
|
2112 |
|
2113 |
|
2114 TInt CTestReceiveMessages::NumberReceived() |
|
2115 /** |
|
2116 * Returns the number of received sms messages |
|
2117 */ |
|
2118 { |
|
2119 return iNumberOfReceivedMessages; |
|
2120 } |
|
2121 |
|
2122 // |
|
2123 // SmsReceiverEnumerator wrapping AO |
|
2124 // |
|
2125 |
|
2126 |
|
2127 EXPORT_C CTestReceiveEnumerateMessages* CTestReceiveEnumerateMessages::NewL(TInt aPriority, RSocketServ& aSocketServer, CSmsStackTestUtils& aTestUtils) |
|
2128 { |
|
2129 CTestReceiveEnumerateMessages* smsReceiverEnumerator = new(ELeave) CTestReceiveEnumerateMessages(aPriority, aSocketServer, aTestUtils); |
|
2130 CleanupStack::PushL(smsReceiverEnumerator); |
|
2131 smsReceiverEnumerator->ConstructL(); |
|
2132 CleanupStack::Pop(smsReceiverEnumerator); |
|
2133 return smsReceiverEnumerator; |
|
2134 } |
|
2135 |
|
2136 CTestReceiveEnumerateMessages::CTestReceiveEnumerateMessages(TInt aPriority, RSocketServ& aSocketServer, CSmsStackTestUtils& aTestUtils) |
|
2137 /** |
|
2138 * Constructor |
|
2139 * * |
|
2140 */ |
|
2141 : CSmsuActiveBase(aPriority), //parent construction |
|
2142 iSocketServer(aSocketServer), |
|
2143 iTestUtils(aTestUtils) |
|
2144 { |
|
2145 } |
|
2146 |
|
2147 |
|
2148 void CTestReceiveEnumerateMessages::ConstructL() |
|
2149 { |
|
2150 iEnumerator = CTestGetSmsList::NewL(KActiveObjectPriority, iSocketServer, iTestUtils); |
|
2151 iReceiver = CTestReceiveMessages::NewL(KActiveObjectPriority, iSocketServer, iTestUtils); |
|
2152 ConstructTimeoutL(); |
|
2153 } |
|
2154 |
|
2155 EXPORT_C void CTestReceiveEnumerateMessages::Start(TInt aEnumExpected, TInt aRecvExpected, TInt aRecvInitial) |
|
2156 /** |
|
2157 * Starts the active object state machine in order to have the following |
|
2158 * -receive iRecvExpected messages |
|
2159 * -Enumerate messages in store and verify there are iEnumExpected and continue receiving |
|
2160 * -Receive the rest of the messages (iRecvExpected in total) |
|
2161 * -Request to receive another message that should time out as only 5 messages are received |
|
2162 * -Flag error if that last message is received |
|
2163 */ |
|
2164 { |
|
2165 iEnumExpected=aEnumExpected; |
|
2166 iRecvExpected=aRecvExpected; |
|
2167 iRecvInitial=aRecvInitial; |
|
2168 |
|
2169 iReceiver->Receive(iStatus, aRecvInitial); |
|
2170 iState = ERecvInitial; |
|
2171 SetActive(); |
|
2172 CActiveScheduler::Start(); |
|
2173 } |
|
2174 |
|
2175 void CTestReceiveEnumerateMessages::Complete(TInt aErr) |
|
2176 { |
|
2177 iStatus=aErr; |
|
2178 CActiveScheduler::Stop(); |
|
2179 } |
|
2180 |
|
2181 void CTestReceiveEnumerateMessages::DoRunL() |
|
2182 { |
|
2183 User::LeaveIfError(iStatus.Int()); |
|
2184 |
|
2185 switch(iState) |
|
2186 { |
|
2187 case ERecvInitial: |
|
2188 { |
|
2189 iEnumerator->GetSmsList(iStatus); |
|
2190 iReceiver->Receive(); |
|
2191 iState=EEnumerating; |
|
2192 SetActive(); |
|
2193 break; |
|
2194 } |
|
2195 case EEnumerating: |
|
2196 { |
|
2197 if(iEnumerator->iMessageCount()==TUint(iEnumExpected)) |
|
2198 iTestUtils.PRINTF1(_L("**enumerated the right number of messages")); |
|
2199 else |
|
2200 User::Leave(KErrCorrupt); |
|
2201 iReceiver->Receive(iStatus, 5); |
|
2202 SetActive(); |
|
2203 iState=ESecondReceiving; |
|
2204 break; |
|
2205 } |
|
2206 case ESecondReceiving: |
|
2207 { |
|
2208 iReceiver->Receive(iStatus, 1 + iRecvExpected); |
|
2209 iState=ETryingToReceiveOneMore; |
|
2210 TimedSetActive(15000000); |
|
2211 break; |
|
2212 } |
|
2213 |
|
2214 case ETryingToReceiveOneMore: |
|
2215 { |
|
2216 User::Leave(KErrOverflow); |
|
2217 break; |
|
2218 } |
|
2219 |
|
2220 } |
|
2221 |
|
2222 } |
|
2223 |
|
2224 void CTestReceiveEnumerateMessages::DoCancel() |
|
2225 /** |
|
2226 * Calls cancel on the active objects this owns |
|
2227 * |
|
2228 */ |
|
2229 { |
|
2230 TimedSetActiveCancel(); |
|
2231 TInt err = KErrCancel; |
|
2232 |
|
2233 switch(iState) |
|
2234 { |
|
2235 case ERecvInitial: |
|
2236 iReceiver->Cancel(); |
|
2237 break; |
|
2238 case EEnumerating: |
|
2239 iEnumerator->Cancel(); |
|
2240 break; |
|
2241 case ESecondReceiving: |
|
2242 |
|
2243 iReceiver->Cancel(); |
|
2244 break; |
|
2245 |
|
2246 case ETryingToReceiveOneMore: |
|
2247 |
|
2248 iReceiver->Cancel(); |
|
2249 |
|
2250 if (TimedOut()) |
|
2251 err = KErrNone; |
|
2252 |
|
2253 break; |
|
2254 } |
|
2255 |
|
2256 Complete(err); |
|
2257 } |
|
2258 |
|
2259 |
|
2260 EXPORT_C CTestReceiveEnumerateMessages::~CTestReceiveEnumerateMessages() |
|
2261 /** |
|
2262 * destructor |
|
2263 */ |
|
2264 { |
|
2265 delete iReceiver; |
|
2266 delete iEnumerator; |
|
2267 } |