|
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 // Converted from TMan test code (TMPNTKEY.CPP) May 2001 |
|
15 // Test Pointer move/drag buffer |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @test |
|
22 @internalComponent - Internal Symbian test code |
|
23 */ |
|
24 |
|
25 #include "TPNTKEY.H" |
|
26 |
|
27 #define LOGGING on //Uncomment this line to get more logging |
|
28 |
|
29 TInt CTPntKeyWindow::iTestScanCodes[ENumPntKeyTests]={'A','B',0,'C',EStdKeyEnter,'Y'}; |
|
30 TUint CTPntKeyWindow::iTestCodes[ENumPntKeyTests]={'a','B',0,'c',EKeyEnter,'y'}; |
|
31 TUint CTPntKeyWindow::iTestModifiers[ENumPntKeyTests]={0,EModifierShift,0,0,0,0}; |
|
32 |
|
33 CTPntKeyWindow::CTPntKeyWindow(CTPntKey *aTest) : iTest(aTest) |
|
34 {} |
|
35 |
|
36 CTPntKeyWindow::~CTPntKeyWindow() |
|
37 { |
|
38 } |
|
39 |
|
40 void CTPntKeyWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent) |
|
41 { |
|
42 ConstructExtLD(*parent,pos,size); |
|
43 iWin.SetPointerGrab(ETrue); |
|
44 iKey1=TRect(size.iWidth*1/16,size.iHeight/2,size.iWidth*5/16,size.iHeight); |
|
45 iKey2=TRect(size.iWidth*6/16,size.iHeight/2,size.iWidth*10/16,size.iHeight); |
|
46 iKey3=TRect(size.iWidth*11/16,size.iHeight/2,size.iWidth*15/16,size.iHeight); |
|
47 iWin.AddKeyRect(iKey1,'A',EFalse); |
|
48 iWin.AddKeyRect(iKey2,'B',EFalse); |
|
49 AssignGC(*Client()->iGc); |
|
50 BaseWin()->EnableOnEvents(); |
|
51 Activate(); |
|
52 } |
|
53 |
|
54 void CTPntKeyWindow::Error(TInt aWhere) |
|
55 { |
|
56 iTest->Failed(aWhere); |
|
57 } |
|
58 |
|
59 void CTPntKeyWindow::NextKey() |
|
60 { |
|
61 if (++iKeyCount!=ENumPntKeyTests) |
|
62 { |
|
63 #if defined(LOGGING) |
|
64 _LIT(KLog,"Next Key KeyCount=%d"); |
|
65 iTest->LOG_MESSAGE2(KLog,iKeyCount); |
|
66 #endif |
|
67 if (iKeyCount==2) |
|
68 iWin.RemoveAllKeyRects(); |
|
69 else if (iKeyCount==3) |
|
70 iWin.AddKeyRect(iKey3,'C',EFalse); |
|
71 else if (iKeyCount==4) |
|
72 { |
|
73 #if !defined(__WINS__) |
|
74 if (iTest->NoDigitiser()) |
|
75 { |
|
76 return; |
|
77 } |
|
78 #endif |
|
79 iWin.RemoveAllKeyRects(); |
|
80 iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Z',EFalse); |
|
81 } |
|
82 else if (iKeyCount==5) |
|
83 { |
|
84 iWin.RemoveAllKeyRects(); |
|
85 Client()->iWs.Flush(); |
|
86 User::After(500000); // Wait half a second |
|
87 iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Y',ETrue); |
|
88 } |
|
89 Invalidate(); |
|
90 } |
|
91 SendEvent(); |
|
92 } |
|
93 |
|
94 void CTPntKeyWindow::SendEvent() |
|
95 { |
|
96 TheClient->WaitForRedrawsToFinish(); |
|
97 #if defined(LOGGING) |
|
98 _LIT(KLog,"SendEvent KeyCount=%d"); |
|
99 iTest->LOG_MESSAGE2(KLog,iKeyCount); |
|
100 #endif |
|
101 switch(iKeyCount) |
|
102 { |
|
103 case 0: |
|
104 SimulatePointerDownUp(iKey1); |
|
105 break; |
|
106 case 1: |
|
107 iTest->TestBase()->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift); |
|
108 SimulatePointerDownUp(iKey2); |
|
109 iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift); |
|
110 break; |
|
111 case 2: |
|
112 case 5: |
|
113 { |
|
114 TPoint pos=Position(); |
|
115 TSize size=Size(); |
|
116 iTest->TestBase()->SimulatePointerDownUp(pos.iX+size.iWidth/2,pos.iY+size.iHeight/4); |
|
117 } |
|
118 break; |
|
119 case 3: |
|
120 SimulatePointerDownUp(iKey3); |
|
121 break; |
|
122 case 4: |
|
123 iTest->TestBase()->SimulateKeyDownUp(EStdKeyEnter); |
|
124 break; |
|
125 } |
|
126 } |
|
127 |
|
128 void CTPntKeyWindow::SimulatePointerDownUp(const TRect& aRect) |
|
129 { |
|
130 iTest->TestBase()->SimulatePointerDownUp((aRect.iTl.iX+aRect.iBr.iX)/2,(aRect.iTl.iY+aRect.iBr.iY)/2); |
|
131 } |
|
132 |
|
133 void CTPntKeyWindow::Test(TInt aCheck) |
|
134 { |
|
135 if (!aCheck) |
|
136 Error(3); |
|
137 } |
|
138 |
|
139 void CTPntKeyWindow::KeyUpL(const TKeyEvent &aKey,const TTime&) |
|
140 { |
|
141 if (aKey.iScanCode==iTestScanCodes[iKeyCount]) |
|
142 NextKey(); |
|
143 } |
|
144 |
|
145 void CTPntKeyWindow::KeyDownL(const TKeyEvent &aKey,const TTime &) |
|
146 { |
|
147 #if defined(LOGGING) |
|
148 _LIT(KLog,"KeyDownL ScanCode=%d '%c' (%d) KeyCount=%d"); |
|
149 iTest->LOG_MESSAGE5(KLog,aKey.iScanCode,aKey.iScanCode,iTestScanCodes[iKeyCount],iKeyCount); |
|
150 #endif |
|
151 if (aKey.iScanCode!=EStdKeyLeftFunc && aKey.iScanCode!=EStdKeyRightFunc && |
|
152 aKey.iScanCode!=EStdKeyLeftAlt && aKey.iScanCode!=EStdKeyRightAlt && |
|
153 aKey.iScanCode!=EStdKeyLeftCtrl && aKey.iScanCode!=EStdKeyRightCtrl && |
|
154 aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift && |
|
155 aKey.iScanCode!=EStdKeyOff && |
|
156 aKey.iScanCode!=EStdKeyEscape) |
|
157 Test(aKey.iScanCode==iTestScanCodes[iKeyCount]); |
|
158 } |
|
159 |
|
160 void CTPntKeyWindow::WinKeyL(const TKeyEvent &aKey,const TTime &) |
|
161 { |
|
162 if (aKey.iCode!=EKeyEscape) |
|
163 { |
|
164 #if defined(LOGGING) |
|
165 _LIT(KLog1,"WinKeyL1 ScanCode=%d (%d) Code=%d '%c' (%d)"); |
|
166 _LIT(KLog2,"WinKeyL2 ScanCode=%d Modifiers=0x%x (0x%x) KeyCount=%d"); |
|
167 iTest->LOG_MESSAGE6(KLog1,aKey.iScanCode,iTestScanCodes[iKeyCount],aKey.iCode,aKey.iCode,iTestCodes[iKeyCount]); |
|
168 iTest->LOG_MESSAGE5(KLog2,aKey.iScanCode,aKey.iModifiers&EModifierMask,iTestModifiers[iKeyCount]&EModifierMask,iKeyCount); |
|
169 #endif |
|
170 Test(aKey.iScanCode==iTestScanCodes[iKeyCount]); |
|
171 Test(aKey.iCode==iTestCodes[iKeyCount]); |
|
172 Test((aKey.iModifiers&EModifierMask)==(iTestModifiers[iKeyCount]&EModifierMask)); |
|
173 } |
|
174 } |
|
175 |
|
176 void CTPntKeyWindow::SwitchOn(const TTime &) |
|
177 { |
|
178 #if defined(LOGGING) |
|
179 _LIT(KLog,"SwitchOn KeyCount=%d"); |
|
180 iTest->LOG_MESSAGE2(KLog,iKeyCount); |
|
181 #endif |
|
182 if (iKeyCount==4) |
|
183 NextKey(); |
|
184 else if (iKeyCount!=5) |
|
185 Error(2); |
|
186 } |
|
187 |
|
188 void CTPntKeyWindow::PointerL(const TPointerEvent &aPointer,const TTime &) |
|
189 { |
|
190 #if defined(LOGGING) |
|
191 _LIT(KLog,"Pointer Event Type=%d Pos=(%d,%d) PPos=(%d,%d) KeyCount=%d"); |
|
192 iTest->LOG_MESSAGE7(KLog,aPointer.iType,aPointer.iPosition.iX,aPointer.iPosition.iY |
|
193 ,aPointer.iParentPosition.iX,aPointer.iParentPosition.iY,iKeyCount); |
|
194 #endif |
|
195 if (aPointer.iType==TPointerEvent::EButton1Down) |
|
196 { |
|
197 if (iKeyCount!=2) |
|
198 Error(1); |
|
199 else |
|
200 NextKey(); |
|
201 } |
|
202 } |
|
203 |
|
204 void CTPntKeyWindow::DrawButton(const TRect &aRect, const TDesC &aText) |
|
205 { |
|
206 iGc->DrawRect(aRect); |
|
207 iGc->DrawText(aText, TPoint((aRect.iBr.iX+aRect.iTl.iX)/2,(aRect.iBr.iY+aRect.iTl.iY)/2)); |
|
208 } |
|
209 |
|
210 void CTPntKeyWindow::Draw() |
|
211 { |
|
212 iGc->SetBrushColor(TRgb::Gray4(0)); |
|
213 iGc->SetPenColor(TRgb::Gray4(3)); |
|
214 iGc->Clear(); |
|
215 DrawButton(iKey1,_L("A")); |
|
216 DrawButton(iKey2,_L("B")); |
|
217 DrawButton(iKey3,_L("C")); |
|
218 switch(iKeyCount) |
|
219 { |
|
220 case 0: |
|
221 iGc->DrawText(_L("Click on 'A'"), TPoint(10,20)); |
|
222 break; |
|
223 case 1: |
|
224 iGc->DrawText(_L("Shift-Click on 'B'"), TPoint(10,20)); |
|
225 break; |
|
226 case 2: |
|
227 iGc->DrawText(_L("Click anywhere in this window"), TPoint(10,20)); |
|
228 break; |
|
229 case 3: |
|
230 iGc->DrawText(_L("Click on 'C'"), TPoint(10,20)); |
|
231 break; |
|
232 case 4: |
|
233 #if defined(__WINS__) // Can't emulate touching dig when switched off under WINS |
|
234 iGc->DrawText(_L("Switch off and on (or press Enter)"), TPoint(10,20)); |
|
235 #else |
|
236 iGc->DrawText(_L("Switch off, then touch the screen to switch on"), TPoint(10,20)); |
|
237 #endif |
|
238 break; |
|
239 case 5: |
|
240 #if defined(__WINS__) // Can't emulate touching dig when switched off under WINS |
|
241 iGc->DrawText(_L("Touch anywhere in the window"), TPoint(10,20)); |
|
242 #else |
|
243 iGc->DrawText(_L("Switch off and touch the screen to switch on again"), TPoint(10,20)); |
|
244 #endif |
|
245 break; |
|
246 } |
|
247 } |
|
248 |
|
249 CTPntKey::CTPntKey(CTestStep* aStep): |
|
250 CTWsGraphicsBase(aStep) |
|
251 { |
|
252 } |
|
253 |
|
254 CTPntKey::~CTPntKey() |
|
255 { |
|
256 HAL::Set(HALData::EPenDisplayOn,iOldPointerState); |
|
257 CTWin::Delete(iWin); |
|
258 Client()->ResetFocus(); |
|
259 delete iTimeOut; |
|
260 } |
|
261 |
|
262 TInt CTPntKey::TimeOut(TAny* aTest) //static |
|
263 { |
|
264 static_cast<CTPntKey*>(aTest)->TimeOut(); |
|
265 return(KErrNone); |
|
266 } |
|
267 |
|
268 void CTPntKey::TimeOut() |
|
269 { |
|
270 TLogMessageText buf; |
|
271 _LIT(KPntKeyTimeOut,"TIMEOUT: Pointer Key, %d, %S"); |
|
272 buf.AppendFormat(KPntKeyTimeOut,iState,&TestBase()->iSubTitle); |
|
273 TheClient->LogMessage(buf); |
|
274 Failed(4); |
|
275 } |
|
276 |
|
277 void CTPntKey::Failed(TInt aWhere) |
|
278 { |
|
279 _LIT(KLog,"Failed at %d"); |
|
280 LOG_MESSAGE2(KLog,aWhere); |
|
281 if (!iFailed) |
|
282 { |
|
283 iFailed=ETrue; |
|
284 Client()->iGroup->ClearCurrentWindow(); |
|
285 } |
|
286 } |
|
287 |
|
288 void CTPntKey::ConstructL() |
|
289 { |
|
290 TInt mods=TheClient->iWs.GetModifierState(); |
|
291 if (mods&EModifierCapsLock) |
|
292 iTest->SimulateKeyDownUp(EStdKeyCapsLock); |
|
293 //Make sure all the keys we test are in the up state |
|
294 iTest->SimulateKeyDownUp(EStdKeyLeftShift); |
|
295 iTest->SimulateKeyDownUp(EStdKeyRightShift); |
|
296 iTest->SimulateKeyDownUp(EStdKeyLeftFunc); |
|
297 iTest->SimulateKeyDownUp(EStdKeyLeftCtrl); |
|
298 iTest->SimulateKeyDownUp(EStdKeyRightCtrl); |
|
299 mods=TheClient->iWs.GetModifierState(); |
|
300 _LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)"); |
|
301 LOG_MESSAGE2(KLog,mods); |
|
302 TheClient->iScreen->SetScreenMode(0); //May sure we are in the right screen size mode |
|
303 TheClient->iScreen->SetAppScreenMode(0); |
|
304 TheClient->iWs.SetPointerCursorArea(TestBase()->iNormalPointerCursorArea); |
|
305 CTPntKeyWindow *win=new(ELeave) CTPntKeyWindow(this); |
|
306 win->SetUpLD(TPoint(20,20),Client()->iScreen->SizeInPixels()-TSize(40,40),Client()->iGroup); |
|
307 iWin=win; |
|
308 Client()->iGroup->SetCurrentWindow(iWin); |
|
309 iNoDigitiser=EFalse; |
|
310 TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState); |
|
311 if (err==KErrNotSupported) |
|
312 { |
|
313 iNoDigitiser=ETrue; |
|
314 } |
|
315 else if (err==KErrNone) |
|
316 { |
|
317 err=HAL::Set(HALData::EPenDisplayOn,ETrue); |
|
318 if (err==KErrNotSupported) |
|
319 iNoDigitiser=(!iOldPointerState); |
|
320 } |
|
321 else |
|
322 { |
|
323 TEST(EFalse); |
|
324 } |
|
325 TheClient->WaitForRedrawsToFinish(); //Make sure all pending events have been delt with (redraw events are lowest priority) |
|
326 iTimeOut=new(ELeave) CTimeOut(); |
|
327 iTimeOut->ConstructL(); |
|
328 iTimeOut->Start(KTimeOutAfter,TCallBack(CTPntKey::TimeOut,this)); |
|
329 } |
|
330 |
|
331 void CTPntKey::RunTestCaseL(TInt /*aCurTestCase*/) |
|
332 { |
|
333 _LIT(KTestName,"Key set 1"); |
|
334 TEST(!iFailed); |
|
335 if (iFailed) |
|
336 { |
|
337 _LIT(KLog,"Test Failed Substate=%d KeyCount=%d"); |
|
338 LOG_MESSAGE3(KLog,iTest->iState,iWin->KeyCount()); |
|
339 } |
|
340 ((CTPntKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
341 switch(++iTest->iState) |
|
342 { |
|
343 /** |
|
344 @SYMTestCaseID GRAPHICS-WSERV-0200 |
|
345 |
|
346 @SYMDEF DEF081259 |
|
347 |
|
348 @SYMTestCaseDesc Test Pointer move/drag buffer |
|
349 |
|
350 @SYMTestPriority High |
|
351 |
|
352 @SYMTestStatus Implemented |
|
353 |
|
354 @SYMTestActions Exercise the pointer move/drag buffer and check |
|
355 that it functions correctly |
|
356 |
|
357 @SYMTestExpectedResults The buffer functions correctly |
|
358 */ |
|
359 case 1: |
|
360 ((CTPntKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0200")); |
|
361 iTest->LogSubTest(KTestName); |
|
362 if (TestBase()->ConfigurationSupportsPointerEventTesting()) |
|
363 { |
|
364 iWin->SendEvent(); |
|
365 TheClient->Flush(); |
|
366 } |
|
367 else |
|
368 { |
|
369 INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing")); |
|
370 } |
|
371 break; |
|
372 case 2: |
|
373 ((CTPntKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
374 ((CTPntKeyStep*)iStep)->CloseTMSGraphicsStep(); |
|
375 if (TestBase()->ConfigurationSupportsPointerEventTesting()) |
|
376 { |
|
377 iTimeOut->Cancel(); |
|
378 } |
|
379 TestComplete(); |
|
380 break; |
|
381 } |
|
382 ((CTPntKeyStep*)iStep)->RecordTestResultL(); |
|
383 } |
|
384 |
|
385 __WS_CONSTRUCT_STEP__(PntKey) |