1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TPROCPRI.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,194 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Test process priority control
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @test
1.24 + @internalComponent - Internal Symbian test code
1.25 +*/
1.26 +
1.27 +
1.28 +#include "TPROCPRI.H"
1.29 +
1.30 +TName OtherGroupName;
1.31 +
1.32 +TInt ProcPriTestOtherProcess(TAny *aScreenNumber)
1.33 + {
1.34 + CTrapCleanup* CleanUpStack=CTrapCleanup::New();
1.35 + RWsSession ws;
1.36 + User::LeaveIfError(ws.Connect());
1.37 + // use correct screen
1.38 + //
1.39 + CWsScreenDevice* screen = NULL;
1.40 + TInt err;
1.41 + TRAP(err, screen = new (ELeave) CWsScreenDevice(ws));
1.42 + if (err!=KErrNone)
1.43 + return err;
1.44 + if ((err=screen->Construct((TInt)aScreenNumber))!=KErrNone)
1.45 + {
1.46 + delete screen;
1.47 + return err;
1.48 + }
1.49 +
1.50 + RWindowGroup group(ws);
1.51 + group.Construct(888);
1.52 + group.SetName(OTHER_PROC_GROUP_NAME);
1.53 + RSemaphore sem1;
1.54 + RSemaphore sem2;
1.55 + sem1.OpenGlobal(PROC_PRI_SEMAPHORE_NAME1);
1.56 + sem2.OpenGlobal(PROC_PRI_SEMAPHORE_NAME2);
1.57 + sem1.Signal(); // Signal thread fully initialised
1.58 + sem2.Wait(); // Wait for command to disable focus
1.59 +//
1.60 + group.EnableReceiptOfFocus(EFalse);
1.61 + ws.Flush();
1.62 + sem1.Signal(); // Signal focus disabled
1.63 + sem2.Wait(); // Wait for command to enable focus
1.64 +
1.65 + group.EnableReceiptOfFocus(ETrue);
1.66 + ws.Flush();
1.67 + sem1.Signal(); // Signal focus enabled
1.68 + sem2.Wait(); // Wait until signalled to exit
1.69 +//
1.70 + group.EnableReceiptOfFocus(EFalse); // To stop shell being tasked into foreground
1.71 + delete screen;
1.72 + ws.Close();
1.73 + sem1.Close();
1.74 + sem2.Close();
1.75 + delete CleanUpStack;
1.76 + return(KErrNone);
1.77 + }
1.78 +
1.79 +CTProcPri::CTProcPri(CTestStep* aStep) : CTWsGraphicsBase(aStep)
1.80 + {
1.81 + }
1.82 +
1.83 +CTProcPri::~CTProcPri()
1.84 + {
1.85 + if (iFlags&ECreatedSem1)
1.86 + iSem1.Close();
1.87 + if (iFlags&ECreatedSem2)
1.88 + iSem2.Close();
1.89 + delete iProcess;
1.90 + }
1.91 +
1.92 +void CTProcPri::TestPriChangeL()
1.93 + {
1.94 + #define BACK_PRI EPriorityForeground
1.95 + #define FORE_PRI EPriorityForeground
1.96 + RProcess proc;
1.97 + TEST(proc.Priority()==BACK_PRI);
1.98 + if (proc.Priority()!=BACK_PRI)
1.99 + INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority());
1.100 +
1.101 + iSem2.Signal();
1.102 + iSem1.Wait();
1.103 +
1.104 + TEST(proc.Priority()==FORE_PRI);
1.105 + if (proc.Priority()!=FORE_PRI)
1.106 + INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority());
1.107 +
1.108 + iSem2.Signal();
1.109 + iSem1.Wait();
1.110 +
1.111 + TEST(proc.Priority()==BACK_PRI);
1.112 + if (proc.Priority()!=BACK_PRI)
1.113 + INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority());
1.114 +
1.115 + TInt ident;
1.116 + User::LeaveIfError(ident=TheClient->iWs.FindWindowGroupIdentifier(0,OTHER_PROC_GROUP_NAME,0));
1.117 + TInt retVal = TheClient->iWs.SetWindowGroupOrdinalPosition(ident,1);
1.118 + TEST(retVal==KErrNone);
1.119 + if (retVal!=KErrNone)
1.120 + INFO_PRINTF3(_L("TheClient->iWs.SetWindowGroupOrdinalPosition(ident,1) return value - Expected: %d, Actual: %d"), KErrNone, retVal);
1.121 +
1.122 + TEST(proc.Priority()==FORE_PRI);
1.123 + if (proc.Priority()!=FORE_PRI)
1.124 + INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority());
1.125 +
1.126 + retVal = TheClient->iWs.SetWindowGroupOrdinalPosition(ident,0);
1.127 + TEST(retVal==KErrNone);
1.128 + if (retVal!=KErrNone)
1.129 + INFO_PRINTF3(_L("TheClient->iWs.SetWindowGroupOrdinalPosition(ident,0) return value - Expected: %d, Actual: %d"), KErrNone, retVal);
1.130 +
1.131 + TEST(proc.Priority()==BACK_PRI);
1.132 + if (proc.Priority()!=BACK_PRI)
1.133 + INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority());
1.134 +
1.135 + TRequestStatus stat;
1.136 + 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
1.137 + iSem2.Signal();
1.138 + User::WaitForRequest(stat);
1.139 +
1.140 + TEST(proc.Priority()==FORE_PRI);
1.141 + if (proc.Priority()!=FORE_PRI)
1.142 + INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority());
1.143 +
1.144 + }
1.145 +
1.146 +void CTProcPri::ConstructL()
1.147 + {
1.148 + User::LeaveIfError(iSem1.CreateGlobal(PROC_PRI_SEMAPHORE_NAME1,0,KOwnerType));
1.149 + iFlags|=ECreatedSem1;
1.150 + User::LeaveIfError(iSem2.CreateGlobal(PROC_PRI_SEMAPHORE_NAME2,0,KOwnerType));
1.151 + iFlags|=ECreatedSem2;
1.152 + iProcess=CProcess::NewL(CProcess::eProcessPriortyTest,iTest->iScreenNumber);
1.153 + iSem1.Wait();
1.154 + }
1.155 +
1.156 +void CTProcPri::RunTestCaseL(TInt /*aCurTestCase*/)
1.157 + {
1.158 + _LIT(KTest1,"Priority Change");
1.159 + ((CTProcPriStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.160 +
1.161 + switch(++iTest->iState)
1.162 + {
1.163 +/**
1.164 +
1.165 + @SYMTestCaseID GRAPHICS-WSERV-0315
1.166 +
1.167 + @SYMDEF DEF081259
1.168 +
1.169 + @SYMTestCaseDesc Test that the priority of a process or thread changes depending
1.170 + on how the the process or thread is being used
1.171 +
1.172 + @SYMTestPriority High
1.173 +
1.174 + @SYMTestStatus Implemented
1.175 +
1.176 + @SYMTestActions Create a process or thread and use it. Check the priority of the
1.177 + process or thread changes depending on how it is being used
1.178 +
1.179 + @SYMTestExpectedResults Prioirty of the process of thread changes depending on
1.180 + how it is being used
1.181 +
1.182 +*/
1.183 + case 1:
1.184 + ((CTProcPriStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0315"));
1.185 + iTest->LogSubTest(KTest1);
1.186 + TestPriChangeL();
1.187 + break;
1.188 + case 2:
1.189 + ((CTProcPriStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.190 + ((CTProcPriStep*)iStep)->CloseTMSGraphicsStep();
1.191 + TestComplete();
1.192 + break;
1.193 + }
1.194 + ((CTProcPriStep*)iStep)->RecordTestResultL();
1.195 + }
1.196 +
1.197 +__WS_CONSTRUCT_STEP__(ProcPri)