|
1 // Copyright (c) 2007-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 is an integration unit test class for the SUPL Sms Trigger Plug-in |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 @prototype |
|
22 */ |
|
23 |
|
24 #include <e32property.h> |
|
25 #include <ecom/ecom.h> |
|
26 #include <centralrepository.h> |
|
27 |
|
28 #include <wapmessage.h> |
|
29 |
|
30 #include "lbssuplpushprops.h" |
|
31 #include "lbsrootcenrepdefs.h" |
|
32 |
|
33 #include "Te_LbsSuplSmsTriggerIntegStep.h" |
|
34 #include "Te_SuplWdpWatcher.h" |
|
35 #include "Te_LbsSuplPush.h" |
|
36 #include "Te_LbsSuplSmsTriggerCommon.h" |
|
37 #include "Te_ErrorPattern.h" |
|
38 |
|
39 |
|
40 /** The port on which test SMS messages sent*/ |
|
41 const TInt KSuplSmsTriggerTestPort = 7276; |
|
42 |
|
43 /** |
|
44 * Constructor. It must call the SetTestStepName as the controlling |
|
45 * framework uses the test step name immediately following construction to set |
|
46 * up the step's unique logging ID. |
|
47 */ |
|
48 CTe_LbsSuplSmsTriggerIntegStep::CTe_LbsSuplSmsTriggerIntegStep() |
|
49 { |
|
50 SetTestStepName(KLbsSuplSmsTriggerIntegStep); |
|
51 CTe_LbsSuplPush::SetTestObserver(this); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Destructor. |
|
56 */ |
|
57 CTe_LbsSuplSmsTriggerIntegStep::~CTe_LbsSuplSmsTriggerIntegStep() |
|
58 { |
|
59 delete iSender; |
|
60 delete iReceiver; |
|
61 delete iWatcherLog; |
|
62 } |
|
63 |
|
64 /** |
|
65 Creates the test step environment: the UDP message sender, the receiver part of the SUPL Push API, |
|
66 and the Watcher Framework logger. |
|
67 |
|
68 @return - always returns EPass. |
|
69 |
|
70 @leave If a error happens, it leaves with one of the system error codes. |
|
71 |
|
72 @see CTe_BaseStep::doTestStepPreambleL |
|
73 */ |
|
74 TVerdict CTe_LbsSuplSmsTriggerIntegStep::doTestStepPreambleL() |
|
75 { |
|
76 CTe_BaseStep::doTestStepPreambleL(); |
|
77 iSender = CTe_LbsSuplSmsTriggerSender::NewL(KSuplSmsTriggerTestPort , *this); |
|
78 iReceiver = CLbsSuplPushRec::NewL(*this); |
|
79 iWatcherLog = CTe_WatcherLog::NewL(); |
|
80 return TestStepResult(); |
|
81 } |
|
82 |
|
83 /** |
|
84 Overrides pure virtual CTe_BaseStep::ReallyDoTestStepL. The test code is run here. |
|
85 |
|
86 @leave If a error happens, it leaves with one of the system error codes or EFail. |
|
87 */ |
|
88 void CTe_LbsSuplSmsTriggerIntegStep::ReallyDoTestStepL() |
|
89 { |
|
90 // Get the CategoryUid from the cenrep file owned by LbsRoot. |
|
91 TInt category; |
|
92 CRepository* rep = CRepository::NewLC(KLbsCenRepUid); |
|
93 User::LeaveIfError(rep->Get(KSuplPushAPIKey, category)); |
|
94 CleanupStack::PopAndDestroy(rep); |
|
95 TUid propOwnerSecureId = TUid::Uid(category); |
|
96 |
|
97 //Reset the values set by previous tests |
|
98 User::LeaveIfError(RProperty::Set(propOwnerSecureId, KLbsSuplPushSmsBusyKey, 1)); |
|
99 User::LeaveIfError(RProperty::Set(propOwnerSecureId, KLbsSuplPushSmsAckKey, 0)); |
|
100 User::LeaveIfError(RProperty::Set(propOwnerSecureId, KLbsSuplPushSmsInitKey, KNullDesC8)); |
|
101 |
|
102 iMsgMaxCount = 1; |
|
103 |
|
104 //Successfuly send/receive a single message |
|
105 CLbsSuplWdpWatcher* wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
106 |
|
107 CTe_LbsSuplWdpWatcher::DisableAsserts(); |
|
108 wdpWatcher->OnTimerError(0, KErrGeneral); //Just to improve code coverage |
|
109 CTe_LbsSuplWdpWatcher::EnableAsserts(); |
|
110 |
|
111 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
112 SendMessage(iSendFillDigit++); |
|
113 iSchedulerWait->Start(); |
|
114 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
115 User::LeaveIfError(iUnexpectedError); |
|
116 CleanupStack::PopAndDestroy(wdpWatcher); |
|
117 |
|
118 //Successfuly send/receive several messages |
|
119 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
120 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
121 for(TInt i=0;i<10;i++) |
|
122 { |
|
123 SendMessage(iSendFillDigit++); |
|
124 iSchedulerWait->Start(); |
|
125 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
126 User::LeaveIfError(iUnexpectedError); |
|
127 } |
|
128 CleanupStack::PopAndDestroy(wdpWatcher); |
|
129 |
|
130 |
|
131 //Memory allocation failure test - creation of WdpWatcher |
|
132 |
|
133 User::__DbgSetAllocFail(EFalse ,RAllocator::EFailNext, 1); |
|
134 |
|
135 TInt* marker = new TInt(0); |
|
136 delete marker; |
|
137 |
|
138 if(!marker) //We only do memory failure tests for the udeb build of the OS |
|
139 { |
|
140 marker = new TInt(0); |
|
141 delete marker; |
|
142 |
|
143 for(TInt i=1; marker; i++) |
|
144 { |
|
145 User::__DbgSetAllocFail(EFalse ,RAllocator::EFailNext, i); |
|
146 |
|
147 TRAPD(err, wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); CleanupStack::Pop(wdpWatcher)); |
|
148 |
|
149 marker = new TInt(0); |
|
150 delete marker; |
|
151 |
|
152 if(!marker || (marker && err==KErrNone)) |
|
153 { |
|
154 if(wdpWatcher==0) |
|
155 { |
|
156 User::Leave(KErrGeneral); |
|
157 } |
|
158 CleanupStack::PushL(wdpWatcher); |
|
159 User::LeaveIfError(err); |
|
160 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected | CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
161 CleanupStack::PopAndDestroy(wdpWatcher); |
|
162 } |
|
163 } |
|
164 |
|
165 //Memory allocation failure test - CLbsSuplWdpWatcher::RunL method |
|
166 marker = new TInt(0); |
|
167 delete marker; |
|
168 for(TInt i=1; marker; i++) |
|
169 { |
|
170 //reset the previous errors and reset the message counter |
|
171 iUnexpectedError = KErrNone; |
|
172 iRecvFillDigit=iSendFillDigit; |
|
173 |
|
174 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
175 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
176 SendMessage(iSendFillDigit++); |
|
177 |
|
178 User::__DbgSetAllocFail(EFalse ,RAllocator::EFailNext, i); |
|
179 |
|
180 //we have to set time limitation here if leave occurs and the msg is not processed |
|
181 iSchedulerWait->Start(15000000); |
|
182 |
|
183 marker = new TInt(0); |
|
184 delete marker; |
|
185 |
|
186 if(marker) //memory leak occurs in our code or in the ActiveScheduler |
|
187 { |
|
188 TRAPD(err, wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize)); |
|
189 if(err!=KErrNone) |
|
190 { |
|
191 iSchedulerWait->Start(11000000); |
|
192 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
193 } |
|
194 } |
|
195 else //memory leak does not occur in our code |
|
196 { |
|
197 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
198 User::LeaveIfError(iUnexpectedError); |
|
199 } |
|
200 CleanupStack::PopAndDestroy(wdpWatcher); |
|
201 } |
|
202 } |
|
203 |
|
204 //Error on starting listening for new messages and restoring the connection afterwards |
|
205 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
206 //The port is occupied here |
|
207 CLbsSuplWdpWatcher* wdpWatcher2 = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
208 CleanupStack::Pop(wdpWatcher2); |
|
209 CleanupStack::PopAndDestroy(wdpWatcher); |
|
210 CleanupStack::PushL(wdpWatcher2); |
|
211 wdpWatcher2->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
212 wdpWatcher2->Cancel(); //This is added to test CLbsSuplWdpWatcher::DoCancel method |
|
213 iSchedulerWait->Start(5000000); |
|
214 wdpWatcher2->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
215 iSchedulerWait->Start(10000000); |
|
216 wdpWatcher2->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
217 SendMessage(iSendFillDigit++); |
|
218 iSchedulerWait->Start(); |
|
219 User::LeaveIfError(iUnexpectedError); |
|
220 wdpWatcher2->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
221 CleanupStack::PopAndDestroy(wdpWatcher2); |
|
222 |
|
223 |
|
224 //Sync error while receiving message size |
|
225 RTe_ErrorPattern::AppendErrorL(KModuleUid, ECWapBoundDatagramService_AwaitRecvDataSize, |
|
226 1, KErrGeneral, EFalse); |
|
227 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
228 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
229 iSchedulerWait->Start(5000000); |
|
230 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
231 iSchedulerWait->Start(10000000); |
|
232 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
233 SendMessage(iSendFillDigit++); |
|
234 iSchedulerWait->Start(); |
|
235 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
236 User::LeaveIfError(iUnexpectedError); |
|
237 CleanupStack::PopAndDestroy(wdpWatcher); |
|
238 RTe_ErrorPattern::Reset(); |
|
239 |
|
240 //Sync error while receiving message size - on the second message |
|
241 RTe_ErrorPattern::AppendErrorL(KModuleUid, ECWapBoundDatagramService_AwaitRecvDataSize, |
|
242 2, KErrGeneral, EFalse); |
|
243 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
244 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
245 SendMessage(iSendFillDigit++); |
|
246 iSchedulerWait->Start(); |
|
247 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
248 User::LeaveIfError(iUnexpectedError); |
|
249 iSchedulerWait->Start(5000000); |
|
250 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
251 iSchedulerWait->Start(10000000); |
|
252 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
253 SendMessage(iSendFillDigit++); |
|
254 iSchedulerWait->Start(); |
|
255 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
256 User::LeaveIfError(iUnexpectedError); |
|
257 CleanupStack::PopAndDestroy(wdpWatcher); |
|
258 RTe_ErrorPattern::Reset(); |
|
259 |
|
260 |
|
261 //Async error while receiving message size |
|
262 RTe_ErrorPattern::AppendAsyncErrorL(KModuleUid, ECWapBoundDatagramService_AwaitRecvDataSize, |
|
263 1, KErrGeneral, EFalse); |
|
264 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
265 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
266 iSchedulerWait->Start(5000000); |
|
267 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
268 iSchedulerWait->Start(10000000); |
|
269 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
270 SendMessage(iSendFillDigit++); |
|
271 iSchedulerWait->Start(); |
|
272 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
273 User::LeaveIfError(iUnexpectedError); |
|
274 CleanupStack::PopAndDestroy(wdpWatcher); |
|
275 RTe_ErrorPattern::Reset(); |
|
276 |
|
277 //Sync error while receiving message |
|
278 RTe_ErrorPattern::AppendErrorL(KModuleUid, ECWapBoundDatagramService_RecvFrom, |
|
279 1, KErrGeneral, EFalse); |
|
280 wdpWatcher = CLbsSuplWdpWatcher::NewLC(iWatcherLog); |
|
281 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
282 SendMessage(iSendFillDigit++); |
|
283 iSchedulerWait->Start(5000000); |
|
284 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EDisconnected); |
|
285 iSchedulerWait->Start(10000000); |
|
286 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
287 iRecvFillDigit=iSendFillDigit; |
|
288 SendMessage(iSendFillDigit++); |
|
289 iSchedulerWait->Start(); |
|
290 wdpWatcher->CheckStateL(CLbsSuplWdpWatcher::EAwaitingDataSize); |
|
291 User::LeaveIfError(iUnexpectedError); |
|
292 CleanupStack::PopAndDestroy(wdpWatcher); |
|
293 RTe_ErrorPattern::Reset(); |
|
294 |
|
295 } |
|
296 |
|
297 /** |
|
298 Overrides the pure virtual MTe_LbsSuplSmsTriggerSenderObserver::OnMessageSent. Receives the result |
|
299 of the message sending. |
|
300 |
|
301 @param aError [In] The error code or KErrNone if successful. |
|
302 |
|
303 @see MTe_LbsSuplSmsTriggerSenderObserver::OnMessageSent |
|
304 @see CTe_LbsSuplSmsTriggerSender::SendMessage |
|
305 */ |
|
306 void CTe_LbsSuplSmsTriggerIntegStep::OnMessageSent(TInt aError) |
|
307 { |
|
308 if(aError!=KErrNone) |
|
309 { |
|
310 iUnexpectedError = aError; |
|
311 iSchedulerWait->AsyncStop(); |
|
312 return; |
|
313 } |
|
314 iMsgCount++; |
|
315 |
|
316 if(iMsgCount<iMsgMaxCount) //continue to send messages |
|
317 { |
|
318 SendMessage(iMsgCount); |
|
319 } |
|
320 else //create the receiver and start to process messages |
|
321 { |
|
322 if(iMsgMaxCount>1) |
|
323 { |
|
324 User::After(5000000); |
|
325 } |
|
326 iMsgCount = 0; |
|
327 } |
|
328 } |
|
329 |
|
330 /** |
|
331 Overrides the pure virtual MLbsSuplPushRecObserver::OnSuplInit. Receives notifications about |
|
332 incoming SUPL INIT messages. |
|
333 |
|
334 @param aChannel [In] The channel the call-back is related to. |
|
335 @param aReqId [In] An Id of the request the call-back is related to. |
|
336 @param aMsg [In] A buffer containing a SUPL INIT message. |
|
337 |
|
338 @see MLbsSuplPushRecObserver::OnSuplInit |
|
339 @see CLbsSuplPushRec |
|
340 */ |
|
341 void CTe_LbsSuplSmsTriggerIntegStep::OnSuplInit(TLbsSuplPushChannel aChannel, |
|
342 TLbsSuplPushRequestId /*aReqId*/, TDesC8& aMsg) |
|
343 { |
|
344 if(aChannel!=ELbsSuplPushChannelSMS || !CompareMessage(iRecvFillDigit++, aMsg)) |
|
345 { |
|
346 if(aChannel!=ELbsSuplPushChannelSMS) |
|
347 { |
|
348 ERR_PRINTF1(_L("CTe_LbsSuplSmsTriggerIntegStep::OnSuplInit: aChannel!=ELbsSuplPushChannelSMS")); |
|
349 } |
|
350 iUnexpectedError = KErrGeneral;; |
|
351 iSchedulerWait->AsyncStop(); |
|
352 return; |
|
353 } |
|
354 } |
|
355 |
|
356 /** |
|
357 Overrides the pure virtual MLbsSuplPushObserver::OnSuplInitComplete. Receives message delivery |
|
358 notifications. |
|
359 |
|
360 @param aChannel [In] The channel the call-back is related to. |
|
361 @param aReqId [In] An Id of the request the call-back is related to. |
|
362 @param aError [In] KErrNone if successful, KErrTimeout if it was not possible to deliver |
|
363 the request before the timeout period, KErrArgument if the structure |
|
364 or content of the SUPL INIT message was incorrect. |
|
365 Any system wide error code otherwise. |
|
366 @param aReserved [In] Reserved for future use. |
|
367 |
|
368 @see MLbsSuplPushObserver::OnSuplInitComplete |
|
369 @see CLbsSuplPush |
|
370 */ |
|
371 void CTe_LbsSuplSmsTriggerIntegStep::OnSuplInitComplete(TLbsSuplPushChannel aChannel, |
|
372 TLbsSuplPushRequestId /*aReqId*/, TInt /*aError*/, TInt /*aReserved*/) |
|
373 { |
|
374 |
|
375 if(aChannel!=ELbsSuplPushChannelSMS) |
|
376 { |
|
377 ERR_PRINTF1(_L("CTe_LbsSuplSmsTriggerIntegStep::OnSuplInit: aChannel!=ELbsSuplPushChannelSMS")); |
|
378 iUnexpectedError = KErrGeneral;; |
|
379 iSchedulerWait->AsyncStop(); |
|
380 return; |
|
381 } |
|
382 |
|
383 iMsgCount++; |
|
384 |
|
385 if(iMsgCount==iMsgMaxCount) |
|
386 { |
|
387 iSchedulerWait->AsyncStop(); |
|
388 } |
|
389 } |
|
390 |
|
391 /** |
|
392 Generates and sends a UDP message using the CTe_LbsSuplSmsTriggerSender object. |
|
393 |
|
394 @param aNum [In] The number used to fill the message. |
|
395 |
|
396 @see CTe_LbsSuplSmsTriggerIntegStep::OnMessageSent |
|
397 @see CTe_LbsSuplSmsTriggerIntegStep::CompareMessage |
|
398 */ |
|
399 void CTe_LbsSuplSmsTriggerIntegStep::SendMessage(TUint aNum) |
|
400 { |
|
401 INFO_PRINTF2(_L("CTe_LbsSuplSmsTriggerIntegStep::SendMessage: msg %d"), aNum); |
|
402 aNum = aNum%10; |
|
403 iMessage.Zero(); |
|
404 TInt maxLength = iMessage.MaxLength(); |
|
405 for(TInt i=0;i<maxLength;i++) |
|
406 { |
|
407 iMessage.AppendNum(aNum); |
|
408 } |
|
409 |
|
410 iMessage[0] = 0; |
|
411 iMessage[1] = 0; |
|
412 |
|
413 // set the encoded length field |
|
414 iMessage[0] |= (TUint8)( maxLength >> 8 ); |
|
415 iMessage[1] |= (TUint8)( maxLength ); |
|
416 |
|
417 iSender->SendMessage(iMessage); |
|
418 } |
|
419 |
|
420 |
|
421 /** |
|
422 Generates a message using the pattern specified and compares it with the given message. |
|
423 |
|
424 @param aNum [In] The number used to fill the generated message. |
|
425 |
|
426 @return ETrue if the messages are identical, EFalse otherwise. |
|
427 |
|
428 @see CTe_LbsSuplSmsTriggerIntegStep::OnSuplInit |
|
429 @see CTe_LbsSuplSmsTriggerIntegStep::SendMessage |
|
430 */ |
|
431 TBool CTe_LbsSuplSmsTriggerIntegStep::CompareMessage(TUint aNum, TDesC8& aMsg) |
|
432 { |
|
433 aNum = aNum%10; |
|
434 iMessage.Zero(); |
|
435 TInt maxLength = iMessage.MaxLength(); |
|
436 for(TInt i=0;i<maxLength;i++) |
|
437 { |
|
438 iMessage.AppendNum(aNum); |
|
439 } |
|
440 |
|
441 iMessage[0] = 0; |
|
442 iMessage[1] = 0; |
|
443 |
|
444 // set the encoded length field |
|
445 iMessage[0] |= (TUint8)( maxLength >> 8 ); |
|
446 iMessage[1] |= (TUint8)( maxLength ); |
|
447 |
|
448 if(aMsg.Compare(iMessage)==0) |
|
449 { |
|
450 return ETrue; |
|
451 } |
|
452 ERR_PRINTF1(_L("CTe_LbsSuplSmsTriggerIntegStep::CompareMessage: aMsg!=iMessage")); |
|
453 return EFalse; |
|
454 } |
|
455 |
|
456 |