First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Test pointer event handling
21 #include "../tlib/testbase.h"
27 class CPointerWindow : public CTWin
29 enum {KRepeatMargin=200000}; // 0.2 Seconds
30 enum {KRepeatCount=4};
31 enum {KRepeatIntervalIncrements=100000};
32 enum {KRepeatRectXExtra=50};
33 enum {KRepeatRectYExtra=50};
34 enum {KStateWaitingForTest1,KStateFailed,KStateTesting1,
35 KStateWaitingForTest2,KStateTesting2,
36 KStateWaitingForTest3,KStateTesting3,
37 KStateWaitingForTest4,KStateTesting4,
38 KStateWaitingForTest5,KStateTesting5,
39 KStateWaitingForTest6,KStateTesting6,
40 KStateWaitingForTest8,KStateTesting8,
41 KStateWaitingForTest7,KStateTesting7,
44 CPointerWindow(CTPointerTest *aTest);
45 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
47 void StartNextRepeatTest();
48 void QueueNextRepeat();
49 void PointerL(const TPointerEvent &aPointer,const TTime&);
50 void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
52 void SwitchOn(const TTime &);
53 void ResetTest(TInt aState);
54 void SetState(TInt aState);
61 TTimeIntervalMicroSeconds32 iInterval;
66 class CGrabWindow2 : public CTWin
69 CGrabWindow2(CGrabWindow *aWindow);
70 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
73 void PointerL(const TPointerEvent &aPointer,const TTime&);
75 CGrabWindow *iGrabWindow;
78 class CGrabWindow : public CTWin
80 enum {KGrabStateWaitingForDown,KGrabStateWaitingForDragOut,KGrabStateWaitingForUp,KGrabStateFinished,
81 KGrabStateWaitingForDown2,KGrabStateWaitingForUp2a,KGrabStateWaitingForDrag2,KGrabStateWaitingForUp2b,
82 KGrabStateWaitingForDown3,KGrabStateWaitingForUp3a,KGrabStateWaitingForUp3b,
83 KGrabStateWaitingForDown4,KGrabStateWaitingForUp4,
84 KGrabStateWaitingForDown5,KGrabStateWaitingForUp5,KGrabStateWaitingForDrag5,
87 CGrabWindow(CTPointerTest *aTest);
88 void Pointer2(const TPointerEvent &aPointer);
89 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
90 void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
93 void SetState(TInt aState);
95 void PointerL(const TPointerEvent &aPointer,const TTime&);
100 CTPointerTest *iTest;
103 class CTPointerTest : public CTestBase
110 void StartGrabTestL();
112 CGrabWindow2 *GrabWin2() const;
113 inline TBool Digitiser() const {return !iNoDigitiser;}
115 TInt doTestFailedL();
117 CPointerWindow *iRepeatWin;
118 CGrabWindow *iGrabWin;
119 CGrabWindow2 *iGrabWin2;
122 TBool iOldPointerState;
126 GLDEF_C CTestBase *CreatePointerTest()
128 return(new(ELeave) CTPointerTest());
131 CPointerWindow::CPointerWindow(CTPointerTest *aTest) : CTWin(), iTest(aTest)
134 void CPointerWindow::SetState(TInt aState)
140 case KStateWaitingForTest1:
141 case KStateWaitingForTest2:
142 case KStateWaitingForTest3:
143 case KStateWaitingForTest4:
144 case KStateWaitingForTest5:
145 case KStateWaitingForTest6:
146 case KStateWaitingForTest8:
147 case KStateWaitingForTest7:
152 Client()->iWs.Flush();
159 void CPointerWindow::ResetTest(TInt aState)
161 TInt newState=KStateFinished;
165 newState=KStateWaitingForTest1;
168 newState=KStateWaitingForTest2;
171 newState=KStateWaitingForTest3;
174 newState=KStateWaitingForTest4;
177 newState=KStateWaitingForTest5;
180 newState=KStateWaitingForTest6;
183 newState=KStateWaitingForTest8;
186 newState=KStateWaitingForTest7;
192 void CPointerWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
194 ConstructExtLD(*parent,pos,size);
197 //SetState(KStateWaitingForTest1);
198 SetState(KStateWaitingForTest7); //Only unconverted test
199 BaseWin()->EnableOnEvents();
202 void CPointerWindow::Draw()
205 iGc->DrawRect(Size());
206 iGc->DrawRect(iRepeatRect);
211 case KStateWaitingForTest1:
212 buf.Format(_L("Click anywhere in the window and hold the pointer steady"));
215 buf.Format(_L("Hold pointer inside the box"));
217 case KStateWaitingForTest2:
218 buf.Format(_L("Release the pointer then click in the window and hold the pointer steady"));
221 buf.Format(_L("Drag the pointer outside the box"));
223 case KStateWaitingForTest3:
224 buf.Format(_L("Release the pointer then click in the window and hold the pointer steady"));
227 buf.Format(_L("Release the pointer"));
229 case KStateWaitingForTest4:
230 buf.Format(_L("Click anywhere in the window and move the pointer slightly"));
233 buf.Format(_L("Release the pointer"));
235 case KStateWaitingForTest5:
236 buf.Format(_L("Click anywhere in the window and move the pointer slightly"));
239 buf.Format(_L("Release the pointer"));
241 case KStateWaitingForTest6:
242 buf.Format(_L("Click anywhere in the window"));
245 buf.Format(_L("Move the pointer"));
247 case KStateWaitingForTest8:
248 buf.Format(_L("Click anywhere in the window, and keep the pointer pressed"));
253 case KStateWaitingForTest7:
254 buf.Format(_L("Switch off and touch the center of the screen"));
263 buf2.Format(TRefByValue<const TDesC>(_L("Repeat (%d/%d), interval=%d.%d")),iRepeatCount,KRepeatCount,iInterval.Int()/1000000,(iInterval.Int()%1000000)/100000);
267 buf2.Format(TRefByValue<const TDesC>(_L("Repeat (%d), interval=%d.%d")),iRepeatCount,iInterval.Int()/1000000,(iInterval.Int()%1000000)/100000);
270 iGc->DrawText(buf,TPoint(10,20));
271 iGc->DrawText(buf2,TPoint(10,40));
274 void CPointerWindow::FinishedTests()
276 iState=KStateFinished;
280 void CPointerWindow::StartNextRepeatTest()
284 if (iState==KStateWaitingForTest4)
285 User::After(TTimeIntervalMicroSeconds32(1000000));
286 else if (iState==KStateWaitingForTest5)
287 User::After(TTimeIntervalMicroSeconds32(1000000));
291 case KStateWaitingForTest1:
292 SetState(KStateTesting1);
294 case KStateWaitingForTest2:
295 SetState(KStateTesting2);
297 case KStateWaitingForTest3:
298 SetState(KStateTesting3);
300 case KStateWaitingForTest4:
301 SetState(KStateTesting4);
303 case KStateWaitingForTest5:
304 SetState(KStateTesting5);
306 case KStateWaitingForTest6:
307 SetState(KStateTesting6);
309 case KStateWaitingForTest8:
310 SetState(KStateTesting8);
312 case KStateWaitingForTest7:
313 SetState(KStateTesting7);
318 void CPointerWindow::QueueNextRepeat()
320 iInterval=iInterval.Int()+KRepeatIntervalIncrements;
321 iWin.RequestPointerRepeatEvent(TTimeIntervalMicroSeconds32(iInterval),TRect(iRepeatRect));
322 iPrevTime.HomeTime();
326 void CPointerWindow::PointerL(const TPointerEvent &aPointer,const TTime &aTime)
328 if (aPointer.iType==TPointerEvent::EButtonRepeat)
330 if (iState!=KStateTesting1 && iState!=KStateTesting2 && iState!=KStateTesting3 && iState!=KStateTesting4)
334 TTimeIntervalMicroSeconds32 interval(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()));
335 if (interval.Int()<(iInterval.Int()-KRepeatMargin) || interval.Int()>(iInterval.Int()+KRepeatMargin))
339 if (!iRepeatRect.Contains(aPointer.iPosition) ||
340 aPointer.iParentPosition!=(aPointer.iPosition+iWin.InquireOffset(*Parent()->WinTreeNode())))
345 if (iState==KStateTesting1 && iRepeatCount==KRepeatCount)
348 Client()->iWs.Flush();
349 User::After(TTimeIntervalMicroSeconds32(iRepeatCount*KRepeatIntervalIncrements));
350 iWin.CancelPointerRepeatEventRequest();
351 SetState(KStateWaitingForTest2);
361 case KStateWaitingForTest1:
362 case KStateWaitingForTest2:
363 case KStateWaitingForTest3:
364 case KStateWaitingForTest4:
365 case KStateWaitingForTest8:
366 if (aPointer.iType==TPointerEvent::EButton1Down)
368 iRepeatRect.iTl=aPointer.iPosition-TPoint(KRepeatRectXExtra,KRepeatRectYExtra);
369 iRepeatRect.iBr=aPointer.iPosition+TPoint(KRepeatRectXExtra,KRepeatRectYExtra);
370 StartNextRepeatTest();
373 case KStateWaitingForTest5:
374 if (aPointer.iType==TPointerEvent::EButton1Down)
376 iRepeatRect.iTl=aPointer.iPosition;
377 iRepeatRect.iBr=aPointer.iPosition+TPoint(1,1);
378 StartNextRepeatTest();
381 case KStateWaitingForTest6:
382 if (aPointer.iType==TPointerEvent::EButton1Down)
384 iRepeatRect.iTl=aPointer.iPosition+TPoint(KRepeatRectXExtra,KRepeatRectYExtra);
385 iRepeatRect.iBr=aPointer.iPosition+TPoint(2*KRepeatRectXExtra,2*KRepeatRectYExtra);
386 StartNextRepeatTest();
393 if (aPointer.iType==TPointerEvent::EDrag)
394 SetState(KStateWaitingForTest3);
399 if (aPointer.iType==TPointerEvent::EButton1Up)
400 SetState(KStateWaitingForTest4);
405 if (aPointer.iType==TPointerEvent::EButton1Up)
406 SetState(KStateWaitingForTest5);
411 if (aPointer.iType==TPointerEvent::EButton1Up)
412 SetState(KStateWaitingForTest6);
413 else if (aPointer.iType!=TPointerEvent::EDrag)
417 if (aPointer.iType==TPointerEvent::EDrag)
419 #if !defined(__WINS__) // Can't emulate touching dig when switched off under WINS
420 if (iTest->Digitiser())
421 SetState(KStateWaitingForTest7);
424 SetState(KStateWaitingForTest8);
429 case KStateWaitingForTest7:
430 if (aPointer.iType==TPointerEvent::EButton1Down || aPointer.iType==TPointerEvent::ESwitchOn)
434 if (aPointer.iType!=TPointerEvent::ESwitchOn)
437 SetState(KStateTesting8); //Jump straight to end as this is only unconverted test.
438 //SetState(KStateWaitingForTest8);
445 void CPointerWindow::TestFailed()
447 if (iState!=KStateFailed)
449 TInt oldState=iState;
451 if (iTest->TestFailed())
456 void CPointerWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
458 if (aKey.iCode==EKeyEscape)
459 FinishedTests(); // Simply skip this test if the Escape key is pressed
462 void CPointerWindow::SwitchOn(const TTime &)
464 if (iState==KStateWaitingForTest7)
465 SetState(KStateTesting7);
474 CGrabWindow::CGrabWindow(CTPointerTest *aTest) : iTest(aTest)
478 void CGrabWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
480 ConstructExtLD(*parent,pos,size);
483 SetState(KGrabStateWaitingForDown);
486 void CGrabWindow::Draw()
489 iGc->DrawRect(Size());
493 case KGrabStateWaitingForDown:
494 case KGrabStateWaitingForDown2:
495 case KGrabStateWaitingForDown5:
496 buf.Copy(_L("Press the pointer inside the window"));
498 case KGrabStateWaitingForDown3:
499 case KGrabStateWaitingForUp3a:
500 buf.Copy(_L("Press and release the pointer inside the window"));
502 case KGrabStateWaitingForDragOut:
503 buf.Copy(_L("Drag the pointer outside into the outside window"));
505 case KGrabStateWaitingForDrag2:
506 buf.Copy(_L("Drag the pointer outside outside both windows"));
508 case KGrabStateWaitingForUp:
509 case KGrabStateWaitingForUp2b:
510 case KGrabStateWaitingForUp5:
511 buf.Copy(_L("Release the pointer"));
513 case KGrabStateWaitingForDown4:
514 buf.Copy(_L("Press then release the pointer"));
518 iGc->DrawText(buf,TPoint(10,20));
521 void CGrabWindow::PointerL(const TPointerEvent &aPointer,const TTime&)
525 case KGrabStateWaitingForDown:
526 if (aPointer.iType==TPointerEvent::EButton1Down)
527 SetState(KGrabStateWaitingForDragOut);
529 case KGrabStateWaitingForDragOut:
530 if (aPointer.iType!=TPointerEvent::EDrag)
534 if (!TRect(Size()).Contains(aPointer.iPosition))
535 SetState(KGrabStateWaitingForUp);
538 case KGrabStateWaitingForUp:
539 if (aPointer.iType==TPointerEvent::EDrag)
541 if (aPointer.iType==TPointerEvent::EButton1Up)
542 SetState(KGrabStateWaitingForDown2);
546 case KGrabStateWaitingForDown2:
547 if (aPointer.iType!=TPointerEvent::EButton1Down)
551 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab();
552 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab(); // Call twice to check it's harmless
553 SetState(KGrabStateWaitingForUp2a);
556 case KGrabStateWaitingForUp2a:
557 SetState(KGrabStateWaitingForDrag2);
559 case KGrabStateWaitingForDrag2:
561 case KGrabStateWaitingForUp2b:
564 case KGrabStateWaitingForDown3:
565 if (aPointer.iType!=TPointerEvent::EButton1Down)
568 SetState(KGrabStateWaitingForUp3a);
570 case KGrabStateWaitingForUp3a:
571 if (aPointer.iType==TPointerEvent::EButton1Up)
573 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab();
574 SetState(KGrabStateWaitingForUp3b);
577 case KGrabStateWaitingForUp3b:
580 case KGrabStateWaitingForDown5:
581 if (aPointer.iType!=TPointerEvent::EButton1Down)
585 iTest->GrabWin2()->BaseWin()->ClaimPointerGrab(EFalse);
586 SetState(KGrabStateWaitingForDrag5);
589 case KGrabStateWaitingForDrag5:
590 if (aPointer.iType==TPointerEvent::EButton1Up)
593 case KGrabStateWaitingForUp5:
596 case KGrabStateWaitingForDown4:
597 SetState(KGrabStateWaitingForUp4);
598 iWin.Close(); // Close the window with the grab captured in it
600 case KGrabStateFinished:
605 void CGrabWindow::ResetTest()
607 SetState(KGrabStateWaitingForDown);
610 void CGrabWindow::Pointer2(const TPointerEvent &aPointer)
614 case KGrabStateWaitingForDrag2:
616 if (aPointer.iType==TPointerEvent::EDrag)
618 SetState(KGrabStateWaitingForUp2b);
622 if (iTest->TestFailed())
627 case KGrabStateWaitingForUp2b:
628 if (aPointer.iType==TPointerEvent::EDrag) // Harmless
630 if (aPointer.iType==TPointerEvent::EButton1Up)
631 SetState(KGrabStateWaitingForDown3);
635 case KGrabStateWaitingForUp3b:
636 if (aPointer.iType==TPointerEvent::EButton1Up)
637 SetState(KGrabStateWaitingForDown5);
641 case KGrabStateWaitingForUp4:
644 case KGrabStateWaitingForDrag5:
646 if (aPointer.iType==TPointerEvent::EDrag)
647 SetState(KGrabStateWaitingForUp5);
648 else if (iTest->TestFailed())
652 case KGrabStateWaitingForUp5:
653 if (aPointer.iType==TPointerEvent::EDrag) // Harmless
655 if (aPointer.iType==TPointerEvent::EButton1Up)
656 SetState(KGrabStateWaitingForDown4);
664 void CGrabWindow::SetState(TInt aState)
670 void CGrabWindow::TestFailed()
672 if (iState!=KStateFailed)
675 if (iTest->TestFailed())
680 void CGrabWindow::FinishedTests()
682 iState=KGrabStateFinished;
686 void CGrabWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
688 if (aKey.iCode==EKeyEscape)
689 FinishedTests(); // Simply skip this test if the Escape key is pressed
693 // CGrabWindow2, used as part of grab tests //
696 CGrabWindow2::CGrabWindow2(CGrabWindow *aWindow) : iGrabWindow(aWindow)
700 void CGrabWindow2::Draw()
702 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
703 iGc->SetBrushColor(TRgb::Gray4(2));
704 iGc->DrawRect(Size());
707 void CGrabWindow2::PointerL(const TPointerEvent &aPointer,const TTime&)
709 iGrabWindow->Pointer2(aPointer);
716 CTPointerTest::CTPointerTest() : CTestBase(_L("CTPointerTest"))
719 CTPointerTest::~CTPointerTest()
721 HAL::Set(HALData::EPenDisplayOn,iOldPointerState);
725 Client()->ResetFocus();
728 void CTPointerTest::ConstructL()
730 iRepeatWin=new(ELeave) CPointerWindow(this);
731 TSize screenSize(Client()->iScreen->SizeInPixels());
732 iRepeatWin->SetUpLD(TPoint(screenSize.iWidth/8,screenSize.iHeight/8),TSize(screenSize.iWidth*3/4,screenSize.iHeight*3/4),Client()->iGroup,*Client()->iGc);
733 Client()->iGroup->SetCurrentWindow(iRepeatWin);
735 TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState);
736 if (err==KErrNotSupported)
738 else if (err==KErrNone)
739 err=HAL::Set(HALData::EPenDisplayOn,ETrue);
740 if (err==KErrNotSupported)
741 iNoDigitiser=(!iOldPointerState);
743 TestL(err==KErrNone);
746 TBool CTPointerTest::TestFailed()
749 TRAP_IGNORE(ret=doTestFailedL());
753 return(ETrue); // Re-try test
761 TInt CTPointerTest::doTestFailedL()
763 CTDialog *dialog=new(ELeave) CTDialog();
764 dialog->SetTitle(_L("Pointer repeat test failed"));
765 dialog->SetNumButtons(2);
766 dialog->SetButtonText(0,_L("Retest"));
767 dialog->SetButtonText(1,_L("Fail"));
768 dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
769 return dialog->Display();
772 CGrabWindow2 *CTPointerTest::GrabWin2() const
777 void CTPointerTest::StartGrabTestL()
779 iGrabWin=new(ELeave) CGrabWindow(this);
780 iGrabWin2=new(ELeave) CGrabWindow2(iGrabWin);
782 TSize screenSize(Client()->iScreen->SizeInPixels());
783 iGrabWin2->SetUpL(TPoint(screenSize.iWidth/8,screenSize.iHeight/8),TSize(screenSize.iWidth*3/4,screenSize.iHeight*3/4),Client()->iGroup,*Client()->iGc);
784 Client()->iGroup->SetCurrentWindow(iGrabWin2);
786 iGrabWin->SetUpLD(TPoint(screenSize.iWidth/4,screenSize.iHeight/4),TSize(screenSize.iWidth/2,screenSize.iHeight/2),Client()->iGroup,*Client()->iGc);
787 Client()->iGroup->SetCurrentWindow(iGrabWin);
791 #pragma warning( disable : 4065 ) //switch statement contains 'default' but no 'case' labels
792 TestState CTPointerTest::DoTestL()
796 #if !defined(__WINS__) //Only unconverted test is MARM only
798 LogSubTest(_L("Repeat tests"),1);
807 #pragma warning( default : 4065 )