|
1 // Copyright (c) 1996-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 // Test process priority control |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 |
|
25 #include "TPROCPRI.H" |
|
26 |
|
27 TName OtherGroupName; |
|
28 |
|
29 TInt ProcPriTestOtherProcess(TAny *aScreenNumber) |
|
30 { |
|
31 CTrapCleanup* CleanUpStack=CTrapCleanup::New(); |
|
32 RWsSession ws; |
|
33 User::LeaveIfError(ws.Connect()); |
|
34 // use correct screen |
|
35 // |
|
36 CWsScreenDevice* screen = NULL; |
|
37 TInt err; |
|
38 TRAP(err, screen = new (ELeave) CWsScreenDevice(ws)); |
|
39 if (err!=KErrNone) |
|
40 return err; |
|
41 if ((err=screen->Construct((TInt)aScreenNumber))!=KErrNone) |
|
42 { |
|
43 delete screen; |
|
44 return err; |
|
45 } |
|
46 |
|
47 RWindowGroup group(ws); |
|
48 group.Construct(888); |
|
49 group.SetName(OTHER_PROC_GROUP_NAME); |
|
50 RSemaphore sem1; |
|
51 RSemaphore sem2; |
|
52 sem1.OpenGlobal(PROC_PRI_SEMAPHORE_NAME1); |
|
53 sem2.OpenGlobal(PROC_PRI_SEMAPHORE_NAME2); |
|
54 sem1.Signal(); // Signal thread fully initialised |
|
55 sem2.Wait(); // Wait for command to disable focus |
|
56 // |
|
57 group.EnableReceiptOfFocus(EFalse); |
|
58 ws.Flush(); |
|
59 sem1.Signal(); // Signal focus disabled |
|
60 sem2.Wait(); // Wait for command to enable focus |
|
61 |
|
62 group.EnableReceiptOfFocus(ETrue); |
|
63 ws.Flush(); |
|
64 sem1.Signal(); // Signal focus enabled |
|
65 sem2.Wait(); // Wait until signalled to exit |
|
66 // |
|
67 group.EnableReceiptOfFocus(EFalse); // To stop shell being tasked into foreground |
|
68 delete screen; |
|
69 ws.Close(); |
|
70 sem1.Close(); |
|
71 sem2.Close(); |
|
72 delete CleanUpStack; |
|
73 return(KErrNone); |
|
74 } |
|
75 |
|
76 CTProcPri::CTProcPri(CTestStep* aStep) : CTWsGraphicsBase(aStep) |
|
77 { |
|
78 } |
|
79 |
|
80 CTProcPri::~CTProcPri() |
|
81 { |
|
82 if (iFlags&ECreatedSem1) |
|
83 iSem1.Close(); |
|
84 if (iFlags&ECreatedSem2) |
|
85 iSem2.Close(); |
|
86 delete iProcess; |
|
87 } |
|
88 |
|
89 void CTProcPri::TestPriChangeL() |
|
90 { |
|
91 #define BACK_PRI EPriorityForeground |
|
92 #define FORE_PRI EPriorityForeground |
|
93 RProcess proc; |
|
94 TEST(proc.Priority()==BACK_PRI); |
|
95 if (proc.Priority()!=BACK_PRI) |
|
96 INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority()); |
|
97 |
|
98 iSem2.Signal(); |
|
99 iSem1.Wait(); |
|
100 |
|
101 TEST(proc.Priority()==FORE_PRI); |
|
102 if (proc.Priority()!=FORE_PRI) |
|
103 INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority()); |
|
104 |
|
105 iSem2.Signal(); |
|
106 iSem1.Wait(); |
|
107 |
|
108 TEST(proc.Priority()==BACK_PRI); |
|
109 if (proc.Priority()!=BACK_PRI) |
|
110 INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority()); |
|
111 |
|
112 TInt ident; |
|
113 User::LeaveIfError(ident=TheClient->iWs.FindWindowGroupIdentifier(0,OTHER_PROC_GROUP_NAME,0)); |
|
114 TInt retVal = TheClient->iWs.SetWindowGroupOrdinalPosition(ident,1); |
|
115 TEST(retVal==KErrNone); |
|
116 if (retVal!=KErrNone) |
|
117 INFO_PRINTF3(_L("TheClient->iWs.SetWindowGroupOrdinalPosition(ident,1) return value - Expected: %d, Actual: %d"), KErrNone, retVal); |
|
118 |
|
119 TEST(proc.Priority()==FORE_PRI); |
|
120 if (proc.Priority()!=FORE_PRI) |
|
121 INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority()); |
|
122 |
|
123 retVal = TheClient->iWs.SetWindowGroupOrdinalPosition(ident,0); |
|
124 TEST(retVal==KErrNone); |
|
125 if (retVal!=KErrNone) |
|
126 INFO_PRINTF3(_L("TheClient->iWs.SetWindowGroupOrdinalPosition(ident,0) return value - Expected: %d, Actual: %d"), KErrNone, retVal); |
|
127 |
|
128 TEST(proc.Priority()==BACK_PRI); |
|
129 if (proc.Priority()!=BACK_PRI) |
|
130 INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), BACK_PRI, proc.Priority()); |
|
131 |
|
132 TRequestStatus stat; |
|
133 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 |
|
134 iSem2.Signal(); |
|
135 User::WaitForRequest(stat); |
|
136 |
|
137 TEST(proc.Priority()==FORE_PRI); |
|
138 if (proc.Priority()!=FORE_PRI) |
|
139 INFO_PRINTF3(_L("proc.Priority() return value - Expected: %d, Actual: %d"), FORE_PRI, proc.Priority()); |
|
140 |
|
141 } |
|
142 |
|
143 void CTProcPri::ConstructL() |
|
144 { |
|
145 User::LeaveIfError(iSem1.CreateGlobal(PROC_PRI_SEMAPHORE_NAME1,0,KOwnerType)); |
|
146 iFlags|=ECreatedSem1; |
|
147 User::LeaveIfError(iSem2.CreateGlobal(PROC_PRI_SEMAPHORE_NAME2,0,KOwnerType)); |
|
148 iFlags|=ECreatedSem2; |
|
149 iProcess=CProcess::NewL(CProcess::eProcessPriortyTest,iTest->iScreenNumber); |
|
150 iSem1.Wait(); |
|
151 } |
|
152 |
|
153 void CTProcPri::RunTestCaseL(TInt /*aCurTestCase*/) |
|
154 { |
|
155 _LIT(KTest1,"Priority Change"); |
|
156 ((CTProcPriStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
157 |
|
158 switch(++iTest->iState) |
|
159 { |
|
160 /** |
|
161 |
|
162 @SYMTestCaseID GRAPHICS-WSERV-0315 |
|
163 |
|
164 @SYMDEF DEF081259 |
|
165 |
|
166 @SYMTestCaseDesc Test that the priority of a process or thread changes depending |
|
167 on how the the process or thread is being used |
|
168 |
|
169 @SYMTestPriority High |
|
170 |
|
171 @SYMTestStatus Implemented |
|
172 |
|
173 @SYMTestActions Create a process or thread and use it. Check the priority of the |
|
174 process or thread changes depending on how it is being used |
|
175 |
|
176 @SYMTestExpectedResults Prioirty of the process of thread changes depending on |
|
177 how it is being used |
|
178 |
|
179 */ |
|
180 case 1: |
|
181 ((CTProcPriStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0315")); |
|
182 iTest->LogSubTest(KTest1); |
|
183 TestPriChangeL(); |
|
184 break; |
|
185 case 2: |
|
186 ((CTProcPriStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
187 ((CTProcPriStep*)iStep)->CloseTMSGraphicsStep(); |
|
188 TestComplete(); |
|
189 break; |
|
190 } |
|
191 ((CTProcPriStep*)iStep)->RecordTestResultL(); |
|
192 } |
|
193 |
|
194 __WS_CONSTRUCT_STEP__(ProcPri) |