コード例 #1
0
TVerdict CShutdownApp::doTestStepL()
	{
	TInt uidValue;
	_LIT(KUidKey, "uid");
	if (!GetHexFromConfig(ConfigSection(), KUidKey, uidValue))
		{
		ERR_PRINTF1(_L("Missing uid"));
		SetTestStepResult(EFail);
		return EFail;
		}
	TInt connectErr = KErrNotFound;
#ifndef SWI_TEXTSHELL_ROM
	TUid appUid;
	appUid.iUid = uidValue;

	TInt wgId=0;
	RWsSession wsSession;
	connectErr = wsSession.Connect();
	if (connectErr != KErrNotFound)
		{
		User::LeaveIfError(connectErr);
		CleanupClosePushL(wsSession);
		
		CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(wsSession);
		CleanupStack::PushL(wgName);
		CApaWindowGroupName::FindByAppUid(appUid, wsSession, wgId);
		
		if (wgId == KErrNotFound)
			{
			ERR_PRINTF2(_L("Running app with UID 0x%x not found."), appUid.iUid);		
			User::Leave(KErrNotFound);
			}
		
		wgName->ConstructFromWgIdL(wgId);
		
		if(wgName->RespondsToShutdownEvent())
			{
			TApaTask task(wsSession);
			task.SetWgId(wgId);
			RThread thread;
			TInt err=thread.Open(task.ThreadId());
			CleanupClosePushL(thread);
			if (!err)
				{
				RProcess process;
				thread.Process(process);
				CleanupClosePushL(process);
				
				TRequestStatus processStatus;
				process.Rendezvous(processStatus);
					
				task.SendSystemEvent(EApaSystemEventShutdown);

				RTimer timer;
				CleanupClosePushL(timer);
				TRequestStatus timerStatus;
				
				User::LeaveIfError(timer.CreateLocal());
				timer.After(timerStatus, KAppShutdownTimeout);

				User::WaitForRequest(processStatus,timerStatus);

				if (processStatus==KRequestPending)
					{
					// timer completed so give up
					process.RendezvousCancel(processStatus);
					User::WaitForRequest(processStatus);
					ERR_PRINTF2(_L("App with UID 0x%x timed out on shutdown."), appUid.iUid);		
					User::Leave(KErrTimedOut);
					}
				else if (timerStatus==KRequestPending)
					{
					// Rendezvous completed so cancel timer
					timer.Cancel();
					User::WaitForRequest(timerStatus);
					}
				else
					{
					 // Both have completed, so prevent stray request
					User::WaitForRequest(processStatus,timerStatus);
					}
					
				CleanupStack::PopAndDestroy(2, &process);
				INFO_PRINTF2(_L("App with UID 0x%x shut down."), appUid.iUid);
				SetTestStepResult(EPass);

				}
			CleanupStack::PopAndDestroy(&thread);
			}
		else 
			{
			ERR_PRINTF2(_L("App with UID %x does not handle shutdown events."), appUid.iUid);
			SetTestStepResult(EFail);
			}
		CleanupStack::PopAndDestroy(2, &wsSession);
	}
#endif
	if (connectErr == KErrNotFound)
		{
		// emulator tests running in textshell or in textshell ROM (#def SWI_TEXTSHELL_ROM)
		ERR_PRINTF1(_L("Ignoring shutdown checks in Textshell Rom"));
		}
	return TestStepResult();
	}
コード例 #2
0
// Each test step must supply a implementation for doTestStepL
enum TVerdict CTestAppLoaderEndTask::doTestStepL( void )
	{
	// Printing to the console and log file
	INFO_PRINTF1(_L("TEST-> END TASK"));

	TPtrC	program;
	if ( !GetStringFromConfig(ConfigSection(), KProgram, program) )
		{
		ERR_PRINTF2(KErrMissingParameter, &KProgram());
		SetTestStepResult(EFail);
		}
	else
		{
		RApaLsSession	apaLsSession;
		User::LeaveIfError(apaLsSession.Connect());
		CleanupClosePushL(apaLsSession);
	    User::LeaveIfError(apaLsSession.GetAllApps());

		RWsSession	ws;
		User::LeaveIfError(ws.Connect());
		CleanupClosePushL(ws);
		
	    TInt					numWindowGroups = ws.NumWindowGroups();
	    CArrayFixFlat<TInt>*	windowGroupList = new(ELeave) CArrayFixFlat<TInt>(numWindowGroups);
	    CleanupStack::PushL(windowGroupList);

	    // Populate array with current group list ids
	    User::LeaveIfError(ws.WindowGroupList(windowGroupList));

	    CApaWindowGroupName*	windowGroupName = CApaWindowGroupName::NewLC(ws);

	    /* Note: we use windowGroupList->Count() instead of numWindowGroups, as in the middle of the
	     * update the list could change in length (or worse, be reduced) thus producing an out of bounds
	     * error if numWindowGroups were used
	     */
	    TBool	searching=ETrue;
	    for ( TInt i=0; (i<windowGroupList->Count()) && searching; ++i )
	    	{
	        TInt	wgId = windowGroupList->At(i);
	        windowGroupName->ConstructFromWgIdL(wgId);

	        TUid	appUid = windowGroupName->AppUid();

	        TApaAppInfo	appInfo;
	        HBufC* 		appCaption = NULL;
	        // Some applications, like midlets, may not provide any info
	        if (apaLsSession.GetAppInfo(appInfo, appUid) == KErrNone)
	        	{
	            appCaption = appInfo.iCaption.AllocL();
	        	}
	        else
	        	{
	            appCaption = windowGroupName->Caption().AllocL();
	        	}
            CleanupStack::PushL(appCaption);

	        // Only list 'visible' applications
	        if ( appCaption->Length() )
	        	{
	            TPtrC	caption=*appCaption;
		        INFO_PRINTF2(KLogTask, &caption);

		        if ( program.CompareC(caption)==0 )
		        	{
					searching=EFalse;
					TApaTask	task(ws);
					task.SetWgId(wgId);
					if (task.Exists())
						{
						task.EndTask();
						}
					else
						{
						ERR_PRINTF2(KErrTaskNotFound, &program);
						SetTestStepResult(EFail);
						}
		        	}
				}
            CleanupStack::Pop(1, appCaption); // taskEntry, appCaption
	    	}

	    if ( searching )
	    	{
			ERR_PRINTF2(KErrTaskNotFound, &program);
			SetTestStepResult(EFail);
	    	}
	    CleanupStack::PopAndDestroy(4, &apaLsSession);    // windowGroupName, windowGroupList
		}

	// test steps return a result
	return TestStepResult();
	}