|
1 // Copyright (c) 2001-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 contains CTestCase which is the base class for all the TestCase DLLs |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <dummyetel.h> // include here to avoid picking up the real etel.h |
|
21 #include <etelmm.h> |
|
22 |
|
23 // Test system includes |
|
24 #include "log.h" |
|
25 #include "teststep.h" |
|
26 #include "TestStepCsdAgt.h" |
|
27 #include "TestSuiteCsdAgt.h" |
|
28 |
|
29 // EConnectionOpen |
|
30 #include <csdprog.h> |
|
31 |
|
32 // Set CDMA or GPRS mode |
|
33 #include "DbUndo.h" |
|
34 |
|
35 // CTestStepCsdAgt |
|
36 |
|
37 /** |
|
38 * Constructor. |
|
39 * |
|
40 */ |
|
41 CTestStepCsdAgt::CTestStepCsdAgt(TPtrC aName) |
|
42 { |
|
43 iTestStepName=aName; |
|
44 // Always start with test stage zero |
|
45 iStage = 0; |
|
46 } |
|
47 |
|
48 /** |
|
49 * Second phase constructor. |
|
50 * |
|
51 */ |
|
52 void CTestStepCsdAgt::ConstructL() |
|
53 { |
|
54 iDlgSvr = new(ELeave)CDialogServer(); |
|
55 } |
|
56 |
|
57 /** |
|
58 * Destructor. |
|
59 * |
|
60 */ |
|
61 CTestStepCsdAgt::~CTestStepCsdAgt() |
|
62 { |
|
63 delete iDlgSvr; |
|
64 } |
|
65 |
|
66 /** |
|
67 * doTestStep is called by the framework to execute a test step |
|
68 * It performs some initialisation steps common to all CSD.Agt tests |
|
69 * before calling the doCsdAgtTestStep() function overridden in |
|
70 * the derived class. |
|
71 * |
|
72 */ |
|
73 enum TVerdict CTestStepCsdAgt::doTestStepL( void ) |
|
74 { |
|
75 TInt processHandleCountBefore; |
|
76 TInt threadHandleCountBefore; |
|
77 TInt reqsBefore; |
|
78 |
|
79 TInt processHandleCountAfter; |
|
80 TInt threadHandleCountAfter; |
|
81 TInt reqsAfter; |
|
82 TBool bResult; |
|
83 |
|
84 reqsBefore= RThread().RequestCount(); |
|
85 RThread().HandleCount(processHandleCountBefore, threadHandleCountBefore); |
|
86 |
|
87 // Create an active scheduler on the heap before the test |
|
88 CActiveScheduler *activeScheduler = new(ELeave) CActiveScheduler; |
|
89 CleanupStack::PushL(activeScheduler); |
|
90 CActiveScheduler::Install(activeScheduler); |
|
91 |
|
92 if(!iDlgSvr) |
|
93 ConstructL(); |
|
94 |
|
95 __UHEAP_MARK; |
|
96 |
|
97 bResult = iDlgSvr->Open(); |
|
98 if (bResult == EFalse) |
|
99 { |
|
100 Log(_L("Cannot connect to Dialog Server")); |
|
101 return EFail; |
|
102 } |
|
103 |
|
104 iDlgSvr->RequestDialogAppearanceNotification(this); |
|
105 |
|
106 // Do the test |
|
107 iResult = doCsdAgtTestStepL(); |
|
108 iDlgSvr->Close(); |
|
109 |
|
110 DelayL(2000000); |
|
111 |
|
112 __UHEAP_MARKEND; |
|
113 |
|
114 // delete the active scheduler |
|
115 CleanupStack::PopAndDestroy(activeScheduler); |
|
116 |
|
117 reqsAfter= RThread().RequestCount(); |
|
118 RThread().HandleCount(processHandleCountAfter, threadHandleCountAfter); |
|
119 |
|
120 |
|
121 TESTL(reqsAfter == reqsBefore); |
|
122 TESTL(threadHandleCountAfter == threadHandleCountBefore); |
|
123 //TESTL(processHandleCountAfter == processHandleCountBefore); |
|
124 |
|
125 return iResult; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Notification is called by PSDAGT when it needs to pass an event to NIFMAN |
|
130 * The call is passed up to here by our CNifAgentRefN1. |
|
131 * |
|
132 */ |
|
133 TInt CTestStepCsdAgt::Notification(TAgentToNifEventType aEvent, TAny* /*aInfo*/) |
|
134 { |
|
135 // This calls the appropriate handler function |
|
136 if(aEvent == EAgentToNifEventTypeDisableConnection) |
|
137 { |
|
138 CsdAgtDisconnectRequest(); |
|
139 } |
|
140 |
|
141 return 0; |
|
142 } |
|
143 |
|
144 /** |
|
145 * Called by Notification function when a EAgentToNifEventTypeDisableConnection |
|
146 * event is received. Should override in derived classes when this request is |
|
147 * expected in the test scenario |
|
148 * |
|
149 */ |
|
150 void CTestStepCsdAgt::CsdAgtDisconnectRequest() |
|
151 { |
|
152 // We're not expecting receive this unless the test case calls for it in |
|
153 // which case the derived class should override this function |
|
154 Log(_L("Unexpected Disconnect Request from CSDAGT")); |
|
155 TESTE(FALSE,KErrNone); |
|
156 } |
|
157 |
|
158 /** |
|
159 * DialogHasAppeared is called by the dummy dialog server |
|
160 * to inform the test case that a dialog has been presented |
|
161 */ |
|
162 void CTestStepCsdAgt::DialogHasAppeared() |
|
163 { |
|
164 // Should not get here in the default implementation of this function |
|
165 Log(_L("Unexpected dialog box")); |
|
166 TEST(FALSE); |
|
167 } |
|
168 |
|
169 |
|
170 void CTestStepCsdAgt::AgentProgress(TInt , TInt ) |
|
171 { |
|
172 // Normally don't care about AgentProgress messages, override when we do care |
|
173 } |
|
174 |
|
175 /** |
|
176 * Allows other active objects to run while waiting for the specified time. |
|
177 * |
|
178 */ |
|
179 void CTestStepCsdAgt::DelayL(TInt aMicroseconds) |
|
180 { |
|
181 // Construct and start the timer |
|
182 TCallBack callbackfn(CTestStepCsdAgt::TimerCallback, this); |
|
183 CPeriodic *regularUpdater = CPeriodic::NewL(CActive::EPriorityStandard); |
|
184 CleanupStack::PushL(regularUpdater); |
|
185 regularUpdater->Start(aMicroseconds,aMicroseconds,callbackfn); |
|
186 |
|
187 // Block until timer complete |
|
188 CActiveScheduler::Start(); |
|
189 |
|
190 // Stop and delete the timer |
|
191 regularUpdater->Cancel(); |
|
192 CleanupStack::PopAndDestroy(); |
|
193 } |
|
194 |
|
195 /** |
|
196 * The callback for the DelayL function. |
|
197 * |
|
198 */ |
|
199 TInt CTestStepCsdAgt::TimerCallback(TAny *) |
|
200 { |
|
201 // Unblock the TAgt::DelayL() function |
|
202 CActiveScheduler::Stop(); |
|
203 return 0; |
|
204 } |
|
205 |
|
206 /** |
|
207 * Set GSM mode. |
|
208 * |
|
209 */ |
|
210 void CTestStepCsdAgt::SetGSMModeL(MAgtNotify &aAgtNotify) |
|
211 { |
|
212 aAgtNotify.SetMode(RTelServer::ENetworkModeGsm); |
|
213 |
|
214 // Open database |
|
215 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
216 CMDBSession* session = CMDBSession::NewL(KCDVersion1_2); |
|
217 #else |
|
218 CMDBSession* session = CMDBSession::NewL(KCDVersion1_1); |
|
219 #endif |
|
220 CleanupStack::PushL(session); |
|
221 |
|
222 // Open outgoing Connection Prefs table |
|
223 CCDConnectionPrefsRecord* connpref = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
224 CleanupStack::PushL(connpref); |
|
225 |
|
226 connpref->iDirection = ECommDbConnectionDirectionOutgoing; |
|
227 if(!connpref->FindL(*session)) |
|
228 { |
|
229 // ignore result as original code, couple of lines above table->GotoFirstRecord(); |
|
230 } |
|
231 |
|
232 // Change IAP to GSM |
|
233 |
|
234 CCDIAPRecord* iap = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord)); |
|
235 CleanupStack::PushL(iap); |
|
236 |
|
237 iap->SetRecordId(KDialOutIAPIndex); |
|
238 if(!iap->FindL(*session)) |
|
239 { |
|
240 // ignore result as original code, couple of lines above table->GotoFirstRecord(); |
|
241 } |
|
242 |
|
243 connpref->iDefaultIAP = iap->RecordId(); |
|
244 connpref->ModifyL(*session); |
|
245 |
|
246 // Cleanup |
|
247 CleanupStack::PopAndDestroy(iap); |
|
248 CleanupStack::PopAndDestroy(connpref); |
|
249 CleanupStack::PopAndDestroy(session); |
|
250 } |
|
251 |
|
252 /** |
|
253 * Set GPRS mode. |
|
254 * |
|
255 */ |
|
256 void CTestStepCsdAgt::SetGPRSModeL(MAgtNotify &aAgtNotify) |
|
257 { |
|
258 aAgtNotify.SetMode(RTelServer::ENetworkModeGsm); |
|
259 |
|
260 // Open database |
|
261 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
262 CMDBSession* session = CMDBSession::NewL(KCDVersion1_2); |
|
263 #else |
|
264 CMDBSession* session = CMDBSession::NewL(KCDVersion1_1); |
|
265 #endif |
|
266 CleanupStack::PushL(session); |
|
267 |
|
268 // Open outgoing Connection Prefs table |
|
269 CCDConnectionPrefsRecord* connpref = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
270 CleanupStack::PushL(connpref); |
|
271 |
|
272 connpref->iDirection = ECommDbConnectionDirectionOutgoing; |
|
273 if(connpref->FindL(*session)) |
|
274 { |
|
275 User::Leave(KErrNotFound); |
|
276 } |
|
277 |
|
278 // Change IAP to GPRS |
|
279 |
|
280 CCDIAPRecord* iap = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord)); |
|
281 CleanupStack::PushL(iap); |
|
282 |
|
283 iap->SetRecordId(KGprsIAPIndex); |
|
284 if(iap->FindL(*session)) |
|
285 { |
|
286 User::Leave(KErrNotFound); |
|
287 } |
|
288 |
|
289 connpref->iDefaultIAP = iap->RecordId(); |
|
290 connpref->ModifyL(*session); |
|
291 |
|
292 // Cleanup |
|
293 CleanupStack::PopAndDestroy(iap); |
|
294 CleanupStack::PopAndDestroy(connpref); |
|
295 CleanupStack::PopAndDestroy(session); |
|
296 } |
|
297 |
|
298 |
|
299 /** |
|
300 * NormalConnect is a utility function to connect and disconnect using an Agent |
|
301 * |
|
302 * The preconditions for this function are assumed to be set so that |
|
303 * a connection attempt will be successful. Any error will be reported to |
|
304 * the test framework as a failed test case |
|
305 * |
|
306 */ |
|
307 void CTestStepCsdAgt::NormalConnectL() |
|
308 { |
|
309 TInt err; |
|
310 TInt stage; |
|
311 CNifAgentRefN1 *agent; |
|
312 |
|
313 // Construct a new Dummy Nifman Instance |
|
314 Log(_L("Loading DUMMYNIF.DLL")); |
|
315 |
|
316 agent = CNifAgentRefN1::NewL(this); |
|
317 CleanupStack::PushL(agent); |
|
318 |
|
319 // Attempt connection |
|
320 Log(_L("Connecting...")); |
|
321 agent->Connect(); |
|
322 |
|
323 // Check for an error code |
|
324 agent->GetCompletionCode(err); |
|
325 TESTEL(err==KErrNone,err); |
|
326 |
|
327 // Check ConnectComplete was reported at the correct stage in the state machine |
|
328 agent->GetProgressStage(stage); |
|
329 TESTEL(stage==ECsdConnectionOpen,stage); |
|
330 |
|
331 Log(_L("Connect Succeeded")); |
|
332 |
|
333 DelayL(2000000); |
|
334 |
|
335 // Disconnect |
|
336 Log(_L("Disconnecting")); |
|
337 agent->Disconnect(); |
|
338 |
|
339 // Check for an error code |
|
340 agent->GetCompletionCode(err); |
|
341 TESTEL(err==KErrNone,err); |
|
342 Log(_L("Disconnect Successful")); |
|
343 |
|
344 |
|
345 // Finished with Dummy Nifman so delete it |
|
346 CleanupStack::PopAndDestroy(agent); |
|
347 Log(_L("DUMMYNIF.DLL Unloaded")); |
|
348 |
|
349 } |
|
350 |
|
351 /** |
|
352 * ReConnect is a utility function to connect and disconnect using an Agt. |
|
353 * |
|
354 * The preconditions for this function are assumed to be set so that |
|
355 * a connection attempt will be successful. Any error will be reported to |
|
356 * the test framework as a failed test case |
|
357 * |
|
358 */ |
|
359 void CTestStepCsdAgt::ReConnectL() |
|
360 { |
|
361 TInt err; |
|
362 TInt stage; |
|
363 CNifAgentRefN1 *agent; |
|
364 |
|
365 // Construct a new Dummy Nifman Instance |
|
366 Log(_L("Loading DUMMYNIF.DLL")); |
|
367 agent = CNifAgentRefN1::NewL(this); |
|
368 CleanupStack::PushL(agent); |
|
369 |
|
370 // Attempt connection |
|
371 Log(_L("Connecting...")); |
|
372 agent->Connect(); |
|
373 |
|
374 // Check for an error code |
|
375 agent->GetCompletionCode(err); |
|
376 TESTEL(err==KErrNone,err); |
|
377 |
|
378 // Check ConnectComplete was reported at the correct stage in the state machine |
|
379 agent->GetProgressStage(stage); |
|
380 TESTEL(stage==ECsdConnectionOpen,stage); |
|
381 |
|
382 Log(_L("Connect Succeeded")); |
|
383 |
|
384 DelayL(2000000); |
|
385 |
|
386 // Attempt connection |
|
387 Log(_L("Reconnecting...")); |
|
388 agent->ReConnect(); |
|
389 |
|
390 // Check for an error code |
|
391 agent->GetCompletionCode(err); |
|
392 TESTEL(err==KErrNone,err); |
|
393 |
|
394 // Check ConnectComplete was reported at the correct stage in the state machine |
|
395 agent->GetProgressStage(stage); |
|
396 TESTEL(stage==ECsdConnectionOpen,stage); |
|
397 |
|
398 Log(_L("Reconnect successful")); |
|
399 |
|
400 DelayL(2000000); |
|
401 |
|
402 // Disconnect |
|
403 Log(_L("Disconnecting...")); |
|
404 agent->Disconnect(); |
|
405 |
|
406 // Check for an error code |
|
407 agent->GetCompletionCode(err); |
|
408 TESTEL(err==KErrNone,err); |
|
409 |
|
410 Log(_L("Disconnect successful")); |
|
411 |
|
412 // Finished with Dummy Nifman so delete it |
|
413 CleanupStack::PopAndDestroy(agent); |
|
414 Log(_L("DUMMYNIF.DLL Unloaded")); |
|
415 } |
|
416 |
|
417 /** |
|
418 * ConnectExpectError is a utility function to connect and disconnect using an Agt |
|
419 * |
|
420 * The preconditions for this function are assumed to be set so that |
|
421 * a connection attempt will fail with the error passed to the function and |
|
422 * at the stage passed to the function. |
|
423 * |
|
424 */ |
|
425 void CTestStepCsdAgt::ConnectExpectErrorL(TInt aError, TInt aStage) |
|
426 { |
|
427 TInt err; |
|
428 TInt stage; |
|
429 CNifAgentRefN1 *agent; |
|
430 |
|
431 // Construct a new Dummy Nifman Instance |
|
432 Log(_L("Loading DUMMYNIF.DLL")); |
|
433 agent = CNifAgentRefN1::NewL(this); |
|
434 CleanupStack::PushL(agent); |
|
435 |
|
436 // Attempt connection |
|
437 Log(_L("Connecting...")); |
|
438 agent->Connect(); |
|
439 |
|
440 // Check result codes |
|
441 agent->GetCompletionCode(err); |
|
442 // If the connection (wrongly) goes ahead without detecting an error, we have to leave, |
|
443 // but if we just return the unexpected KErrNone, the caller will think everything's |
|
444 // OK. Make sure that if we have got a KErrNone, we return something else, so that it |
|
445 // gets spotted as a test failure. |
|
446 if (err == KErrNone) |
|
447 TESTEL(err==aError,KErrGeneral); |
|
448 else |
|
449 TESTEL(err==aError,err); |
|
450 |
|
451 // Check ConnectComplete was reported at the correct stage in the state machine |
|
452 agent->GetProgressStage(stage); |
|
453 TESTEL(stage==aStage,stage); |
|
454 |
|
455 Log(_L("Connect failed as expected")); |
|
456 |
|
457 DelayL(2000000); |
|
458 |
|
459 // Disconnect |
|
460 Log(_L("Disconnecting...")); |
|
461 agent->Disconnect(); |
|
462 |
|
463 // Check result code |
|
464 agent->GetCompletionCode(err); |
|
465 TESTEL(err==KErrNone,err); |
|
466 Log(_L("Disconnect successful")); |
|
467 |
|
468 // Finished with Dummy Nifman so delete it |
|
469 CleanupStack::PopAndDestroy(agent); |
|
470 Log(_L("DUMMYNIF.DLL Unloaded")); |
|
471 } |
|
472 |
|
473 /** |
|
474 * Connect, and block execution, ie. wait for an asyncronous request |
|
475 * |
|
476 * The response function for the asyncronous callback should unblock |
|
477 * |
|
478 */ |
|
479 void CTestStepCsdAgt::ConnectAndWaitForAsyncronousRequestL() |
|
480 { |
|
481 TInt err; |
|
482 TInt stage; |
|
483 CNifAgentRefN1 *agent; |
|
484 |
|
485 // Construct a new Dummy Nifman Instance |
|
486 Log(_L("Loading DUMMYNIF.DLL")); |
|
487 agent = CNifAgentRefN1::NewL(this); |
|
488 CleanupStack::PushL(agent); |
|
489 |
|
490 // Attempt connection |
|
491 Log(_L("Connecting...")); |
|
492 agent->Connect(); |
|
493 |
|
494 // Check result codes |
|
495 agent->GetCompletionCode(err); |
|
496 TESTEL(err==KErrNone,err); |
|
497 |
|
498 // Check ConnectComplete was reported at the correct stage in the state machine |
|
499 agent->GetProgressStage(stage); |
|
500 TESTEL(stage==ECsdConnectionOpen,stage); |
|
501 |
|
502 Log(_L("Connect Successful")); |
|
503 Log(_L("Wait for EAgentToNifEventTypeGetDataTransfer event")); |
|
504 |
|
505 DelayL(2000000); |
|
506 |
|
507 iStage++; // increment stage so we know that we are connected |
|
508 |
|
509 // Block until request arrives |
|
510 CActiveScheduler::Start(); |
|
511 |
|
512 DelayL(2000000); |
|
513 |
|
514 // Disconnect |
|
515 Log(_L("Disconnecting...")); |
|
516 agent->Disconnect(); |
|
517 |
|
518 // Check result code |
|
519 agent->GetCompletionCode(err); |
|
520 TESTEL(err==KErrNone,err); |
|
521 Log(_L("Disconnect Successful")); |
|
522 |
|
523 // Finished with Dummy Nifman so delete it |
|
524 CleanupStack::PopAndDestroy(agent); |
|
525 Log(_L("DUMMYNIF.DLL Unloaded")); |
|
526 } |
|
527 |
|
528 /** |
|
529 * NormalConnectDisconnectExpectsError is a utility function to connect and disconnect using an Agt. |
|
530 * |
|
531 * The preconditions for this function are assumed to be set so that a connection |
|
532 * attempt will succeed, but disconnect will fail with the error passed to the |
|
533 * method and at the stage passed to the method. |
|
534 * |
|
535 */ |
|
536 void CTestStepCsdAgt::NormalConnectDisconnectExpectsErrorL(TInt aError, TInt aStage) |
|
537 { |
|
538 TInt err; |
|
539 TInt stage; |
|
540 CNifAgentRefN1 *agent; |
|
541 |
|
542 // Construct a new Dummy Nifman Instance |
|
543 Log(_L("Loading DUMMYNIF.DLL")); |
|
544 agent = CNifAgentRefN1::NewL(this); |
|
545 CleanupStack::PushL(agent); |
|
546 |
|
547 // Attempt connection |
|
548 Log(_L("Connecting...")); |
|
549 agent->Connect(); |
|
550 |
|
551 // Check result codes |
|
552 agent->GetCompletionCode(err); |
|
553 TESTEL(err==KErrNone,err); |
|
554 |
|
555 // Check ConnectComplete was reported at the correct stage in the state machine |
|
556 agent->GetProgressStage(stage); |
|
557 TESTEL(stage==ECsdConnectionOpen,stage); |
|
558 |
|
559 // Disconnect |
|
560 DelayL(2000000); |
|
561 |
|
562 // Disconnect |
|
563 Log(_L("Disconnecting...")); |
|
564 agent->Disconnect(); |
|
565 |
|
566 // Check result code |
|
567 agent->GetCompletionCode(err); |
|
568 TESTEL(err!=KErrNone,aError); |
|
569 Log(_L("Disconnect Successful")); |
|
570 |
|
571 // Check the correct stage in the state machine |
|
572 agent->GetProgressStage(stage); |
|
573 TESTEL(stage!=ECsdConnectionOpen,aStage); |
|
574 |
|
575 // Finished with Dummy Nifman so delete it |
|
576 CleanupStack::PopAndDestroy(agent); |
|
577 Log(_L("DUMMYNIF.DLL Unloaded")); |
|
578 } |