|
1 // Copyright (c) 1995-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 capture key |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32svr.h> |
|
20 #include "W32STD.H" |
|
21 #include "../tlib/testbase.h" |
|
22 #include "TMAN.H" |
|
23 |
|
24 enum THotKeyRetValues |
|
25 { |
|
26 EHotKeyOkay, |
|
27 EHotKeyRetry, |
|
28 EHotKeyFail, |
|
29 }; |
|
30 |
|
31 struct SHotKeyParams |
|
32 { |
|
33 THotKey hotKey; |
|
34 TUint keyCode; |
|
35 TUint mod_mask; |
|
36 TUint modifiers; |
|
37 }; |
|
38 |
|
39 struct SHotKeyTestParams |
|
40 { |
|
41 TText *txt; // Text message telling user what to do |
|
42 }; |
|
43 |
|
44 LOCAL_D SHotKeyParams HotKeys[]={ |
|
45 {EHotKeyEnableLogging,'e',EModifierFunc|EModifierCtrl|EModifierShift,0}, |
|
46 {EHotKeyDisableLogging,'d',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc}, |
|
47 {EHotKeyOfDeath,'q',0}, |
|
48 {EHotKeyOfDeath,'w',0}, |
|
49 }; |
|
50 |
|
51 LOCAL_D SHotKeyTestParams HotKeyTests[]={ |
|
52 {(TText *)_S("Use \"e\" to enable logging")}, |
|
53 {(TText *)_S("Use \"<Alt>d\" to disable logging")}, |
|
54 {(TText *)_S("Use \"q\" to kill the foreground app")}, |
|
55 {(TText *)_S("Use \"w\" to kill the foreground app")}, |
|
56 {(TText *)_S("Use \"<Cntrl><Alt><Shift>K\" to kill the foreground app")}, |
|
57 }; |
|
58 |
|
59 LOCAL_D TBool HotKeyTestIsDeathTest[]={EFalse, EFalse, ETrue, ETrue, ETrue}; |
|
60 |
|
61 struct SErrorHotKey |
|
62 { |
|
63 THotKey hotKey; |
|
64 TUint keyCode; |
|
65 TUint mod_mask; |
|
66 TUint modifiers; |
|
67 }; |
|
68 |
|
69 LOCAL_D SErrorHotKey errorKeys[]={ |
|
70 {EHotKeyEnableLogging,'a',EModifierFunc|EModifierShift,EModifierFunc|EModifierCtrl}, |
|
71 {EHotKeyDisableLogging,'1',0,EModifierFunc}, |
|
72 {EHotKeyEnableLogging,3,EModifierCtrl,EModifierCtrl|EModifierShift}, |
|
73 {EHotKeyDisableLogging,'a',EModifierFunc|EModifierShift,EModifierFunc|EModifierCtrl}, |
|
74 {(THotKey)100,'1',0,EModifierFunc}, |
|
75 {(THotKey)200, 3,EModifierCtrl,EModifierCtrl|EModifierShift}, |
|
76 }; |
|
77 |
|
78 const TInt numHotKeys=sizeof(HotKeys)/sizeof(HotKeys[0]); |
|
79 const TInt numHotKeyTests=sizeof(HotKeyTests)/sizeof(HotKeyTests[0]); |
|
80 const TInt numErrorKeys=sizeof(errorKeys)/sizeof(errorKeys[0]); |
|
81 |
|
82 class SHKWindow; |
|
83 class THotKeyTest; |
|
84 class SHKConnection; |
|
85 |
|
86 class SHKDeath : public CActive |
|
87 { |
|
88 public: |
|
89 SHKDeath(TInt aPriority); |
|
90 void SetConnection(SHKConnection *aConn); |
|
91 virtual void DoCancel(); |
|
92 virtual void RunL(); |
|
93 void Request(); |
|
94 private: |
|
95 SHKConnection *iConn; |
|
96 }; |
|
97 |
|
98 class SHKWindowGroup : public CTWindowGroup |
|
99 { |
|
100 public: |
|
101 SHKWindowGroup(CTClient *aClient); |
|
102 void KeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
103 }; |
|
104 |
|
105 class SHKConnection : public CTClient |
|
106 { |
|
107 public: |
|
108 SHKConnection(THotKeyTest *aTest, TInt aMode); |
|
109 ~SHKConnection(); |
|
110 void ConstructL(); |
|
111 void KeyL(const TKeyEvent &aKey); |
|
112 void SubStateChangedL(); |
|
113 void CompleteL(); |
|
114 protected: |
|
115 TInt iMode; |
|
116 SHKDeath iDeath; |
|
117 THotKeyTest *iTest; |
|
118 CTWin *iWin; |
|
119 static TInt iMainWinId; |
|
120 }; |
|
121 |
|
122 class SHKWindow : public CTWin |
|
123 { |
|
124 public: |
|
125 SHKWindow(THotKeyTest *aTest); |
|
126 void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); |
|
127 void Draw(); |
|
128 protected: |
|
129 THotKeyTest *iTest; |
|
130 TRgb iBack; |
|
131 }; |
|
132 |
|
133 class SHKWindow2 : public CTWin |
|
134 { |
|
135 public: |
|
136 SHKWindow2(); |
|
137 void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc); |
|
138 void Draw(); |
|
139 }; |
|
140 |
|
141 class THotKeyTest : public CTestBase |
|
142 { |
|
143 public: |
|
144 THotKeyTest(); |
|
145 ~THotKeyTest(); |
|
146 TestState DoTestL(); |
|
147 void ConstructL(); |
|
148 void EndCaptureKeyTest(); |
|
149 TInt SubState() const; |
|
150 void IncSubStateL(); |
|
151 void BadParamsL(); |
|
152 private: |
|
153 SHKConnection *iConn1; |
|
154 TSize iWinSize; |
|
155 TInt iState; |
|
156 TInt iSubState; |
|
157 TBool iIsInActiveScheduler; |
|
158 }; |
|
159 |
|
160 TInt SHKConnection::iMainWinId; |
|
161 |
|
162 TInt SubThread(TAny *); |
|
163 |
|
164 GLDEF_C CTestBase *CreateHotKeyTest() |
|
165 { |
|
166 return(new(ELeave) THotKeyTest()); |
|
167 } |
|
168 |
|
169 THotKeyTest::THotKeyTest() : CTestBase(_L("Hot Key")) |
|
170 {} |
|
171 |
|
172 THotKeyTest::~THotKeyTest() |
|
173 { |
|
174 User::SetJustInTime(ETrue); |
|
175 for(TInt index=0;index<numHotKeys;index++) |
|
176 { |
|
177 Client()->iWs.ClearHotKeys(HotKeys[index].hotKey); |
|
178 Client()->iWs.RestoreDefaultHotKey(HotKeys[index].hotKey); |
|
179 } |
|
180 delete iConn1; |
|
181 if (iIsInActiveScheduler) |
|
182 CActiveScheduler::Stop(); |
|
183 } |
|
184 |
|
185 void THotKeyTest::EndCaptureKeyTest() |
|
186 { |
|
187 Request(); |
|
188 } |
|
189 |
|
190 void THotKeyTest::ConstructL() |
|
191 { |
|
192 iConn1=new(ELeave) SHKConnection(this, EFalse); |
|
193 iConn1->ConstructL(); |
|
194 for(TInt index=0;index<numHotKeys;index++) |
|
195 User::LeaveIfError(Client()->iWs.SetHotKey(HotKeys[index].hotKey, HotKeys[index].keyCode,HotKeys[index].mod_mask,HotKeys[index].modifiers)); |
|
196 User::SetJustInTime(EFalse); |
|
197 } |
|
198 |
|
199 // |
|
200 // SHKDeath // |
|
201 // |
|
202 |
|
203 SHKDeath::SHKDeath(TInt aPriority) : CActive(aPriority) |
|
204 { |
|
205 CActiveScheduler::Add(this); |
|
206 } |
|
207 |
|
208 void SHKDeath::SetConnection(SHKConnection *aConn) |
|
209 { |
|
210 iConn=aConn; |
|
211 } |
|
212 |
|
213 void SHKDeath::DoCancel() |
|
214 { |
|
215 } |
|
216 |
|
217 void SHKDeath::RunL() |
|
218 { |
|
219 iConn->CompleteL(); |
|
220 } |
|
221 |
|
222 void SHKDeath::Request() |
|
223 { |
|
224 SetActive(); |
|
225 } |
|
226 |
|
227 // |
|
228 |
|
229 SHKWindowGroup::SHKWindowGroup(CTClient *aClient) : CTWindowGroup(aClient) |
|
230 {} |
|
231 |
|
232 void SHKWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &) |
|
233 { |
|
234 ((SHKConnection *)iClient)->KeyL(aKey); |
|
235 } |
|
236 |
|
237 // |
|
238 // SHKConnection |
|
239 |
|
240 SHKConnection::SHKConnection(THotKeyTest *aTest, TInt aMode) : iMode(aMode), iDeath(100), iTest(aTest) |
|
241 { |
|
242 iDeath.SetConnection(this); |
|
243 } |
|
244 |
|
245 SHKConnection::~SHKConnection() |
|
246 { |
|
247 iGroup->GroupWin()->EnableReceiptOfFocus(EFalse); |
|
248 CTWin::Delete(iWin); |
|
249 } |
|
250 |
|
251 void SHKConnection::KeyL(const TKeyEvent &aKey) |
|
252 { |
|
253 if (iTest) |
|
254 { |
|
255 if (aKey.iCode==EKeyEnter && !HotKeyTestIsDeathTest[iTest->SubState()]) |
|
256 iTest->IncSubStateL(); |
|
257 else if (aKey.iCode==EKeyEscape) |
|
258 iTest->AbortL(); |
|
259 } |
|
260 } |
|
261 |
|
262 void SHKConnection::CompleteL() |
|
263 { |
|
264 iTest->IncSubStateL(); |
|
265 } |
|
266 |
|
267 void SHKConnection::SubStateChangedL() |
|
268 { |
|
269 if (HotKeyTestIsDeathTest[iTest->SubState()]) |
|
270 { |
|
271 RThread thread; |
|
272 iMainWinId=iGroup->GroupWin()->Identifier(); |
|
273 TInt subState=iTest->SubState(); |
|
274 User::After(100000); |
|
275 User::LeaveIfError(thread.Create(_L("SubThread"),SubThread,KDefaultStackSize,0x2000,0x2000,&subState,EOwnerThread)); |
|
276 thread.Logon(iDeath.iStatus); |
|
277 iDeath.Request(); |
|
278 thread.Resume(); |
|
279 thread.Close(); |
|
280 } |
|
281 iWin->Invalidate(); |
|
282 iWs.Flush(); |
|
283 } |
|
284 |
|
285 void SHKConnection::ConstructL() |
|
286 { |
|
287 CTClient::ConstructL(); |
|
288 iGroup=new(ELeave) SHKWindowGroup(this); |
|
289 iGroup->ConstructL(); |
|
290 TSize screenSize=iGroup->Size(); |
|
291 iGroup->GroupWin()->AutoForeground(EFalse); // Don't allow clicking to cause foreground, might mess up test |
|
292 TInt winWidth; |
|
293 TInt winHeight; |
|
294 if (iMode==0) |
|
295 { |
|
296 winWidth=screenSize.iWidth/2; |
|
297 winHeight=screenSize.iHeight-10; |
|
298 SHKWindow *win=new(ELeave) SHKWindow(iTest); |
|
299 win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc); |
|
300 iWin=win; |
|
301 } |
|
302 else |
|
303 { |
|
304 winWidth=150; |
|
305 winHeight=50; |
|
306 iGroup->GroupWin()->SetOwningWindowGroup(iMainWinId); |
|
307 SHKWindow2 *win=new(ELeave) SHKWindow2(); |
|
308 win->SetUpL(TPoint((screenSize.iWidth-winWidth)/2,(screenSize.iHeight-winHeight)/2),TSize(winWidth,winHeight),iGroup,*iGc); |
|
309 iWin=win; |
|
310 } |
|
311 iWs.Flush(); |
|
312 } |
|
313 |
|
314 // |
|
315 // SHKWindow, class // |
|
316 // |
|
317 |
|
318 SHKWindow::SHKWindow(THotKeyTest *aTest) : CTWin(), iTest(aTest) |
|
319 { |
|
320 iBack=TRgb::Gray256(230); |
|
321 } |
|
322 |
|
323 void SHKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) |
|
324 { |
|
325 ConstructExtLD(*parent,pos,size); |
|
326 iWin.SetBackgroundColor(iBack); |
|
327 Activate(); |
|
328 AssignGC(aGc); |
|
329 } |
|
330 |
|
331 void SHKWindow::Draw() |
|
332 { |
|
333 iGc->Clear(); |
|
334 iGc->DrawText(TPtrC(HotKeyTests[iTest->SubState()].txt), TPoint(10,20)); |
|
335 iGc->DrawText(TPtrC(_L("Press <Enter> when tested okay")), TPoint(10,35)); |
|
336 iGc->DrawText(TPtrC(_L("or escape to abort tests")), TPoint(10,50)); |
|
337 } |
|
338 |
|
339 // |
|
340 // SHKWindow2, class // |
|
341 // |
|
342 |
|
343 SHKWindow2::SHKWindow2() : CTWin() |
|
344 { |
|
345 } |
|
346 |
|
347 void SHKWindow2::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) |
|
348 { |
|
349 ConstructExtLD(*parent,pos,size); |
|
350 iWin.SetBackgroundColor(TRgb(0,0,0)); |
|
351 Activate(); |
|
352 AssignGC(aGc); |
|
353 } |
|
354 |
|
355 void SHKWindow2::Draw() |
|
356 { |
|
357 iGc->SetBrushColor(TRgb::Gray4(1)); |
|
358 iGc->Clear(); |
|
359 iGc->SetPenColor(TRgb::Gray4(3)); |
|
360 iGc->DrawText(TPtrC(_L("Kill me!!!")), TPoint(10,15)); |
|
361 } |
|
362 |
|
363 // |
|
364 |
|
365 TInt THotKeyTest::SubState() const |
|
366 { |
|
367 return(iSubState); |
|
368 } |
|
369 |
|
370 void THotKeyTest::IncSubStateL() |
|
371 { |
|
372 if (iSubState==(numHotKeyTests-1)) |
|
373 EndCaptureKeyTest(); |
|
374 else |
|
375 { |
|
376 iSubState++; |
|
377 iConn1->SubStateChangedL(); |
|
378 } |
|
379 } |
|
380 |
|
381 void THotKeyTest::BadParamsL() |
|
382 { |
|
383 TInt resCount=Client()->iWs.ResourceCount(); |
|
384 for(TInt index=0;index<numErrorKeys;index++) |
|
385 TestL(Client()->iWs.SetHotKey(errorKeys[index].hotKey, errorKeys[index].keyCode,errorKeys[index].mod_mask,errorKeys[index].modifiers)==KErrArgument); |
|
386 TestL(Client()->iWs.ResourceCount()==resCount); |
|
387 } |
|
388 |
|
389 TestState THotKeyTest::DoTestL() |
|
390 { |
|
391 switch(iState) |
|
392 { |
|
393 case 0: |
|
394 LogSubTest(_L("Errors"),1); |
|
395 BadParamsL(); |
|
396 LogSubTest(_L("CaptureKey"),2); |
|
397 iState++; |
|
398 return(EContinue); |
|
399 default: |
|
400 return(EFinished); |
|
401 } |
|
402 } |
|
403 |
|
404 //======================================================// |
|
405 // Sub thread to do tests and get shot by window server // |
|
406 //======================================================// |
|
407 |
|
408 void SubThreadMain() |
|
409 { |
|
410 CActiveScheduler *TheActiveScheduler=new(ELeave) CActiveScheduler; |
|
411 CActiveScheduler::Install(TheActiveScheduler); |
|
412 SHKConnection *conn=new(ELeave) SHKConnection(NULL, ETrue); |
|
413 conn->ConstructL(); |
|
414 CActiveScheduler::Start(); |
|
415 delete TheActiveScheduler; |
|
416 } |
|
417 |
|
418 TInt SubThread(TAny *) |
|
419 { |
|
420 CTrapCleanup* CleanUpStack=CTrapCleanup::New(); |
|
421 TRAPD(err,SubThreadMain()); |
|
422 delete CleanUpStack; |
|
423 return(err); |
|
424 } |