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 // Keyboard repeat test
21 #include "../tlib/testbase.h"
26 class TKRepeatTest : public CTestBase
33 void TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime);
38 TTimeIntervalMicroSeconds32 iOldInitialTime;
39 TTimeIntervalMicroSeconds32 iOldTime;
45 class CRKWindow : public CTWin
48 EStateWaitingForKeyDown,
49 EStateWaitingForKeyCode,
50 EStateWaitingForFirstRepeat,
51 EStateWaitingForNthRepeat,
52 EStateWaitingForKeyUp,
57 CRKWindow(TKRepeatTest *aTest);
58 void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
59 void SetState(TRKStates aState);
60 void SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime);
61 void WinKeyL(const TKeyEvent &,const TTime &);
62 void KeyUpL(const TKeyEvent &aKey,const TTime &aTime);
63 void KeyDownL(const TKeyEvent &aKey,const TTime &aTime);
74 TTimeIntervalMicroSeconds32 iInitialRepeatSet;
75 TTimeIntervalMicroSeconds32 iRepeatSet;
77 TTimeIntervalMicroSeconds32 iInitialGap;
78 TTimeIntervalMicroSeconds32 iTotalGap;
79 TTimeIntervalMicroSeconds32 iMinGap;
80 TTimeIntervalMicroSeconds32 iMaxGap;
84 GLDEF_C CTestBase *CreateKRepeatTest()
86 return(new(ELeave) TKRepeatTest());
90 // CRKWindow, class //
93 CRKWindow::CRKWindow(TKRepeatTest *aTest) : CTWin(), iTest(aTest)
97 void CRKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
99 ConstructExtLD(*parent,pos,size);
100 iWin.SetBackgroundColor(TRgb::Gray256(230));
105 void CRKWindow::Draw()
110 case EStateWaitingForKeyDown:
111 iGc->DrawText(_L("Press and hold the space bar"), TPoint(10,20));
113 case EStateWaitingForFirstRepeat:
114 case EStateWaitingForNthRepeat:
117 buf.Format(TRefByValue<const TDesC>(_L("Keep space bar down (%d repeats so far)")),iRepCount);
118 iGc->DrawText(buf, TPoint(10,20));
121 case EStateWaitingForKeyUp:
122 iGc->DrawText(_L("Release space bar"), TPoint(10,20));
128 void CRKWindow::SetState(TRKStates aState)
134 TBool CRKWindow::CheckResults()
137 // Checks repeat results, first convert everything to 10th's as that what is actually used
138 // for the timer in the window server.
140 // Return ETrue if the inacuracy in the average time is greater than 1/10th either way
141 // Allow initial 2/10ths either
142 // Allow min 2/10ths below
143 // Allow max 2/10ths above
145 if (iState!=EStateInactive)
147 TInt initial=iInitialGap.Int()/100000;
148 TInt initialX=iInitialRepeatSet.Int()/100000;
151 TInt average=(iTotalGap.Int()/100000)/(iRepCount-1);
152 TInt repeatX=iRepeatSet.Int()/100000;
155 TInt min=iMinGap.Int()/100000;
156 TInt max=iMaxGap.Int()/100000;
157 if (average>(repeatX+1) || average<(repeatX-1))
159 if (initial>(initialX+2) || initial<(initialX-2))
161 if (min>(repeatX+1) || min<(repeatX-2))
163 if (max>(repeatX+3) || max<repeatX)
168 TDesC& CRKWindow::Report()
170 if (iState!=EStateInactive)
172 iReport.Format(_L("Error, test not completed"));
176 TInt initial=iInitialGap.Int()/10000;
177 TInt initialX=iInitialRepeatSet.Int()/10000;
178 TInt average=(iTotalGap.Int()/10000/(iRepCount-1));
179 TInt repeatX=iRepeatSet.Int()/10000;
180 TInt min=iMinGap.Int()/10000;
181 TInt max=iMaxGap.Int()/10000;
182 iReport.Format(TRefByValue<const TDesC>(_L("Initial=%d [%d], Av=%d [%d], Min=%d, Max=%d")),initial,initialX,average,repeatX,min,max);
187 void CRKWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
191 case EStateWaitingForKeyDown:
192 SetState(EStateWaitingForKeyCode);
193 iDownCode=aKey.iScanCode;
199 void CRKWindow::KeyUpL(const TKeyEvent &aKey,const TTime &)
201 if (aKey.iScanCode==iDownCode)
205 case EStateWaitingForKeyUp:
206 SetState(EStateInactive);
209 SetState(EStateError);
212 CActiveScheduler::Stop();
216 void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime)
218 if (aKey.iCode==EKeyEscape)
220 CActiveScheduler::Stop();
227 case EStateWaitingForKeyCode:
228 SetState(EStateWaitingForFirstRepeat);
231 case EStateWaitingForFirstRepeat:
233 iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64());
234 SetState(EStateWaitingForNthRepeat);
236 case EStateWaitingForNthRepeat:
238 SetState(EStateWaitingForKeyUp);
241 TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()));
246 iTotalGap=iTotalGap.Int()+gap.Int(); // Horrible way to do a +=
248 SetState(EStateWaitingForNthRepeat);
250 case EStateWaitingForKeyUp: // Do nothing here
253 iTest->TestL(EFalse);
259 void CRKWindow::SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
261 iInitialRepeatSet=aInitialTime;
263 iMinGap=TTimeIntervalMicroSeconds32(100000000); // Any very big number will do
264 iMaxGap=TTimeIntervalMicroSeconds32(0);
265 iTotalGap=TTimeIntervalMicroSeconds32(0);
266 SetState(EStateWaitingForKeyDown);
267 Client()->iWs.Flush();
272 TKRepeatTest::TKRepeatTest() : CTestBase(_L("KRepeat"))
275 TKRepeatTest::~TKRepeatTest()
278 Client()->iWs.SetKeyboardRepeatRate(iOldInitialTime, iOldTime);
281 void TKRepeatTest::ConstructL()
283 iWin=new(ELeave) CRKWindow(this);
284 TSize screenSize=Client()->iGroup->Size();
285 iWin->SetUpL(TPoint(5,5),TSize(screenSize.iWidth/2,screenSize.iHeight-10),Client()->iGroup,*Client()->iGc);
286 Client()->iGroup->SetCurrentWindow(iWin);
287 Client()->iWs.GetKeyboardRepeatRate(iOldInitialTime, iOldTime);
290 TInt TKRepeatTest::CheckReportL()
292 if (iWin->CheckResults())
294 CTDialog *dialog=new(ELeave) CTDialog();
295 dialog->SetTitle(_L("Keyboard repeat innacuracies"));
296 dialog->SetLine1(iWin->Report());
297 dialog->SetNumButtons(2);
298 dialog->SetButtonText(0,_L("Okay"));
299 dialog->SetButtonText(1,_L("Retest"));
300 dialog->SetButtonText(2,_L("Fail"));
301 dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
302 switch(dialog->Display())
307 return(ETrue); // Redo test
316 void TKRepeatTest::TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
320 Client()->iWs.SetKeyboardRepeatRate(aInitialTime, aTime);
321 iWin->SetKeyboardRepeatRate(aInitialTime, aTime);
322 CActiveScheduler::Start();
325 } while(CheckReportL());
328 TestState TKRepeatTest::DoTestL()
333 LogSubTest(_L("Keyboard Repeat"),1);
334 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(1000000), TTimeIntervalMicroSeconds32(500000));
335 LogSubTest(_L("Keyboard Repeat"),2);
336 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(200000), TTimeIntervalMicroSeconds32(100000));
337 LogSubTest(_L("Keyboard Repeat"),3);
338 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(0), TTimeIntervalMicroSeconds32(100000));
339 LogSubTest(_L("Keyboard Repeat"),4);
340 TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(100000), TTimeIntervalMicroSeconds32(100000));