|
1 // Copyright (c) 2008-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 // TVIEW1 |
|
15 // Tests integration of view architecture throughout the ViewSrv, Cone, Apparc, Uikon and RefUI layers. |
|
16 // Tests basic view switching and appUi embedding. Tests various exceptional view switch conditions |
|
17 // including OOM during activation, attempts to start missing apps, tests panics while idle, while |
|
18 // activating and while deactivating and very slow activations and deactivations. |
|
19 // Includes test of a waiting activation - an abuse of the architecture |
|
20 // Should be used with companion test app TVIEW2 which provides the target view for each test view switch. |
|
21 // Regression test for EDNMMAT-4L3QZH 'Bad things happen if an application that has called NotifyNextActivation() dies' |
|
22 // - TVIEW1 registers a view activation observer which keeps an outstanding request for view activation notification. |
|
23 // Regression test for DOE-4SSJUR 'ViewSrv can miss notification of change of focused window group' - TVIEW1 creates an |
|
24 // event to activate a view in TVIEW2, waits for 0.5s to allow this activation to be half processed, then brings itself |
|
25 // back into foreground. The foreground task cross-check should then fail and a new activation event should be created for |
|
26 // TVIEW1. |
|
27 // TVIEW1 can be used for stress testing the view arc by setting up queues of events while doing |
|
28 // the longer tests and killing random apps etc. |
|
29 // An endurance auto test runs a series of random activations of any of the views in TVIEW1,TVIEW2 and TVIEW3 timed at short |
|
30 // varying intervals and continuing forever - TVIEW2 and TVIEW3 also generate similar activation requests |
|
31 // The endurance test can also be run with TVIEW1 set to sporadically kill TVIEW2 and TVIEW3, and for TVIEW1 and TVIEW2 to |
|
32 // occasionally exit, to test interactions between view activations and app starts and stops |
|
33 // |
|
34 // |
|
35 |
|
36 /** |
|
37 @file |
|
38 @internalComponent - Internal Symbian test code |
|
39 */ |
|
40 #include <e32math.h> |
|
41 #include <barsread.h> |
|
42 #include <gulalign.h> |
|
43 #include <txtrich.h> |
|
44 #include <apgtask.h> |
|
45 #include <apgcli.h> |
|
46 #include <viewcli.h> |
|
47 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
48 #include <viewclipartner.h> |
|
49 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
50 |
|
51 #include <techview/eiktxlbx.h> |
|
52 #include <techview/eiktxlbm.h> |
|
53 #include <techview/eiklabel.h> |
|
54 #include <techview/eikcmbut.h> |
|
55 #include <techview/eikbtpan.h> |
|
56 #include <techview/eikmenub.h> |
|
57 #include <techview/eikdialg.h> |
|
58 #include <eikdll.h> |
|
59 #include <eiksvdef.h> |
|
60 #include <techview/eikrted.h> |
|
61 #include <techview/eikwbtb.h> |
|
62 #include <eikenv.h> |
|
63 #include <eikstart.h> |
|
64 |
|
65 #include <techview/eikon.hrh> |
|
66 #include <techview/eikon.rsg> |
|
67 |
|
68 #include <tview1.rsg> |
|
69 |
|
70 #include "tview1.H" |
|
71 #include "tview1.HRH" |
|
72 #include "tvwuids.H" |
|
73 |
|
74 #define VIEW_ONE TVwsViewId(KUidViewAppOne,KUidViewOne) |
|
75 #define VIEW_TWO TVwsViewId(KUidViewAppOne,KUidViewTwo) |
|
76 #define APP_TEXT _L("TVIEW1") |
|
77 |
|
78 // |
|
79 // EXPORTed functions |
|
80 // |
|
81 |
|
82 LOCAL_C CApaApplication* NewApplication() |
|
83 { |
|
84 return new CTestApplication; |
|
85 } |
|
86 |
|
87 GLDEF_C TInt E32Main() |
|
88 { |
|
89 return EikStart::RunApplication(NewApplication); |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 // |
|
95 // CTestApplication |
|
96 // |
|
97 |
|
98 TUid CTestApplication::AppDllUid() const |
|
99 { |
|
100 return KUidViewAppOne; |
|
101 } |
|
102 |
|
103 CApaDocument* CTestApplication::CreateDocumentL() |
|
104 { |
|
105 return new (ELeave) CTestDocument(*this); |
|
106 } |
|
107 |
|
108 |
|
109 // |
|
110 // CTestDocument |
|
111 // |
|
112 |
|
113 CTestDocument::CTestDocument(CEikApplication& aApp) |
|
114 : CEikDocument(aApp) |
|
115 { |
|
116 } |
|
117 |
|
118 CEikAppUi* CTestDocument::CreateAppUiL() |
|
119 { |
|
120 return new(ELeave) CTestAppUi; |
|
121 } |
|
122 |
|
123 |
|
124 // |
|
125 // CTestSwitchDialog. |
|
126 // |
|
127 |
|
128 CTestSwitchDialog::~CTestSwitchDialog() |
|
129 { |
|
130 } |
|
131 |
|
132 CTestSwitchDialog::CTestSwitchDialog(CTestAppUi& aAppUi) : iAppUi(aAppUi) |
|
133 { |
|
134 } |
|
135 |
|
136 TBool CTestSwitchDialog::OkToExitL(TInt aButtonId) |
|
137 { |
|
138 if (aButtonId!=EEikBidOk) |
|
139 return EFalse; |
|
140 |
|
141 switch (ChoiceListCurrentItem(ESwitchDlg_ViewChoice)) |
|
142 { |
|
143 case 0: |
|
144 iAppUi.iViewToActivate.iViewUid=KUidViewOne; |
|
145 break; |
|
146 case 1: |
|
147 iAppUi.iViewToActivate.iViewUid=KUidViewTwo; |
|
148 break; |
|
149 default: |
|
150 break; |
|
151 } |
|
152 |
|
153 if (ChoiceListCurrentItem(ESwitchDlg_AppChoice)==0) |
|
154 { |
|
155 iAppUi.iViewToActivate.iAppUid=KUidViewAppOne; |
|
156 } |
|
157 else if (ChoiceListCurrentItem(ESwitchDlg_AppChoice)==1) |
|
158 { |
|
159 iAppUi.iViewToActivate.iAppUid=KUidViewAppTwo; |
|
160 } |
|
161 |
|
162 delete iAppUi.iCustomMsg; |
|
163 iAppUi.iCustomMsg=HBufC::NewL(STATIC_CAST(CEikEdwin*,Control(ESwitchDlg_CustomMsg))->TextLength()); |
|
164 TPtr des=iAppUi.iCustomMsg->Des(); |
|
165 GetEdwinText(des,ESwitchDlg_CustomMsg); |
|
166 return ETrue; |
|
167 } |
|
168 |
|
169 // |
|
170 // CTestRichTextDialog |
|
171 // |
|
172 |
|
173 class CTestRichTextDialog : public CEikDialog |
|
174 { |
|
175 public: |
|
176 CTestRichTextDialog(CRichText*& aRichText,CParaFormatLayer*& aRichParaFormatLayer,CCharFormatLayer*& aRichCharFormatLayer); |
|
177 private: // framework |
|
178 void PreLayoutDynInitL(); |
|
179 TBool OkToExitL(TInt aKeycode); |
|
180 private: |
|
181 CRichText*& iRichText; |
|
182 CParaFormatLayer*& iRichParaFormatLayer; |
|
183 CCharFormatLayer*& iRichCharFormatLayer; |
|
184 }; |
|
185 |
|
186 |
|
187 CTestRichTextDialog::CTestRichTextDialog(CRichText*& aRichText,CParaFormatLayer*& aRichParaFormatLayer, |
|
188 CCharFormatLayer*& aRichCharFormatLayer) |
|
189 : iRichText(aRichText),iRichParaFormatLayer(aRichParaFormatLayer),iRichCharFormatLayer(aRichCharFormatLayer) |
|
190 {} |
|
191 |
|
192 |
|
193 void CTestRichTextDialog::PreLayoutDynInitL() |
|
194 { |
|
195 CEikRichTextEditor* ed=(CEikRichTextEditor*)Control(ERtextedDlg_Editor); |
|
196 ed->SetDocumentContentL(*iRichText); |
|
197 } |
|
198 |
|
199 TBool CTestRichTextDialog::OkToExitL(TInt /*aKeycode*/) |
|
200 { |
|
201 delete iRichText; |
|
202 delete iRichParaFormatLayer; |
|
203 delete iRichCharFormatLayer; |
|
204 CEikRichTextEditor* edwin=STATIC_CAST(CEikRichTextEditor*,Control(ERtextedDlg_Editor)); |
|
205 edwin->SetDocumentOwnership(CEikEdwin::EDoesNotOwnText); |
|
206 iRichText=edwin->RichText(); |
|
207 iRichText->SetPictureFactory(iRichText->PictureFactory(),NULL); |
|
208 iRichParaFormatLayer=((CParaFormatLayer*)iRichText->GlobalParaFormatLayer()); |
|
209 iRichCharFormatLayer=((CCharFormatLayer*)iRichText->GlobalCharFormatLayer()); |
|
210 return(ETrue); |
|
211 } |
|
212 |
|
213 |
|
214 // |
|
215 // CTestAppUi |
|
216 // |
|
217 |
|
218 CTestAppUi::~CTestAppUi() |
|
219 { |
|
220 delete iCustomMsg; |
|
221 delete iRichText; |
|
222 delete iRichParaFormatLayer; |
|
223 delete iRichCharFormatLayer; |
|
224 delete iViewActivationObserver; |
|
225 delete iAutoTestTimer; |
|
226 } |
|
227 |
|
228 const TInt KRandSeed=12345; |
|
229 |
|
230 CTestAppUi::CTestAppUi() |
|
231 : iRandSeed(KRandSeed), |
|
232 iDoKills(EFalse), |
|
233 iIsServerEventTimeOutEnabled(ETrue) |
|
234 { |
|
235 TTime time; |
|
236 time.HomeTime(); |
|
237 iRandSeed=time.Int64(); |
|
238 } |
|
239 |
|
240 void CTestAppUi::ConstructL() |
|
241 { |
|
242 CTestVwAppUi::ConstructL(); |
|
243 iRichParaFormatLayer=CEikonEnv::NewDefaultParaFormatLayerL(); |
|
244 iRichCharFormatLayer=CEikonEnv::NewDefaultCharFormatLayerL(); |
|
245 iRichText=CRichText::NewL(iRichParaFormatLayer,iRichCharFormatLayer); |
|
246 CreateViewsL(); |
|
247 iViewActivationObserver=new(ELeave) CTestViewActivationObserver(*this); |
|
248 iViewActivationObserver->ConstructL(); |
|
249 iAutoTestTimer=CPeriodic::NewL(0); |
|
250 } |
|
251 |
|
252 void CTestAppUi::DynInitMenuPaneL(TInt aMenuId,CEikMenuPane* aMenuPane) |
|
253 { |
|
254 if (aMenuId==R_VW_BASIC_MENU && iIsServerEventTimeOutEnabled) |
|
255 { |
|
256 aMenuPane->SetItemButtonState(EToggleTimeOutEnabled, EEikMenuItemSymbolOn); |
|
257 } |
|
258 } |
|
259 |
|
260 void CTestAppUi::CreateViewsL() |
|
261 { |
|
262 if (iViewsCreated) |
|
263 { |
|
264 RDebug::Print(_L("Views already created")); |
|
265 return; |
|
266 } |
|
267 |
|
268 AddViewL(VIEW_ONE); |
|
269 AddViewL(VIEW_TWO); |
|
270 STATIC_CAST(CTestView*,View(VIEW_TWO))->InitializeAsDefaultL(); |
|
271 RDebug::Print(_L("All views created")); |
|
272 iViewsCreated=ETrue; |
|
273 } |
|
274 |
|
275 void CTestAppUi::AddViewL(const TVwsViewId& aViewId) |
|
276 { |
|
277 RDebug::Print(_L("Creating %x..."),aViewId.iViewUid.iUid); |
|
278 CTestView* view=new(ELeave) CTestView(aViewId,*this); |
|
279 CleanupStack::PushL(view); |
|
280 view->ConstructL(); |
|
281 CTestVwAppUi::AddViewL(view); |
|
282 CleanupStack::Pop(); |
|
283 } |
|
284 |
|
285 void CTestAppUi::DisplaySwitchViewDialogL() |
|
286 { |
|
287 CEikDialog* dlg=new(ELeave) CTestSwitchDialog(*this); |
|
288 if (dlg->ExecuteLD(R_VW_VIEW_SWITCH_DIALOG)) |
|
289 { |
|
290 DoActivationL(); |
|
291 } |
|
292 } |
|
293 |
|
294 void CTestAppUi::HandleCommandL(TInt aCommand) |
|
295 { |
|
296 switch (aCommand) |
|
297 { |
|
298 case ESwitchView: |
|
299 DisplaySwitchViewDialogL(); |
|
300 break; |
|
301 case EDisplayRichText: |
|
302 DisplayRichTextDialogL(); |
|
303 break; |
|
304 case EEikCmdExit: |
|
305 Exit(); |
|
306 break; |
|
307 case EDisplayTaskList: |
|
308 CEikonEnv::Static()->DisplayTaskList(); |
|
309 break; |
|
310 case EActivationOOM: |
|
311 TestActivationOOML(); |
|
312 break; |
|
313 case ESuccesiveAllocFail: |
|
314 TestSuccesiveAllocFailL(); |
|
315 break; |
|
316 case EWaitingActivation: |
|
317 TestWaitingActivationL(); |
|
318 break; |
|
319 case EStartMissingApp: |
|
320 TestStartMissingAppL(); |
|
321 break; |
|
322 case EPanicedActivation: |
|
323 TestPanicedActivationL(); |
|
324 break; |
|
325 case EPanicedDeactivation: |
|
326 TestPanicedDeactivationL(); |
|
327 break; |
|
328 case ESlowActivation: |
|
329 TestSlowActivationL(); |
|
330 break; |
|
331 case ESlowDeactivation: |
|
332 TestSlowDeactivationL(); |
|
333 break; |
|
334 case EEnduranceTest : |
|
335 TestServerEnduranceL(); |
|
336 break; |
|
337 case EEnduranceWithKillsTest : |
|
338 TestServerEnduranceWithKillsL(); |
|
339 break; |
|
340 case EExitAndDoubleActivaiton : |
|
341 TestExitAndDoubleActivationL(); |
|
342 break; |
|
343 case EActivateInsideViewActivated : |
|
344 TestActivateInsideViewActivatedL(); |
|
345 break; |
|
346 case EWaitOnAppStart : |
|
347 TestWaitOnAppStartL(); |
|
348 break; |
|
349 case EForegroundChange : |
|
350 TestForegroundChangeWhileEventsOnQueueL(); |
|
351 break; |
|
352 case ECheckForegroundChange : |
|
353 CheckForegroundChangeWhileEventsOnQueue(); |
|
354 break; |
|
355 case EToggleTimeOutEnabled : |
|
356 TestToggleTimeOutEnabledL(); |
|
357 break; |
|
358 default: |
|
359 if (ActiveView()) |
|
360 ActiveView()->HandleCommandL(aCommand); |
|
361 else |
|
362 RDebug::Print(_L("No active view")); |
|
363 break; |
|
364 } |
|
365 } |
|
366 |
|
367 void CTestAppUi::DisplayRichTextDialogL() |
|
368 { |
|
369 CEikDialog* dialog=new(ELeave) CTestRichTextDialog(iRichText,iRichParaFormatLayer,iRichCharFormatLayer); |
|
370 dialog->ExecuteLD(R_VW_RTEXTED_DIALOG); |
|
371 } |
|
372 |
|
373 void CTestAppUi::DoActivationL() |
|
374 { |
|
375 if (iCustomMsg->Length()) |
|
376 { |
|
377 ActivateViewL(iViewToActivate,KUidTestCustomMesssageId,*iCustomMsg); |
|
378 } |
|
379 else |
|
380 { |
|
381 TVwsViewId viewId; |
|
382 CCoeAppUi::SetCustomControl(ETrue); |
|
383 CCoeAppUi::GetActiveViewId(viewId); |
|
384 CCoeAppUi::ActivateViewL(iViewToActivate); |
|
385 CCoeAppUi::GetActiveViewId(viewId); |
|
386 } |
|
387 } |
|
388 |
|
389 void CTestAppUi::TestSuccesiveAllocFailL() |
|
390 { |
|
391 RDebug::Print(_L("TVIEW1 : Test Succesive Alloc Failure During Activation Until Success")); |
|
392 TInt error=KErrUnknown; |
|
393 for(TInt fail=1;error!=KErrNone;fail++) |
|
394 { |
|
395 RDebug::Print(_L("TVIEW2 : Next Failure Test")); |
|
396 __UHEAP_FAILNEXT(fail);// fail on succesive allocations |
|
397 __UHEAP_MARK; |
|
398 TRAP(error,CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne))); |
|
399 __UHEAP_MARKEND; // Check nothing has alloc'd due to fail |
|
400 } |
|
401 __UHEAP_SETFAIL(RHeap::ENone,0);// turn failure off |
|
402 } |
|
403 |
|
404 void CTestAppUi::TestActivationOOML() |
|
405 { |
|
406 RDebug::Print(_L("TVIEW1 : Test Activation OOM")); |
|
407 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivationOOM,KNullDesC16); |
|
408 } |
|
409 |
|
410 void CTestAppUi::TestWaitingActivationL() |
|
411 { |
|
412 RDebug::Print(_L("TVIEW1 : Test Waiting Activation")); |
|
413 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidStartScheduler,KNullDesC16); |
|
414 } |
|
415 |
|
416 void CTestAppUi::TestPanicedActivationL() |
|
417 { |
|
418 RDebug::Print(_L("TVIEW1 : Test Paniced Activation")); |
|
419 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivationPanic,KNullDesC16); |
|
420 } |
|
421 |
|
422 void CTestAppUi::TestPanicedDeactivationL() |
|
423 { |
|
424 RDebug::Print(_L("TVIEW1 : Test Paniced Deactivation")); |
|
425 STATIC_CAST(CTestView*,View(VIEW_ONE))->iDeactivationPanic=ETrue; |
|
426 STATIC_CAST(CTestView*,View(VIEW_TWO))->iDeactivationPanic=ETrue; |
|
427 CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)); |
|
428 } |
|
429 |
|
430 void CTestAppUi::TestSlowActivationL() |
|
431 { |
|
432 RDebug::Print(_L("TVIEW1 : Test Slow Activation")); |
|
433 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidSlowActivation,KNullDesC16); |
|
434 } |
|
435 |
|
436 void CTestAppUi::TestSlowDeactivationL() |
|
437 { |
|
438 RDebug::Print(_L("TVIEW1 : Test Slow Deactivation")); |
|
439 STATIC_CAST(CTestView*,View(VIEW_ONE))->iSlowDeactivation=ETrue; |
|
440 STATIC_CAST(CTestView*,View(VIEW_TWO))->iSlowDeactivation=ETrue; |
|
441 CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)); |
|
442 } |
|
443 |
|
444 void CTestAppUi::TestServerEnduranceL() |
|
445 { |
|
446 RDebug::Print(_L("TVIEW1 : Test Server Endurance")); |
|
447 iDoKills=EFalse; |
|
448 DoNextEnduranceTestActivation(); |
|
449 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidEndurance,KNullDesC16); |
|
450 ActivateViewL(TVwsViewId(KUidViewAppThree,KUidViewOne),KUidEndurance,KNullDesC16); |
|
451 } |
|
452 |
|
453 void CTestAppUi::TestServerEnduranceWithKillsL() |
|
454 { |
|
455 RDebug::Print(_L("TVIEW1 : Test Server Endurance With Client Kills")); |
|
456 iDoKills=ETrue; |
|
457 DoNextEnduranceTestActivation(); |
|
458 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidEndurance,KNullDesC16); |
|
459 ActivateViewL(TVwsViewId(KUidViewAppThree,KUidViewOne),KUidEndurance,KNullDesC16); |
|
460 } |
|
461 |
|
462 void CTestAppUi::TestExitAndDoubleActivationL() |
|
463 { |
|
464 RDebug::Print(_L("TVIEW1 : Test Exit And Double Activation")); |
|
465 CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KNullUid,KNullDesC8); |
|
466 CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewTwo),KUidActivationExit,KNullDesC8); |
|
467 CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewTwo),KNullUid,KNullDesC8); |
|
468 } |
|
469 |
|
470 void CTestAppUi::TestActivateInsideViewActivatedL() |
|
471 { |
|
472 RDebug::Print(_L("TVIEW1 : Test Activate Inside ViewActivated")); |
|
473 ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivateAgain,KNullDesC16); |
|
474 } |
|
475 |
|
476 void CTestAppUi::TestWaitOnAppStartL() |
|
477 { |
|
478 RDebug::Print(_L("TVIEW1 : Test Wait On App Start")); |
|
479 |
|
480 RThread appThread; |
|
481 TRequestStatus status; |
|
482 TThreadId threadId; |
|
483 |
|
484 RApaLsSession ls; |
|
485 CleanupClosePushL(ls); |
|
486 User::LeaveIfError(ls.Connect()); |
|
487 TApaAppInfo info; |
|
488 User::LeaveIfError(ls.GetAppInfo(info,KUidViewAppTwo)); |
|
489 CleanupStack::PopAndDestroy(); // ls |
|
490 |
|
491 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); |
|
492 cmdLine->SetExecutableNameL(info.iFullName); |
|
493 cmdLine->SetCommandL(EApaCommandViewActivate); |
|
494 TFileName fName=_L("c:\\Documents\\"); |
|
495 TParsePtrC parse(info.iFullName); |
|
496 fName.Append(parse.Name()); |
|
497 cmdLine->SetDocumentNameL(fName); |
|
498 |
|
499 RApaLsSession lsSession; |
|
500 User::LeaveIfError(lsSession.Connect()); |
|
501 CleanupClosePushL(lsSession); |
|
502 threadId=User::LeaveIfError(lsSession.StartApp(*cmdLine, threadId)); |
|
503 CleanupStack::PopAndDestroy(&lsSession); |
|
504 CleanupStack::PopAndDestroy(); // cmdLine |
|
505 User::LeaveIfError(appThread.Open(threadId)); |
|
506 appThread.Logon(status); |
|
507 User::WaitForRequest(status); |
|
508 } |
|
509 |
|
510 void CTestAppUi::TestForegroundChangeWhileEventsOnQueueL() |
|
511 { |
|
512 RDebug::Print(_L("TVIEW1 : Test Foreground Change While Events On Queue")); |
|
513 // Activate a view in TView2 first to make sure that the app is available |
|
514 CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)); |
|
515 // Activate a view in TView1 to get into a known state so that we can do a check of the outcome of the real test |
|
516 CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewOne)); |
|
517 |
|
518 // Create an activation event for TView2 and stall long enough so that the event will be waiting for the deactivation |
|
519 // in this app. Then immediately bring this app into the foreground. |
|
520 CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KNullUid,KNullDesC8); |
|
521 User::After(50000); // 0.5 sec |
|
522 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
523 TApaTask task=taskList.FindApp(KUidViewAppOne); |
|
524 task.BringToForeground(); |
|
525 } |
|
526 |
|
527 void CTestAppUi::CheckForegroundChangeWhileEventsOnQueue() |
|
528 { |
|
529 TVwsViewId activeView; |
|
530 if (GetActiveViewId(activeView)!=KErrNotFound && activeView==TVwsViewId(KUidViewAppOne,KUidViewOne)) |
|
531 { |
|
532 iEikonEnv->InfoMsg(_L("Test passed")); |
|
533 } |
|
534 else |
|
535 { |
|
536 iEikonEnv->InfoMsg(_L("Test failed")); |
|
537 } |
|
538 } |
|
539 |
|
540 void CTestAppUi::TestToggleTimeOutEnabledL() |
|
541 { |
|
542 CVwsSessionWrapper* vwsSession=CVwsSessionWrapper::NewLC(); |
|
543 User::LeaveIfError(vwsSession->EnableServerEventTimeOut(!iIsServerEventTimeOutEnabled)); |
|
544 iIsServerEventTimeOutEnabled=(!iIsServerEventTimeOutEnabled); |
|
545 CleanupStack::PopAndDestroy(); |
|
546 } |
|
547 |
|
548 const TInt KMinimumDelay=50000; |
|
549 |
|
550 void CTestAppUi::DoNextEnduranceTestActivation() |
|
551 { |
|
552 if (iAutoTestTimer->IsActive()) |
|
553 iAutoTestTimer->Cancel(); |
|
554 |
|
555 TInt rand=0; |
|
556 if (iDoKills) |
|
557 { |
|
558 // Occasionally we kill another TVIEW |
|
559 TUid killAppUid=KNullUid; |
|
560 rand=Math::Rand(iRandSeed); |
|
561 if (rand<=KMaxTInt/8) // 1 in 8 chance |
|
562 { |
|
563 killAppUid=KUidViewAppTwo; |
|
564 } |
|
565 else if (rand/2<=KMaxTInt/8) |
|
566 { |
|
567 killAppUid=KUidViewAppThree; |
|
568 } |
|
569 |
|
570 if (killAppUid!=KNullUid) |
|
571 { |
|
572 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
573 TApaTask task=taskList.FindApp(killAppUid); |
|
574 if (task.Exists()) |
|
575 { |
|
576 RDebug::Print(_L("TVIEW1 : ********************* KILLING %x ********************* "),killAppUid.iUid); |
|
577 task.KillTask(); |
|
578 User::After(10000); // 0.1 sec |
|
579 } |
|
580 |
|
581 // Start the timer again with a new time delay |
|
582 TTimeIntervalMicroSeconds32 delay(KMinimumDelay+KMinimumDelay*Math::Rand(iRandSeed)/KMaxTInt); |
|
583 iAutoTestTimer->Start(delay,delay,TCallBack(EnduranceTestCallBack,this)); |
|
584 |
|
585 TRAPD(err,ActivateViewL(TVwsViewId(killAppUid,KUidViewOne),KUidEndurance,KNullDesC16)); |
|
586 __ASSERT_ALWAYS(!err,User::Panic(_L("ActivateViewL(TVwsViewId(killAppUid,KUidViewOne),KUidEndurance,KNullDesC16)"),err)); |
|
587 return; |
|
588 } |
|
589 } |
|
590 // Otherwise we do another random activation |
|
591 |
|
592 // Find a new view to activate |
|
593 TUid viewUid = (Math::Rand(iRandSeed)>KMaxTInt/2) ? KUidViewOne : KUidViewTwo; |
|
594 TUid appUid = KNullUid; |
|
595 rand=Math::Rand(iRandSeed); |
|
596 if (rand<=KMaxTInt/3) // 1 in 3 chance |
|
597 { |
|
598 appUid=KUidViewAppOne; |
|
599 } |
|
600 else if (rand/2<=KMaxTInt/3) |
|
601 { |
|
602 appUid=KUidViewAppTwo; |
|
603 } |
|
604 else |
|
605 { |
|
606 appUid=KUidViewAppThree; |
|
607 } |
|
608 |
|
609 // Decide whether any special condition should be used with activation. |
|
610 // This can mean the activation will be sluggish, a deactivation will be sluggish |
|
611 // or the activation will leave or exit |
|
612 TUid messageUid=KNullUid; |
|
613 rand=Math::Rand(iRandSeed); |
|
614 if (rand<KMaxTInt/10) // 1 in 10 chance |
|
615 { |
|
616 messageUid=KUidActivationOOM; |
|
617 } |
|
618 else if (rand/2<KMaxTInt/10) |
|
619 { |
|
620 messageUid=KUidSluggishActivation; |
|
621 } |
|
622 else if (rand/3<KMaxTInt/10) |
|
623 { |
|
624 STATIC_CAST(CTestView*,View(VIEW_ONE))->iSluggishDeactivation=ETrue; |
|
625 } |
|
626 else if (rand/4<=KMaxTInt/10 && iDoKills) |
|
627 { |
|
628 STATIC_CAST(CTestView*,View(VIEW_ONE))->iExitDeactivation=ETrue; |
|
629 } |
|
630 else if (rand<=KMaxTInt && iDoKills && appUid==KUidViewAppTwo) |
|
631 { |
|
632 messageUid=KUidActivationExit; |
|
633 } |
|
634 |
|
635 // Start the timer again with a new time delay |
|
636 TTimeIntervalMicroSeconds32 delay(KMinimumDelay+KMinimumDelay*Math::Rand(iRandSeed)/KMaxTInt); |
|
637 iAutoTestTimer->Start(delay,delay,TCallBack(EnduranceTestCallBack,this)); |
|
638 |
|
639 TRAPD(err,ActivateViewL(TVwsViewId(appUid,viewUid),messageUid,KNullDesC)); |
|
640 __ASSERT_ALWAYS(!err,User::Panic(_L("ActivateViewL(TVwsViewId(appUid,viewUid),messageUid,KNullDesC)"),err)); |
|
641 } |
|
642 |
|
643 TInt CTestAppUi::EnduranceTestCallBack(TAny* aSelf) |
|
644 { // static |
|
645 REINTERPRET_CAST(CTestAppUi*,aSelf)->DoNextEnduranceTestActivation(); |
|
646 return 0; |
|
647 } |
|
648 |
|
649 // |
|
650 // This UID defined in Uikon. Not an app. |
|
651 // |
|
652 const TUid KUidPasswordMode={268435755}; |
|
653 |
|
654 void CTestAppUi::TestStartMissingAppL() |
|
655 { |
|
656 RDebug::Print(_L("TVIEW1 : Test Start Missing App")); |
|
657 CCoeAppUi::ActivateViewL(TVwsViewId(KUidPasswordMode,KUidViewOne)); |
|
658 } |
|
659 |
|
660 |
|
661 CTestViewControl::~CTestViewControl() |
|
662 { |
|
663 } |
|
664 |
|
665 void CTestViewControl::ConstructL(const TVwsViewId& aViewId) |
|
666 { |
|
667 iViewId=aViewId; |
|
668 CreateWindowL(); |
|
669 Window().SetShadowDisabled(ETrue); |
|
670 Window().SetBackgroundColor(KRgbRed); |
|
671 ActivateL(); |
|
672 } |
|
673 |
|
674 const TInt KXStart = 50; |
|
675 const TInt KYStart = 50; |
|
676 |
|
677 void CTestViewControl::Draw(const TRect& /*aRect*/) const |
|
678 { |
|
679 CWindowGc& gc = SystemGc(); |
|
680 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
681 gc.SetBrushColor(KRgbDitheredLightGray); |
|
682 gc.DrawRect(Rect()); |
|
683 |
|
684 gc.UseFont(iEikonEnv->TitleFont()); |
|
685 |
|
686 TInt yPos = KYStart; |
|
687 TInt xPos = KXStart; |
|
688 |
|
689 gc.DrawText(APP_TEXT,TPoint(xPos,yPos)); |
|
690 |
|
691 yPos+=30; |
|
692 |
|
693 TBuf<256> viewNameBuf; |
|
694 viewNameBuf.Append(_L("View ")); |
|
695 TBuf<16> numBuf; |
|
696 numBuf.Num((TInt)iViewId.iViewUid.iUid); |
|
697 viewNameBuf.Append(numBuf); |
|
698 |
|
699 |
|
700 gc.DrawText(viewNameBuf,TPoint(xPos,yPos)); |
|
701 |
|
702 } |
|
703 |
|
704 |
|
705 // |
|
706 // CTestView |
|
707 // |
|
708 |
|
709 CTestView::~CTestView() |
|
710 { |
|
711 delete iControl; |
|
712 } |
|
713 |
|
714 CTestView::CTestView(const TVwsViewId& aViewId,CTestAppUi& aAppUi) |
|
715 :CTestVwAppView(aViewId,aAppUi), iDeactivationPanic(EFalse), iSlowDeactivation(EFalse), iSluggishDeactivation(EFalse), |
|
716 iExitDeactivation(EFalse) |
|
717 { |
|
718 } |
|
719 |
|
720 void CTestView::ConstructL() |
|
721 { |
|
722 iControl=new(ELeave) CTestViewControl; |
|
723 iControl->ConstructL(ViewId()); |
|
724 iControl->SetRect(ClientRect()); |
|
725 } |
|
726 |
|
727 void CTestView::InitializeAsDefaultL() |
|
728 { |
|
729 AppUi().SetDefaultViewL(*this); |
|
730 |
|
731 if (!iControl) |
|
732 ConstructL(); |
|
733 |
|
734 iControl->ActivateL(); |
|
735 iControl->DrawNow(); |
|
736 } |
|
737 |
|
738 void CTestView::DoActivateL(const TVwsViewId& /*aPrevViewUid*/,TUid aCustomMessageId,const TDesC16& /*aCustomMessage*/) |
|
739 { |
|
740 iActivated=ETrue; |
|
741 if(aCustomMessageId==KUidActivationOOM) |
|
742 { |
|
743 User::Leave(KErrNoMemory); |
|
744 } |
|
745 else if(aCustomMessageId==KUidSluggishActivation) |
|
746 { |
|
747 User::After(1000000); // 1.0 sec |
|
748 } |
|
749 iControl->DrawableWindow()->SetOrdinalPosition(0); |
|
750 } |
|
751 |
|
752 void CTestView::DoDeactivate() |
|
753 { |
|
754 if (!iActivated) |
|
755 { |
|
756 RDebug::Print(_L("%x,%x deactivated when not active"),ViewId().iAppUid.iUid,ViewId().iViewUid.iUid); |
|
757 ASSERT(iActivated); |
|
758 } |
|
759 if (iDeactivationPanic) |
|
760 { |
|
761 RDebug::Print(_L("TVIEW1 : Deactivation Panic")); |
|
762 User::Panic(APP_TEXT,1); |
|
763 } |
|
764 else if (iSlowDeactivation) |
|
765 { |
|
766 RDebug::Print(_L("TVIEW1 : Slow Deactivation")); |
|
767 User::After(5000000); // 5 sec |
|
768 iSlowDeactivation=EFalse; |
|
769 } |
|
770 else if (iSluggishDeactivation) |
|
771 { |
|
772 RDebug::Print(_L("TVIEW1 : Sluggish Deactivation")); |
|
773 User::After(500000); // 0.5 sec |
|
774 iSluggishDeactivation=EFalse; |
|
775 } |
|
776 else if (iExitDeactivation) |
|
777 { |
|
778 RDebug::Print(_L("TVIEW1 : Exit During Deactivation")); |
|
779 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
780 TApaTask task=taskList.FindApp(KUidViewAppTwo); |
|
781 if (task.Exists()) |
|
782 { |
|
783 RDebug::Print(_L("TVIEW1 : ********************* KILLING TVIEW2 ********************* ")); |
|
784 task.KillTask(); |
|
785 User::After(10000); // 0.1 sec |
|
786 } |
|
787 iExitDeactivation=EFalse; |
|
788 } |
|
789 iActivated=EFalse; |
|
790 } |
|
791 |
|
792 void CTestView::HandleCommandL(TInt aCommand) |
|
793 { |
|
794 switch (aCommand) |
|
795 { |
|
796 case ETaskToAppAViewOne: |
|
797 ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewOne)); |
|
798 break; |
|
799 case ETaskToAppAViewTwo: |
|
800 ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewTwo)); |
|
801 break; |
|
802 case EDNLViewAppC: |
|
803 //ActivateViewL(TVwsViewId(KUidViewAppCApp,KUidViewAppCOne)); |
|
804 break; |
|
805 default: |
|
806 break; |
|
807 } |
|
808 } |
|
809 |
|
810 void CTestView::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/) |
|
811 { |
|
812 } |
|
813 |
|
814 |
|
815 // |
|
816 // Class CTestViewDeactivationObserver |
|
817 // |
|
818 |
|
819 CTestViewActivationObserver::CTestViewActivationObserver(CCoeAppUi& aAppUi) |
|
820 : iAppUi(aAppUi), iActivationCount(0) |
|
821 {} |
|
822 |
|
823 void CTestViewActivationObserver::ConstructL() |
|
824 { |
|
825 iAppUi.NotifyNextActivation(*this); |
|
826 } |
|
827 |
|
828 const TInt KLargeInt=KMaxTInt/2; |
|
829 |
|
830 void CTestViewActivationObserver::HandleViewActivation(const TVwsViewId& /*aNewlyActivatedViewId*/,const TVwsViewId& /*aViewIdToBeDeactivated*/) |
|
831 { |
|
832 // reset count if it gets big |
|
833 if (iActivationCount>KLargeInt) |
|
834 { |
|
835 iActivationCount=0; |
|
836 } |
|
837 iActivationCount++; |
|
838 iAppUi.NotifyNextActivation(*this); |
|
839 } |
|
840 |