commonuisupport/uikon/test/tviews/tview1/tview1.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-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 
       
    48 #include <techview/eiktxlbx.h>
       
    49 #include <techview/eiktxlbm.h>
       
    50 #include <techview/eiklabel.h>
       
    51 #include <techview/eikcmbut.h>
       
    52 #include <techview/eikbtpan.h>
       
    53 #include <techview/eikmenub.h>
       
    54 #include <techview/eikdialg.h>
       
    55 #include <eikdll.h>
       
    56 #include <eiksvdef.h>
       
    57 #include <techview/eikrted.h>
       
    58 #include <techview/eikwbtb.h>
       
    59 #include <eikenv.h>
       
    60 #include <eikstart.h>
       
    61 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    62 #include <viewclipartner.h>
       
    63 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    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 		CCoeAppUi::ActivateViewL(iViewToActivate);
       
   382 		}
       
   383 	}
       
   384 
       
   385 void CTestAppUi::TestSuccesiveAllocFailL()
       
   386 	{
       
   387 	RDebug::Print(_L("TVIEW1 : Test Succesive Alloc Failure During Activation Until Success"));	
       
   388 	TInt error=KErrUnknown;
       
   389 	for(TInt fail=1;error!=KErrNone;fail++)
       
   390 		{
       
   391 		RDebug::Print(_L("TVIEW2 : Next Failure Test"));
       
   392 		__UHEAP_FAILNEXT(fail);// fail on succesive allocations
       
   393 		__UHEAP_MARK;
       
   394 		TRAP(error,CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)));
       
   395 		__UHEAP_MARKEND; // Check nothing has alloc'd due to fail
       
   396 		}
       
   397 	__UHEAP_SETFAIL(RHeap::ENone,0);// turn failure off
       
   398 	}
       
   399 
       
   400 void CTestAppUi::TestActivationOOML()
       
   401 	{
       
   402 	RDebug::Print(_L("TVIEW1 : Test Activation OOM"));
       
   403 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivationOOM,KNullDesC16);
       
   404 	}
       
   405 
       
   406 void CTestAppUi::TestWaitingActivationL()
       
   407 	{
       
   408 	RDebug::Print(_L("TVIEW1 : Test Waiting Activation"));
       
   409 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidStartScheduler,KNullDesC16);
       
   410 	}
       
   411 
       
   412 void CTestAppUi::TestPanicedActivationL()
       
   413 	{
       
   414 	RDebug::Print(_L("TVIEW1 : Test Paniced Activation"));
       
   415 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivationPanic,KNullDesC16);
       
   416 	}
       
   417 
       
   418 void CTestAppUi::TestPanicedDeactivationL()
       
   419 	{
       
   420 	RDebug::Print(_L("TVIEW1 : Test Paniced Deactivation"));
       
   421 	STATIC_CAST(CTestView*,View(VIEW_ONE))->iDeactivationPanic=ETrue;
       
   422 	STATIC_CAST(CTestView*,View(VIEW_TWO))->iDeactivationPanic=ETrue;
       
   423 	CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne));
       
   424 	}
       
   425 
       
   426 void CTestAppUi::TestSlowActivationL()
       
   427 	{
       
   428 	RDebug::Print(_L("TVIEW1 : Test Slow Activation"));
       
   429 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidSlowActivation,KNullDesC16);
       
   430 	}
       
   431 
       
   432 void CTestAppUi::TestSlowDeactivationL()
       
   433 	{
       
   434 	RDebug::Print(_L("TVIEW1 : Test Slow Deactivation"));
       
   435 	STATIC_CAST(CTestView*,View(VIEW_ONE))->iSlowDeactivation=ETrue;
       
   436 	STATIC_CAST(CTestView*,View(VIEW_TWO))->iSlowDeactivation=ETrue;
       
   437 	CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne));
       
   438 	}
       
   439 
       
   440 void CTestAppUi::TestServerEnduranceL()
       
   441 	{
       
   442 	RDebug::Print(_L("TVIEW1 : Test Server Endurance"));
       
   443 	iDoKills=EFalse;
       
   444 	DoNextEnduranceTestActivation();
       
   445 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidEndurance,KNullDesC16);
       
   446 	ActivateViewL(TVwsViewId(KUidViewAppThree,KUidViewOne),KUidEndurance,KNullDesC16);
       
   447 	}
       
   448 
       
   449 void CTestAppUi::TestServerEnduranceWithKillsL()
       
   450 	{
       
   451 	RDebug::Print(_L("TVIEW1 : Test Server Endurance With Client Kills"));
       
   452 	iDoKills=ETrue;
       
   453 	DoNextEnduranceTestActivation();
       
   454 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidEndurance,KNullDesC16);
       
   455 	ActivateViewL(TVwsViewId(KUidViewAppThree,KUidViewOne),KUidEndurance,KNullDesC16);
       
   456 	}
       
   457 
       
   458 void CTestAppUi::TestExitAndDoubleActivationL()
       
   459 	{
       
   460 	RDebug::Print(_L("TVIEW1 : Test Exit And Double Activation"));
       
   461 	CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KNullUid,KNullDesC8);
       
   462 	CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewTwo),KUidActivationExit,KNullDesC8);
       
   463 	CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewTwo),KNullUid,KNullDesC8);
       
   464 	}
       
   465 
       
   466 void CTestAppUi::TestActivateInsideViewActivatedL()
       
   467 	{
       
   468 	RDebug::Print(_L("TVIEW1 : Test Activate Inside ViewActivated"));
       
   469 	ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KUidActivateAgain,KNullDesC16);
       
   470 	}
       
   471 
       
   472 void CTestAppUi::TestWaitOnAppStartL()
       
   473 	{
       
   474 	RDebug::Print(_L("TVIEW1 : Test Wait On App Start"));
       
   475 
       
   476 	RThread appThread;
       
   477 	TRequestStatus status;
       
   478 	TThreadId threadId;
       
   479 
       
   480 	RApaLsSession ls;
       
   481 	CleanupClosePushL(ls);
       
   482 	User::LeaveIfError(ls.Connect());
       
   483 	TApaAppInfo info;
       
   484 	User::LeaveIfError(ls.GetAppInfo(info,KUidViewAppTwo));
       
   485 	CleanupStack::PopAndDestroy();	// ls 
       
   486 
       
   487 	CApaCommandLine* cmdLine=CApaCommandLine::NewLC();	
       
   488 	cmdLine->SetExecutableNameL(info.iFullName);
       
   489 	cmdLine->SetCommandL(EApaCommandViewActivate);
       
   490 	TFileName fName=_L("c:\\Documents\\");
       
   491 	TParsePtrC parse(info.iFullName);
       
   492 	fName.Append(parse.Name());
       
   493 	cmdLine->SetDocumentNameL(fName);
       
   494 
       
   495 	RApaLsSession lsSession;
       
   496   	User::LeaveIfError(lsSession.Connect());
       
   497   	CleanupClosePushL(lsSession);
       
   498   	threadId=User::LeaveIfError(lsSession.StartApp(*cmdLine, threadId));
       
   499   	CleanupStack::PopAndDestroy(&lsSession);
       
   500 	CleanupStack::PopAndDestroy(); // cmdLine
       
   501 	User::LeaveIfError(appThread.Open(threadId));
       
   502 	appThread.Logon(status);
       
   503 	User::WaitForRequest(status);
       
   504 	}
       
   505 
       
   506 void CTestAppUi::TestForegroundChangeWhileEventsOnQueueL()
       
   507 	{
       
   508 	RDebug::Print(_L("TVIEW1 : Test Foreground Change While Events On Queue"));
       
   509 	// Activate a view in TView2 first to make sure that the app is available
       
   510 	CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne));
       
   511 	// 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
       
   512 	CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewOne));
       
   513 
       
   514 	// Create an activation event for TView2 and stall long enough so that the event will be waiting for the deactivation
       
   515 	// in this app. Then immediately bring this app into the foreground.
       
   516 	CreateActivateViewEventL(TVwsViewId(KUidViewAppTwo,KUidViewOne),KNullUid,KNullDesC8);
       
   517 	User::After(50000);	// 0.5 sec
       
   518 	TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   519 	TApaTask task=taskList.FindApp(KUidViewAppOne);
       
   520 	task.BringToForeground();
       
   521 	}
       
   522 
       
   523 void CTestAppUi::CheckForegroundChangeWhileEventsOnQueue()
       
   524 	{
       
   525 	TVwsViewId activeView;
       
   526 	if (GetActiveViewId(activeView)!=KErrNotFound && activeView==TVwsViewId(KUidViewAppOne,KUidViewOne))
       
   527 		{
       
   528 		iEikonEnv->InfoMsg(_L("Test passed"));
       
   529 		}
       
   530 	else
       
   531 		{
       
   532 		iEikonEnv->InfoMsg(_L("Test failed"));
       
   533 		}
       
   534 	}
       
   535 
       
   536 void CTestAppUi::TestToggleTimeOutEnabledL()
       
   537 	{
       
   538 	CVwsSessionWrapper* vwsSession=CVwsSessionWrapper::NewLC();
       
   539 	User::LeaveIfError(vwsSession->EnableServerEventTimeOut(!iIsServerEventTimeOutEnabled));
       
   540 	iIsServerEventTimeOutEnabled=(!iIsServerEventTimeOutEnabled);
       
   541 	CleanupStack::PopAndDestroy();
       
   542 	}
       
   543 
       
   544 const TInt KMinimumDelay=50000;
       
   545 
       
   546 void CTestAppUi::DoNextEnduranceTestActivation()
       
   547 	{
       
   548 	if (iAutoTestTimer->IsActive())
       
   549 		iAutoTestTimer->Cancel();
       
   550 	
       
   551 	TInt rand=0;
       
   552 	if (iDoKills)
       
   553 		{
       
   554 		// Occasionally we kill another TVIEW
       
   555 		TUid killAppUid=KNullUid;
       
   556 		rand=Math::Rand(iRandSeed);
       
   557 		if (rand<=KMaxTInt/8)	// 1 in 8 chance
       
   558 			{
       
   559 			killAppUid=KUidViewAppTwo;
       
   560 			}
       
   561 		else if (rand/2<=KMaxTInt/8)
       
   562 			{
       
   563 			killAppUid=KUidViewAppThree;
       
   564 			}
       
   565 			
       
   566 		if (killAppUid!=KNullUid)
       
   567 			{
       
   568 			TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   569 			TApaTask task=taskList.FindApp(killAppUid);
       
   570 			if (task.Exists())
       
   571 				{
       
   572 				RDebug::Print(_L("TVIEW1 : ********************* KILLING %x ********************* "),killAppUid.iUid);
       
   573 				task.KillTask();
       
   574 				User::After(10000);	// 0.1 sec
       
   575 				}
       
   576 
       
   577 			// Start the timer again with a new time delay
       
   578 			TTimeIntervalMicroSeconds32 delay(KMinimumDelay+KMinimumDelay*Math::Rand(iRandSeed)/KMaxTInt);
       
   579 			iAutoTestTimer->Start(delay,delay,TCallBack(EnduranceTestCallBack,this));
       
   580 			
       
   581 			TRAPD(err,ActivateViewL(TVwsViewId(killAppUid,KUidViewOne),KUidEndurance,KNullDesC16));
       
   582 			__ASSERT_ALWAYS(!err,User::Panic(_L("ActivateViewL(TVwsViewId(killAppUid,KUidViewOne),KUidEndurance,KNullDesC16)"),err));
       
   583 			return;
       
   584 			}
       
   585 		}	
       
   586 	// Otherwise we do another random activation
       
   587 
       
   588 	// Find a new view to activate
       
   589 	TUid viewUid = (Math::Rand(iRandSeed)>KMaxTInt/2) ? KUidViewOne : KUidViewTwo;
       
   590 	TUid appUid = KNullUid;
       
   591 	rand=Math::Rand(iRandSeed);
       
   592 	if (rand<=KMaxTInt/3)	// 1 in 3 chance
       
   593 		{
       
   594 		appUid=KUidViewAppOne;
       
   595 		}
       
   596 	else if (rand/2<=KMaxTInt/3)	
       
   597 		{
       
   598 		appUid=KUidViewAppTwo;
       
   599 		}
       
   600 	else	
       
   601 		{
       
   602 		appUid=KUidViewAppThree;
       
   603 		}
       
   604 
       
   605 	// Decide whether any special condition should be used with activation.
       
   606 	// This can mean the activation will be sluggish, a deactivation will be sluggish
       
   607 	// or the activation will leave or exit
       
   608 	TUid messageUid=KNullUid;
       
   609 	rand=Math::Rand(iRandSeed);
       
   610 	if (rand<KMaxTInt/10)	// 1 in 10 chance
       
   611 		{
       
   612 		messageUid=KUidActivationOOM;
       
   613 		}
       
   614 	else if (rand/2<KMaxTInt/10)
       
   615 		{
       
   616 		messageUid=KUidSluggishActivation;
       
   617 		}
       
   618 	else if (rand/3<KMaxTInt/10)
       
   619 		{
       
   620 		STATIC_CAST(CTestView*,View(VIEW_ONE))->iSluggishDeactivation=ETrue;
       
   621 		}
       
   622 	else if (rand/4<=KMaxTInt/10 && iDoKills)
       
   623 		{
       
   624 		STATIC_CAST(CTestView*,View(VIEW_ONE))->iExitDeactivation=ETrue;
       
   625 		}
       
   626 	else if (rand<=KMaxTInt && iDoKills && appUid==KUidViewAppTwo)
       
   627 		{
       
   628 		messageUid=KUidActivationExit;
       
   629 		}
       
   630 
       
   631 	// Start the timer again with a new time delay
       
   632 	TTimeIntervalMicroSeconds32 delay(KMinimumDelay+KMinimumDelay*Math::Rand(iRandSeed)/KMaxTInt);
       
   633 	iAutoTestTimer->Start(delay,delay,TCallBack(EnduranceTestCallBack,this));
       
   634 
       
   635 	TRAPD(err,ActivateViewL(TVwsViewId(appUid,viewUid),messageUid,KNullDesC));
       
   636 	__ASSERT_ALWAYS(!err,User::Panic(_L("ActivateViewL(TVwsViewId(appUid,viewUid),messageUid,KNullDesC)"),err));
       
   637 	}
       
   638 
       
   639 TInt CTestAppUi::EnduranceTestCallBack(TAny* aSelf)
       
   640 	{ // static
       
   641 	REINTERPRET_CAST(CTestAppUi*,aSelf)->DoNextEnduranceTestActivation();
       
   642 	return 0;
       
   643 	}
       
   644 
       
   645 //
       
   646 // This UID defined in Uikon. Not an app.
       
   647 //
       
   648 const TUid KUidPasswordMode={268435755};
       
   649 
       
   650 void CTestAppUi::TestStartMissingAppL()
       
   651 	{
       
   652 	RDebug::Print(_L("TVIEW1 : Test Start Missing App"));
       
   653 	CCoeAppUi::ActivateViewL(TVwsViewId(KUidPasswordMode,KUidViewOne));
       
   654 	}
       
   655 
       
   656 
       
   657 CTestViewControl::~CTestViewControl()
       
   658 	{
       
   659 	}
       
   660 
       
   661 void CTestViewControl::ConstructL(const TVwsViewId& aViewId)
       
   662     {
       
   663 	iViewId=aViewId;
       
   664     CreateWindowL();
       
   665     Window().SetShadowDisabled(ETrue);
       
   666 	Window().SetBackgroundColor(KRgbRed);
       
   667     ActivateL();
       
   668     }
       
   669 
       
   670 const TInt KXStart = 50;
       
   671 const TInt KYStart = 50;
       
   672 
       
   673 void CTestViewControl::Draw(const TRect& /*aRect*/) const
       
   674 	{
       
   675 	CWindowGc& gc = SystemGc();
       
   676 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   677 	gc.SetBrushColor(KRgbDitheredLightGray);
       
   678 	gc.DrawRect(Rect());
       
   679 
       
   680 	gc.UseFont(iEikonEnv->TitleFont());
       
   681 
       
   682 	TInt yPos = KYStart;
       
   683 	TInt xPos = KXStart;
       
   684 
       
   685 	gc.DrawText(APP_TEXT,TPoint(xPos,yPos));
       
   686 
       
   687 	yPos+=30;
       
   688 
       
   689 	TBuf<256> viewNameBuf;
       
   690 	viewNameBuf.Append(_L("View "));
       
   691 	TBuf<16> numBuf;
       
   692 	numBuf.Num((TInt)iViewId.iViewUid.iUid);
       
   693 	viewNameBuf.Append(numBuf);
       
   694 
       
   695 
       
   696 	gc.DrawText(viewNameBuf,TPoint(xPos,yPos));
       
   697 
       
   698 	}
       
   699 
       
   700 
       
   701 //
       
   702 // CTestView
       
   703 //
       
   704 
       
   705 CTestView::~CTestView()
       
   706 	{
       
   707 	delete iControl;
       
   708 	}
       
   709 
       
   710 CTestView::CTestView(const TVwsViewId& aViewId,CTestAppUi& aAppUi)
       
   711 	:CTestVwAppView(aViewId,aAppUi), iDeactivationPanic(EFalse), iSlowDeactivation(EFalse), iSluggishDeactivation(EFalse),
       
   712 	iExitDeactivation(EFalse)
       
   713 	{
       
   714 	}
       
   715 
       
   716 void CTestView::ConstructL() 
       
   717 	{
       
   718 	iControl=new(ELeave) CTestViewControl;
       
   719     iControl->ConstructL(ViewId());
       
   720 	iControl->SetRect(ClientRect());
       
   721 	}
       
   722 
       
   723 void CTestView::InitializeAsDefaultL()
       
   724 	{
       
   725 	AppUi().SetDefaultViewL(*this);
       
   726 
       
   727 	if (!iControl)
       
   728 		ConstructL();
       
   729 
       
   730 	iControl->ActivateL();
       
   731 	iControl->DrawNow();
       
   732 	}
       
   733 
       
   734 void CTestView::DoActivateL(const TVwsViewId& /*aPrevViewUid*/,TUid aCustomMessageId,const TDesC16& /*aCustomMessage*/)
       
   735 	{
       
   736 	iActivated=ETrue;
       
   737 	if(aCustomMessageId==KUidActivationOOM)
       
   738 		{
       
   739 		User::Leave(KErrNoMemory);
       
   740 		}
       
   741 	else if(aCustomMessageId==KUidSluggishActivation)
       
   742 		{
       
   743 		User::After(1000000);	// 1.0 sec
       
   744 		}
       
   745 	iControl->DrawableWindow()->SetOrdinalPosition(0);
       
   746 	}
       
   747 
       
   748 void CTestView::DoDeactivate()
       
   749 	{
       
   750 	if (!iActivated)
       
   751 		{
       
   752 		RDebug::Print(_L("%x,%x deactivated when not active"),ViewId().iAppUid.iUid,ViewId().iViewUid.iUid);
       
   753 		ASSERT(iActivated);
       
   754 		}
       
   755 	if (iDeactivationPanic)
       
   756 		{
       
   757 		RDebug::Print(_L("TVIEW1 : Deactivation Panic"));
       
   758 		User::Panic(APP_TEXT,1);
       
   759 		}
       
   760 	else if (iSlowDeactivation)
       
   761 		{
       
   762 		RDebug::Print(_L("TVIEW1 : Slow Deactivation"));
       
   763 		User::After(5000000);	// 5 sec
       
   764 		iSlowDeactivation=EFalse;
       
   765 		}
       
   766 	else if (iSluggishDeactivation)
       
   767 		{
       
   768 		RDebug::Print(_L("TVIEW1 : Sluggish Deactivation"));
       
   769 		User::After(500000);	// 0.5 sec
       
   770 		iSluggishDeactivation=EFalse;
       
   771 		}
       
   772 	else if (iExitDeactivation)
       
   773 		{
       
   774 		RDebug::Print(_L("TVIEW1 : Exit During Deactivation"));
       
   775 		TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
   776 		TApaTask task=taskList.FindApp(KUidViewAppTwo);
       
   777 		if (task.Exists())
       
   778 			{
       
   779 			RDebug::Print(_L("TVIEW1 : ********************* KILLING TVIEW2 ********************* "));
       
   780 			task.KillTask();
       
   781 			User::After(10000);	// 0.1 sec
       
   782 			}
       
   783 		iExitDeactivation=EFalse;
       
   784 		}
       
   785 	iActivated=EFalse;
       
   786 	}
       
   787 
       
   788 void CTestView::HandleCommandL(TInt aCommand)
       
   789 	{
       
   790 	switch (aCommand)
       
   791 		{
       
   792 	case ETaskToAppAViewOne:
       
   793 		ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewOne));
       
   794 		break;
       
   795 	case ETaskToAppAViewTwo:
       
   796 		ActivateViewL(TVwsViewId(KUidViewAppOne,KUidViewTwo));
       
   797 		break;
       
   798 	case EDNLViewAppC:
       
   799 		//ActivateViewL(TVwsViewId(KUidViewAppCApp,KUidViewAppCOne));
       
   800 		break;
       
   801 	default:
       
   802 		break;
       
   803 		}
       
   804 	}
       
   805 
       
   806 void CTestView::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)
       
   807 	{
       
   808 	}
       
   809 
       
   810 
       
   811 //
       
   812 // Class CTestViewDeactivationObserver
       
   813 //
       
   814 
       
   815 CTestViewActivationObserver::CTestViewActivationObserver(CCoeAppUi& aAppUi)
       
   816 	: iAppUi(aAppUi), iActivationCount(0)
       
   817 	{}
       
   818 
       
   819 void CTestViewActivationObserver::ConstructL()
       
   820 	{
       
   821 	iAppUi.NotifyNextActivation(*this);
       
   822 	}
       
   823 
       
   824 const TInt KLargeInt=KMaxTInt/2;
       
   825 
       
   826 void CTestViewActivationObserver::HandleViewActivation(const TVwsViewId& /*aNewlyActivatedViewId*/,const TVwsViewId& /*aViewIdToBeDeactivated*/)
       
   827 	{
       
   828 	// reset count if it gets big
       
   829 	if (iActivationCount>KLargeInt)
       
   830 		{
       
   831 		iActivationCount=0;
       
   832 		}
       
   833 	iActivationCount++;
       
   834 	iAppUi.NotifyNextActivation(*this);
       
   835 	}
       
   836