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 // Converted from TMan test code (TMPNTKEY.CPP) May 2001
15 // Test Pointer move/drag buffer
22 @internalComponent - Internal Symbian test code
27 #define LOGGING on //Uncomment this line to get more logging
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};
33 CTPntKeyWindow::CTPntKeyWindow(CTPntKey *aTest) : iTest(aTest)
36 CTPntKeyWindow::~CTPntKeyWindow()
40 void CTPntKeyWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
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();
54 void CTPntKeyWindow::Error(TInt aWhere)
56 iTest->Failed(aWhere);
59 void CTPntKeyWindow::NextKey()
61 if (++iKeyCount!=ENumPntKeyTests)
64 _LIT(KLog,"Next Key KeyCount=%d");
65 iTest->LOG_MESSAGE2(KLog,iKeyCount);
68 iWin.RemoveAllKeyRects();
69 else if (iKeyCount==3)
70 iWin.AddKeyRect(iKey3,'C',EFalse);
71 else if (iKeyCount==4)
73 #if !defined(__WINS__)
74 if (iTest->NoDigitiser())
79 iWin.RemoveAllKeyRects();
80 iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Z',EFalse);
82 else if (iKeyCount==5)
84 iWin.RemoveAllKeyRects();
85 Client()->iWs.Flush();
86 User::After(500000); // Wait half a second
87 iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Y',ETrue);
94 void CTPntKeyWindow::SendEvent()
96 TheClient->WaitForRedrawsToFinish();
98 _LIT(KLog,"SendEvent KeyCount=%d");
99 iTest->LOG_MESSAGE2(KLog,iKeyCount);
104 SimulatePointerDownUp(iKey1);
107 iTest->TestBase()->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
108 SimulatePointerDownUp(iKey2);
109 iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
114 TPoint pos=Position();
116 iTest->TestBase()->SimulatePointerDownUp(pos.iX+size.iWidth/2,pos.iY+size.iHeight/4);
120 SimulatePointerDownUp(iKey3);
123 iTest->TestBase()->SimulateKeyDownUp(EStdKeyEnter);
128 void CTPntKeyWindow::SimulatePointerDownUp(const TRect& aRect)
130 iTest->TestBase()->SimulatePointerDownUp((aRect.iTl.iX+aRect.iBr.iX)/2,(aRect.iTl.iY+aRect.iBr.iY)/2);
133 void CTPntKeyWindow::Test(TInt aCheck)
139 void CTPntKeyWindow::KeyUpL(const TKeyEvent &aKey,const TTime&)
141 if (aKey.iScanCode==iTestScanCodes[iKeyCount])
145 void CTPntKeyWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
148 _LIT(KLog,"KeyDownL ScanCode=%d '%c' (%d) KeyCount=%d");
149 iTest->LOG_MESSAGE5(KLog,aKey.iScanCode,aKey.iScanCode,iTestScanCodes[iKeyCount],iKeyCount);
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]);
160 void CTPntKeyWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
162 if (aKey.iCode!=EKeyEscape)
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);
170 Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
171 Test(aKey.iCode==iTestCodes[iKeyCount]);
172 Test((aKey.iModifiers&EModifierMask)==(iTestModifiers[iKeyCount]&EModifierMask));
176 void CTPntKeyWindow::SwitchOn(const TTime &)
179 _LIT(KLog,"SwitchOn KeyCount=%d");
180 iTest->LOG_MESSAGE2(KLog,iKeyCount);
184 else if (iKeyCount!=5)
188 void CTPntKeyWindow::PointerL(const TPointerEvent &aPointer,const TTime &)
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);
195 if (aPointer.iType==TPointerEvent::EButton1Down)
204 void CTPntKeyWindow::DrawButton(const TRect &aRect, const TDesC &aText)
206 iGc->DrawRect(aRect);
207 iGc->DrawText(aText, TPoint((aRect.iBr.iX+aRect.iTl.iX)/2,(aRect.iBr.iY+aRect.iTl.iY)/2));
210 void CTPntKeyWindow::Draw()
212 iGc->SetBrushColor(TRgb::Gray4(0));
213 iGc->SetPenColor(TRgb::Gray4(3));
215 DrawButton(iKey1,_L("A"));
216 DrawButton(iKey2,_L("B"));
217 DrawButton(iKey3,_L("C"));
221 iGc->DrawText(_L("Click on 'A'"), TPoint(10,20));
224 iGc->DrawText(_L("Shift-Click on 'B'"), TPoint(10,20));
227 iGc->DrawText(_L("Click anywhere in this window"), TPoint(10,20));
230 iGc->DrawText(_L("Click on 'C'"), TPoint(10,20));
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));
236 iGc->DrawText(_L("Switch off, then touch the screen to switch on"), TPoint(10,20));
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));
243 iGc->DrawText(_L("Switch off and touch the screen to switch on again"), TPoint(10,20));
249 CTPntKey::CTPntKey(CTestStep* aStep):
250 CTWsGraphicsBase(aStep)
254 CTPntKey::~CTPntKey()
256 HAL::Set(HALData::EPenDisplayOn,iOldPointerState);
258 Client()->ResetFocus();
262 TInt CTPntKey::TimeOut(TAny* aTest) //static
264 static_cast<CTPntKey*>(aTest)->TimeOut();
268 void CTPntKey::TimeOut()
271 _LIT(KPntKeyTimeOut,"TIMEOUT: Pointer Key, %d, %S");
272 buf.AppendFormat(KPntKeyTimeOut,iState,&TestBase()->iSubTitle);
273 TheClient->LogMessage(buf);
277 void CTPntKey::Failed(TInt aWhere)
279 _LIT(KLog,"Failed at %d");
280 LOG_MESSAGE2(KLog,aWhere);
284 Client()->iGroup->ClearCurrentWindow();
288 void CTPntKey::ConstructL()
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);
308 Client()->iGroup->SetCurrentWindow(iWin);
310 TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState);
311 if (err==KErrNotSupported)
315 else if (err==KErrNone)
317 err=HAL::Set(HALData::EPenDisplayOn,ETrue);
318 if (err==KErrNotSupported)
319 iNoDigitiser=(!iOldPointerState);
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));
331 void CTPntKey::RunTestCaseL(TInt /*aCurTestCase*/)
333 _LIT(KTestName,"Key set 1");
337 _LIT(KLog,"Test Failed Substate=%d KeyCount=%d");
338 LOG_MESSAGE3(KLog,iTest->iState,iWin->KeyCount());
340 ((CTPntKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
341 switch(++iTest->iState)
344 @SYMTestCaseID GRAPHICS-WSERV-0200
348 @SYMTestCaseDesc Test Pointer move/drag buffer
350 @SYMTestPriority High
352 @SYMTestStatus Implemented
354 @SYMTestActions Exercise the pointer move/drag buffer and check
355 that it functions correctly
357 @SYMTestExpectedResults The buffer functions correctly
360 ((CTPntKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0200"));
361 iTest->LogSubTest(KTestName);
362 if (TestBase()->ConfigurationSupportsPointerEventTesting())
369 INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
373 ((CTPntKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
374 ((CTPntKeyStep*)iStep)->CloseTMSGraphicsStep();
375 if (TestBase()->ConfigurationSupportsPointerEventTesting())
382 ((CTPntKeyStep*)iStep)->RecordTestResultL();
385 __WS_CONSTRUCT_STEP__(PntKey)