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 May 2001
15 // Keyboard repeat test
24 // CRKWindow, class //
27 CRKWindow::CRKWindow(CTKRepeat *aTest) : CTWin(), iTest(aTest)
31 void CRKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
33 ConstructExtLD(*parent,pos,size);
34 iWin.SetBackgroundColor(TRgb::Gray256(230));
39 void CRKWindow::Draw()
44 case EStateWaitingForKeyDown:
45 iGc->DrawText(_L("Press and hold the space bar"), TPoint(10,20));
47 case EStateWaitingForFirstRepeat:
48 case EStateWaitingForNthRepeat:
51 buf.Format(TRefByValue<const TDesC>(_L("Keep space bar down (%d repeats so far)")),iRepCount);
52 iGc->DrawText(buf, TPoint(10,20));
55 case EStateWaitingForKeyUp:
56 iGc->DrawText(_L("Release space bar"), TPoint(10,20));
62 void CRKWindow::SetState(TRKStates aState)
65 TLogMessageText logMessageText;
66 _LIT(KStateChange,"State Change Old=%d New=%d");
67 logMessageText.Format(KStateChange,iState,aState);
68 iTest->LOG_MESSAGE(logMessageText);
72 TheClient->WaitForRedrawsToFinish();
76 void CRKWindow::SendEvent()
80 case EStateWaitingForKeyDown:
81 case EStateWaitingForKeyUp:
83 _LIT(KKeyUp,"Send key up event substate 0");
84 _LIT(KKeyDown,"Send key down event substate 4");
85 iTest->LOG_MESSAGE(iState==EStateWaitingForKeyDown ? KKeyDown() : KKeyUp());
87 iTest->TestBase()->SimulateKey((iState==EStateWaitingForKeyDown ? TRawEvent::EKeyDown : TRawEvent::EKeyUp),EStdKeySpace);
89 case EStateWaitingForKeyCode:
90 case EStateWaitingForFirstRepeat:
91 case EStateWaitingForNthRepeat:
95 _LIT(KLog,"SendEvent: substate %d so no event to send");
96 iTest->LOG_MESSAGE2(KLog,iState);
102 TBool CRKWindow::CheckResults()
105 // Checks repeat results, first convert everything to 10th's as that what is actually used
106 // for the timer in the window server.
108 // Return ETrue if the inacuracy in the average time is greater than 1/10th either way
109 // Allow initial 2/10ths either
110 // Allow min 2/10ths below
111 // Allow max 2/10ths above
113 if (iState!=EStateInactive)
115 TInt initial=iInitialGap.Int()/100000;
116 TInt initialX=iInitialRepeatSet.Int()/100000;
119 TInt average=(iTotalGap.Int()/100000)/(iRepCount-1);
120 TInt repeatX=iRepeatSet.Int()/100000;
123 TInt min=iMinGap.Int()/100000;
124 TInt max=iMaxGap.Int()/100000;
125 if (average>(repeatX+1) || average<(repeatX-1))
127 if (initial>(initialX+2) || initial<(initialX-2))
129 #if defined(__MARM_ARM4__)
130 if (min>(repeatX+1) || min<(repeatX-2) || max>(repeatX+3) || max<repeatX)
132 if (max<min || (max+min)<2*(repeatX-2) || (max+min)>2*(repeatX+2))
136 if (min>(repeatX+1) || min<(repeatX-2))
138 if (max>(repeatX+3) || max<repeatX)
144 TDesC& CRKWindow::Report()
146 if (iState!=EStateInactive)
148 iReport.Format(_L("Error, test not completed"));
152 TInt initial=iInitialGap.Int()/10000;
153 TInt initialX=iInitialRepeatSet.Int()/10000;
154 TInt average=(iTotalGap.Int()/10000/(iRepCount-1));
155 TInt repeatX=iRepeatSet.Int()/10000;
156 TInt min=iMinGap.Int()/10000;
157 TInt max=iMaxGap.Int()/10000;
158 iReport.Format(TRefByValue<const TDesC>(_L("Initial=%d [%d], Av=%d [%d], Min=%d, Max=%d")),initial,initialX,average,repeatX,min,max);
163 void CRKWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
166 TLogMessageText logMessageText;
167 _LIT(KKeyDown,"CRKWindow::KeyDownL Code=%d '%c' State=%d (0)");
168 logMessageText.Format(KKeyDown,aKey.iScanCode,aKey.iScanCode,iState);
169 iTest->LOG_MESSAGE(logMessageText);
173 case EStateWaitingForKeyDown:
174 SetState(EStateWaitingForKeyCode);
175 iDownCode=aKey.iScanCode;
181 void CRKWindow::KeyUpL(const TKeyEvent &aKey,const TTime &)
184 TLogMessageText logMessageText;
185 _LIT(KKeyUp,"CRKWindow::KeyUpL Code=%d (%c) State=%d Down=%d");
186 logMessageText.Format(KKeyUp,aKey.iScanCode,aKey.iScanCode,iState,iDownCode);
187 iTest->LOG_MESSAGE(logMessageText);
189 if (aKey.iScanCode==iDownCode)
193 case EStateWaitingForKeyUp:
194 SetState(EStateInactive);
197 SetState(EStateError);
200 CActiveScheduler::Stop();
204 void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime)
206 if (aKey.iCode==EKeyEscape)
208 CActiveScheduler::Stop();
212 TLogMessageText logMessageText;
213 _LIT(KKey,"CRKWindow::WinKeyL Code=%d (%c) State=%d RepeatCount=%d");
214 logMessageText.Format(KKey,aKey.iScanCode,aKey.iScanCode,iState,iRepCount);
215 iTest->LOG_MESSAGE(logMessageText);
221 case EStateWaitingForKeyCode:
222 SetState(EStateWaitingForFirstRepeat);
225 case EStateWaitingForFirstRepeat:
227 iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64());
228 SetState(EStateWaitingForNthRepeat);
230 case EStateWaitingForNthRepeat:
232 SetState(EStateWaitingForKeyUp);
235 TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()));
237 TLogMessageText logMessageText;
238 _LIT(KRepeatGap,"Repeat after %d");
239 logMessageText.AppendFormat(KRepeatGap,gap.Int());
240 iTest->LOG_MESSAGE(logMessageText);
247 iTotalGap=iTotalGap.Int()+gap.Int(); // Horrible way to do a +=
249 SetState(EStateWaitingForNthRepeat);
251 case EStateWaitingForKeyUp: // Do nothing here
254 //iTest->Test(EFalse);
255 iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeySpace);
256 CActiveScheduler::Stop();
262 void CRKWindow::SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
264 iInitialRepeatSet=aInitialTime;
266 iMinGap=TTimeIntervalMicroSeconds32(100000000); // Any very big number will do
267 iMaxGap=TTimeIntervalMicroSeconds32(0);
268 iTotalGap=TTimeIntervalMicroSeconds32(0);
269 SetState(EStateWaitingForKeyDown);
270 Client()->iWs.Flush();
275 CTKRepeat::CTKRepeat(CTestStep* aStep) : CTWsGraphicsBase(aStep)
279 CTKRepeat::~CTKRepeat()
282 Client()->iWs.SetKeyboardRepeatRate(iOldInitialTime, iOldTime);
285 void CTKRepeat::ConstructL()
287 TheClient->iWs.SetFocusScreen(iTest->iScreenNumber);
288 iWin=new(ELeave) CRKWindow(this);
289 TSize screenSize=Client()->iGroup->Size();
290 iWin->SetUpL(TPoint(5,5),TSize(Min(Max(screenSize.iWidth/2,250),screenSize.iWidth-10),screenSize.iHeight-10),Client()->iGroup,*Client()->iGc);
291 Client()->iGroup->WinTreeNode()->SetOrdinalPosition(0);
292 Client()->iGroup->SetCurrentWindow(iWin);
293 Client()->iWs.GetKeyboardRepeatRate(iOldInitialTime, iOldTime);
294 iTest->SimulateKeyDownUp(EStdKeyLeftCtrl);
295 iTest->SimulateKeyDownUp(EStdKeyRightCtrl);
296 TInt mods=Client()->iWs.GetModifierState();
297 TheClient->WaitForRedrawsToFinish(); //Let all pending events be processed before test begins
298 _LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
299 LOG_MESSAGE2(KLog,mods);
302 TInt CTKRepeat::CheckReportL()
304 if (iWin->CheckResults())
306 /*CTDialog *dialog=new(ELeave) CTDialog();
307 dialog->SetTitle(_L("Keyboard repeat innacuracies"));
308 dialog->SetLine1(iWin->Report());
309 dialog->SetNumButtons(3);
310 dialog->SetButtonText(0,_L("Okay"));
311 dialog->SetButtonText(1,_L("Retest"));
312 dialog->SetButtonText(2,_L("Fail"));
313 dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
314 switch(dialog->Display())
319 return(ETrue); // Redo test
321 Client()->iGroup->ClearCurrentWindow();
329 void CTKRepeat::TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
334 const TInt KOneSec=1000000;
335 const TInt KOneHundrethSec=KOneSec/100;
336 TLogMessageText logMessageText;
337 _LIT(KRepeatRate,"Repeat Rate Initial=%d.%02dsecs, Subsequent=%d.%02dsecs");
338 logMessageText.Format(KRepeatRate,aInitialTime.Int()/KOneSec,(aInitialTime.Int()%KOneSec)/KOneHundrethSec
339 ,aTime.Int()/KOneSec,(aTime.Int()%KOneSec)/KOneHundrethSec);
340 LOG_MESSAGE(logMessageText);
342 TheClient->iWs.SetKeyboardRepeatRate(aInitialTime, aTime);
343 iWin->SetKeyboardRepeatRate(aInitialTime, aTime);
344 CActiveScheduler::Start();
349 } while(CheckReportL());
352 void CTKRepeat::RunTestCaseL(TInt /*aCurTestCase*/)
354 _LIT(KTestName1,"Keyboard Repeat 1");
355 _LIT(KTestName2,"Keyboard Repeat 2");
356 _LIT(KTestName3,"Keyboard Repeat 3");
357 _LIT(KTestName4,"Keyboard Repeat 4");
358 ((CTKRepeatStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
359 switch(++iTest->iState)
363 @SYMTestCaseID GRAPHICS-WSERV-0311
367 @SYMTestCaseDesc Test that a key can be repeatedly struck after a second, then every half second
369 @SYMTestPriority High
371 @SYMTestStatus Implemented
373 @SYMTestActions Simulate a key being struck first after a second and then repeatedly every
374 half second and check the response time to the key strike is correct
376 @SYMTestExpectedResults Response time each time the key is struck is correct
380 ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0311"));
381 iTest->LogSubTest(KTestName1);
382 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(1000000), TTimeIntervalMicroSeconds32(500000));
386 @SYMTestCaseID GRAPHICS-WSERV-0312
390 @SYMTestCaseDesc Test that a key can be repeatedly struck after a 5th of a second, then every 10th of a second
392 @SYMTestPriority High
394 @SYMTestStatus Implemented
396 @SYMTestActions Simulate a key being struck first after a 5th of a second and then repeatedly every
397 10th of a second and check the response time to the key strike is correct
399 @SYMTestExpectedResults Response time each time the key is struck is correct
403 ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0312"));
404 iTest->LogSubTest(KTestName2);
405 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(200000), TTimeIntervalMicroSeconds32(100000));
409 @SYMTestCaseID GRAPHICS-WSERV-0313
413 @SYMTestCaseDesc Test that a key can be repeatedly struck immediately, then every 10th of a second
415 @SYMTestPriority High
417 @SYMTestStatus Implemented
419 @SYMTestActions Simulate a key being struck first immediately and then repeatedly every
420 10th of a second and check the response time to the key strike is correct
422 @SYMTestExpectedResults Response time each time the key is struck is correct
426 ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0313"));
427 iTest->LogSubTest(KTestName3);
428 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(0), TTimeIntervalMicroSeconds32(100000));
432 @SYMTestCaseID GRAPHICS-WSERV-0314
436 @SYMTestCaseDesc Test that a key can be repeatedly struck after a 10 of a second, then every 10th of a second
438 @SYMTestPriority High
440 @SYMTestStatus Implemented
442 @SYMTestActions Simulate a key being struck first after a 10th of a second and then repeatedly every
443 10th of a second and check the response time to the key strike is correct
445 @SYMTestExpectedResults Response time each time the key is struck is correct
450 ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0314"));
451 iTest->LogSubTest(KTestName4);
452 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(100000), TTimeIntervalMicroSeconds32(100000));
455 ((CTKRepeatStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
456 ((CTKRepeatStep*)iStep)->CloseTMSGraphicsStep();
460 ((CTKRepeatStep*)iStep)->RecordTestResultL();
463 __WS_CONSTRUCT_STEP__(KRepeat)