sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Test process priority control sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "TPROCPRI.H" sl@0: sl@0: TName OtherGroupName; sl@0: sl@0: TInt ProcPriTestOtherProcess(TAny *aScreenNumber) sl@0: { sl@0: CTrapCleanup* CleanUpStack=CTrapCleanup::New(); sl@0: RWsSession ws; sl@0: User::LeaveIfError(ws.Connect()); sl@0: // use correct screen sl@0: // sl@0: CWsScreenDevice* screen = NULL; sl@0: TInt err; sl@0: TRAP(err, screen = new (ELeave) CWsScreenDevice(ws)); sl@0: if (err!=KErrNone) sl@0: return err; sl@0: if ((err=screen->Construct((TInt)aScreenNumber))!=KErrNone) sl@0: { sl@0: delete screen; sl@0: return err; sl@0: } sl@0: sl@0: RWindowGroup group(ws); sl@0: group.Construct(888); sl@0: group.SetName(OTHER_PROC_GROUP_NAME); sl@0: RSemaphore sem1; sl@0: RSemaphore sem2; sl@0: sem1.OpenGlobal(PROC_PRI_SEMAPHORE_NAME1); sl@0: sem2.OpenGlobal(PROC_PRI_SEMAPHORE_NAME2); sl@0: sem1.Signal(); // Signal thread fully initialised sl@0: sem2.Wait(); // Wait for command to disable focus sl@0: // sl@0: group.EnableReceiptOfFocus(EFalse); sl@0: ws.Flush(); sl@0: sem1.Signal(); // Signal focus disabled sl@0: sem2.Wait(); // Wait for command to enable focus sl@0: sl@0: group.EnableReceiptOfFocus(ETrue); sl@0: ws.Flush(); sl@0: sem1.Signal(); // Signal focus enabled sl@0: sem2.Wait(); // Wait until signalled to exit sl@0: // sl@0: group.EnableReceiptOfFocus(EFalse); // To stop shell being tasked into foreground sl@0: delete screen; sl@0: ws.Close(); sl@0: sem1.Close(); sl@0: sem2.Close(); sl@0: delete CleanUpStack; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: CTProcPri::CTProcPri(CTestStep* aStep) : CTWsGraphicsBase(aStep) sl@0: { sl@0: } sl@0: sl@0: CTProcPri::~CTProcPri() sl@0: { sl@0: if (iFlags&ECreatedSem1) sl@0: iSem1.Close(); sl@0: if (iFlags&ECreatedSem2) sl@0: iSem2.Close(); sl@0: delete iProcess; sl@0: } sl@0: sl@0: void CTProcPri::TestPriChangeL() sl@0: { sl@0: #define BACK_PRI EPriorityForeground sl@0: #define FORE_PRI EPriorityForeground sl@0: RProcess proc; sl@0: TEST(proc.Priority()==BACK_PRI); sl@0: if (proc.Priority()!=BACK_PRI) sl@0: INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority()); sl@0: sl@0: iSem2.Signal(); sl@0: iSem1.Wait(); sl@0: sl@0: TEST(proc.Priority()==FORE_PRI); sl@0: if (proc.Priority()!=FORE_PRI) sl@0: INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority()); sl@0: sl@0: iSem2.Signal(); sl@0: iSem1.Wait(); sl@0: sl@0: TEST(proc.Priority()==BACK_PRI); sl@0: if (proc.Priority()!=BACK_PRI) sl@0: INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority()); sl@0: sl@0: TInt ident; sl@0: User::LeaveIfError(ident=TheClient->iWs.FindWindowGroupIdentifier(0,OTHER_PROC_GROUP_NAME,0)); sl@0: TInt retVal = TheClient->iWs.SetWindowGroupOrdinalPosition(ident,1); sl@0: TEST(retVal==KErrNone); sl@0: if (retVal!=KErrNone) sl@0: INFO_PRINTF3(_L("TheClient->iWs.SetWindowGroupOrdinalPosition(ident,1) return value - Expected: %d, Actual: %d"), KErrNone, retVal); sl@0: sl@0: TEST(proc.Priority()==FORE_PRI); sl@0: if (proc.Priority()!=FORE_PRI) sl@0: INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority()); sl@0: sl@0: retVal = TheClient->iWs.SetWindowGroupOrdinalPosition(ident,0); sl@0: TEST(retVal==KErrNone); sl@0: if (retVal!=KErrNone) sl@0: INFO_PRINTF3(_L("TheClient->iWs.SetWindowGroupOrdinalPosition(ident,0) return value - Expected: %d, Actual: %d"), KErrNone, retVal); sl@0: sl@0: TEST(proc.Priority()==BACK_PRI); sl@0: if (proc.Priority()!=BACK_PRI) sl@0: INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority()); sl@0: sl@0: TRequestStatus stat; sl@0: iProcess->Logon(stat); //Must Logon before the last Signal so we can be sure that it is still alive to get round a base issue sl@0: iSem2.Signal(); sl@0: User::WaitForRequest(stat); sl@0: sl@0: TEST(proc.Priority()==FORE_PRI); sl@0: if (proc.Priority()!=FORE_PRI) sl@0: INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority()); sl@0: sl@0: } sl@0: sl@0: void CTProcPri::ConstructL() sl@0: { sl@0: User::LeaveIfError(iSem1.CreateGlobal(PROC_PRI_SEMAPHORE_NAME1,0,KOwnerType)); sl@0: iFlags|=ECreatedSem1; sl@0: User::LeaveIfError(iSem2.CreateGlobal(PROC_PRI_SEMAPHORE_NAME2,0,KOwnerType)); sl@0: iFlags|=ECreatedSem2; sl@0: iProcess=CProcess::NewL(CProcess::eProcessPriortyTest,iTest->iScreenNumber); sl@0: iSem1.Wait(); sl@0: } sl@0: sl@0: void CTProcPri::RunTestCaseL(TInt /*aCurTestCase*/) sl@0: { sl@0: _LIT(KTest1,"Priority Change"); sl@0: ((CTProcPriStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: sl@0: switch(++iTest->iState) sl@0: { sl@0: /** sl@0: sl@0: @SYMTestCaseID GRAPHICS-WSERV-0315 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Test that the priority of a process or thread changes depending sl@0: on how the the process or thread is being used sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Create a process or thread and use it. Check the priority of the sl@0: process or thread changes depending on how it is being used sl@0: sl@0: @SYMTestExpectedResults Prioirty of the process of thread changes depending on sl@0: how it is being used sl@0: sl@0: */ sl@0: case 1: sl@0: ((CTProcPriStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0315")); sl@0: iTest->LogSubTest(KTest1); sl@0: TestPriChangeL(); sl@0: break; sl@0: case 2: sl@0: ((CTProcPriStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTProcPriStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTProcPriStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: __WS_CONSTRUCT_STEP__(ProcPri)